[capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare?

Gustavo Carneiro gjcarneiro at gmail.com
Mon Dec 17 12:23:59 CET 2012


On Thu, Dec 13, 2012 at 4:21 PM, Robert Steckroth <robertsteckroth at gmail.com
> wrote:

> Does the below statement have a memory leak?
>
> if ( PyObject_Compare(update_var, Py_False)
>
> Do I need to assign the Py_False first and DECREF it, or is the above
> snippet ok alone.
>

It's safe, but note that it is more correct to use PyObject_IsTrue: there
are more values that can be considered true or false, besides python's True
and False objects.

if (!PyObject_IsTrue(update_var)) { ... }

-- 
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic." -- Frank Herbert


More information about the capi-sig mailing list