Skip to content

Commit c310185

Browse files
authored
bpo-42161: Remove private _PyLong_Zero and _PyLong_One (GH-23003)
Use PyLong_FromLong(0) and PyLong_FromLong(1) of the public C API instead. For Python internals, _PyLong_GetZero() and _PyLong_GetOne() of pycore_long.h can be used.
1 parent 0564aaf commit c310185

File tree

3 files changed

+0
-23
lines changed

3 files changed

+0
-23
lines changed

Include/longobject.h

-3
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,6 @@ PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
210210
#endif /* !Py_LIMITED_API */
211211

212212
#ifndef Py_LIMITED_API
213-
PyAPI_DATA(PyObject *) _PyLong_Zero;
214-
PyAPI_DATA(PyObject *) _PyLong_One;
215-
216213
PyAPI_FUNC(PyObject *) _PyLong_Rshift(PyObject *, size_t);
217214
PyAPI_FUNC(PyObject *) _PyLong_Lshift(PyObject *, size_t);
218215
#endif

Objects/longobject.c

-18
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ _Py_IDENTIFIER(big);
3232
(Py_SIZE(x) == 0 ? (sdigit)0 : \
3333
(sdigit)(x)->ob_digit[0]))
3434

35-
PyObject *_PyLong_Zero = NULL;
36-
PyObject *_PyLong_One = NULL;
37-
3835
#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS)
3936
#define IS_SMALL_UINT(ival) ((ival) < NSMALLPOSINTS)
4037

@@ -5723,16 +5720,6 @@ _PyLong_Init(PyThreadState *tstate)
57235720
}
57245721

57255722
if (_Py_IsMainInterpreter(tstate)) {
5726-
_PyLong_Zero = PyLong_FromLong(0);
5727-
if (_PyLong_Zero == NULL) {
5728-
return 0;
5729-
}
5730-
5731-
_PyLong_One = PyLong_FromLong(1);
5732-
if (_PyLong_One == NULL) {
5733-
return 0;
5734-
}
5735-
57365723
/* initialize int_info */
57375724
if (Int_InfoType.tp_name == NULL) {
57385725
if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) {
@@ -5747,11 +5734,6 @@ _PyLong_Init(PyThreadState *tstate)
57475734
void
57485735
_PyLong_Fini(PyThreadState *tstate)
57495736
{
5750-
if (_Py_IsMainInterpreter(tstate)) {
5751-
Py_CLEAR(_PyLong_One);
5752-
Py_CLEAR(_PyLong_Zero);
5753-
}
5754-
57555737
for (Py_ssize_t i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) {
57565738
Py_CLEAR(tstate->interp->small_ints[i]);
57575739
}

Tools/c-analyzer/TODO

-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ Objects/bytesobject.c:nullstring static PyBytesO
154154
Objects/codeobject.c:PyCode_NewEmpty():nulltuple static PyObject *nulltuple
155155
Objects/dictobject.c:empty_values static PyObject *empty_values[1]
156156
Objects/listobject.c:indexerr static PyObject *indexerr
157-
Objects/longobject.c:_PyLong_One PyObject *_PyLong_One
158-
Objects/longobject.c:_PyLong_Zero PyObject *_PyLong_Zero
159157
Objects/longobject.c:small_ints static PyLongObject small_ints[NSMALLNEGINTS + NSMALLPOSINTS]
160158
Objects/setobject.c:emptyfrozenset static PyObject *emptyfrozenset
161159
Python/context.c:_token_missing static PyObject *_token_missing

0 commit comments

Comments
 (0)