Skip to content

Commit

Permalink
Python3.12+: Avoid taking references for know immutable values in cod…
Browse files Browse the repository at this point in the history
…e helpers

* Boolean values do not need reference to be taken or released.
  • Loading branch information
kayhayen committed May 31, 2024
1 parent 2b8d078 commit 9a41bf0
Show file tree
Hide file tree
Showing 57 changed files with 2,971 additions and 2,968 deletions.
2 changes: 1 addition & 1 deletion nuitka/build/static_src/CompiledCellType.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static PyObject *Nuitka_Cell_tp_richcompare(PyObject *a, PyObject *b, int op) {
return NULL;
}

Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions nuitka/build/static_src/CompiledCodeHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ PyObject *BUILTIN_ALL(PyThreadState *tstate, PyObject *value) {

if (cmp == 0) {
Py_DECREF(it);
Py_INCREF(Py_False);
Py_INCREF_IMMORTAL(Py_False);
return Py_False;
}
}
Expand All @@ -596,7 +596,7 @@ PyObject *BUILTIN_ALL(PyThreadState *tstate, PyObject *value) {
return NULL;
}

Py_INCREF(Py_True);
Py_INCREF_IMMORTAL(Py_True);
return Py_True;
}

Expand Down Expand Up @@ -635,7 +635,7 @@ PyObject *BUILTIN_ANY(PyThreadState *tstate, PyObject *value) {
}
if (cmp > 0) {
Py_DECREF(it);
Py_INCREF(Py_True);
Py_INCREF_IMMORTAL(Py_True);
return Py_True;
}
}
Expand All @@ -645,7 +645,7 @@ PyObject *BUILTIN_ANY(PyThreadState *tstate, PyObject *value) {
return NULL;
}

Py_INCREF(Py_False);
Py_INCREF_IMMORTAL(Py_False);
return Py_False;
}

Expand Down Expand Up @@ -1382,7 +1382,7 @@ PyObject *BUILTIN_SUM1(PyThreadState *tstate, PyObject *sequence) {
#endif

if (item == Py_False) {
Py_DECREF(item);
Py_DECREF_IMMORTAL(item);
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions nuitka/build/static_src/CompiledFrameType.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static PyObject *Nuitka_Frame_get_restricted(struct Nuitka_FrameObject *frame, v
CHECK_OBJECT((PyObject *)frame);
assert(_PyObject_GC_IS_TRACKED(frame));

Py_INCREF(Py_False);
Py_INCREF_IMMORTAL(Py_False);
return Py_False;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ static PyObject *Nuitka_Frame_gettracelines(struct Nuitka_FrameObject *frame, vo
assert(_PyObject_GC_IS_TRACKED(frame));

PyObject *result = Py_False;
Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}

Expand All @@ -294,7 +294,7 @@ static PyObject *Nuitka_Frame_gettraceopcodes(struct Nuitka_FrameObject *frame,
assert(_PyObject_GC_IS_TRACKED(frame));

PyObject *result = Py_False;
Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}

Expand Down
5 changes: 2 additions & 3 deletions nuitka/build/static_src/CompiledFunctionType.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ static PyObject *_Nuitka_FunctionEmptyCodeTrueImpl(PyThreadState *tstate, struct

PyObject *result = Py_True;

Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}

Expand All @@ -1038,8 +1038,7 @@ static PyObject *_Nuitka_FunctionEmptyCodeFalseImpl(PyThreadState *tstate, struc
}

PyObject *result = Py_False;

Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion nuitka/build/static_src/CompiledGeneratorType.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ static PyObject *Nuitka_Generator_get_running(struct Nuitka_GeneratorObject *gen
result = PyInt_FromLong(generator->m_running);
#else
result = BOOL_FROM(generator->m_running != 0);
Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
#endif
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion nuitka/build/static_src/CompiledMethodType.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static PyObject *Nuitka_Method_tp_richcompare(struct Nuitka_MethodObject *a, str
result = BOOL_FROM(!b_res);
}

Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion nuitka/build/static_src/HelpersBuiltin.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ PyObject *BUILTIN_SUPER0(PyThreadState *tstate, PyDictObject *module_dict, PyObj
PyObject *BUILTIN_CALLABLE(PyObject *value) {
int res = PyCallable_Check(value);
PyObject *result = BOOL_FROM(res != 0);
Py_INCREF(result);
Py_INCREF_IMMORTAL(result);
return result;
}

Expand Down
Loading

0 comments on commit 9a41bf0

Please sign in to comment.