From: Robert K. <rob...@gm...> - 2006-10-26 23:49:58
|
Jonathan Wang wrote: > It's just confusing as the documentation indicates that the setitem > function should return 0 for success and a negative number for failure. > But within Array_FromPyScalar, we have: > > ret->descr->f->setitem(op, ret->data, ret); > > if (PyErr_Occurred()) { > Py_DECREF(ret); > return NULL; > } else { > return (PyObject *)ret; > } > > So, someone reading the documentation could return -1 on failure without > setting the Python error flag, and the function would happily continue > on its way and fail to perform the proper casts. That's a documentation vagueness, then. This is a convention established by the Python C API. If an error happens in a function that returns PyObject*, then it should return NULL to inform the caller that an error happened; other functions should return 0 for success and -1 for an error. However, the function must still set an exception object. The rest is just a convenient convention. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |