[sr-dev] [kamailio/kamailio] python3: `PyErr_SetString` is a void function. It doesn't return NULL. (PR #3231)

Matthias Urlichs notifications at github.com
Fri Sep 2 16:54:09 CEST 2022


Just compile the old code! You get a ton of warnings that PyErr_SetString "returns" `void`.

Python has, at heart, a very simple API. A C function **either** returns an object **or** it sets an exception (and returns NULL). Never both! (Or None for that matter.)

PyNone is a regular Python object. NULL is not, it's the API's marker for raising an exception.

Thus, the old code works perfectly well as long as it doesn't raise an exception. If/when it does, depending on the whims of the C compiler, the return value for the old version might be anything whatsoever. Even NULL if you're lucky.

Python has a ton of somewhat-higher-level error-generating functions which explicitly return NULL so that you can use the old construct but sadly PyErr_SetString is not one of these.

https://docs.python.org/3/c-api/exceptions.html

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3231#issuecomment-1235599065
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/pull/3231/c1235599065 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20220902/c55a8fbf/attachment.htm>


More information about the sr-dev mailing list