[Python-Dev] Re: Proposal: C API Macro to decref and set to NULL
David Abrahams
dave at boost-consulting.com
Fri Jul 16 01:25:46 CEST 2004
Tim Peters <tim.peters at gmail.com> writes:
> [Jim Fulton]
> ...
>> If there are no objections I'll add the following definition to object.h,
>> after the definition for Py_DECREF:
>>
>> #define Py_CLEAR(op) \
>> do { \
>> if (op) { \
>> PyObject *tmp = (op); \
>> (op) = NULL; \
>> Py_DECREF(tmp); \
>> } \
>> } while (0)
>>
>> and update the docs and the tutorial on creating types in C.
>
> +1. At least pystate.c can get rid of its functionally identical
> private ZAP macro then.
FWIW our experience in the C++ community suggests that
deallocate-and-NULL tends to hide bugs. In general we prefer to use
deallocate-and-fill-pointer-with-garbage. I'm not sure if the
experience translates here, of course.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Python-Dev
mailing list