Skip to content

Commit 3673c6c

Browse files
Leave all the functions.
1 parent b7f00c5 commit 3673c6c

File tree

7 files changed

+56
-75
lines changed

7 files changed

+56
-75
lines changed

Include/cpython/abstract.h

-4
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethod(PyObject *obj,
120120
PyObject *name,
121121
const char *format, ...);
122122

123-
#ifdef _Py_IDENTIFIER
124-
125123
/* Like PyObject_CallMethod(), but expect a _Py_Identifier*
126124
as the method name. */
127125
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj,
@@ -167,8 +165,6 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg
167165
2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
168166
}
169167

170-
#endif /* _Py_IDENTIFIER */
171-
172168
PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);
173169

174170
/* Guess the size of object 'o' using len(o) or o.__length_hint__().

Include/cpython/ceval.h

-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void);
1616

1717
/* Helper to look up a builtin object */
1818
PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *);
19-
#ifdef _Py_IDENTIFIER
2019
PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *);
21-
#endif
2220
/* Look at the current frame's (if any) code's co_flags, and turn on
2321
the corresponding compiler flags in cf->cf_flags. Return 1 if any
2422
flag was set, else return 0. */

Include/cpython/dictobject.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ typedef struct {
3131
PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
3232
Py_hash_t hash);
3333
PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
34+
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
35+
struct _Py_Identifier *key);
3436
PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
3537
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
3638
PyObject *mp, PyObject *key, PyObject *defaultobj);
@@ -47,6 +49,7 @@ PyAPI_FUNC(int) _PyDict_Next(
4749
/* Get the number of items of a dictionary. */
4850
#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
4951
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
52+
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *);
5053
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
5154
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
5255
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
@@ -63,21 +66,15 @@ PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
6366
argument is raised.
6467
*/
6568
PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
69+
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
6670

71+
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);
6772
PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
6873

6974
int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
7075
PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
7176
Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **);
7277

73-
#ifdef _Py_IDENTIFIER
74-
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
75-
struct _Py_Identifier *key);
76-
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *);
77-
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
78-
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);
79-
#endif
80-
8178
/* _PyDictView */
8279

8380
typedef struct {

Include/cpython/import.h

-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ PyMODINIT_FUNC PyInit__imp(void);
66

77
PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *);
88

9-
#ifdef _Py_IDENTIFIER
109
PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(struct _Py_Identifier *name);
11-
#endif
1210
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
1311
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
1412

Include/cpython/object.h

+43-44
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
1414
#endif
1515

1616

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+
1754
/* buffer interface */
1855
typedef struct bufferinfo {
1956
void *buf;
@@ -268,19 +305,24 @@ typedef struct _heaptypeobject {
268305

269306
PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *);
270307
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
308+
PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
271309
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
310+
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *);
272311
PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
273312
PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
274313
PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
275314
struct PyModuleDef;
276315
PyAPI_FUNC(PyObject *) _PyType_GetModuleByDef(PyTypeObject *, struct PyModuleDef *);
277316

317+
struct _Py_Identifier;
278318
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
279319
PyAPI_FUNC(void) _Py_BreakPoint(void);
280320
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
281321
PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
282322

283323
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 *);
284326
/* Replacements of PyObject_GetAttr() and _PyObject_GetAttrId() which
285327
don't raise AttributeError.
286328
@@ -291,6 +333,7 @@ PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
291333
is raised.
292334
*/
293335
PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **);
336+
PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **);
294337

295338
PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
296339

@@ -309,50 +352,6 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
309352

310353
PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
311354

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-
356355
/* Safely decref `op` and set `op` to `op2`.
357356
*
358357
* As in case of Py_CLEAR "the obvious" code can be deadly:

Include/cpython/sysmodule.h

-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
PyAPI_FUNC(PyObject *) _PySys_GetAttr(PyThreadState *tstate,
66
PyObject *name);
7-
8-
#ifdef _Py_IDENTIFIER
97
PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key);
108
PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *);
11-
#endif
129

1310
PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *);
1411

Include/cpython/unicodeobject.h

+8-12
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,14 @@ PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray(
861861
Py_ssize_t seqlen
862862
);
863863

864+
/* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
865+
0 otherwise. The right argument must be ASCII identifier.
866+
Any error occurs inside will be cleared before return. */
867+
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
868+
PyObject *left, /* Left string */
869+
_Py_Identifier *right /* Right identifier */
870+
);
871+
864872
/* Test whether a unicode is equal to ASCII string. Return 1 if true,
865873
0 otherwise. The right argument must be ASCII-encoded string.
866874
Any error occurs inside will be cleared before return. */
@@ -1005,21 +1013,9 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha(
10051013

10061014
PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int);
10071015

1008-
#ifdef _Py_IDENTIFIER
1009-
1010-
/* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
1011-
0 otherwise. The right argument must be ASCII identifier.
1012-
Any error occurs inside will be cleared before return. */
1013-
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
1014-
PyObject *left, /* Left string */
1015-
_Py_Identifier *right /* Right identifier */
1016-
);
1017-
10181016
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
10191017
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
10201018

1021-
#endif /* _Py_IDENTIFIER */
1022-
10231019
/* Fast equality check when the inputs are known to be exact unicode types
10241020
and where the hash values are equal (i.e. a very probable match) */
10251021
PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *);

0 commit comments

Comments
 (0)