Skip to content

Commit b4dfe45

Browse files
committed
Use _PyObject_Call_Prepend() in load_newobj()
Export it from pycore_call.h, since _pickle can be built as a shared extension and cannot link against a hidden internal symbol.
1 parent 25eb25a commit b4dfe45

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

Include/internal/pycore_call.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ PyAPI_FUNC(PyObject*) _Py_CheckFunctionResult(
3232
PyObject *result,
3333
const char *where);
3434

35-
extern PyObject* _PyObject_Call_Prepend(
35+
// Export for '_pickle' shared extension.
36+
PyAPI_FUNC(PyObject*) _PyObject_Call_Prepend(
3637
PyThreadState *tstate,
3738
PyObject *callable,
3839
PyObject *obj,

Modules/_pickle.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "Python.h"
1212
#include "pycore_bytesobject.h" // _PyBytesWriter
13+
#include "pycore_call.h" // _PyObject_Call_Prepend()
1314
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
1415
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
1516
#include "pycore_dict.h" // _PyDict_SetItem_Take2()
@@ -6343,19 +6344,8 @@ load_newobj(PickleState *state, UnpicklerObject *self, int use_kwargs)
63436344
if (func == NULL) {
63446345
goto error;
63456346
}
6346-
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
6347-
PyObject *newargs = PyTuple_New(nargs + 1);
6348-
if (newargs == NULL) {
6349-
Py_DECREF(func);
6350-
goto error;
6351-
}
6352-
PyTuple_SET_ITEM(newargs, 0, Py_NewRef(cls));
6353-
for (Py_ssize_t i = 0; i < nargs; i++) {
6354-
PyTuple_SET_ITEM(newargs, i + 1,
6355-
Py_NewRef(PyTuple_GET_ITEM(args, i)));
6356-
}
6357-
obj = PyObject_Call(func, newargs, kwargs);
6358-
Py_DECREF(newargs);
6347+
PyThreadState *tstate = _PyThreadState_GET();
6348+
obj = _PyObject_Call_Prepend(tstate, func, cls, args, kwargs);
63596349
Py_DECREF(func);
63606350
}
63616351
if (obj == NULL) {

0 commit comments

Comments
 (0)