Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c77355

Browse files
committed
Make cPickle use the recently-added PyInstance_NewRaw() API to create
instance objects without calling the constructor. This is the same as the new.instance() function.
1 parent 53f5968 commit 2c77355

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

Modules/cPickle.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,20 +2922,12 @@ Instance_New(PyObject *cls, PyObject *args) {
29222922
UNLESS (__getinitargs__=PyObject_GetAttr(cls, __getinitargs___str)) {
29232923
/* We have a class with no __getinitargs__, so bypass usual
29242924
construction */
2925-
PyInstanceObject *inst;
2925+
PyObject *inst;
29262926

29272927
PyErr_Clear();
2928-
UNLESS (inst=PyObject_New(PyInstanceObject, &PyInstance_Type))
2928+
UNLESS (inst=PyInstance_NewRaw(cls, NULL))
29292929
goto err;
2930-
inst->in_class=(PyClassObject*)cls;
2931-
Py_INCREF(cls);
2932-
UNLESS (inst->in_dict=PyDict_New()) {
2933-
inst = (PyInstanceObject *) PyObject_AS_GC(inst);
2934-
PyObject_DEL(inst);
2935-
goto err;
2936-
}
2937-
PyObject_GC_Init(inst);
2938-
return (PyObject *)inst;
2930+
return inst;
29392931
}
29402932
Py_DECREF(__getinitargs__);
29412933
}

0 commit comments

Comments
 (0)