@@ -4383,7 +4383,6 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
4383
4383
_Py_IDENTIFIER (__reduce__ );
4384
4384
_Py_IDENTIFIER (__reduce_ex__ );
4385
4385
4386
-
4387
4386
/* XXX: If the __reduce__ method is defined, __reduce_ex__ is
4388
4387
automatically defined as __reduce__. While this is convenient, this
4389
4388
make it impossible to know which method was actually called. Of
@@ -4404,14 +4403,15 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
4404
4403
}
4405
4404
}
4406
4405
else {
4407
- PickleState * st = _Pickle_GetGlobalState ();
4408
-
4409
4406
/* Check for a __reduce__ method. */
4410
- reduce_func = _PyObject_GetAttrId (obj , & PyId___reduce__ );
4407
+ if (_PyObject_LookupAttrId (obj , & PyId___reduce__ , & reduce_func ) < 0 ) {
4408
+ goto error ;
4409
+ }
4411
4410
if (reduce_func != NULL ) {
4412
4411
reduce_value = PyObject_CallNoArgs (reduce_func );
4413
4412
}
4414
4413
else {
4414
+ PickleState * st = _Pickle_GetGlobalState ();
4415
4415
PyErr_Format (st -> PicklingError ,
4416
4416
"can't pickle '%.200s' object: %R" ,
4417
4417
type -> tp_name , obj );
@@ -6446,7 +6446,9 @@ do_append(UnpicklerObject *self, Py_ssize_t x)
6446
6446
PyObject * extend_func ;
6447
6447
_Py_IDENTIFIER (extend );
6448
6448
6449
- extend_func = _PyObject_GetAttrId (list , & PyId_extend );
6449
+ if (_PyObject_LookupAttrId (list , & PyId_extend , & extend_func ) < 0 ) {
6450
+ return -1 ;
6451
+ }
6450
6452
if (extend_func != NULL ) {
6451
6453
slice = Pdata_poplist (self -> stack , x );
6452
6454
if (!slice ) {
@@ -6466,7 +6468,6 @@ do_append(UnpicklerObject *self, Py_ssize_t x)
6466
6468
/* Even if the PEP 307 requires extend() and append() methods,
6467
6469
fall back on append() if the object has no extend() method
6468
6470
for backward compatibility. */
6469
- PyErr_Clear ();
6470
6471
append_func = _PyObject_GetAttrId (list , & PyId_append );
6471
6472
if (append_func == NULL )
6472
6473
return -1 ;
0 commit comments