[Python-Dev] cpython: Add Py_RETURN_NOTIMPLEMENTED macro. Fixes #12724.

Antoine Pitrou solipsis at pitrou.net
Mon Aug 15 15:29:48 CEST 2011


On Mon, 15 Aug 2011 15:21:43 +0200
Stefan Behnel <stefan_ml at behnel.de> wrote:

> Nick Coghlan, 15.08.2011 14:35:
> > On Mon, Aug 15, 2011 at 10:17 PM, Antoine Pitrou<solipsis at pitrou.net>  wrote:
> >> AFAICT, often with True and False:
> >>
> >>     x = (some condition) ? Py_True : Py_False;
> >>     Py_INCREF(x);
> >>     return x;
> >
> > And that's an idiom that works better with a Py_RETURN macro than it
> > would separate macros:
> >
> > Py_RETURN(cond ? Py_True : Py_False);
> 
> And that would do what exactly? Duplicate the evaluation of the condition?

You don't need to.

#define Py_RETURN (x) do { \
     PyObject *_tmp = (x); \
     Py_INCREF(_tmp);      \
     return _tmp;          \
} while(0)





More information about the Python-Dev mailing list