Commit 9fd9d301 authored by Stefan Behnel's avatar Stefan Behnel

replace dead left-over code by the actually intended fast bint->True/False...

replace dead left-over code by the actually intended fast bint->True/False formatting implementation
parent 2661e438
......@@ -1765,7 +1765,22 @@ class CBIntType(CIntType):
exception_check = 1 # for C++ bool
def can_coerce_to_pystring(self, env, format_spec=None):
return False
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
code.globalstate.use_utility_code(to_pyunicode_utility)
return utility_code_name
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
......
......@@ -654,16 +654,10 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, char format_ch
}
/////////////// NewOwnedRef.proto ///////////////
/////////////// CBIntToPyUnicode.proto ///////////////
static CYTHON_INLINE PyObject* __Pyx_NewOwnedRef(PyObject* value);
/////////////// NewOwnedRef ///////////////
static CYTHON_INLINE PyObject* __Pyx_NewOwnedRef(PyObject* value) {
Py_INCREF(value);
return value;
}
#define {{TO_PY_FUNCTION}}(value, format_char) \
((value) ? (Py_INCREF({{TRUE_CONST}}), {{TRUE_CONST}}) : (Py_INCREF({{FALSE_CONST}}), {{FALSE_CONST}}))
/////////////// PyIntFromDouble.proto ///////////////
......
......@@ -66,6 +66,41 @@ def format_c_numbers(signed char c, short s, int n, long l, float f, double d):
return s1, s2, s3, s4
def format_bool(bint x):
"""
>>> a, b, c, d = format_bool(1)
>>> print(a) # 1
True
>>> print(b) # 1
True
>>> print(c) # 1
False
>>> print(d) # 1
False
>>> a, b, c, d = format_bool(2)
>>> print(a) # 2
True
>>> print(b) # 2
True
>>> print(c) # 2
False
>>> print(d) # 2
False
>>> a, b, c, d = format_bool(0)
>>> print(a) # 3
False
>>> print(b) # 3
True
>>> print(c) # 3
False
>>> print(d) # 3
False
"""
return f'{x}', f'{True}', f'{x == 2}', f'{2 > 3}'
def format_c_values(Py_UCS4 uchar, Py_UNICODE pyunicode):
"""
>>> s, s1, s2 = format_c_values(b'A'.decode('ascii'), b'X'.decode('ascii'))
......
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