[Python-checkins] python/dist/src/Modules cPickle.c,2.145,2.146
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Mon, 16 Jun 2003 13:19:52 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv21457
Modified Files:
cPickle.c
Log Message:
Remove many blanket try/except clauses.
SF bug [ 751276 ] cPickle doesn't raise error, pickle does (recursiondepth)
Most of the calls to PyErr_Clear() were intended to catch & clear an
attribute error and try something different. Guard all those cases
with a PyErr_ExceptionMatches() and fail if some other error
occurred. The other error is likely a bug in the user code.
This is basically the C equivalent of changing "except:" to
"except AttributeError:"
Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.145
retrieving revision 2.146
diff -C2 -d -r2.145 -r2.146
*** cPickle.c 21 May 2003 21:29:47 -0000 2.145
--- cPickle.c 16 Jun 2003 20:19:49 -0000 2.146
***************
*** 834,839 ****
module = PyObject_GetAttrString(global, "__module__");
! if (module) return module;
! PyErr_Clear();
if (!( modules_dict = PySys_GetObject("modules")))
--- 834,843 ----
module = PyObject_GetAttrString(global, "__module__");
! if (module)
! return module;
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! return NULL;
if (!( modules_dict = PySys_GetObject("modules")))
***************
*** 847,851 ****
global_name_attr = PyObject_GetAttr(module, global_name);
if (!global_name_attr) {
! PyErr_Clear();
continue;
}
--- 851,858 ----
global_name_attr = PyObject_GetAttr(module, global_name);
if (!global_name_attr) {
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! return NULL;
continue;
}
***************
*** 1815,1819 ****
}
else {
! PyErr_Clear();
}
--- 1822,1829 ----
}
else {
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! goto finally;
}
***************
*** 1860,1867 ****
}
else {
! PyErr_Clear();
if (!( state = PyObject_GetAttr(args, __dict___str))) {
! PyErr_Clear();
res = 0;
goto finally;
--- 1870,1883 ----
}
else {
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! goto finally;
if (!( state = PyObject_GetAttr(args, __dict___str))) {
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! goto finally;
res = 0;
goto finally;
***************
*** 2142,2146 ****
if (temp == NULL) {
! PyErr_Clear();
use_newobj = 0;
}
--- 2158,2165 ----
if (temp == NULL) {
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! return -1;
use_newobj = 0;
}
***************
*** 2177,2182 ****
ob_dot_class = PyObject_GetAttr(ob, __class___str);
! if (ob_dot_class == NULL)
! PyErr_Clear();
i = ob_dot_class != cls; /* true iff a problem */
Py_XDECREF(ob_dot_class);
--- 2196,2206 ----
ob_dot_class = PyObject_GetAttr(ob, __class___str);
! if (ob_dot_class == NULL) {
! if (PyErr_ExceptionMatches(
! PyExc_AttributeError))
! PyErr_Clear();
! else
! return -1;
! }
i = ob_dot_class != cls; /* true iff a problem */
Py_XDECREF(ob_dot_class);
***************
*** 2448,2452 ****
}
else {
! PyErr_Clear();
/* Check for a __reduce__ method. */
__reduce__ = PyObject_GetAttr(args, __reduce___str);
--- 2472,2479 ----
}
else {
! if (PyErr_ExceptionMatches(PyExc_AttributeError))
! PyErr_Clear();
! else
! goto finally;
/* Check for a __reduce__ method. */
__reduce__ = PyObject_GetAttr(args, __reduce___str);
***************
*** 3565,3569 ****
__getinitargs__ = PyObject_GetAttr(cls,
! __getinitargs___str);
if (!__getinitargs__) {
/* We have a class with no __getinitargs__,
--- 3592,3596 ----
__getinitargs__ = PyObject_GetAttr(cls,
! __getinitargs___str);
if (!__getinitargs__) {
/* We have a class with no __getinitargs__,
***************
*** 4254,4257 ****
--- 4281,4286 ----
return 0;
}
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
+ return -1;
PyErr_Clear();