Repository navigation
PyMemberDef missing in limited API / Deprecate structmember.h #47146
Description
Activity
As the comment in descrobject.c says:
/* Why is this not included in Python.h? */
- addedtype-featureA feature request or enhancementA feature request or enhancementinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on May 16, 2008 We could include it in Py3k.
Note that structmember.h pollutes global namespace with macros that do not
have conventional Py_ or PY_ prefix. READONLY and RESTRICTED macros seem
to be most likely to conflict with other code. I would be -0 on including tructmember.h in Python.h if flags macros are not properly renamed. +0
otherwise. T_* macros are probably OK, but T prefix is reminiscent of
popular (in some circles) Taligent naming conventions:http://pcroot.cern.ch/TaligentDocs/TaligentOnline/DocumentRoot/1.0/Docs/bo
oks/WM/WM_63.html#HEADING77Martin, do you want to make the call on this one?
I agree with Alexander; the header shouldn't be included into Python.h
as-is.I would propose to eliminate it eventually, with the following steps:
- move PyMemberDef and the function declarations into object.h
- (simultaneously) introduce properly-prefixed macros in object.h
- deprecate structmember.h
- remove it
I am attaching a patch that implements steps 1 and 2 of Martin's plan. There are over 50 files that include structmember.h. I am not sure it is worth the trouble to update all those files before structmember.h is actually removed. If we agree that this is the right way forward, I'll make the necessary changes to the docs.
I would also like this opportunity to rename T_PYSSIZET to something more readable: maybe PY_T_PY_SSIZE_T or PY_T_SSIZE_T.
Please don't forget to use "hg copy" for creating object.h from structmember.h. This preserves the history.
structmember.h should be implemented using object.h. Include object.h and add aliases.
Only READONLY flag is used in 3.x (bpo-28349). Other flags can be removed.
17 remaining items
The proposed patch here, would fix this!
The issue title is misleading, it says "Deprecate structmember.h". Is the plan still to deprecate it? Or to make it usable in the limited C API? Please update the title.
Note that structmember.h pollutes global namespace with macros that do not have conventional Py_ or PY_ prefix. READONLY and RESTRICTED macros seem to be most likely to conflict with other code.
One small enhance would be to add such prefix when Py_LIMITED_API is defined.
The issue title is misleading, it says "Deprecate structmember.h". Is the plan still to deprecate it? Or to make it usable in the limited C API? Please update the title.
As far as I understand it: The attached diff, moves the interesting declaration to
object.hsolving the limited API problem. And only leaves structmember.h around for backward compatibility for people using the "old" namesREADONLYorRESTRICTED. So in that sense it does deprecate structmember.hBut indeed I hijacked this issue with my complaints about the limited API which may not have been the original intention here, but they get solved nonetheless.
Also, the bare minimum enhancement would be add rename READONLY to PY_READONLY, but keep a deprecated alias READONLY to PY_READONLY, and update CPython code base to use PY_READONLY. (Same for other similar flags.)
- changed the title
[-]Deprecate structmember.h[/-][+]PyMemberDef missing in limited API / Deprecate structmember.h[/+]on May 27, 2020 Happy to take the proposed diff here (assuming @belopolsky wont mind) and include it into a pull request that also renames the uses of the READONLY flags (and maybe removes the RESTRICTED flags) within cpython source itself.
While working on the pull request I felt that the type and constants better fit
descrobject.hrather thanobject.h.I ran into this issue, so I made a PR: #99014
The twist is that old code doesn't need to change. That would be unnecessary churn. Keeping a few weirdly named aliases around is not a maintenance burden, and since they need the extra header they won't pollute new code.- added a commit that references this issue
on Nov 22, 2022 - added a commit that references this issue
on Jul 21, 2023
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: