mirror of https://github.com/python/cpython
bpo-42161: Use _PyLong_GetZero() and _PyLong_GetOne() (GH-22995)
Use _PyLong_GetZero() and _PyLong_GetOne() in Objects/ and Python/ directories.
This commit is contained in:
parent
303aac8c56
commit
c9bc290dd6
|
@ -90,7 +90,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||||
PyObject * const *fastargs;
|
PyObject * const *fastargs;
|
||||||
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
||||||
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
|
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
|
||||||
PyObject *r = _PyLong_Zero;
|
PyObject *r = NULL;
|
||||||
PyObject *i = NULL;
|
PyObject *i = NULL;
|
||||||
|
|
||||||
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
|
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
|
||||||
|
@ -113,4 +113,4 @@ skip_optional_pos:
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=193a37aebaaa5f89 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=056cac3226d94967 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -206,7 +206,7 @@ static PyObject *
|
||||||
float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
PyObject *x = _PyLong_Zero;
|
PyObject *x = NULL;
|
||||||
|
|
||||||
if ((type == &PyFloat_Type) &&
|
if ((type == &PyFloat_Type) &&
|
||||||
!_PyArg_NoKeywords("float", kwargs)) {
|
!_PyArg_NoKeywords("float", kwargs)) {
|
||||||
|
@ -387,4 +387,4 @@ float___format__(PyObject *self, PyObject *arg)
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=25fbbe253f44e2df input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=bb079c3e130e4ce6 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
/* Submitted by Jim Hugunin */
|
/* Submitted by Jim Hugunin */
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
#include "pycore_long.h" // _PyLong_GetZero()
|
||||||
#include "pycore_object.h" // _PyObject_Init()
|
#include "pycore_object.h" // _PyObject_Init()
|
||||||
#include "structmember.h" // PyMemberDef
|
#include "structmember.h" // PyMemberDef
|
||||||
|
|
||||||
|
@ -870,7 +871,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
@classmethod
|
@classmethod
|
||||||
complex.__new__ as complex_new
|
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
|
imag as i: object(c_default="NULL") = 0
|
||||||
|
|
||||||
Create a complex number from a real part and an optional imaginary part.
|
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 *
|
static PyObject *
|
||||||
complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
|
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;
|
PyObject *tmp;
|
||||||
PyNumberMethods *nbr, *nbi = NULL;
|
PyNumberMethods *nbr, *nbi = NULL;
|
||||||
|
@ -889,6 +890,10 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
|
||||||
int cr_is_complex = 0;
|
int cr_is_complex = 0;
|
||||||
int ci_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. */
|
/* Special-case for a single argument when type(arg) is complex. */
|
||||||
if (PyComplex_CheckExact(r) && i == NULL &&
|
if (PyComplex_CheckExact(r) && i == NULL &&
|
||||||
type == &PyComplex_Type) {
|
type == &PyComplex_Type) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* enumerate object */
|
/* enumerate object */
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
#include "pycore_long.h" // _PyLong_GetOne()
|
||||||
|
|
||||||
#include "clinic/enumobject.c.h"
|
#include "clinic/enumobject.c.h"
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ enum_next_long(enumobject *en, PyObject* next_item)
|
||||||
}
|
}
|
||||||
next_index = en->en_longindex;
|
next_index = en->en_longindex;
|
||||||
assert(next_index != NULL);
|
assert(next_index != NULL);
|
||||||
stepped_up = PyNumber_Add(next_index, _PyLong_One);
|
stepped_up = PyNumber_Add(next_index, _PyLong_GetOne());
|
||||||
if (stepped_up == NULL) {
|
if (stepped_up == NULL) {
|
||||||
Py_DECREF(next_item);
|
Py_DECREF(next_item);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_dtoa.h" // _Py_dg_dtoa()
|
#include "pycore_dtoa.h" // _Py_dg_dtoa()
|
||||||
#include "pycore_interp.h" // _PyInterpreterState.float_state
|
#include "pycore_interp.h" // _PyInterpreterState.float_state
|
||||||
|
#include "pycore_long.h" // _PyLong_GetOne()
|
||||||
#include "pycore_object.h" // _PyObject_Init()
|
#include "pycore_object.h" // _PyObject_Init()
|
||||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||||
|
|
||||||
|
@ -504,7 +505,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
|
||||||
Py_DECREF(vv);
|
Py_DECREF(vv);
|
||||||
vv = temp;
|
vv = temp;
|
||||||
|
|
||||||
temp = PyNumber_Or(vv, _PyLong_One);
|
temp = PyNumber_Or(vv, _PyLong_GetOne());
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
goto Error;
|
goto Error;
|
||||||
Py_DECREF(vv);
|
Py_DECREF(vv);
|
||||||
|
@ -1605,7 +1606,7 @@ float_subtype_new(PyTypeObject *type, PyObject *x);
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
@classmethod
|
@classmethod
|
||||||
float.__new__ as float_new
|
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.
|
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 *
|
static PyObject *
|
||||||
float_new_impl(PyTypeObject *type, PyObject *x)
|
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 */
|
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
|
/* If it's a string, but not a string subclass, use
|
||||||
PyFloat_FromString. */
|
PyFloat_FromString. */
|
||||||
if (PyUnicode_CheckExact(x))
|
if (PyUnicode_CheckExact(x))
|
||||||
|
@ -1662,7 +1671,7 @@ float_vectorcall(PyObject *type, PyObject * const*args,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *x = nargs >= 1 ? args[0] : _PyLong_Zero;
|
PyObject *x = nargs >= 1 ? args[0] : NULL;
|
||||||
return float_new_impl((PyTypeObject *)type, x);
|
return float_new_impl((PyTypeObject *)type, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_abstract.h" // _PyIndex_Check()
|
#include "pycore_abstract.h" // _PyIndex_Check()
|
||||||
|
#include "pycore_long.h" // _PyLong_GetZero()
|
||||||
#include "pycore_tuple.h" // _PyTuple_ITEMS()
|
#include "pycore_tuple.h" // _PyTuple_ITEMS()
|
||||||
#include "structmember.h" // PyMemberDef
|
#include "structmember.h" // PyMemberDef
|
||||||
|
|
||||||
|
@ -105,10 +106,10 @@ range_from_array(PyTypeObject *type, PyObject *const *args, Py_ssize_t num_args)
|
||||||
if (!stop) {
|
if (!stop) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(_PyLong_Zero);
|
start = _PyLong_GetZero();
|
||||||
start = _PyLong_Zero;
|
Py_INCREF(start);
|
||||||
Py_INCREF(_PyLong_One);
|
step = _PyLong_GetOne();
|
||||||
step = _PyLong_One;
|
Py_INCREF(step);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -190,7 +191,10 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
|
||||||
PyObject *tmp1 = NULL, *tmp2 = NULL, *result;
|
PyObject *tmp1 = NULL, *tmp2 = NULL, *result;
|
||||||
/* holds sub-expression evaluations */
|
/* holds sub-expression evaluations */
|
||||||
|
|
||||||
cmp_result = PyObject_RichCompareBool(step, _PyLong_Zero, Py_GT);
|
PyObject *zero = _PyLong_GetZero(); // borrowed reference
|
||||||
|
PyObject *one = _PyLong_GetOne(); // borrowed reference
|
||||||
|
|
||||||
|
cmp_result = PyObject_RichCompareBool(step, zero, Py_GT);
|
||||||
if (cmp_result == -1)
|
if (cmp_result == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -212,19 +216,21 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
|
||||||
Py_DECREF(step);
|
Py_DECREF(step);
|
||||||
if (cmp_result < 0)
|
if (cmp_result < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyLong_FromLong(0);
|
result = zero;
|
||||||
|
Py_INCREF(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL)
|
if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL)
|
||||||
goto Fail;
|
goto Fail;
|
||||||
|
|
||||||
if ((diff = PyNumber_Subtract(tmp1, _PyLong_One)) == NULL)
|
if ((diff = PyNumber_Subtract(tmp1, one)) == NULL)
|
||||||
goto Fail;
|
goto Fail;
|
||||||
|
|
||||||
if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL)
|
if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL)
|
||||||
goto Fail;
|
goto Fail;
|
||||||
|
|
||||||
if ((result = PyNumber_Add(tmp2, _PyLong_One)) == NULL)
|
if ((result = PyNumber_Add(tmp2, one)) == NULL)
|
||||||
goto Fail;
|
goto Fail;
|
||||||
|
|
||||||
Py_DECREF(tmp2);
|
Py_DECREF(tmp2);
|
||||||
|
@ -254,7 +260,7 @@ compute_item(rangeobject *r, PyObject *i)
|
||||||
/* PyLong equivalent to:
|
/* PyLong equivalent to:
|
||||||
* return r->start + (i * r->step)
|
* return r->start + (i * r->step)
|
||||||
*/
|
*/
|
||||||
if (r->step == _PyLong_One) {
|
if (r->step == _PyLong_GetOne()) {
|
||||||
result = PyNumber_Add(r->start, i);
|
result = PyNumber_Add(r->start, i);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -271,6 +277,7 @@ compute_item(rangeobject *r, PyObject *i)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
compute_range_item(rangeobject *r, PyObject *arg)
|
compute_range_item(rangeobject *r, PyObject *arg)
|
||||||
{
|
{
|
||||||
|
PyObject *zero = _PyLong_GetZero(); // borrowed reference
|
||||||
int cmp_result;
|
int cmp_result;
|
||||||
PyObject *i, *result;
|
PyObject *i, *result;
|
||||||
|
|
||||||
|
@ -281,7 +288,7 @@ compute_range_item(rangeobject *r, PyObject *arg)
|
||||||
* i = arg
|
* i = arg
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
cmp_result = PyObject_RichCompareBool(arg, _PyLong_Zero, Py_LT);
|
cmp_result = PyObject_RichCompareBool(arg, zero, Py_LT);
|
||||||
if (cmp_result == -1) {
|
if (cmp_result == -1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +307,7 @@ compute_range_item(rangeobject *r, PyObject *arg)
|
||||||
* <report index out of bounds>
|
* <report index out of bounds>
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
cmp_result = PyObject_RichCompareBool(i, _PyLong_Zero, Py_LT);
|
cmp_result = PyObject_RichCompareBool(i, zero, Py_LT);
|
||||||
if (cmp_result == 0) {
|
if (cmp_result == 0) {
|
||||||
cmp_result = PyObject_RichCompareBool(i, r->length, Py_GE);
|
cmp_result = PyObject_RichCompareBool(i, r->length, Py_GE);
|
||||||
}
|
}
|
||||||
|
@ -375,6 +382,7 @@ fail:
|
||||||
static int
|
static int
|
||||||
range_contains_long(rangeobject *r, PyObject *ob)
|
range_contains_long(rangeobject *r, PyObject *ob)
|
||||||
{
|
{
|
||||||
|
PyObject *zero = _PyLong_GetZero(); // borrowed reference
|
||||||
int cmp1, cmp2, cmp3;
|
int cmp1, cmp2, cmp3;
|
||||||
PyObject *tmp1 = NULL;
|
PyObject *tmp1 = NULL;
|
||||||
PyObject *tmp2 = NULL;
|
PyObject *tmp2 = NULL;
|
||||||
|
@ -382,7 +390,7 @@ range_contains_long(rangeobject *r, PyObject *ob)
|
||||||
|
|
||||||
/* Check if the value can possibly be in the range. */
|
/* Check if the value can possibly be in the range. */
|
||||||
|
|
||||||
cmp1 = PyObject_RichCompareBool(r->step, _PyLong_Zero, Py_GT);
|
cmp1 = PyObject_RichCompareBool(r->step, zero, Py_GT);
|
||||||
if (cmp1 == -1)
|
if (cmp1 == -1)
|
||||||
goto end;
|
goto end;
|
||||||
if (cmp1 == 1) { /* positive steps: start <= ob < stop */
|
if (cmp1 == 1) { /* positive steps: start <= ob < stop */
|
||||||
|
@ -409,7 +417,7 @@ range_contains_long(rangeobject *r, PyObject *ob)
|
||||||
if (tmp2 == NULL)
|
if (tmp2 == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
/* result = ((int(ob) - start) % step) == 0 */
|
/* result = ((int(ob) - start) % step) == 0 */
|
||||||
result = PyObject_RichCompareBool(tmp2, _PyLong_Zero, Py_EQ);
|
result = PyObject_RichCompareBool(tmp2, zero, Py_EQ);
|
||||||
end:
|
end:
|
||||||
Py_XDECREF(tmp1);
|
Py_XDECREF(tmp1);
|
||||||
Py_XDECREF(tmp2);
|
Py_XDECREF(tmp2);
|
||||||
|
@ -460,7 +468,7 @@ range_equals(rangeobject *r0, rangeobject *r1)
|
||||||
/* Return False or error to the caller. */
|
/* Return False or error to the caller. */
|
||||||
if (cmp_result != 1)
|
if (cmp_result != 1)
|
||||||
return cmp_result;
|
return cmp_result;
|
||||||
cmp_result = PyObject_RichCompareBool(r0->length, _PyLong_One, Py_EQ);
|
cmp_result = PyObject_RichCompareBool(r0->length, _PyLong_GetOne(), Py_EQ);
|
||||||
/* Return True or error to the caller. */
|
/* Return True or error to the caller. */
|
||||||
if (cmp_result != 0)
|
if (cmp_result != 0)
|
||||||
return cmp_result;
|
return cmp_result;
|
||||||
|
@ -529,7 +537,7 @@ range_hash(rangeobject *r)
|
||||||
else {
|
else {
|
||||||
Py_INCREF(r->start);
|
Py_INCREF(r->start);
|
||||||
PyTuple_SET_ITEM(t, 1, r->start);
|
PyTuple_SET_ITEM(t, 1, r->start);
|
||||||
cmp_result = PyObject_RichCompareBool(r->length, _PyLong_One, Py_EQ);
|
cmp_result = PyObject_RichCompareBool(r->length, _PyLong_GetOne(), Py_EQ);
|
||||||
if (cmp_result == -1)
|
if (cmp_result == -1)
|
||||||
goto end;
|
goto end;
|
||||||
if (cmp_result == 1) {
|
if (cmp_result == 1) {
|
||||||
|
@ -587,7 +595,7 @@ range_index(rangeobject *r, PyObject *ob)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->step == _PyLong_One) {
|
if (r->step == _PyLong_GetOne()) {
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -974,14 +982,15 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored))
|
||||||
static PyObject *
|
static PyObject *
|
||||||
longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
|
longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
|
||||||
{
|
{
|
||||||
|
PyObject *zero = _PyLong_GetZero(); // borrowed reference
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
||||||
/* clip the value */
|
/* clip the value */
|
||||||
cmp = PyObject_RichCompareBool(state, _PyLong_Zero, Py_LT);
|
cmp = PyObject_RichCompareBool(state, zero, Py_LT);
|
||||||
if (cmp < 0)
|
if (cmp < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (cmp > 0) {
|
if (cmp > 0) {
|
||||||
state = _PyLong_Zero;
|
state = zero;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmp = PyObject_RichCompareBool(r->len, state, Py_LT);
|
cmp = PyObject_RichCompareBool(r->len, state, Py_LT);
|
||||||
|
@ -1022,7 +1031,7 @@ longrangeiter_next(longrangeiterobject *r)
|
||||||
if (PyObject_RichCompareBool(r->index, r->len, Py_LT) != 1)
|
if (PyObject_RichCompareBool(r->index, r->len, Py_LT) != 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
new_index = PyNumber_Add(r->index, _PyLong_One);
|
new_index = PyNumber_Add(r->index, _PyLong_GetOne());
|
||||||
if (!new_index)
|
if (!new_index)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1119,7 +1128,7 @@ range_iter(PyObject *seq)
|
||||||
it->start = r->start;
|
it->start = r->start;
|
||||||
it->step = r->step;
|
it->step = r->step;
|
||||||
it->len = r->length;
|
it->len = r->length;
|
||||||
it->index = _PyLong_Zero;
|
it->index = _PyLong_GetZero();
|
||||||
Py_INCREF(it->start);
|
Py_INCREF(it->start);
|
||||||
Py_INCREF(it->step);
|
Py_INCREF(it->step);
|
||||||
Py_INCREF(it->len);
|
Py_INCREF(it->len);
|
||||||
|
@ -1207,7 +1216,7 @@ long_range:
|
||||||
it->len = range->length;
|
it->len = range->length;
|
||||||
Py_INCREF(it->len);
|
Py_INCREF(it->len);
|
||||||
|
|
||||||
diff = PyNumber_Subtract(it->len, _PyLong_One);
|
diff = PyNumber_Subtract(it->len, _PyLong_GetOne());
|
||||||
if (!diff)
|
if (!diff)
|
||||||
goto create_failure;
|
goto create_failure;
|
||||||
|
|
||||||
|
@ -1226,7 +1235,7 @@ long_range:
|
||||||
if (!it->step)
|
if (!it->step)
|
||||||
goto create_failure;
|
goto create_failure;
|
||||||
|
|
||||||
it->index = _PyLong_Zero;
|
it->index = _PyLong_GetZero();
|
||||||
Py_INCREF(it->index);
|
Py_INCREF(it->index);
|
||||||
return (PyObject *)it;
|
return (PyObject *)it;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ this type and there is exactly one in existence.
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_abstract.h" // _PyIndex_Check()
|
#include "pycore_abstract.h" // _PyIndex_Check()
|
||||||
|
#include "pycore_long.h" // _PyLong_GetZero()
|
||||||
#include "pycore_object.h" // _PyObject_GC_TRACK()
|
#include "pycore_object.h" // _PyObject_GC_TRACK()
|
||||||
#include "structmember.h" // PyMemberDef
|
#include "structmember.h" // PyMemberDef
|
||||||
|
|
||||||
|
@ -388,7 +389,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
|
||||||
|
|
||||||
/* Convert step to an integer; raise for zero step. */
|
/* Convert step to an integer; raise for zero step. */
|
||||||
if (self->step == Py_None) {
|
if (self->step == Py_None) {
|
||||||
step = _PyLong_One;
|
step = _PyLong_GetOne();
|
||||||
Py_INCREF(step);
|
Py_INCREF(step);
|
||||||
step_is_negative = 0;
|
step_is_negative = 0;
|
||||||
}
|
}
|
||||||
|
@ -417,7 +418,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lower = _PyLong_Zero;
|
lower = _PyLong_GetZero();
|
||||||
Py_INCREF(lower);
|
Py_INCREF(lower);
|
||||||
upper = length;
|
upper = length;
|
||||||
Py_INCREF(upper);
|
Py_INCREF(upper);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_initconfig.h"
|
#include "pycore_initconfig.h"
|
||||||
#include "pycore_interp.h" // PyInterpreterState.warnings
|
#include "pycore_interp.h" // PyInterpreterState.warnings
|
||||||
|
#include "pycore_long.h" // _PyLong_GetZero()
|
||||||
#include "pycore_pyerrors.h"
|
#include "pycore_pyerrors.h"
|
||||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||||
#include "frameobject.h" // PyFrame_GetBack()
|
#include "frameobject.h" // PyFrame_GetBack()
|
||||||
|
@ -73,7 +74,7 @@ create_filter(PyObject *category, _Py_Identifier *id, const char *modname)
|
||||||
|
|
||||||
/* This assumes the line number is zero for now. */
|
/* This assumes the line number is zero for now. */
|
||||||
return PyTuple_Pack(5, action_str, Py_None,
|
return PyTuple_Pack(5, action_str, Py_None,
|
||||||
category, modname_obj, _PyLong_Zero);
|
category, modname_obj, _PyLong_GetZero());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -472,7 +473,7 @@ update_registry(PyObject *registry, PyObject *text, PyObject *category,
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (add_zero)
|
if (add_zero)
|
||||||
altkey = PyTuple_Pack(3, text, category, _PyLong_Zero);
|
altkey = PyTuple_Pack(3, text, category, _PyLong_GetZero());
|
||||||
else
|
else
|
||||||
altkey = PyTuple_Pack(2, text, category);
|
altkey = PyTuple_Pack(2, text, category);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
#include "pycore_long.h" // _PyLong_GetZero()
|
||||||
|
|
||||||
#include "Python-ast.h"
|
#include "Python-ast.h"
|
||||||
#include "ast.h"
|
#include "ast.h"
|
||||||
|
@ -603,7 +604,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
|
||||||
compiler_unit_free(u);
|
compiler_unit_free(u);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
res = PyDict_SetItem(u->u_cellvars, name, _PyLong_Zero);
|
res = PyDict_SetItem(u->u_cellvars, name, _PyLong_GetZero());
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
compiler_unit_free(u);
|
compiler_unit_free(u);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3218,11 +3219,12 @@ compiler_import(struct compiler *c, stmt_ty s)
|
||||||
*/
|
*/
|
||||||
Py_ssize_t i, n = asdl_seq_LEN(s->v.Import.names);
|
Py_ssize_t i, n = asdl_seq_LEN(s->v.Import.names);
|
||||||
|
|
||||||
|
PyObject *zero = _PyLong_GetZero(); // borrowed reference
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
|
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
ADDOP_LOAD_CONST(c, _PyLong_Zero);
|
ADDOP_LOAD_CONST(c, zero);
|
||||||
ADDOP_LOAD_CONST(c, Py_None);
|
ADDOP_LOAD_CONST(c, Py_None);
|
||||||
ADDOP_NAME(c, IMPORT_NAME, alias->name, names);
|
ADDOP_NAME(c, IMPORT_NAME, alias->name, names);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue