[Python-3000] [Python-3000-checkins] r54588 (original) (raw)
Brett Cannon brett at python.org
Thu Mar 29 21:52:40 CEST 2007
- Previous message: [Python-3000] [Python-3000-checkins] r54588
- Next message: [Python-3000] [Python-3000-checkins] r54588
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 3/29/07, Amaury Forgeot d'Arc <amauryfa at gmail.com> wrote:
Hello,
Sorry if I am wrong, but it seems to me that the change in r54588 has a problem: http://mail.python.org/pipermail/python-3000-checkins/2007-March/000433.html - in the normal case, the return value is INCREF'ed twice - in the error case, PyINCREF(NULL) is called... One easy way to correct this is to move the last INCREF: (sorry for the approximative patch format) python/branches/p3yk/Objects/typeobject.c: ================================================= static PyObject * objectrichcompare(PyObject *self, PyObject *other, int op) { PyObject *res; switch (op) { case PyEQ: res = (self == other) ? PyTrue : PyFalse; + PyINCREF(res); break; case PyNE: /* By default, != returns the opposite of ==, unless the latter returns NotImplemented. */ res = PyObjectRichCompare(self, other, PyEQ); if (res != NULL && res != PyNotImplemented) { int ok = PyObjectIsTrue(res); PyDECREF(res); if (ok < 0) res = NULL; else { if (ok) res = PyFalse; else res = PyTrue; PyINCREF(res); } } break; default: res = PyNotImplemented; + PyINCREF(res); break; } - PyINCREF(res); return res; }
It looks right, although you could also remove the INCREF in Py_NE and change the INCREF at the bottom to XINCREF or just return on the error.
-Brett
- Previous message: [Python-3000] [Python-3000-checkins] r54588
- Next message: [Python-3000] [Python-3000-checkins] r54588
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]