@@ -4198,19 +4198,23 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
4198
4198
self -> fast = 0 ;
4199
4199
self -> fast_nesting = 0 ;
4200
4200
self -> fast_memo = NULL ;
4201
- self -> pers_func = NULL ;
4202
- if ( _PyObject_HasAttrId (( PyObject * )self , & PyId_persistent_id )) {
4203
- self -> pers_func = _PyObject_GetAttrId (( PyObject * ) self ,
4204
- & PyId_persistent_id );
4205
- if (self -> pers_func == NULL )
4201
+
4202
+ self -> pers_func = _PyObject_GetAttrId (( PyObject * )self ,
4203
+ & PyId_persistent_id );
4204
+ if ( self -> pers_func == NULL ) {
4205
+ if (! PyErr_ExceptionMatches ( PyExc_AttributeError )) {
4206
4206
return -1 ;
4207
+ }
4208
+ PyErr_Clear ();
4207
4209
}
4208
- self -> dispatch_table = NULL ;
4209
- if ( _PyObject_HasAttrId (( PyObject * )self , & PyId_dispatch_table )) {
4210
- self -> dispatch_table = _PyObject_GetAttrId (( PyObject * ) self ,
4211
- & PyId_dispatch_table );
4212
- if (self -> dispatch_table == NULL )
4210
+
4211
+ self -> dispatch_table = _PyObject_GetAttrId (( PyObject * )self ,
4212
+ & PyId_dispatch_table );
4213
+ if ( self -> dispatch_table == NULL ) {
4214
+ if (! PyErr_ExceptionMatches ( PyExc_AttributeError )) {
4213
4215
return -1 ;
4216
+ }
4217
+ PyErr_Clear ();
4214
4218
}
4215
4219
4216
4220
return 0 ;
@@ -5165,22 +5169,24 @@ load_frozenset(UnpicklerObject *self)
5165
5169
static PyObject *
5166
5170
instantiate (PyObject * cls , PyObject * args )
5167
5171
{
5168
- PyObject * result = NULL ;
5169
- _Py_IDENTIFIER (__getinitargs__ );
5170
5172
/* Caller must assure args are a tuple. Normally, args come from
5171
5173
Pdata_poptuple which packs objects from the top of the stack
5172
5174
into a newly created tuple. */
5173
5175
assert (PyTuple_Check (args ));
5174
- if (Py_SIZE (args ) > 0 || !PyType_Check (cls ) ||
5175
- _PyObject_HasAttrId (cls , & PyId___getinitargs__ )) {
5176
- result = PyObject_CallObject (cls , args );
5177
- }
5178
- else {
5176
+ if (!PyTuple_GET_SIZE (args ) && PyType_Check (cls )) {
5177
+ _Py_IDENTIFIER (__getinitargs__ );
5179
5178
_Py_IDENTIFIER (__new__ );
5180
-
5181
- result = _PyObject_CallMethodId (cls , & PyId___new__ , "O" , cls );
5179
+ PyObject * func = _PyObject_GetAttrId (cls , & PyId___getinitargs__ );
5180
+ if (func == NULL ) {
5181
+ if (!PyErr_ExceptionMatches (PyExc_AttributeError )) {
5182
+ return NULL ;
5183
+ }
5184
+ PyErr_Clear ();
5185
+ return _PyObject_CallMethodIdObjArgs (cls , & PyId___new__ , cls , NULL );
5186
+ }
5187
+ Py_DECREF (func );
5182
5188
}
5183
- return result ;
5189
+ return PyObject_CallObject ( cls , args ) ;
5184
5190
}
5185
5191
5186
5192
static int
@@ -6626,17 +6632,14 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
6626
6632
return -1 ;
6627
6633
6628
6634
self -> fix_imports = fix_imports ;
6629
- if (self -> fix_imports == -1 )
6630
- return -1 ;
6631
6635
6632
- if (_PyObject_HasAttrId ((PyObject * )self , & PyId_persistent_load )) {
6633
- self -> pers_func = _PyObject_GetAttrId ((PyObject * )self ,
6634
- & PyId_persistent_load );
6635
- if (self -> pers_func == NULL )
6636
- return 1 ;
6637
- }
6638
- else {
6639
- self -> pers_func = NULL ;
6636
+ self -> pers_func = _PyObject_GetAttrId ((PyObject * )self ,
6637
+ & PyId_persistent_load );
6638
+ if (self -> pers_func == NULL ) {
6639
+ if (!PyErr_ExceptionMatches (PyExc_AttributeError )) {
6640
+ return -1 ;
6641
+ }
6642
+ PyErr_Clear ();
6640
6643
}
6641
6644
6642
6645
self -> stack = (Pdata * )Pdata_New ();
0 commit comments