Defining custom types

Robert Kern robert.kern at gmail.com
Thu Oct 26 19:49:25 EDT 2006


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


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list