From: Billy G. A. <bal...@us...> - 2001-09-17 04:37:14
|
Update of /cvsroot/pypgsql/pypgsql In directory usw-pr-cvs1:/tmp/cvs-serv18017 Modified Files: pgversion.c Log Message: 16SEP2001 bga Corrected a mis-conception on my part about how Python handles exceptions generated during coercion. Index: pgversion.c =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pgversion.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** pgversion.c 2001/09/17 03:44:53 1.10 --- pgversion.c 2001/09/17 04:37:06 1.11 *************** *** 32,38 **** | Date Ini Description | | --------- --- ------------------------------------------------------- | ! | 16SEP2001 bga Fixed a problem that occurred with Python 2.2, which | ! | requires a -1 to be returned from the comparison func- | ! | tion before it honors any exception. | | 15SEP2001 bga Fixed problem where a variable in PgVersion_New() could | | be used before it was initialized. | --- 32,37 ---- | Date Ini Description | | --------- --- ------------------------------------------------------- | ! | 16SEP2001 bga Corrected my mis-conceptions about Python ignoring ex- | ! | ceptions generated during coercion. | | 15SEP2001 bga Fixed problem where a variable in PgVersion_New() could | | be used before it was initialized. | *************** *** 280,284 **** { PyErr_NoMemory(); ! return (1); } --- 279,283 ---- { PyErr_NoMemory(); ! return (-1); } *************** *** 344,383 **** coerce_error: - /*******************************************************************\ - | A bit of explaination is in order here. | - | | - | Python will ignore any exceptions raised from the call to coerce | - | types. In order to work around this problem, coerce will always | - | convert the other type to a PgVersion object, but if an error oc- | - | curs, that object will contain the saved error information. When | - | the compare function for PgVersion is call, it will re-raise the | - | saved exception. | - \*******************************************************************/ - PyMem_Free(vstr); ! ! PyErr_Fetch(&exception, &message, &traceback); ! ! s = (PgVersion *)PyObject_New(PgVersion, &PgVersion_Type); ! if (s == (PgVersion *)NULL) ! return (1); ! ! s->version = message; ! s->major = exception; ! s->minor = traceback; ! s->patch = Py_None; Py_INCREF(Py_None); ! s->post70 = Py_None; Py_INCREF(Py_None); ! s->value = Py_BuildValue("i", -1); ! ! if (PyErr_Occurred()) ! { ! PgVersion_dealloc(s); ! return (1); ! } ! ! *r = (PyObject *)s; ! Py_XINCREF(*l); ! ! return (0); } --- 343,348 ---- coerce_error: PyMem_Free(vstr); ! return (-1); } *************** *** 477,495 **** long right = PyInt_AS_LONG(o->value); - /*******************************************************************\ - | Check to see if one of the PgVersion objects contain error infor- | - | mation. If it does, restore the error condition. | - \*******************************************************************/ - - if (left < 0 || right < 0) - { - PgVersion *t = (left < 0 ? s : o); - - PyErr_Restore(t->major, t->version, t->minor); - t->major = Py_None; Py_XINCREF(t->major); - t->version = Py_None; Py_XINCREF(t->version); - t->minor = Py_None; Py_XINCREF(t->minor); - return (-1); - } return (left < right) ? -1 : (left > right) ? 1 : 0; } --- 442,445 ---- |