[Python-Dev] Py_DECREF causes spurious gcc warning

Zack Weinberg zack at codesourcery.com
Sat Dec 20 14:42:51 EST 2003

"Tim Peters" <tim.one at comcast.net> writes:

> [Zack Weinberg]
>>>> It does, however, lead to a different problem:
>>>>   if (condition)
>>>>     Py_DECREF (foo);
>>>>   else               // oops, syntax error here
> [Martin v. Löwis]
>>> How so? This expands to
>>> if(condition)
>>>   if(cond2)action1;
>>>   else action2;
>>> else
> [Zack]
>> No, it expands to
>>  if(condition)
>>   if(cond2) action1;
>>   else action2;;
>>  else
>> -- note the extra semicolon, which provokes a syntax error.
> Zack, which version of Python are you using?  The current definition of
> Py_DECREF doesn't end with a semicolon:

I thought you might come back at me with that.  Yes, you can avoid the
syntax error by carefully leaving off the semicolon here.  I don't
consider this to be good style, though.  It's easy to forget, and it's
easy for someone to come along later and be confused and check in an
'obvious' patch that adds a semicolon - and it might not even break
anything... then.

I'm really not speaking about the python source code in specific.  I'm
speaking about general style principles, and I really do think it is
good style *always* to wrap complex macros in do { } while (0) whether
or not they need it.


More information about the Python-Dev mailing list