Merge lp:~drlh/pybindgen/py3kx into lp:~dan-eicher/pybindgen/py3k

Proposed by Doug Heisterkamp
Status: Merged
Merged at revision: 790
Proposed branch: lp:~drlh/pybindgen/py3kx
Merge into: lp:~dan-eicher/pybindgen/py3k
Diff against target: 102 lines (+41/-15)
3 files modified
pybindgen/cppclass.py (+15/-3)
pybindgen/typehandlers/base.py (+11/-9)
pybindgen/wrapper_registry.py (+15/-3)
To merge this branch: bzr merge lp:~drlh/pybindgen/py3kx
Reviewer Review Type Date Requested Status
dna Pending
Review via email: mp+165718@code.launchpad.net

Description of the change

Switches between CObject and Capsule calls based on python version. Approached based on numpy's npy_3kcompat.h (which would be nice to use, but overkill in this case) and cython's generated code.

Also reverted to raising a TypeLookupError in typehandlers/base.py to match behavior of truck.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pybindgen/cppclass.py'
2--- pybindgen/cppclass.py 2012-12-01 23:36:44 +0000
3+++ pybindgen/cppclass.py 2013-05-24 23:28:26 +0000
4@@ -1904,7 +1904,13 @@
5 " _%s = new pybindgen::TypeMap;\n"
6 " PyErr_Clear();\n"
7 "} else {\n"
8- " _%s = reinterpret_cast<pybindgen::TypeMap*> (PyCObject_AsVoidPtr (_cobj));\n"
9+ " _%s = reinterpret_cast<pybindgen::TypeMap*> (\n"
10+ "#if ((PY_VERSION_HEX < 0x02070000) || ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000)))\n"
11+ " PyCObject_AsVoidPtr (_cobj)\n"
12+ "#else\n"
13+ " PyCapsule_GetPointer(c_obj, NULL)\n"
14+ "#endif\n"
15+ ");\n"
16 " Py_DECREF(_cobj);\n"
17 "}"
18 % (self.typeid_map_name, self.typeid_map_name))
19@@ -1927,8 +1933,14 @@
20
21 if self.typeid_map_name is not None:
22 code_sink.writeln("\npybindgen::TypeMap %s;\n" % self.typeid_map_name)
23- module.after_init.write_code("PyModule_AddObject(m, (char *) \"_%s\", PyCObject_FromVoidPtr(&%s, NULL));"
24- % (self.typeid_map_name, self.typeid_map_name))
25+ module.after_init.write_code(
26+ "PyModule_AddObject(m, (char *) \"_%s\", \n"
27+ "#if ((PY_VERSION_HEX < 0x02070000) || ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000)))\n"
28+ " PyCObject_FromVoidPtr(&%s, NULL)\n"
29+ "#else\n"
30+ " PyCapsule_New(&%s, NULL, NULL)\n"
31+ "#endif\n"
32+ ");" % (self.typeid_map_name, self.typeid_map_name, self.typeid_map_name))
33
34 if self.automatic_type_narrowing:
35 self._register_typeid(module)
36
37=== modified file 'pybindgen/typehandlers/base.py'
38--- pybindgen/typehandlers/base.py 2012-10-01 02:37:22 +0000
39+++ pybindgen/typehandlers/base.py 2013-05-24 23:28:26 +0000
40@@ -1402,15 +1402,17 @@
41 # existing.sort()
42 # raise TypeLookupError((tried_names, existing, self._type_aliases))
43 #else:
44- rtypes = {}
45- for t in tried_names:
46- if self._type_aliases.has_key(t):
47- rtypes[t] = self._type_aliases[t]
48- elif self._type_aliases_rev.has_key(t):
49- rtypes[t] = "rev:%s"%self._type_aliases_rev[t]
50- else:
51- rtypes[t] = "???"
52- #raise TypeLookupError(rtypes)
53+ raise TypeLookupError(tried_names)
54+ # removed to restore main branch behavior
55+ #rtypes = {}
56+ #for t in tried_names:
57+ # if self._type_aliases.has_key(t):
58+ # rtypes[t] = self._type_aliases[t]
59+ # elif self._type_aliases_rev.has_key(t):
60+ # rtypes[t] = "rev:%s"%self._type_aliases_rev[t]
61+ # else:
62+ # rtypes[t] = "???"
63+ ##raise TypeLookupError(rtypes)
64 else:
65 logger.debug("try to lookup type handler for %r => success (%r)", name, rv)
66 return rv
67
68=== modified file 'pybindgen/wrapper_registry.py'
69--- pybindgen/wrapper_registry.py 2012-02-20 12:01:39 +0000
70+++ pybindgen/wrapper_registry.py 2013-05-24 23:28:26 +0000
71@@ -84,8 +84,14 @@
72 def generate(self, code_sink, module):
73 code_sink.writeln("std::map<void*, PyObject*> %s;" % self.map_name)
74 # register the map in the module namespace
75- module.after_init.write_code("PyModule_AddObject(m, (char *) \"_%s\", PyCObject_FromVoidPtr(&%s, NULL));"
76- % (self.map_name, self.map_name))
77+ module.after_init.write_code("PyModule_AddObject(m, (char *) \"_%s\", \n"
78+ "#if ((PY_VERSION_HEX < 0x02070000) || ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000)))\n"
79+ " PyCObject_FromVoidPtr(&%s, NULL)\n"
80+ "#else\n"
81+ " PyCapsule_New(&%s, NULL, NULL)\n"
82+ "#endif\n"
83+ ");"
84+ % (self.map_name, self.map_name, self.map_name))
85
86 def generate_import(self, code_sink, code_block, module_pyobj_var):
87 code_sink.writeln("std::map<void*, PyObject*> *_%s;" % self.map_name)
88@@ -95,7 +101,13 @@
89 " _%(MAP)s = NULL;\n"
90 " PyErr_Clear();\n"
91 "} else {\n"
92- " _%(MAP)s = reinterpret_cast< std::map<void*, PyObject*> *> (PyCObject_AsVoidPtr (_cobj));\n"
93+ " _%(MAP)s = reinterpret_cast< std::map<void*, PyObject*> *> (\n"
94+ "#if ((PY_VERSION_HEX < 0x02070000) || ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000)))\n"
95+ " PyCObject_AsVoidPtr (_cobj)\n"
96+ "#else\n"
97+ " PyCapsule_GetPointer(c_obj, NULL)\n"
98+ "#endif\n"
99+ ");\n"
100 " Py_DECREF(_cobj);\n"
101 "}"
102 % dict(MAP=self.map_name))

Subscribers

People subscribed via source and target branches

to all changes: