Re: PROPOSAL: A Generic Python Object Interface for Python C Modules

Jim Fulton (jfulton@qvarsx.er.usgs.GOV)
Wed, 22 Mar 1995 00:13:53 GMT

The subject proposal contains a note that would be, I thought, a bit
controversial:

1
Some special routines currently return 0 on success and -1 on
failure. In the proposal above, I return 1 on success and 0 on
failure. This makes error checking more consistent. For example, I
find the following macro very useful:

#define TRY(E) if(! (E)) return NULL;

This allows things like:

TRY(spam=PySequence_getitem(o,i));

which I find more readable (especially if there are a lot of these)
than:

if(! (spam=PySequence_getitem(o,i))
return NULL;

or:

spam=PySequence_getitem(o,i);
if(! spam)
return NULL;

The proposed change in return semantics could be implemented by an
abstraction layer without changing existing code.

I would say that most integer Python C routines return -1 to indicate
failure. Some very noticable exceptions are getargs and newgetargs.
In my proposal, PyObject_Hash, PyObject_Length, PySequence_Count,
PySequence_In, PySequence_Index, PyMapping_Length return -1 on
failure. Other integer functions in my propsal return 0 on failure.

Does anyone have an opinion on this?

--
-- Jim Fulton      jfulton@mailqvarsa.er.usgs.gov    (703) 648-5622
                   U.S. Geological Survey, Reston VA  22092 
This message is being posted to obtain or provide technical information
relating to my duties at the U.S. Geological Survey.