Skip to content

Commit

Permalink
Make sure that _PyFloat_FromDouble_ConsumeInputs is safe in the no-gi…
Browse files Browse the repository at this point in the history
…l build
  • Loading branch information
markshannon committed Oct 14, 2024
1 parent 07df2d0 commit 94273bf
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,9 @@ PyFloat_FromDouble(double fval)

PyObject *_PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value)
{
PyObject *left_o = PyStackRef_NotDeferred_AsPyObject(left);
PyObject *right_o = PyStackRef_NotDeferred_AsPyObject(right);
assert(PyLong_Check(left_o));
assert(PyLong_Check(right_o));
if (Py_REFCNT(left_o) == 1) {
((PyFloatObject *)left_o)->ob_fval = value;
_Py_DECREF_SPECIALIZED(right_o, _PyFloat_ExactDealloc);
return left_o;
}
else if (Py_REFCNT(right_o) == 1) {
((PyFloatObject *)right_o)->ob_fval = value;
_Py_DECREF_NO_DEALLOC(left_o);
return right_o;
}
else {
PyObject *result = PyFloat_FromDouble(value);
_Py_DECREF_NO_DEALLOC(left_o);
_Py_DECREF_NO_DEALLOC(right_o);
return result;
}
PyStackRef_CLOSE(left);
PyStackRef_CLOSE(right);
return PyFloat_FromDouble(value);
}

#else // Py_GIL_DISABLED
Expand Down

0 comments on commit 94273bf

Please sign in to comment.