initproc is declared to return an int, but what returned values mean is not documented. Noddy_init in http://docs.python.org/3/extending/newtypes.html?highlight=initproc#adding-data-and-methods-to-the-basic-example can be seen to return 0 on success and -1 on error, but that's about it. Also, when I wrote a function which return 1 on error, on every second invocation the exception would be ignored: static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { ... if (flags && path) { PyErr_SetString(PyExc_ValueError, "cannot use both flags and path"); return 1; } ... } >>> obj(123, '/tmp') >>> obj(123, '/tmp') ... ValueError >>> obj(123, '/tmp') >>> obj(123, '/tmp') ... ValueError I'm not sure how to interpret this since I couldn't find the documentation for the expected value.
The return value for error conditions should be -1. - typeobject.c checks with "< 0" - in _iomodule.c, there is "== -1" - and pygobject/gobject/gobjectmodule.c just does:: if (...tp_init(...)) PyErr_Print();
On Fri, Mar 08, 2013 at 02:30:18PM +0000, Amaury Forgeot d'Arc wrote: > > Amaury Forgeot d'Arc added the comment: > > The return value for error conditions should be -1. > > - typeobject.c checks with "< 0" > - in _iomodule.c, there is "== -1" > - and pygobject/gobject/gobjectmodule.c just does:: > if (...tp_init(...)) > PyErr_Print(); That's not very nice. Would it make sense to unify those checks, e.g. for "initproc() < 0"? Than the documentation could be updated. Zbyszek