
Sorry to bringing this up again. I was hoping we were done with that. When discussing the name of the Py_SETREF macro I was supposed to add a pair of macros: for Py_DECREF and Py_XDECREF. But I got a lot of opinions to be limited to only one macro. On 28.02.14 15:58, Kristján Valur Jónsson wrote:
Also, for the equivalence to hold there is no separate Py_XSETREF, the X behaviour is implied, which I favour. Enough of this X-proliferation already!
On 16.12.15 16:53, Random832 wrote:
I think "SET" names imply that it's safe if the original reference is NULL. This isn't an objection to the names, but if it is given one of those names I think it should use Py_XDECREF.
It was my initial intension. But then I had got a number of voices for single macros. On 16.12.15 23:16, Victor Stinner wrote:
I would prefer a single macro to avoid bugs, I don't think that such macro has a critical impact on performances. It's more designed for safety, no?
On 17.12.15 08:22, Nick Coghlan wrote:
1. Py_SETREF
+1 if it always uses Py_XDECREF on the previous value (as I'd expect this to work even if the previous value was NULL)
There was no (besides my) clearly expressed vote for two macros. As a result I have replaced both Py_DECREF and Py_XDECREF with the macro that always uses Py_XDECREF. Now Raymond, who was not involved in the previous discussions, expressed the view that we should to rename Py_SETREF to Py_XSETREF and add new Py_SETREF that uses Py_DECREF for using in the code that used Py_DECREF previously. [1] We should discuss the need for this, and may be re-discuss the names for the macros. [1] http://bugs.python.org/issue26200

On 12 February 2016 at 19:45, Serhiy Storchaka <storchaka@gmail.com> wrote:
Now Raymond, who was not involved in the previous discussions, expressed the view that we should to rename Py_SETREF to Py_XSETREF and add new Py_SETREF that uses Py_DECREF for using in the code that used Py_DECREF previously. [1]
We should discuss the need for this, and may be re-discuss the names for the macros.
I'm inclined to go with the resolution discussed later in the comments on that tracker issue - switch to spelling out the details when you want to avoid the Py_XDECREF inside the Py_SETREF macro. As Raymond notes, if you're wanting to manage when and how DECREF's occur, you may not want to hide them inside another macro at all. I'm also wondering if it may be worth adding some notes about reference counting to PEP 7, such as: * using Py_RETURN_NONE/FALSE/TRUE * using Py_CLEAR * using Py_SETREF (but being free to avoid it if you want to use Py_DECREF instead or are hand-optimising the code in some other way) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On 02/12/2016 10:45 AM, Serhiy Storchaka wrote:
Sorry to bringing this up again. I was hoping we were done with that.
When discussing the name of the Py_SETREF macro I was supposed to add a pair of macros: for Py_DECREF and Py_XDECREF. But I got a lot of opinions to be limited to only one macro.
There was no (besides my) clearly expressed vote for two macros.
I would have voted in favor. Spelling the SETREF out, as Nick proposes, kind of defies the purpose of the macro: it's not strictly a convenience macro, it helps prevent refcounting bugs.
As a result I have replaced both Py_DECREF and Py_XDECREF with the macro that always uses Py_XDECREF.
Can you roughly say which fraction of replacements changed DECREF to an implicit XDECREF? Georg

On 12.02.16 15:43, Georg Brandl wrote:
On 02/12/2016 10:45 AM, Serhiy Storchaka wrote:
Sorry to bringing this up again. I was hoping we were done with that.
When discussing the name of the Py_SETREF macro I was supposed to add a pair of macros: for Py_DECREF and Py_XDECREF. But I got a lot of opinions to be limited to only one macro.
There was no (besides my) clearly expressed vote for two macros.
I would have voted in favor.
Spelling the SETREF out, as Nick proposes, kind of defies the purpose of the macro: it's not strictly a convenience macro, it helps prevent refcounting bugs.
As a result I have replaced both Py_DECREF and Py_XDECREF with the macro that always uses Py_XDECREF.
Can you roughly say which fraction of replacements changed DECREF to an implicit XDECREF?
Changesets c4e8751ce637, bc7c56a225de, 539ba7267701, b02d256b8827, 1118dfcbcc35. Rough estimation: Py_DECREF - 62 Py_XDECREF - 57 Py_CLEAR - 46 Total statistic of using macros in current code: Py_SETREF 174 2.5% Py_CLEAR 781 11% Py_XDECREF 1443 20.5% Py_DECREF 4631 66%
participants (3)
-
Georg Brandl
-
Nick Coghlan
-
Serhiy Storchaka