Commit 558f4ef1 authored by Stefan Behnel's avatar Stefan Behnel

fix 'type' adaptation code to work with PyPy

parent ea539d24
...@@ -2187,10 +2187,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2187,10 +2187,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
objstruct = type.objstruct_cname objstruct = type.objstruct_cname
else: else:
objstruct = "struct %s" % type.objstruct_cname objstruct = "struct %s" % type.objstruct_cname
# Some builtin types have a tp_basicsize which differs from sizeof(...): sizeof_objstruct = objstruct
objstruct = Code.basicsize_builtins_map.get(objstruct, objstruct)
module_name = type.module_name module_name = type.module_name
condition = None condition = replacement = None
if module_name not in ('__builtin__', 'builtins'): if module_name not in ('__builtin__', 'builtins'):
module_name = '"%s"' % module_name module_name = '"%s"' % module_name
else: else:
...@@ -2198,22 +2197,38 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2198,22 +2197,38 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if type.name in Code.non_portable_builtins_map: if type.name in Code.non_portable_builtins_map:
condition, replacement = Code.non_portable_builtins_map[type.name] condition, replacement = Code.non_portable_builtins_map[type.name]
code.putln("#if %s" % condition) code.putln("#if %s" % condition)
code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s), 1); %s' % ( if objstruct in Code.basicsize_builtins_map:
# Some builtin types have a tp_basicsize which differs from sizeof(...):
sizeof_objstruct = Code.basicsize_builtins_map[objstruct]
code.put('%s = __Pyx_ImportType(%s,' % (
type.typeptr_cname, type.typeptr_cname,
module_name, module_name))
replacement,
objstruct, if condition and replacement:
error_code)) code.putln("") # start in new line
code.putln("#if %s" % condition)
code.putln('"%s",' % replacement)
code.putln("#else") code.putln("#else")
code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s), %i); %s' % ( code.putln('"%s",' % type.name)
type.typeptr_cname, code.putln("#endif")
module_name, else:
type.name, code.put(' "%s", ' % type.name)
objstruct,
if sizeof_objstruct != objstruct:
if not condition:
code.putln("") # start in new line
code.putln("#if CYTHON_COMPILING_IN_PYPY")
code.putln('sizeof(%s),' % objstruct)
code.putln("#else")
code.putln('sizeof(%s),' % sizeof_objstruct)
code.putln("#endif")
else:
code.put('sizeof(%s), ' % objstruct)
code.putln('%i); %s' % (
not type.is_external or type.is_subclassed, not type.is_external or type.is_subclassed,
error_code)) error_code))
if condition:
code.putln("#endif")
def generate_type_ready_code(self, env, entry, code): def generate_type_ready_code(self, env, entry, code):
# Generate a call to PyType_Ready for an extension # Generate a call to PyType_Ready for an extension
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment