summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-10-27 01:24:34 (GMT)
committerGitHub <noreply@github.com>2020-10-27 01:24:34 (GMT)
commitc9bc290dd6e3994a4ead2a224178bcba86f0c0e4 (patch)
treef3a4e137da850af0438119da460877c3a4fd8532 /Objects/complexobject.c
parent303aac8c56609290e122eecc14c038e9b1e4174a (diff)
downloadcpython-c9bc290dd6e3994a4ead2a224178bcba86f0c0e4.zip
cpython-c9bc290dd6e3994a4ead2a224178bcba86f0c0e4.tar.gz
cpython-c9bc290dd6e3994a4ead2a224178bcba86f0c0e4.tar.bz2
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/complexobject.c')
-rw-r--r--Objects/complexobject.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 5ab839a..a481d9a 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -6,6 +6,7 @@
/* Submitted by Jim Hugunin */
#include "Python.h"
+#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_object.h" // _PyObject_Init()
#include "structmember.h" // PyMemberDef
@@ -870,7 +871,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
/*[clinic input]
@classmethod
complex.__new__ as complex_new
- real as r: object(c_default="_PyLong_Zero") = 0
+ real as r: object(c_default="NULL") = 0
imag as i: object(c_default="NULL") = 0
Create a complex number from a real part and an optional imaginary part.
@@ -880,7 +881,7 @@ This is equivalent to (real + imag*1j) where imag defaults to 0.
static PyObject *
complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
-/*[clinic end generated code: output=b6c7dd577b537dc1 input=6f6b0bedba29bcb5]*/
+/*[clinic end generated code: output=b6c7dd577b537dc1 input=f4c667f2596d4fd1]*/
{
PyObject *tmp;
PyNumberMethods *nbr, *nbi = NULL;
@@ -889,6 +890,10 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
int cr_is_complex = 0;
int ci_is_complex = 0;
+ if (r == NULL) {
+ r = _PyLong_GetZero();
+ }
+
/* Special-case for a single argument when type(arg) is complex. */
if (PyComplex_CheckExact(r) && i == NULL &&
type == &PyComplex_Type) {