You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-02-13.03:23:38.855>labels= ['expert-C-API', 'type-feature']
title='PyObject_GetAttrString and tp_getattr do not agree'updated_at=<Date2021-06-22.14:42:14.566>user='https://github.com/petdance'
The outer PyObject_GetAttrString takes a const char *name, but then casts away the const when calling the underlying tp_getattr. This means that an underlying function would be free to modify or free() the char* passed in to it, which might be, for example, a string literal, which would be a Bad Thing.
The setattr function pair has the same problem.
The API doc at https://docs.python.org/3/c-api/typeobj.html says that the tp_getattr and tp_setattr slots are deprecated. If they're not going away soon, I would think this should be addressed.
Fixing this in the cPython code by making tp_getattr and tp_setattr take const char * pointers would be simple. I don't have any idea how much outside code it would affect.
Do you know why it was reverted? (Granted, it was 15 years ago...)
It looks like the original changeset is trying to address at least two different problems with non-const string literals. My ticket here is focusing only on getattrfunc and setattrfunc. The handling of all the kwlist is a separate issue, that I'm about to write up as a different ticket.
It was reverted because it is backward incompatible change. It breaks a code which assigns to the tp_getattr field without explicit type cast to getattrfunc.
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: