[Python-Dev] PyNumber_*() binary operations & coercion (original) (raw)
Guido van Rossum guido@beopen.com
Wed, 23 Aug 2000 18:28:03 -0500
- Previous message: [Python-Dev] PyNumber_*() binary operations & coercion
- Next message: [Python-Dev] PyNumber_*() binary operations & coercion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
While re-writing the PyNumberInPlace*() functions in augmented assignment to something Guido and I agree on should be the Right Way, I found something that might be a bug. But I'm not sure.
The PyNumber*() methods for binary operations (found in abstract.c) have the following construct: if (v->obtype->tpasnumber != NULL) { PyObject *x = NULL; PyObject * (*f)(PyObject *, PyObject *); if (PyNumberCoerce(&v, &w) != 0) return NULL; if ((f = v->obtype->tpasnumber->nbxor) != NULL) x = (*f)(v, w); PyDECREF(v); PyDECREF(w); if (f != NULL) return x; } (This is after a check if either argument is an instance object, so both are C objects here.) Now, I'm not sure how coercion is supposed to work, but I see one problem here: 'v' can be changed by PyNumberCoerce(), and the new object's tpasnumber pointer could be NULL. I bet it's pretty unlikely that (numeric) coercion of a numeric object and an unspecified object turns up a non-numeric object, but I don't see anything guaranteeing it won't, either. Is this a non-issue, or should I bother with adding the extra check in the current binary operations (and the new inplace ones) ?
I think this currently can't happen because coercions never return non-numeric objects, but it sounds like a good sanity check to add.
Please check this in as a separate patch (not as part of the huge augmented assignment patch).
--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)
- Previous message: [Python-Dev] PyNumber_*() binary operations & coercion
- Next message: [Python-Dev] PyNumber_*() binary operations & coercion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]