-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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.
- Loading branch information
Showing
8 changed files
with
66 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters