Skip to content

Commit a171a03

Browse files
Issue python#29058: All stable API extensions added after Python 3.2 are now
available only when Py_LIMITED_API is set to the PY_VERSION_HEX value of the minimum Python version supporting this API.
2 parents fdb4eaf + 34d0ac8 commit a171a03

19 files changed

+89
-7
lines changed

Include/abstract.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,10 @@ PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
612612
This is the equivalent of the Python expression: o1 * o2. */
613613
PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
614614

615+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
615616
/* This is the equivalent of the Python expression: o1 @ o2. */
616617
PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2);
618+
#endif
617619

618620
/* Returns the result of dividing o1 by o2 giving an integral result,
619621
or NULL on failure.
@@ -743,8 +745,10 @@ PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
743745
This is the equivalent of the Python expression: o1 *= o2. */
744746
PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
745747

748+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
746749
/* This is the equivalent of the Python expression: o1 @= o2. */
747750
PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2);
751+
#endif
748752

749753
/* Returns the result of dividing o1 by o2 giving an integral result, possibly
750754
in-place, or NULL on failure.

Include/bytesobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ PyAPI_FUNC(PyObject*) _PyBytes_FromHex(
7474
PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
7575
const char *, Py_ssize_t,
7676
const char *);
77+
#ifndef Py_LIMITED_API
7778
/* Helper for PyBytes_DecodeEscape that detects invalid escape chars. */
7879
PyAPI_FUNC(PyObject *) _PyBytes_DecodeEscape(const char *, Py_ssize_t,
7980
const char *, Py_ssize_t,
8081
const char *,
8182
const char **);
83+
#endif
8284

8385
/* Macro, trading safety for speed */
8486
#ifndef Py_LIMITED_API

Include/codecs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,14 @@ PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
225225
/* replace the unicode encode error with backslash escapes (\x, \u and \U) */
226226
PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
227227

228+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
228229
/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */
229230
PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);
231+
#endif
230232

233+
#ifndef Py_LIMITED_API
231234
PyAPI_DATA(const char *) Py_hexdigits;
235+
#endif
232236

233237
#ifdef __cplusplus
234238
}

Include/fileobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
2323
If non-NULL, this is different than the default encoding for strings
2424
*/
2525
PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
26+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
2627
PyAPI_DATA(const char *) Py_FileSystemDefaultEncodeErrors;
28+
#endif
2729
PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding;
2830

2931
/* Internal API

Include/fileutils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
extern "C" {
66
#endif
77

8+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
89
PyAPI_FUNC(wchar_t *) Py_DecodeLocale(
910
const char *arg,
1011
size_t *size);
1112

1213
PyAPI_FUNC(char*) Py_EncodeLocale(
1314
const wchar_t *text,
1415
size_t *error_pos);
16+
#endif
1517

1618
#ifndef Py_LIMITED_API
1719

Include/import.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ extern "C" {
99

1010
#ifndef Py_LIMITED_API
1111
PyAPI_FUNC(void) _PyImportZip_Init(void);
12-
#endif /* !Py_LIMITED_API */
1312

1413
PyMODINIT_FUNC PyInit_imp(void);
14+
#endif /* !Py_LIMITED_API */
1515
PyAPI_FUNC(long) PyImport_GetMagicNumber(void);
1616
PyAPI_FUNC(const char *) PyImport_GetMagicTag(void);
1717
PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(
@@ -29,16 +29,20 @@ PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleWithPathnames(
2929
const char *pathname, /* decoded from the filesystem encoding */
3030
const char *cpathname /* decoded from the filesystem encoding */
3131
);
32+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
3233
PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleObject(
3334
PyObject *name,
3435
PyObject *co,
3536
PyObject *pathname,
3637
PyObject *cpathname
3738
);
39+
#endif
3840
PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);
41+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
3942
PyAPI_FUNC(PyObject *) PyImport_AddModuleObject(
4043
PyObject *name
4144
);
45+
#endif
4246
PyAPI_FUNC(PyObject *) PyImport_AddModule(
4347
const char *name /* UTF-8 encoded string */
4448
);
@@ -55,13 +59,15 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
5559
PyObject *fromlist,
5660
int level
5761
);
62+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
5863
PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevelObject(
5964
PyObject *name,
6065
PyObject *globals,
6166
PyObject *locals,
6267
PyObject *fromlist,
6368
int level
6469
);
70+
#endif
6571

6672
#define PyImport_ImportModuleEx(n, g, l, f) \
6773
PyImport_ImportModuleLevel(n, g, l, f, 0)
@@ -70,9 +76,11 @@ PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);
7076
PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);
7177
PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
7278
PyAPI_FUNC(void) PyImport_Cleanup(void);
79+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
7380
PyAPI_FUNC(int) PyImport_ImportFrozenModuleObject(
7481
PyObject *name
7582
);
83+
#endif
7684
PyAPI_FUNC(int) PyImport_ImportFrozenModule(
7785
const char *name /* UTF-8 encoded string */
7886
);

Include/memoryobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
2121
#endif
2222

2323
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
24+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
2425
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
2526
int flags);
27+
#endif
2628
#ifndef Py_LIMITED_API
2729
PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
2830
#endif

Include/moduleobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ PyAPI_DATA(PyTypeObject) PyModule_Type;
1212
#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
1313
#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)
1414

15+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
1516
PyAPI_FUNC(PyObject *) PyModule_NewObject(
1617
PyObject *name
1718
);
19+
#endif
1820
PyAPI_FUNC(PyObject *) PyModule_New(
1921
const char *name /* UTF-8 encoded string */
2022
);
2123
PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
24+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
2225
PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *);
26+
#endif
2327
PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
2428
PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *) Py_DEPRECATED(3.2);
2529
PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *);

Include/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
547547
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
548548
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
549549
PyObject *, PyObject *);
550+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
550551
PyAPI_FUNC(int) PyObject_GenericSetDict(PyObject *, PyObject *, void *);
552+
#endif
551553
PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
552554
PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
553555
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);

Include/objimpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ PyObject_{New, NewVar, Del}.
9595
the raw memory.
9696
*/
9797
PyAPI_FUNC(void *) PyObject_Malloc(size_t size);
98+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
9899
PyAPI_FUNC(void *) PyObject_Calloc(size_t nelem, size_t elsize);
100+
#endif
99101
PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size);
100102
PyAPI_FUNC(void) PyObject_Free(void *ptr);
101103

0 commit comments

Comments
 (0)