Skip to content

Commit ca82910

Browse files
committed
Issue 24365: Conditionalize PEP 489 additions to the stable ABI
Patch by Petr Viktorin.
1 parent 72ea27c commit ca82910

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

Include/modsupport.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
4949
PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
5050
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
5151
#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
52+
53+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
54+
/* New in 3.5 */
5255
PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *);
5356
PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *);
5457
PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
58+
#endif
5559

5660
#define Py_CLEANUP_SUPPORTED 0x20000
5761

@@ -126,6 +130,8 @@ PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
126130
PyModule_Create2(module, PYTHON_API_VERSION)
127131
#endif
128132

133+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
134+
/* New in 3.5 */
129135
PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
130136
PyObject *spec,
131137
int module_api_version);
@@ -136,7 +142,8 @@ PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
136142
#else
137143
#define PyModule_FromDefAndSpec(module, spec) \
138144
PyModule_FromDefAndSpec2(module, spec, PYTHON_API_VERSION)
139-
#endif
145+
#endif /* Py_LIMITED_API */
146+
#endif /* New in 3.5 */
140147

141148
#ifndef Py_LIMITED_API
142149
PyAPI_DATA(char *) _Py_PackageContext;

Include/moduleobject.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ PyAPI_FUNC(void) _PyModule_ClearDict(PyObject *);
3030
PyAPI_FUNC(struct PyModuleDef*) PyModule_GetDef(PyObject*);
3131
PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
3232

33+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
34+
/* New in 3.5 */
3335
PyAPI_FUNC(PyObject *) PyModuleDef_Init(struct PyModuleDef*);
3436
PyAPI_DATA(PyTypeObject) PyModuleDef_Type;
37+
#endif
3538

3639
typedef struct PyModuleDef_Base {
3740
PyObject_HEAD
@@ -47,30 +50,35 @@ typedef struct PyModuleDef_Base {
4750
NULL, /* m_copy */ \
4851
}
4952

53+
struct PyModuleDef_Slot;
54+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
55+
/* New in 3.5 */
5056
typedef struct PyModuleDef_Slot{
5157
int slot;
5258
void *value;
5359
} PyModuleDef_Slot;
5460

61+
#define Py_mod_create 1
62+
#define Py_mod_exec 2
63+
64+
#ifndef Py_LIMITED_API
65+
#define _Py_mod_LAST_SLOT 2
66+
#endif
67+
68+
#endif /* New in 3.5 */
69+
5570
typedef struct PyModuleDef{
5671
PyModuleDef_Base m_base;
5772
const char* m_name;
5873
const char* m_doc;
5974
Py_ssize_t m_size;
6075
PyMethodDef *m_methods;
61-
PyModuleDef_Slot* m_slots;
76+
struct PyModuleDef_Slot* m_slots;
6277
traverseproc m_traverse;
6378
inquiry m_clear;
6479
freefunc m_free;
6580
}PyModuleDef;
6681

67-
#define Py_mod_create 1
68-
#define Py_mod_exec 2
69-
70-
#ifndef Py_LIMITED_API
71-
#define _Py_mod_LAST_SLOT 2
72-
#endif
73-
7482
#ifdef __cplusplus
7583
}
7684
#endif

Include/typeslots.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,7 @@
7979
#define Py_am_await 77
8080
#define Py_am_aiter 78
8181
#define Py_am_anext 79
82+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
83+
/* New in 3.5 */
8284
#define Py_tp_finalize 80
85+
#endif

0 commit comments

Comments
 (0)