summaryrefslogtreecommitdiff
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-10-27 02:24:34 +0100
committerGitHub <noreply@github.com>2020-10-27 02:24:34 +0100
commitc9bc290dd6e3994a4ead2a224178bcba86f0c0e4 (patch)
treef3a4e137da850af0438119da460877c3a4fd8532 /Objects/floatobject.c
parent303aac8c56609290e122eecc14c038e9b1e4174a (diff)
downloadcpython-git-c9bc290dd6e3994a4ead2a224178bcba86f0c0e4.tar.gz
bpo-42161: Use _PyLong_GetZero() and _PyLong_GetOne() (GH-22995)
Use _PyLong_GetZero() and _PyLong_GetOne() in Objects/ and Python/ directories.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 828bde18df..1550b2eedc 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -6,6 +6,7 @@
#include "Python.h"
#include "pycore_dtoa.h" // _Py_dg_dtoa()
#include "pycore_interp.h" // _PyInterpreterState.float_state
+#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_object.h" // _PyObject_Init()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
@@ -504,7 +505,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
Py_DECREF(vv);
vv = temp;
- temp = PyNumber_Or(vv, _PyLong_One);
+ temp = PyNumber_Or(vv, _PyLong_GetOne());
if (temp == NULL)
goto Error;
Py_DECREF(vv);
@@ -1605,7 +1606,7 @@ float_subtype_new(PyTypeObject *type, PyObject *x);
/*[clinic input]
@classmethod
float.__new__ as float_new
- x: object(c_default="_PyLong_Zero") = 0
+ x: object(c_default="NULL") = 0
/
Convert a string or number to a floating point number, if possible.
@@ -1613,10 +1614,18 @@ Convert a string or number to a floating point number, if possible.
static PyObject *
float_new_impl(PyTypeObject *type, PyObject *x)
-/*[clinic end generated code: output=ccf1e8dc460ba6ba input=540ee77c204ff87a]*/
+/*[clinic end generated code: output=ccf1e8dc460ba6ba input=f43661b7de03e9d8]*/
{
- if (type != &PyFloat_Type)
+ if (type != &PyFloat_Type) {
+ if (x == NULL) {
+ x = _PyLong_GetZero();
+ }
return float_subtype_new(type, x); /* Wimp out */
+ }
+
+ if (x == NULL) {
+ return PyFloat_FromDouble(0.0);
+ }
/* If it's a string, but not a string subclass, use
PyFloat_FromString. */
if (PyUnicode_CheckExact(x))
@@ -1662,7 +1671,7 @@ float_vectorcall(PyObject *type, PyObject * const*args,
return NULL;
}
- PyObject *x = nargs >= 1 ? args[0] : _PyLong_Zero;
+ PyObject *x = nargs >= 1 ? args[0] : NULL;
return float_new_impl((PyTypeObject *)type, x);
}