From: Robert Bradshaw Date: Fri, 27 Mar 2009 11:58:21 +0000 (-0700) Subject: Remove internal dependancy on included .pxd files X-Git-Tag: 0.12.alpha0~334^2~12 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=29676ce1559a392670eea09211e65adcfc3391e3;p=cython.git Remove internal dependancy on included .pxd files --- diff --git a/Cython/Compiler/CythonScope.py b/Cython/Compiler/CythonScope.py index 5a4a8c9d..54dc3866 100644 --- a/Cython/Compiler/CythonScope.py +++ b/Cython/Compiler/CythonScope.py @@ -15,7 +15,7 @@ class CythonScope(ModuleScope): pos=None, defining = 1, cname='') - + def lookup_type(self, name): # This function should go away when types are all first-level objects. type = parse_basic_type(name) @@ -23,4 +23,27 @@ class CythonScope(ModuleScope): return type def create_cython_scope(context): + create_utility_scope(context) return CythonScope(context) + + +def create_utility_scope(context): + global utility_scope + utility_scope = ModuleScope(u'utility', None, context) + + # These are used to optimize isinstance in FinalOptimizePhase + type_object = utility_scope.declare_typedef('PyTypeObject', + base_type = c_void_type, + pos = None, + cname = 'PyTypeObject') + type_object.is_void = True + + utility_scope.declare_cfunction( + 'PyObject_TypeCheck', + CFuncType(c_bint_type, [CFuncTypeArg("o", py_object_type, None), + CFuncTypeArg("t", c_ptr_type(type_object), None)]), + pos = None, + defining = 1, + cname = 'PyObject_TypeCheck') + + return utility_scope diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 7aec738a..5e94aa2b 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -640,11 +640,9 @@ class FinalOptimizePhase(Visitor.CythonTransform): if node.function.name == 'isinstance': type_arg = node.args[1] if type_arg.type.is_builtin_type and type_arg.type.name == 'type': - object_module = self.context.find_module('python_object') - node.function.entry = object_module.lookup('PyObject_TypeCheck') - if node.function.entry is None: - return node # only happens when there was an error earlier + from CythonScope import utility_scope + node.function.entry = utility_scope.lookup('PyObject_TypeCheck') node.function.type = node.function.entry.type - PyTypeObjectPtr = PyrexTypes.CPtrType(object_module.lookup('PyTypeObject').type) + PyTypeObjectPtr = PyrexTypes.CPtrType(utility_scope.lookup('PyTypeObject').type) node.args[1] = ExprNodes.CastNode(node.args[1], PyTypeObjectPtr) return node