[Python-Dev] warnings --with-pydebug

Thomas Wouters thomas@xs4all.net
Sat, 14 Oct 2000 01:33:59 +0200


On Fri, Oct 13, 2000 at 07:11:10PM -0400, Jeremy Hylton wrote:
> If you configure using '--with-pydebug' you get a lot of compile-time
> warnings. 

> ../../Python/ceval.c: In function `eval_code2':
> ../../Python/ceval.c:672: warning: value computed is not used
> ../../Python/ceval.c:675: warning: value computed is not used
> ../../Python/ceval.c:678: warning: value computed is not used
> ../../Python/ceval.c:680: warning: value computed is not used
> ../../Python/ceval.c:681: warning: value computed is not used
> [etc.]

> I assume these are caused by the definition of Py_INCREF
> #define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++)

> Is there some way to change this macro so that the warnings are
> silenced? 

Yes, prefix it with '(void)':

#define Py_INCREF(op) (void)(_Py_RefTotal++, (op)->ob_refcnt++)

However, that means that the 'return value' of Py_INCREF() must never be
used anywhere. (If it does, it'll generate an error.) The return value of
Py_INCREF() is not terribly useful, though. Both in debug and in normal
mode, it expands to the refcount of the object *before* it was INCREF'd.

I still consider this kind of warning (I've seen it before, always with
macros that do several things by using the otherwise fairly useless
tuple-creator in C ;) a bit of a bug in gcc: it knows both those statements
have sideeffects, and it's obvious we want to throw away the first result,
so why worry about the second ? But at least it isn't screwing up
floating-point operations, and nobody's perfect :-)

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!