mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-106320: Remove private _Py_Identifier API (#108593)
Remove the private _Py_Identifier type and related private functions from the public C API: * _PyObject_GetAttrId() * _PyObject_LookupSpecialId() * _PyObject_SetAttrId() * _PyType_LookupId() * _Py_IDENTIFIER() * _Py_static_string() * _Py_static_string_init() Move them to the internal C API: add a new pycore_identifier.h header file. No longer export these functions.
This commit is contained in:
parent
88f1c5b454
commit
4fb96a11db
8 changed files with 66 additions and 46 deletions
|
|
@ -19,43 +19,6 @@ PyAPI_FUNC(Py_ssize_t) _PyInterpreterState_GetRefTotal(PyInterpreterState *);
|
|||
#endif
|
||||
|
||||
|
||||
/********************* String Literals ****************************************/
|
||||
/* This structure helps managing static strings. The basic usage goes like this:
|
||||
Instead of doing
|
||||
|
||||
r = PyObject_CallMethod(o, "foo", "args", ...);
|
||||
|
||||
do
|
||||
|
||||
_Py_IDENTIFIER(foo);
|
||||
...
|
||||
r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
|
||||
|
||||
PyId_foo is a static variable, either on block level or file level. On first
|
||||
usage, the string "foo" is interned, and the structures are linked. On interpreter
|
||||
shutdown, all strings are released.
|
||||
|
||||
Alternatively, _Py_static_string allows choosing the variable name.
|
||||
_PyUnicode_FromId returns a borrowed reference to the interned string.
|
||||
_PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
|
||||
*/
|
||||
typedef struct _Py_Identifier {
|
||||
const char* string;
|
||||
// Index in PyInterpreterState.unicode.ids.array. It is process-wide
|
||||
// unique and must be initialized to -1.
|
||||
Py_ssize_t index;
|
||||
} _Py_Identifier;
|
||||
|
||||
#ifndef Py_BUILD_CORE
|
||||
// For now we are keeping _Py_IDENTIFIER for continued use
|
||||
// in non-builtin extensions (and naughty PyPI modules).
|
||||
|
||||
#define _Py_static_string_init(value) { .string = (value), .index = -1 }
|
||||
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
|
||||
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
|
||||
|
||||
#endif /* !Py_BUILD_CORE */
|
||||
|
||||
typedef struct {
|
||||
/* Number implementations must check *both*
|
||||
arguments for proper type and implement the necessary conversions
|
||||
|
|
@ -273,8 +236,6 @@ typedef struct _heaptypeobject {
|
|||
|
||||
PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *);
|
||||
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
|
||||
PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
|
||||
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *);
|
||||
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, PyModuleDef *);
|
||||
PyAPI_FUNC(PyObject *) PyType_GetDict(PyTypeObject *);
|
||||
|
||||
|
|
@ -282,9 +243,6 @@ PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
|
|||
PyAPI_FUNC(void) _Py_BreakPoint(void);
|
||||
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
|
||||
|
||||
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
|
||||
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, _Py_Identifier *, PyObject *);
|
||||
|
||||
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
|
||||
PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
|
||||
PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ extern "C" {
|
|||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#include "pycore_identifier.h" // _Py_Identifier
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
|
||||
/* Suggested size (number of positional arguments) for arrays of PyObject*
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#include "pycore_identifier.h" // _Py_Identifier
|
||||
#include "pycore_object.h" // PyDictOrValues
|
||||
|
||||
// Unsafe flavor of PyDict_GetItemWithError(): no error checking
|
||||
|
|
|
|||
54
Include/internal/pycore_identifier.h
Normal file
54
Include/internal/pycore_identifier.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* String Literals: _Py_Identifier API */
|
||||
|
||||
#ifndef Py_INTERNAL_IDENTIFIER_H
|
||||
#define Py_INTERNAL_IDENTIFIER_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef Py_BUILD_CORE
|
||||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
/* This structure helps managing static strings. The basic usage goes like this:
|
||||
Instead of doing
|
||||
|
||||
r = PyObject_CallMethod(o, "foo", "args", ...);
|
||||
|
||||
do
|
||||
|
||||
_Py_IDENTIFIER(foo);
|
||||
...
|
||||
r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
|
||||
|
||||
PyId_foo is a static variable, either on block level or file level. On first
|
||||
usage, the string "foo" is interned, and the structures are linked. On interpreter
|
||||
shutdown, all strings are released.
|
||||
|
||||
Alternatively, _Py_static_string allows choosing the variable name.
|
||||
_PyUnicode_FromId returns a borrowed reference to the interned string.
|
||||
_PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
|
||||
*/
|
||||
typedef struct _Py_Identifier {
|
||||
const char* string;
|
||||
// Index in PyInterpreterState.unicode.ids.array. It is process-wide
|
||||
// unique and must be initialized to -1.
|
||||
Py_ssize_t index;
|
||||
} _Py_Identifier;
|
||||
|
||||
// For now we are keeping _Py_IDENTIFIER for continued use
|
||||
// in non-builtin extensions (and naughty PyPI modules).
|
||||
|
||||
#define _Py_static_string_init(value) { .string = (value), .index = -1 }
|
||||
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
|
||||
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
|
||||
|
||||
extern PyObject* _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
|
||||
extern PyObject* _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *);
|
||||
extern PyObject* _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
|
||||
extern int _PyObject_SetAttrId(PyObject *, _Py_Identifier *, PyObject *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // !Py_INTERNAL_IDENTIFIER_H
|
||||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "pycore_fileutils.h" // _Py_error_handler
|
||||
#include "pycore_identifier.h" // _Py_Identifier
|
||||
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
|
||||
|
||||
/* --- Characters Type APIs ----------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -1769,6 +1769,7 @@ PYTHON_HEADERS= \
|
|||
$(srcdir)/Include/internal/pycore_global_objects_fini_generated.h \
|
||||
$(srcdir)/Include/internal/pycore_hamt.h \
|
||||
$(srcdir)/Include/internal/pycore_hashtable.h \
|
||||
$(srcdir)/Include/internal/pycore_identifier.h \
|
||||
$(srcdir)/Include/internal/pycore_import.h \
|
||||
$(srcdir)/Include/internal/pycore_initconfig.h \
|
||||
$(srcdir)/Include/internal/pycore_interp.h \
|
||||
|
|
|
|||
|
|
@ -235,6 +235,7 @@
|
|||
<ClInclude Include="..\Include\internal\pycore_global_objects_fini_generated.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_hamt.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_hashtable.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_identifier.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_import.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_initconfig.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_interp.h" />
|
||||
|
|
@ -248,7 +249,7 @@
|
|||
<ClInclude Include="..\Include\internal\pycore_object_state.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_obmalloc.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_obmalloc_init.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_optimizer.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_optimizer.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_pyarena.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_pyerrors.h" />
|
||||
|
|
@ -280,7 +281,7 @@
|
|||
<ClInclude Include="..\Include\internal\pycore_unionobject.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_unicodeobject.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_unicodeobject_generated.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_uops.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_uops.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_warnings.h" />
|
||||
<ClInclude Include="..\Include\internal\pycore_weakref.h" />
|
||||
<ClInclude Include="..\Include\interpreteridobject.h" />
|
||||
|
|
|
|||
|
|
@ -609,6 +609,9 @@
|
|||
<ClInclude Include="..\Include\internal\pycore_hashtable.h">
|
||||
<Filter>Include\internal</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Include\internal\pycore_identifier.h">
|
||||
<Filter>Include\internal</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Include\internal\pycore_import.h">
|
||||
<Filter>Include\internal</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -650,7 +653,7 @@
|
|||
</ClInclude>
|
||||
<ClInclude Include="..\Include\internal\pycore_optimizer.h">
|
||||
<Filter>Include\internal</Filter>
|
||||
</ClInclude>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Include\internal\pycore_pathconfig.h">
|
||||
<Filter>Include\internal</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -737,7 +740,7 @@
|
|||
</ClInclude>
|
||||
<ClInclude Include="..\Include\internal\pycore_uops.h">
|
||||
<Filter>Include\internal</Filter>
|
||||
</ClInclude>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(zlibDir)\crc32.h">
|
||||
<Filter>Modules\zlib</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue