PyRun_String
Duncan Booth
duncan.booth at invalid.invalid
Thu Mar 9 14:06:54 EST 2006
Matthias wrote:
> Log("Marker 1");
> Py_XDECREF( PyRun_String( "print 'Hi!'", Py_single_input, Dict, Dict) );
> Log("Marker 2");
>
> The output looks like
>
> Marker 1
> Hi!
> Hi!
> Marker 2
>
> Obviously Hi! is printed twice.
Py_XDECREF is a C macro. If you check its definition you will see that it
does indeed evaluate the argument twice. This is a not uncommon problem
when using macros in C: if in doubt, do not call a macro with anything
as a parameter which has side effects.
#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
More information about the Python-list
mailing list