Skip to content

Commit b4e8f2a

Browse files
authored
C API: Use _Py_PACK_VERSION() in Py_LIMITED_API version checks (#161622)
Move _Py_PACK_VERSION() from pymacro.h to patchlevel.h. PR generated with these shell commands on Linux: HEADERS=$(find Include -name "*.h") sed -i -e "s#0x030[aA]0000#_Py_PACK_VERSION(3, 10)#g" $HEADERS sed -i -e "s#0x030[bB]0000#_Py_PACK_VERSION(3, 11)#g" $HEADERS sed -i -e "s#0x030[cC]0000#_Py_PACK_VERSION(3, 12)#g" $HEADERS sed -i -e "s#0x030[dD]0000#_Py_PACK_VERSION(3, 13)#g" $HEADERS sed -i -e "s#0x030[eE]0000#_Py_PACK_VERSION(3, 14)#g" $HEADERS sed -i -e "s#0x030[fF]0000#_Py_PACK_VERSION(3, 15)#g" $HEADERS sed -i -e "s#0x030a00A7#_Py_PACK_VERSION(3, 10)#g" Include/refcount.h
1 parent f9e53a5 commit b4e8f2a

27 files changed

Lines changed: 68 additions & 68 deletions

‎Include/Python.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
//
3636
// The <ctype.h> and <unistd.h> headers are not included by limited C API
3737
// version 3.13 and newer.
38-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
38+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11)
3939
# include <errno.h> // errno
4040
# include <stdio.h> // FILE*
4141
# include <stdlib.h> // getenv()
4242
#endif
43-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000
43+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13)
4444
# include <ctype.h> // tolower()
4545
# ifndef MS_WINDOWS
4646
# include <unistd.h> // close()

‎Include/abstract.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extern "C" {
141141
This is the equivalent of the Python statement: del o.attr_name.
142142
143143
Implemented as a macro in the limited C API 3.12 and older. */
144-
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000
144+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13)
145145
# define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL)
146146
#endif
147147

@@ -155,7 +155,7 @@ extern "C" {
155155
statement: del o.attr_name.
156156
157157
Implemented as a macro in the limited C API 3.12 and older. */
158-
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000
158+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13)
159159
# define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL)
160160
#endif
161161

@@ -282,7 +282,7 @@ PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf);
282282
"tuple" and keyword arguments "dict". "dict" may also be NULL */
283283
PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);
284284

285-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
285+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 12)
286286
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
287287
(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
288288

@@ -407,7 +407,7 @@ PyAPI_FUNC(int) PyIter_Check(PyObject *);
407407
This function always succeeds. */
408408
PyAPI_FUNC(int) PyAIter_Check(PyObject *);
409409

410-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030e0000
410+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 14)
411411
/* Return 1 and set 'item' to the next item of 'iter' on success.
412412
* Return 0 and set 'item' to NULL when there are no remaining values.
413413
* Return -1, set 'item' to NULL and set an exception on error.
@@ -426,7 +426,7 @@ PyAPI_FUNC(int) PyIter_NextItem(PyObject *iter, PyObject **item);
426426
Prefer PyIter_NextItem() instead. */
427427
PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
428428

429-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
429+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 10)
430430

431431
/* Takes generator, coroutine or iterator object and sends the value into it.
432432
Returns:
@@ -885,7 +885,7 @@ PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
885885
If an error other than KeyError is raised, return -1 and
886886
set *result to NULL.
887887
*/
888-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
888+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
889889
PyAPI_FUNC(int) PyMapping_GetOptionalItem(PyObject *, PyObject *, PyObject **);
890890
PyAPI_FUNC(int) PyMapping_GetOptionalItemString(PyObject *, const char *, PyObject **);
891891
#endif

‎Include/audit.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
#endif
66

77

8-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
8+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
99
PyAPI_FUNC(int) PySys_Audit(
1010
const char *event,
1111
const char *argFormat,

‎Include/boolobject.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PyAPI_DATA(PyLongObject) _Py_FalseStruct;
1818
PyAPI_DATA(PyLongObject) _Py_TrueStruct;
1919

2020
/* Use these macros */
21-
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030D0000
21+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
2222
# define Py_False Py_GetConstantBorrowed(Py_CONSTANT_FALSE)
2323
# define Py_True Py_GetConstantBorrowed(Py_CONSTANT_TRUE)
2424
#else
@@ -37,7 +37,7 @@ PyAPI_FUNC(int) Py_IsFalse(PyObject *x);
3737
/* Macros for returning Py_True or Py_False, respectively.
3838
* Only treat Py_True and Py_False as immortal in the limited C API 3.12
3939
* and newer. */
40-
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030c0000
40+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 12)
4141
# define Py_RETURN_TRUE return Py_NewRef(Py_True)
4242
# define Py_RETURN_FALSE return Py_NewRef(Py_False)
4343
#else

‎Include/dictobject.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
5858
PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
5959
PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
6060

61-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030D0000
61+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
6262
// Return the object from dictionary *op* which has a key *key*.
6363
// - If the key is present, set *result to a new strong reference to the value
6464
// and return 1.
@@ -68,7 +68,7 @@ PyAPI_FUNC(int) PyDict_GetItemRef(PyObject *mp, PyObject *key, PyObject **result
6868
PyAPI_FUNC(int) PyDict_GetItemStringRef(PyObject *mp, const char *key, PyObject **result);
6969
#endif
7070

71-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030F0000
71+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
7272
// Inserts `key` with a value `default_value`, if `key` is not already present
7373
// in the dictionary. If `result` is not NULL, then the value associated
7474
// with `key` is returned in `*result` (either the existing value, or the now
@@ -80,7 +80,7 @@ PyAPI_FUNC(int) PyDict_GetItemStringRef(PyObject *mp, const char *key, PyObject
8080
PyAPI_FUNC(int) PyDict_SetDefaultRef(PyObject *mp, PyObject *key, PyObject *default_value, PyObject **result);
8181
#endif
8282

83-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
83+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 10)
8484
PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *);
8585
#endif
8686

‎Include/import.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ PyAPI_FUNC(PyObject *) PyImport_AddModuleObject(
4343
PyAPI_FUNC(PyObject *) PyImport_AddModule(
4444
const char *name /* UTF-8 encoded string */
4545
);
46-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
46+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
4747
PyAPI_FUNC(PyObject *) PyImport_AddModuleRef(
4848
const char *name /* UTF-8 encoded string */
4949
);

‎Include/listobject.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
2929
PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
3030

3131
PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
32-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
32+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
3333
PyAPI_FUNC(PyObject *) PyList_GetItemRef(PyObject *, Py_ssize_t);
3434
#endif
3535
PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);

‎Include/longobject.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
2626
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
2727
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
2828

29-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
29+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
3030
PyAPI_FUNC(int) PyLong_AsInt(PyObject *);
3131
#endif
3232

33-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030e0000
33+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 14)
3434
PyAPI_FUNC(PyObject*) PyLong_FromInt32(int32_t value);
3535
PyAPI_FUNC(PyObject*) PyLong_FromUInt32(uint32_t value);
3636
PyAPI_FUNC(PyObject*) PyLong_FromInt64(int64_t value);
@@ -104,7 +104,7 @@ PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
104104
#if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
105105
#define _Py_PARSE_PID "i"
106106
#define PyLong_FromPid PyLong_FromLong
107-
# if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
107+
# if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13)
108108
# define PyLong_AsPid PyLong_AsInt
109109
# elif SIZEOF_INT == SIZEOF_LONG
110110
# define PyLong_AsPid PyLong_AsLong

‎Include/memoryobject.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
1515
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
1616
int flags);
1717
#endif
18-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030b0000
18+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 11)
1919
PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(const Py_buffer *info);
2020
#endif
2121
PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,

‎Include/methodobject.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,
111111

112112
#define METH_COEXIST 0x0040
113113

114-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000
114+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 10)
115115
# define METH_FASTCALL 0x0080
116116
#endif
117117

0 commit comments

Comments
 (0)