This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients pablogsal, serhiy.storchaka
Date 2021-09-29.19:48:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632944934.76.0.0308250067474.issue45325@roundup.psfhosted.org>
In-reply-to
Content
There was no much need of this feature. In rare cases when we needed to build a bool in Py_BuildValue (I have found only 2 cases in the stdlib, and one of them is added by me) we use the following idiom:

   Py_BuildValue("...O...", ..., expr ? Py_True : Py_False, ...)

You can have a temptation to write it as

   Py_BuildValue("...p...", ..., expr, ...)

but there is a catch -- the arguments should be a C int. If it is not, you can break a stack. Explicit cast to int ("(int)expr") is not always correct, so you will need to write "expr ? 1 : 0" which is not much better than "expr ? Py_True : Py_False".
History
Date User Action Args
2021-09-29 19:48:54serhiy.storchakasetrecipients: + serhiy.storchaka, pablogsal
2021-09-29 19:48:54serhiy.storchakasetmessageid: <1632944934.76.0.0308250067474.issue45325@roundup.psfhosted.org>
2021-09-29 19:48:54serhiy.storchakalinkissue45325 messages
2021-09-29 19:48:54serhiy.storchakacreate