Title: [C API] PyUnicode_CHECK_INTERNED() doesn't work in the limited C API
Type: Stage: resolved
Components: C API Versions: Python 3.11, Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, petr.viktorin, vstinner
Priority: normal Keywords: patch

Created on 2021-12-07 17:34 by vstinner, last changed 2021-12-09 09:00 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29987 merged vstinner, 2021-12-08 11:44
Messages (3)
msg407955 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-12-07 17:34
The PyUnicode_CHECK_INTERNED() macro uses the PyASCIIObject structure which is *excluded* from the limited C API:

/* Use only if you know it's a string */
#define PyUnicode_CHECK_INTERNED(op) \
    (((PyASCIIObject *)(op))->state.interned)

Using this macro in the limited C API doesn't work.

I propose to remove it from the limited C API.

IMO it's not a good idea to fix the function in the limited C API by converting it to a regular function hiding the implementation details and so working at the ABI level. We should not expose such "implementation detail" (if a string is "interned or not") in the *limited* C API.
msg408007 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-12-08 10:41
+1, PyUnicodeObject/PyASCIIObject is excluded from the limited API since Python 3.2, so it wasn't possible to use this macro.
msg408086 - (view) Author: miss-islington (miss-islington) Date: 2021-12-09 08:58
New changeset 73325bbe774b16891f999fb557177206470676b1 by Victor Stinner in branch 'main':
bpo-46007: Exclude PyUnicode_CHECK_INTERNED() from limited C API (GH-29987)
Date User Action Args
2021-12-09 09:00:19vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-12-09 08:58:21miss-islingtonsetnosy: + miss-islington
messages: + msg408086
2021-12-08 11:44:02vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request28210
2021-12-08 10:41:28petr.viktorinsetmessages: + msg408007
2021-12-07 17:34:31vstinnersetnosy: + petr.viktorin
2021-12-07 17:34:25vstinnercreate