@@ -14,6 +14,43 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
14
14
#endif
15
15
16
16
17
+ /********************* String Literals ****************************************/
18
+ /* This structure helps managing static strings. The basic usage goes like this:
19
+ Instead of doing
20
+
21
+ r = PyObject_CallMethod(o, "foo", "args", ...);
22
+
23
+ do
24
+
25
+ _Py_IDENTIFIER(foo);
26
+ ...
27
+ r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
28
+
29
+ PyId_foo is a static variable, either on block level or file level. On first
30
+ usage, the string "foo" is interned, and the structures are linked. On interpreter
31
+ shutdown, all strings are released.
32
+
33
+ Alternatively, _Py_static_string allows choosing the variable name.
34
+ _PyUnicode_FromId returns a borrowed reference to the interned string.
35
+ _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
36
+ */
37
+ typedef struct _Py_Identifier {
38
+ const char * string ;
39
+ // Index in PyInterpreterState.unicode.ids.array. It is process-wide
40
+ // unique and must be initialized to -1.
41
+ Py_ssize_t index ;
42
+ } _Py_Identifier ;
43
+
44
+ #if !defined(Py_BUILD_CORE ) || defined(Py_BUILD_CORE_MODULE )
45
+ // For now we are keeping _Py_IDENTIFIER for continued use
46
+ // in non-builtin extensions (and naughty PyPI modules).
47
+
48
+ #define _Py_static_string_init (value ) { .string = value, .index = -1 }
49
+ #define _Py_static_string (varname , value ) static _Py_Identifier varname = _Py_static_string_init(value)
50
+ #define _Py_IDENTIFIER (varname ) _Py_static_string(PyId_##varname, #varname)
51
+
52
+ #endif /* ! Py_BUILD_CORE */
53
+
17
54
/* buffer interface */
18
55
typedef struct bufferinfo {
19
56
void * buf ;
@@ -268,19 +305,24 @@ typedef struct _heaptypeobject {
268
305
269
306
PyAPI_FUNC (const char * ) _PyType_Name (PyTypeObject * );
270
307
PyAPI_FUNC (PyObject * ) _PyType_Lookup (PyTypeObject * , PyObject * );
308
+ PyAPI_FUNC (PyObject * ) _PyType_LookupId (PyTypeObject * , _Py_Identifier * );
271
309
PyAPI_FUNC (PyObject * ) _PyObject_LookupSpecial (PyObject * , PyObject * );
310
+ PyAPI_FUNC (PyObject * ) _PyObject_LookupSpecialId (PyObject * , _Py_Identifier * );
272
311
PyAPI_FUNC (PyTypeObject * ) _PyType_CalculateMetaclass (PyTypeObject * , PyObject * );
273
312
PyAPI_FUNC (PyObject * ) _PyType_GetDocFromInternalDoc (const char * , const char * );
274
313
PyAPI_FUNC (PyObject * ) _PyType_GetTextSignatureFromInternalDoc (const char * , const char * );
275
314
struct PyModuleDef ;
276
315
PyAPI_FUNC (PyObject * ) _PyType_GetModuleByDef (PyTypeObject * , struct PyModuleDef * );
277
316
317
+ struct _Py_Identifier ;
278
318
PyAPI_FUNC (int ) PyObject_Print (PyObject * , FILE * , int );
279
319
PyAPI_FUNC (void ) _Py_BreakPoint (void );
280
320
PyAPI_FUNC (void ) _PyObject_Dump (PyObject * );
281
321
PyAPI_FUNC (int ) _PyObject_IsFreed (PyObject * );
282
322
283
323
PyAPI_FUNC (int ) _PyObject_IsAbstract (PyObject * );
324
+ PyAPI_FUNC (PyObject * ) _PyObject_GetAttrId (PyObject * , struct _Py_Identifier * );
325
+ PyAPI_FUNC (int ) _PyObject_SetAttrId (PyObject * , struct _Py_Identifier * , PyObject * );
284
326
/* Replacements of PyObject_GetAttr() and _PyObject_GetAttrId() which
285
327
don't raise AttributeError.
286
328
@@ -291,6 +333,7 @@ PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
291
333
is raised.
292
334
*/
293
335
PyAPI_FUNC (int ) _PyObject_LookupAttr (PyObject * , PyObject * , PyObject * * );
336
+ PyAPI_FUNC (int ) _PyObject_LookupAttrId (PyObject * , struct _Py_Identifier * , PyObject * * );
294
337
295
338
PyAPI_FUNC (int ) _PyObject_GetMethod (PyObject * obj , PyObject * name , PyObject * * method );
296
339
@@ -309,50 +352,6 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
309
352
310
353
PyAPI_FUNC (PyObject * ) _PyObject_FunctionStr (PyObject * );
311
354
312
- /********************* String Literals ****************************************/
313
- /* This structure helps managing static strings. The basic usage goes like this:
314
- Instead of doing
315
-
316
- r = PyObject_CallMethod(o, "foo", "args", ...);
317
-
318
- do
319
-
320
- _Py_IDENTIFIER(foo);
321
- ...
322
- r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
323
-
324
- PyId_foo is a static variable, either on block level or file level. On first
325
- usage, the string "foo" is interned, and the structures are linked. On interpreter
326
- shutdown, all strings are released.
327
-
328
- Alternatively, _Py_static_string allows choosing the variable name.
329
- _PyUnicode_FromId returns a borrowed reference to the interned string.
330
- _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
331
- */
332
- typedef struct _Py_Identifier {
333
- const char * string ;
334
- // Index in PyInterpreterState.unicode.ids.array. It is process-wide
335
- // unique and must be initialized to -1.
336
- Py_ssize_t index ;
337
- } _Py_Identifier ;
338
-
339
- #if !defined(Py_BUILD_CORE ) || defined(Py_BUILD_CORE_MODULE )
340
- // For now we are keeping _Py_IDENTIFIER for continued use
341
- // in non-builtin extensions (and naughty PyPI modules).
342
-
343
- #define _Py_static_string_init (value ) { .string = value, .index = -1 }
344
- #define _Py_static_string (varname , value ) static _Py_Identifier varname = _Py_static_string_init(value)
345
- #define _Py_IDENTIFIER (varname ) _Py_static_string(PyId_##varname, #varname)
346
-
347
- #endif /* ! Py_BUILD_CORE */
348
-
349
- PyAPI_FUNC (PyObject * ) _PyType_LookupId (PyTypeObject * , _Py_Identifier * );
350
- PyAPI_FUNC (PyObject * ) _PyObject_LookupSpecialId (PyObject * , _Py_Identifier * );
351
- struct _Py_Identifier ;
352
- PyAPI_FUNC (PyObject * ) _PyObject_GetAttrId (PyObject * , struct _Py_Identifier * );
353
- PyAPI_FUNC (int ) _PyObject_SetAttrId (PyObject * , struct _Py_Identifier * , PyObject * );
354
- PyAPI_FUNC (int ) _PyObject_LookupAttrId (PyObject * , struct _Py_Identifier * , PyObject * * );
355
-
356
355
/* Safely decref `op` and set `op` to `op2`.
357
356
*
358
357
* As in case of Py_CLEAR "the obvious" code can be deadly:
0 commit comments