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:
type.typeptr_cname, # Some builtin types have a tp_basicsize which differs from sizeof(...):
module_name, sizeof_objstruct = Code.basicsize_builtins_map[objstruct]
replacement,
objstruct, code.put('%s = __Pyx_ImportType(%s,' % (
error_code)) type.typeptr_cname,
code.putln("#else") module_name))
code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s), %i); %s' % (
type.typeptr_cname, if condition and replacement:
module_name, code.putln("") # start in new line
type.name, code.putln("#if %s" % condition)
objstruct, code.putln('"%s",' % replacement)
not type.is_external or type.is_subclassed, code.putln("#else")
error_code)) code.putln('"%s",' % type.name)
if condition: code.putln("#endif")
else:
code.put(' "%s", ' % type.name)
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") code.putln("#endif")
else:
code.put('sizeof(%s), ' % objstruct)
code.putln('%i); %s' % (
not type.is_external or type.is_subclassed,
error_code))
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