File tree Expand file tree Collapse file tree 4 files changed +14
-4
lines changed Expand file tree Collapse file tree 4 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -63,12 +63,12 @@ extern void _PyLong_FiniTypes(PyInterpreterState *interp);
63
63
# error "_PY_NSMALLPOSINTS must be greater than or equal to 257"
64
64
#endif
65
65
66
- // Return a reference to the immortal zero singleton.
66
+ // Return a borrowed reference to the immortal zero singleton.
67
67
// The function cannot return NULL.
68
68
static inline PyObject * _PyLong_GetZero (void )
69
69
{ return (PyObject * )& _PyLong_SMALL_INTS [_PY_NSMALLNEGINTS ]; }
70
70
71
- // Return a reference to the immortal one singleton.
71
+ // Return a borrowed reference to the immortal one singleton.
72
72
// The function cannot return NULL.
73
73
static inline PyObject * _PyLong_GetOne (void )
74
74
{ return (PyObject * )& _PyLong_SMALL_INTS [_PY_NSMALLNEGINTS + 1 ]; }
Original file line number Diff line number Diff line change @@ -874,6 +874,15 @@ PyAPI_DATA(int) _Py_SwappedOp[];
874
874
875
875
extern void _Py_GetConstant_Init (void );
876
876
877
+
878
+ // Similar to Py_NewRef() but for immortal objects.
879
+ // obj must be immortal.
880
+ static inline PyObject * _Py_NewImmortalRef (PyObject * obj )
881
+ {
882
+ assert (_Py_IsImmortalLoose (obj ));
883
+ return obj ;
884
+ }
885
+
877
886
#ifdef __cplusplus
878
887
}
879
888
#endif
Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ bool_repr(PyObject *self)
20
20
21
21
PyObject * PyBool_FromLong (long ok )
22
22
{
23
- return ok ? Py_True : Py_False ;
23
+ PyObject * result = ok ? Py_True : Py_False ;
24
+ return _Py_NewImmortalRef (result );
24
25
}
25
26
26
27
/* We define bool_new to always return either Py_True or Py_False */
Original file line number Diff line number Diff line change @@ -3025,7 +3025,7 @@ PyObject*
3025
3025
Py_GetConstant (unsigned int constant_id )
3026
3026
{
3027
3027
if (constant_id < Py_ARRAY_LENGTH (constants )) {
3028
- return constants [constant_id ];
3028
+ return _Py_NewImmortalRef ( constants [constant_id ]) ;
3029
3029
}
3030
3030
else {
3031
3031
PyErr_BadInternalCall ();
You can’t perform that action at this time.
0 commit comments