A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-May/079864.html below:

[Python-Dev] Py_SETREF/Py_XSETREF (was: Why is type_modified() in typeobject.c not a public function?)

[Python-Dev] Py_SETREF/Py_XSETREF (was: Why is type_modified() in typeobject.c not a public function?) [Python-Dev] Py_SETREF/Py_XSETREF (was: Why is type_modified() in typeobject.c not a public function?)Stefan Behnel stefan_ml at behnel.de
Thu May 29 11:55:38 CEST 2008
Antoine Pitrou wrote:
> Stefan Behnel <stefan_ml <at> behnel.de> writes:
>> BTW, I noticed that the code in typeobject.c uses "DECREF before set" two
>> times, like this:
>>
>> 		method_cache[h].version = type->tp_version_tag;
>> 		method_cache[h].value = res;  /* borrowed */
>> 		Py_INCREF(name);
>> 		Py_DECREF(method_cache[h].name);
>> 		method_cache[h].name = name;
> 
> Since this is so common, would it be useful to define a macro for the correct
> construct?
> 
> Something like
> 
> #define Py_SETREF(var, obj) \
>     { PyObject *tmp = (var); Py_INCREF(obj); \
>       (var) = (obj); Py_XDECREF(tmp); }
> 
> Or, if we want to allow more optimizations, make two versions of it:
> 
> #define Py_SETREF(var, obj) \
>     { PyObject *tmp = (var); Py_INCREF(obj); \
>       (var) = (obj); Py_DECREF(tmp); }
> 
> #define Py_XSETREF(var, obj) \
>     { PyObject *tmp = (var); Py_INCREF(obj); \
>       (var) = (obj); Py_XDECREF(tmp); }

Both sound like a good idea to me. Having to think about whether or not DECREF
poses a problem in a specific case is just cumbersome.

Stefan

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4