Commit 337bf7f3 authored by da-woods's avatar da-woods

Always use "new" string->float conversions

This ensures that 1_2_3 type numbers are handled correctly
whether or not the argument type is known.

Fixes https://github.com/cython/cython/issues/3958 (and thus the
currently broken builtin_float test)
parent e6f92c17
......@@ -2195,6 +2195,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
args=[func_arg],
py_name='float',
is_temp=node.is_temp,
utility_code = UtilityCode.load_cached("pynumber_float", "TypeConversion.c"),
result_is_used=node.result_is_used,
).coerce_to(node.type, self.current_env())
return node
......
......@@ -713,7 +713,6 @@ static double __Pyx_SlowPyString_AsDouble(PyObject *obj) {
static const char* __Pyx__PyBytes_AsDouble_Copy(const char* start, char* buffer, Py_ssize_t length) {
Py_ssize_t i;
char *digit = buffer;
for (i=0; i < length; i++) {
if (start[i] != '_') *buffer++ = start[i];
}
......
......@@ -126,7 +126,8 @@ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
// __Pyx_PyNumber_Float is now in it's own section since it has dependencies (needed to make
// string conversion work the same in all circumstances)
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
......@@ -463,6 +464,27 @@ static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
return PyInt_FromSize_t(ival);
}
/////////////// pynumber_float.proto ///////////////
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Float(PyObject* obj); /* proto */
/////////////// pynumber_float ///////////////
//@requires: Optimize.c::pybytes_as_double
//@requires: Optimize.c::pyunicode_as_double
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Float(PyObject* obj) {
if (PyFloat_CheckExact(obj)) {
return __Pyx_NewRef(obj);
} else if (PyUnicode_CheckExact(obj)) {
return PyFloat_FromDouble(__Pyx_PyUnicode_AsDouble(obj));
} else if (PyBytes_CheckExact(obj)) {
return PyFloat_FromDouble(__Pyx_PyBytes_AsDouble(obj));
} else if (PyByteArray_CheckExact(obj)) {
return PyFloat_FromDouble(__Pyx_PyByteArray_AsDouble(obj));
} else {
return PyNumber_Float(obj);
}
}
/////////////// GCCDiagnostics.proto ///////////////
......
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