New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Py_(X)SETREF macros #47331
Comments
This is an implementation of the Py_SETREF and Py_XSETREF macros As an example, I added a few conversions among the extension modules. |
FWIW, I also wanted to propose for Py_INCREF(op) to evaluate as (op), so but it's perhaps a bit more controversial. |
Benjamin, the patch is against py3k, also it might also apply cleanly on |
Sorry for the confusion. It seems to me this sort of thing would be |
A comment on the patch: Since object.h may be included from C++ extensions, you should not use a |
This new patch avoids using temporary variables named "new", it also |
-1 on the new macros. The mnemonic doesn't work for me and the example Assigning from an INCREF feels weird. It is somewhat at odds with our |
Le samedi 28 juin 2008 à 20:12 +0000, Raymond Hettinger a écrit :
They might not be ideal, but I think they can be helpful to avoid
Ok. |
Just to note, I proposed similar macro on the mailing list under the |
The name suggests a different behavior to me - I assumed it would set the reference count to a specific value. Maybe this is the kind of thing Raymond had in mind when he said "The mnemonic doesn't work for me". |
Py_ASSIGN could be a better name, but given the enthusiasm generated by this proposal, I think we might just as well close the issue. |
I agree with Raymond about the Py_INCREF. I could see more uses for this macro without the Py_INCREF, especially for things like in-place arithmetic operations. The following pattern appears a lot in code like Objects/longobject.c: Old code: /* add one to x */
temp = PyNumber_Add(x, one);
Py_DECREF(x);
x = temp;
if (x == NULL)
return NULL; With a non-INCREF version of Py_SETREF: /* add one to x */
Py_SETREF(x, PyNumber_Add(x, one));
if (x == NULL)
return NULL; |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: