diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 30d48e791aed4e24ba1d2e6edba97c5365812a49..49b35ead4258785dd41ed1135299f37c9fca32d0 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1768,17 +1768,14 @@ class CBIntType(CIntType): return not format_spec def to_pystring_function(self, code): - if self.to_pyunicode_utility is None: - utility_code_name = "__Pyx_PyUnicode_FromBInt_" + self.specialization_name() - to_pyunicode_utility = TempitaUtilityCode.load_cached( - "CBIntToPyUnicode", "TypeConversion.c", context={ - "TRUE_CONST": code.globalstate.get_py_string_const(StringEncoding.EncodedString("True")).cname, - "FALSE_CONST": code.globalstate.get_py_string_const(StringEncoding.EncodedString("False")).cname, - "TO_PY_FUNCTION": utility_code_name, - }) - self.to_pyunicode_utility = (utility_code_name, to_pyunicode_utility) - else: - utility_code_name, to_pyunicode_utility = self.to_pyunicode_utility + # NOTE: no caching here as the string constant cnames depend on the current module + utility_code_name = "__Pyx_PyUnicode_FromBInt_" + self.specialization_name() + to_pyunicode_utility = TempitaUtilityCode.load_cached( + "CBIntToPyUnicode", "TypeConversion.c", context={ + "TRUE_CONST": code.globalstate.get_py_string_const(StringEncoding.EncodedString("True")).cname, + "FALSE_CONST": code.globalstate.get_py_string_const(StringEncoding.EncodedString("False")).cname, + "TO_PY_FUNCTION": utility_code_name, + }) code.globalstate.use_utility_code(to_pyunicode_utility) return utility_code_name diff --git a/Cython/Utility/TypeConversion.c b/Cython/Utility/TypeConversion.c index 33129f0ba141f937016423e7d14cc9a0092bc822..97e8c0bdcff5939517169d4689f9e94799837335 100644 --- a/Cython/Utility/TypeConversion.c +++ b/Cython/Utility/TypeConversion.c @@ -657,7 +657,7 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, char format_ch /////////////// CBIntToPyUnicode.proto /////////////// #define {{TO_PY_FUNCTION}}(value, format_char) \ - ((value) ? (Py_INCREF({{TRUE_CONST}}), {{TRUE_CONST}}) : (Py_INCREF({{FALSE_CONST}}), {{FALSE_CONST}})) + ((value) ? __Pyx_NewRef({{TRUE_CONST}}) : __Pyx_NewRef({{FALSE_CONST}})) /////////////// PyIntFromDouble.proto ///////////////