Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf22eec

Browse files
authored
gh-89653: PEP 670: Macros always cast arguments in cpython/ (#93766)
Header files in the Include/cpython/ are only included ifthe Py_LIMITED_API macro is not defined.
1 parentc200757 commitdf22eec

File tree

9 files changed

+28
-92
lines changed

9 files changed

+28
-92
lines changed

‎Include/cpython/bytearrayobject.h‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ static inline char* PyByteArray_AS_STRING(PyObject *op)
2525
}
2626
return_PyByteArray_empty_string;
2727
}
28-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
29-
# definePyByteArray_AS_STRING(self) PyByteArray_AS_STRING(_PyObject_CAST(self))
30-
#endif
28+
#definePyByteArray_AS_STRING(self) PyByteArray_AS_STRING(_PyObject_CAST(self))
3129

3230
staticinlinePy_ssize_tPyByteArray_GET_SIZE(PyObject*op) {
3331
PyByteArrayObject*self=_PyByteArray_CAST(op);
3432
returnPy_SIZE(self);
3533
}
36-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
37-
# definePyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self))
38-
#endif
34+
#definePyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self))

‎Include/cpython/bytesobject.h‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ static inline char* PyBytes_AS_STRING(PyObject *op)
3636
{
3737
return_PyBytes_CAST(op)->ob_sval;
3838
}
39-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
40-
# definePyBytes_AS_STRING(op) PyBytes_AS_STRING(_PyObject_CAST(op))
41-
#endif
39+
#definePyBytes_AS_STRING(op) PyBytes_AS_STRING(_PyObject_CAST(op))
4240

4341
staticinlinePy_ssize_tPyBytes_GET_SIZE(PyObject*op) {
4442
PyBytesObject*self=_PyBytes_CAST(op);
4543
returnPy_SIZE(self);
4644
}
47-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
48-
# definePyBytes_GET_SIZE(self) PyBytes_GET_SIZE(_PyObject_CAST(self))
49-
#endif
45+
#definePyBytes_GET_SIZE(self) PyBytes_GET_SIZE(_PyObject_CAST(self))
5046

5147
/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*,
5248
x must be an iterable object. */

‎Include/cpython/cellobject.h‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ static inline PyObject* PyCell_GET(PyObject *op) {
2727
cell=_Py_CAST(PyCellObject*,op);
2828
returncell->ob_ref;
2929
}
30-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030c0000
31-
# definePyCell_GET(op) PyCell_GET(_PyObject_CAST(op))
32-
#endif
30+
#definePyCell_GET(op) PyCell_GET(_PyObject_CAST(op))
3331

3432
staticinlinevoidPyCell_SET(PyObject*op,PyObject*value) {
3533
PyCellObject*cell;
3634
assert(PyCell_Check(op));
3735
cell=_Py_CAST(PyCellObject*,op);
3836
cell->ob_ref=value;
3937
}
40-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030c0000
41-
# definePyCell_SET(op,value) PyCell_SET(_PyObject_CAST(op), (value))
42-
#endif
38+
#definePyCell_SET(op,value) PyCell_SET(_PyObject_CAST(op), (value))
4339

4440
#ifdef__cplusplus
4541
}

‎Include/cpython/dictobject.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
5252
mp=_Py_CAST(PyDictObject*,op);
5353
returnmp->ma_used;
5454
}
55-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030c0000
56-
# definePyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
57-
#endif
55+
#definePyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
5856

5957
PyAPI_FUNC(int)_PyDict_Contains_KnownHash(PyObject*,PyObject*,Py_hash_t);
6058
PyAPI_FUNC(int)_PyDict_ContainsId(PyObject*,_Py_Identifier*);

‎Include/cpython/listobject.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) {
3434
PyListObject*list=_PyList_CAST(op);
3535
returnPy_SIZE(list);
3636
}
37-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
38-
# definePyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
39-
#endif
37+
#definePyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
4038

4139
#definePyList_GET_ITEM(op,index) (_PyList_CAST(op)->ob_item[index])
4240

@@ -45,7 +43,5 @@ PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
4543
PyListObject*list=_PyList_CAST(op);
4644
list->ob_item[index]=value;
4745
}
48-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
4946
#definePyList_SET_ITEM(op,index,value) \
5047
PyList_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
51-
#endif

‎Include/cpython/methodobject.h‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ PyAPI_DATA(PyTypeObject) PyCMethod_Type;
4040
staticinlinePyCFunctionPyCFunction_GET_FUNCTION(PyObject*func) {
4141
return_PyCFunctionObject_CAST(func)->m_ml->ml_meth;
4242
}
43-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
44-
# definePyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func))
45-
#endif
43+
#definePyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func))
4644

4745
staticinlinePyObject*PyCFunction_GET_SELF(PyObject*func_obj) {
4846
PyCFunctionObject*func=_PyCFunctionObject_CAST(func_obj);
@@ -51,16 +49,12 @@ static inline PyObject* PyCFunction_GET_SELF(PyObject *func_obj) {
5149
}
5250
returnfunc->m_self;
5351
}
54-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
55-
# definePyCFunction_GET_SELF(func) PyCFunction_GET_SELF(_PyObject_CAST(func))
56-
#endif
52+
#definePyCFunction_GET_SELF(func) PyCFunction_GET_SELF(_PyObject_CAST(func))
5753

5854
staticinlineintPyCFunction_GET_FLAGS(PyObject*func) {
5955
return_PyCFunctionObject_CAST(func)->m_ml->ml_flags;
6056
}
61-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
62-
# definePyCFunction_GET_FLAGS(func) PyCFunction_GET_FLAGS(_PyObject_CAST(func))
63-
#endif
57+
#definePyCFunction_GET_FLAGS(func) PyCFunction_GET_FLAGS(_PyObject_CAST(func))
6458

6559
staticinlinePyTypeObject*PyCFunction_GET_CLASS(PyObject*func_obj) {
6660
PyCFunctionObject*func=_PyCFunctionObject_CAST(func_obj);
@@ -69,6 +63,4 @@ static inline PyTypeObject* PyCFunction_GET_CLASS(PyObject *func_obj) {
6963
}
7064
return_Py_NULL;
7165
}
72-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
73-
# definePyCFunction_GET_CLASS(func) PyCFunction_GET_CLASS(_PyObject_CAST(func))
74-
#endif
66+
#definePyCFunction_GET_CLASS(func) PyCFunction_GET_CLASS(_PyObject_CAST(func))

‎Include/cpython/tupleobject.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) {
2323
PyTupleObject*tuple=_PyTuple_CAST(op);
2424
returnPy_SIZE(tuple);
2525
}
26-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
27-
# definePyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
28-
#endif
26+
#definePyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
2927

3028
#definePyTuple_GET_ITEM(op,index) (_PyTuple_CAST(op)->ob_item[index])
3129

@@ -35,9 +33,7 @@ PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
3533
PyTupleObject*tuple=_PyTuple_CAST(op);
3634
tuple->ob_item[index]=value;
3735
}
38-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
3936
#definePyTuple_SET_ITEM(op,index,value) \
4037
PyTuple_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
41-
#endif
4238

4339
PyAPI_FUNC(void)_PyTuple_DebugMallocStats(FILE*out);

‎Include/cpython/unicodeobject.h‎

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -188,45 +188,35 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
188188
staticinlineunsignedintPyUnicode_CHECK_INTERNED(PyObject*op) {
189189
return_PyASCIIObject_CAST(op)->state.interned;
190190
}
191-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
192-
# definePyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
193-
#endif
191+
#definePyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
194192

195193
/* For backward compatibility */
196194
staticinlineunsignedintPyUnicode_IS_READY(PyObject*Py_UNUSED(op)) {
197195
return1;
198196
}
199-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
200-
# definePyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
201-
#endif
197+
#definePyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
202198

203199
/* Return true if the string contains only ASCII characters, or 0 if not. The
204200
string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
205201
ready. */
206202
staticinlineunsignedintPyUnicode_IS_ASCII(PyObject*op) {
207203
return_PyASCIIObject_CAST(op)->state.ascii;
208204
}
209-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
210-
# definePyUnicode_IS_ASCII(op) PyUnicode_IS_ASCII(_PyObject_CAST(op))
211-
#endif
205+
#definePyUnicode_IS_ASCII(op) PyUnicode_IS_ASCII(_PyObject_CAST(op))
212206

213207
/* Return true if the string is compact or 0 if not.
214208
No type checks or Ready calls are performed. */
215209
staticinlineunsignedintPyUnicode_IS_COMPACT(PyObject*op) {
216210
return_PyASCIIObject_CAST(op)->state.compact;
217211
}
218-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
219-
# definePyUnicode_IS_COMPACT(op) PyUnicode_IS_COMPACT(_PyObject_CAST(op))
220-
#endif
212+
#definePyUnicode_IS_COMPACT(op) PyUnicode_IS_COMPACT(_PyObject_CAST(op))
221213

222214
/* Return true if the string is a compact ASCII string (use PyASCIIObject
223215
structure), or 0 if not. No type checks or Ready calls are performed. */
224216
staticinlineintPyUnicode_IS_COMPACT_ASCII(PyObject*op) {
225217
return (_PyASCIIObject_CAST(op)->state.ascii&&PyUnicode_IS_COMPACT(op));
226218
}
227-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
228-
# definePyUnicode_IS_COMPACT_ASCII(op) PyUnicode_IS_COMPACT_ASCII(_PyObject_CAST(op))
229-
#endif
219+
#definePyUnicode_IS_COMPACT_ASCII(op) PyUnicode_IS_COMPACT_ASCII(_PyObject_CAST(op))
230220

231221
enumPyUnicode_Kind {
232222
/* Return values of the PyUnicode_KIND() function: */
@@ -236,22 +226,14 @@ enum PyUnicode_Kind {
236226
};
237227

238228
// PyUnicode_KIND(): Return one of the PyUnicode_*_KIND values defined above.
239-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030c0000
229+
//
240230
// gh-89653: Converting this macro to a static inline function would introduce
241231
// new compiler warnings on "kind < PyUnicode_KIND(str)" (compare signed and
242232
// unsigned numbers) where kind type is an int or on
243233
// "unsigned int kind = PyUnicode_KIND(str)" (cast signed to unsigned).
244234
// Only declare the function as static inline function in the limited C API
245235
// version 3.12 which is stricter.
246-
#definePyUnicode_KIND(op) \
247-
(_PyASCIIObject_CAST(op)->state.kind)
248-
#else
249-
// Limited C API 3.12 and newer
250-
staticinlineintPyUnicode_KIND(PyObject*op) {
251-
assert(PyUnicode_IS_READY(op));
252-
return_PyASCIIObject_CAST(op)->state.kind;
253-
}
254-
#endif
236+
#definePyUnicode_KIND(op) (_PyASCIIObject_CAST(op)->state.kind)
255237

256238
/* Return a void pointer to the raw unicode buffer. */
257239
staticinlinevoid*_PyUnicode_COMPACT_DATA(PyObject*op) {
@@ -275,9 +257,7 @@ static inline void* PyUnicode_DATA(PyObject *op) {
275257
}
276258
return_PyUnicode_NONCOMPACT_DATA(op);
277259
}
278-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
279-
# definePyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op))
280-
#endif
260+
#definePyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op))
281261

282262
/* Return pointers to the canonical representation cast to unsigned char,
283263
Py_UCS2, or Py_UCS4 for direct character access.
@@ -292,9 +272,7 @@ static inline void* PyUnicode_DATA(PyObject *op) {
292272
staticinlinePy_ssize_tPyUnicode_GET_LENGTH(PyObject*op) {
293273
return_PyASCIIObject_CAST(op)->length;
294274
}
295-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
296-
# definePyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
297-
#endif
275+
#definePyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
298276

299277
/* Write into the canonical representation, this function does not do any sanity
300278
checks and is intended for usage in loops. The caller should cache the
@@ -319,11 +297,9 @@ static inline void PyUnicode_WRITE(int kind, void *data,
319297
_Py_STATIC_CAST(Py_UCS4*,data)[index]=value;
320298
}
321299
}
322-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
323300
#definePyUnicode_WRITE(kind,data,index,value) \
324301
PyUnicode_WRITE(_Py_STATIC_CAST(int, kind), _Py_CAST(void*, data), \
325302
(index), _Py_STATIC_CAST(Py_UCS4, value))
326-
#endif
327303

328304
/* Read a code point from the string's canonical representation. No checks
329305
or ready calls are performed. */
@@ -340,12 +316,10 @@ static inline Py_UCS4 PyUnicode_READ(int kind,
340316
assert(kind==PyUnicode_4BYTE_KIND);
341317
return_Py_STATIC_CAST(constPy_UCS4*,data)[index];
342318
}
343-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
344319
#definePyUnicode_READ(kind,data,index) \
345320
PyUnicode_READ(_Py_STATIC_CAST(int, kind), \
346321
_Py_STATIC_CAST(const void*, data), \
347322
(index))
348-
#endif
349323

350324
/* PyUnicode_READ_CHAR() is less efficient than PyUnicode_READ() because it
351325
calls PyUnicode_KIND() and might call it twice. For single reads, use
@@ -369,10 +343,8 @@ static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
369343
assert(kind==PyUnicode_4BYTE_KIND);
370344
returnPyUnicode_4BYTE_DATA(unicode)[index];
371345
}
372-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
373-
# definePyUnicode_READ_CHAR(unicode,index) \
374-
PyUnicode_READ_CHAR(_PyObject_CAST(unicode), (index))
375-
#endif
346+
#definePyUnicode_READ_CHAR(unicode,index) \
347+
PyUnicode_READ_CHAR(_PyObject_CAST(unicode), (index))
376348

377349
/* Return a maximum character value which is suitable for creating another
378350
string based on op. This is always an approximation but more efficient
@@ -395,10 +367,8 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
395367
assert(kind==PyUnicode_4BYTE_KIND);
396368
return0x10ffffU;
397369
}
398-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
399-
# definePyUnicode_MAX_CHAR_VALUE(op) \
400-
PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op))
401-
#endif
370+
#definePyUnicode_MAX_CHAR_VALUE(op) \
371+
PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op))
402372

403373
/* === Public API ========================================================= */
404374

@@ -417,9 +387,7 @@ static inline int PyUnicode_READY(PyObject* Py_UNUSED(op))
417387
{
418388
return0;
419389
}
420-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
421-
# definePyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
422-
#endif
390+
#definePyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
423391

424392
/* Get a copy of a Unicode string. */
425393
PyAPI_FUNC(PyObject*)_PyUnicode_Copy(

‎Include/cpython/weakrefobject.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,4 @@ static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj) {
5353
}
5454
returnPy_None;
5555
}
56-
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0<0x030b0000
57-
# definePyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))
58-
#endif
56+
#definePyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp