Commit 4b834fed authored by Shane Hathaway's avatar Shane Hathaway

Fixed a potential Python 2.2+ bug and tidied the code slightly.

In Python 2.2 and above, getattr operations distinguish
AttributeErrors from other kinds of operations.  But Wrapper_acquire
was masking some errors as AttributeErrors.  Fixed.

Added a comment explaining apply_filter, added curly brackets to
disambiguate nesting in Wrapper_acquire, and re-indented to clarify.
parent d50be848
...@@ -346,6 +346,16 @@ static int ...@@ -346,6 +346,16 @@ static int
apply_filter(PyObject *filter, PyObject *inst, PyObject *oname, PyObject *r, apply_filter(PyObject *filter, PyObject *inst, PyObject *oname, PyObject *r,
PyObject *extra, PyObject *orig) PyObject *extra, PyObject *orig)
{ {
/* Calls the filter, passing arguments.
Returns 1 if the filter accepts the value, 0 if not, -1 if an
exception occurred.
Note the special reference counting rule: This function decrements
the refcount of 'r' when it returns 0 or -1. When it returns 1, it
leaves the refcount unchanged.
*/
PyObject *fr; PyObject *fr;
int ir; int ir;
...@@ -518,12 +528,11 @@ Wrapper_acquire(Wrapper *self, PyObject *oname, ...@@ -518,12 +528,11 @@ Wrapper_acquire(Wrapper *self, PyObject *oname,
else else
{ {
if ((r=PyObject_GetAttr(self->container,oname))) { if ((r=PyObject_GetAttr(self->container,oname))) {
if (r == Acquired) if (r == Acquired) {
{ Py_DECREF(r);
Py_DECREF(r); }
}
else { else {
if (filter) if (filter) {
switch(apply_filter(filter,self->container,oname,r, switch(apply_filter(filter,self->container,oname,r,
extra,orig)) extra,orig))
{ {
...@@ -533,13 +542,17 @@ Wrapper_acquire(Wrapper *self, PyObject *oname, ...@@ -533,13 +542,17 @@ Wrapper_acquire(Wrapper *self, PyObject *oname,
if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self))); if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self)));
return r; return r;
} }
else }
{ else {
if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self))); if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self)));
return r; return r;
} }
} }
} }
else {
/* May be AttributeError or some other kind of error */
return NULL;
}
} }
} }
...@@ -1515,7 +1528,7 @@ initAcquisition(void) ...@@ -1515,7 +1528,7 @@ initAcquisition(void)
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.60 2002/11/13 17:45:53 jeremy Exp $\n", "$Id: Acquisition.c,v 1.61 2003/06/10 15:28:46 shane Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment