Skip to content

Commit c280136

Browse files
committed
fix behaviour of PyFloat_AsDouble
1 parent c7310a1 commit c280136

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

graalpython/com.oracle.graal.python.cext/src/floatobject.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@
4242
PyTypeObject PyFloat_Type = PY_TRUFFLE_TYPE("float", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, sizeof(PyFloatObject));
4343

4444
double PyFloat_AsDouble(PyObject *op) {
45-
if (op == NULL || !PyFloat_Check(op)) {
45+
if (op == NULL) {
4646
PyErr_BadArgument();
4747
return -1.0;
4848
}
49-
return ((PyFloatObject*)op)->ob_fval;
49+
50+
if (PyFloat_Check(op)) {
51+
return PyFloat_AS_DOUBLE(op);
52+
}
53+
54+
op = UPCALL_CEXT_O("PyFloat_FromObject", native_to_java(op));
55+
if (op == NULL) {
56+
return -1.0;
57+
} else {
58+
return PyFloat_AS_DOUBLE(op);
59+
}
5060
}
5161

5262
PyObject* PyFloat_FromDouble(double fval) {

graalpython/lib-graalpython/python_cext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ def PyFloat_FromDouble(n):
348348
return float(n)
349349

350350

351+
@may_raise
352+
def PyFloat_FromObject(n):
353+
return float(n)
354+
355+
351356
##################### NUMBER
352357

353358
def _safe_check(v, type_check):

0 commit comments

Comments
 (0)