@@ -3466,29 +3466,19 @@ load_dict(UnpicklerObject *self)
34663466static PyObject *
34673467instantiate (PyObject * cls , PyObject * args )
34683468{
3469- PyObject * r = NULL ;
3470-
3471- /* XXX: The pickle.py module does not create instances this way when the
3472- args tuple is empty. See Unpickler._instantiate(). */
3473- if ((r = PyObject_CallObject (cls , args )))
3474- return r ;
3475-
3476- /* XXX: Is this still nescessary? */
3477- {
3478- PyObject * tp , * v , * tb , * tmp_value ;
3479-
3480- PyErr_Fetch (& tp , & v , & tb );
3481- tmp_value = v ;
3482- /* NULL occurs when there was a KeyboardInterrupt */
3483- if (tmp_value == NULL )
3484- tmp_value = Py_None ;
3485- if ((r = PyTuple_Pack (3 , tmp_value , cls , args ))) {
3486- Py_XDECREF (v );
3487- v = r ;
3488- }
3489- PyErr_Restore (tp , v , tb );
3469+ PyObject * result = NULL ;
3470+ /* Caller must assure args are a tuple. Normally, args come from
3471+ Pdata_poptuple which packs objects from the top of the stack
3472+ into a newly created tuple. */
3473+ assert (PyTuple_Check (args ));
3474+ if (Py_SIZE (args ) > 0 || !PyType_Check (cls ) ||
3475+ PyObject_HasAttrString (cls , "__getinitargs__" )) {
3476+ result = PyObject_CallObject (cls , args );
34903477 }
3491- return NULL ;
3478+ else {
3479+ result = PyObject_CallMethod (cls , "__new__" , "O" , cls );
3480+ }
3481+ return result ;
34923482}
34933483
34943484static int
@@ -3547,7 +3537,7 @@ load_inst(UnpicklerObject *self)
35473537 if (len < 2 )
35483538 return bad_readline ();
35493539 class_name = PyUnicode_DecodeASCII (s , len - 1 , "strict" );
3550- if (class_name = = NULL ) {
3540+ if (class_name ! = NULL ) {
35513541 cls = find_class (self , module_name , class_name );
35523542 Py_DECREF (class_name );
35533543 }
@@ -4276,7 +4266,7 @@ load_reduce(UnpicklerObject *self)
42764266 return -1 ;
42774267 PDATA_POP (self -> stack , callable );
42784268 if (callable ) {
4279- obj = instantiate (callable , argtup );
4269+ obj = PyObject_CallObject (callable , argtup );
42804270 Py_DECREF (callable );
42814271 }
42824272 Py_DECREF (argtup );
0 commit comments