From f6fb2ff56e1b13c002b9b73a613c1e9fd6c2d78d Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sat, 24 Aug 2013 20:52:37 -0700 Subject: [PATCH] Conversion for extern int types. --- Cython/Compiler/PyrexTypes.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index a30c81a..431b58d 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -368,11 +368,12 @@ class CTypedefType(BaseType): if not self.to_py_utility_code: base_type = self.typedef_base_type if type(base_type) is CIntType: - # Various subclasses have special methods - # that should be inherited. - self.to_py_utility_code, self.to_py_function = \ - self._create_utility_code(c_typedef_int_to_py_function, - '__Pyx_PyInt_to_py_%s') + self.from_py_function = "__Pyx_PyInt_from_py_" + self.specialization_name() + env.use_utility_code(TempitaUtilityCode.load( + "CIntFromPy", "TypeConversion.c", + context={"TYPE": self.declaration_code(''), + "FROM_PY_FUNCTION": self.from_py_function})) + return True elif base_type.is_float: pass # XXX implement! elif base_type.is_complex: @@ -389,11 +390,12 @@ class CTypedefType(BaseType): if not self.from_py_utility_code: base_type = self.typedef_base_type if type(base_type) is CIntType: - # Various subclasses have special methods - # that should be inherited. - self.from_py_utility_code, self.from_py_function = \ - self._create_utility_code(c_typedef_int_from_py_function, - '__Pyx_PyInt_from_py_%s') + self.to_py_function = "__Pyx_PyInt_to_py_" + self.specialization_name() + env.use_utility_code(TempitaUtilityCode.load( + "CIntToPy", "TypeConversion.c", + context={"TYPE": self.declaration_code(''), + "TO_PY_FUNCTION": self.to_py_function})) + return True elif base_type.is_float: pass # XXX implement! elif base_type.is_complex: @@ -1565,18 +1567,20 @@ class CIntType(CNumericType): # Inject specializatioin used elsewhere. self.get_from_py_type_conversion() - def create_from_py_utility_code(self, env): - self.from_py_function = "__Pyx_PyInt_from_py_" + self.specialization_name() - env.use_utility_code(TempitaUtilityCode.load( - "CIntFromPy", "TypeConversion.c", - context={"TYPE": self.declaration_code(''), "FROM_PY_FUNCTION": self.from_py_function})) - return True - def create_to_py_utility_code(self, env): self.to_py_function = "__Pyx_PyInt_to_py_" + self.specialization_name() env.use_utility_code(TempitaUtilityCode.load( "CIntToPy", "TypeConversion.c", - context={"TYPE": self.declaration_code(''), "TO_PY_FUNCTION": self.to_py_function})) + context={"TYPE": self.declaration_code(''), + "TO_PY_FUNCTION": self.to_py_function})) + return True + + def create_from_py_utility_code(self, env): + self.from_py_function = "__Pyx_PyInt_from_py_" + self.specialization_name() + env.use_utility_code(TempitaUtilityCode.load( + "CIntFromPy", "TypeConversion.c", + context={"TYPE": self.declaration_code(''), + "FROM_PY_FUNCTION": self.from_py_function})) return True def get_to_py_type_conversion(self): -- 2.7.4