[Python-Dev] Py_DECREF causes spurious gcc warning (original) (raw)

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Wed Dec 17 20:14:27 EST 2003


From: Skip Montanaro

_#define PyDECREF(op) _ _if (PyDECREFTOTAL PyREFDEBUGCOMMA _ _--(op)->obrefcnt != 0) { _ _PyCHECKREFCNT(op) _ _} else { _ _PyDealloc((PyObject *)(op)) _ } PyINCREF would be left alone, and the X variants would become #define PyXINCREF(op) if ((op) == NULL) {;} else { PyINCREF(op) } #define PyXDECREF(op) if ((op) == NULL) {;} else {PyDECREF(op) }

Then you will probably end up with different warnings - semicolons following closing braces, etc.

As Tim Peters said, the way to deal with that is to enclose the entire bit in a do ( ... } while (0) no-op (after the compiler optimises it away) but that - as he rightly pointed out - is pretty blecherous.

#define Py_XINCREF(op) do { if ((op) != NULL) { Py_INCREF(op) } } while (0) #define Py_XDECREF(op) do { if ((op) != NULL) { Py_DECREF(op) } } while (0)

or

#define Py_XINCREF(op) do { if ((op) != NULL) Py_INCREF(op) } while (0) #define Py_XDECREF(op) do { if ((op) != NULL) Py_DECREF(op) } while (0)

Tim Delaney



More information about the Python-Dev mailing list