.gitignore added
[dotfiles/.git] / .local / include / python3.9 / pygame / include / pgimport.h
1 #ifndef PGIMPORT_H
2 #define PGIMPORT_H
3
4 /* Prefix when initializing module */
5 #define MODPREFIX ""
6 /* Prefix when importing module */
7 #define IMPPREFIX "pygame."
8
9 #ifdef __SYMBIAN32__
10
11 /* On Symbian there is no pygame package. The extensions are built-in or in
12  * sys\bin. */
13 #undef MODPREFIX
14 #undef IMPPREFIX
15 #define MODPREFIX "pygame_"
16 #define IMPPREFIX "pygame_"
17
18 #endif /* __SYMBIAN32__ */
19
20 #include "pgcompat.h"
21
22 #define PYGAMEAPI_LOCAL_ENTRY "_PYGAME_C_API"
23 #define PG_CAPSULE_NAME(m) (IMPPREFIX m "." PYGAMEAPI_LOCAL_ENTRY)
24
25 /*
26  * fill API slots defined by PYGAMEAPI_DEFINE_SLOTS/PYGAMEAPI_EXTERN_SLOTS
27  */
28 #define _IMPORT_PYGAME_MODULE(module)                                        \
29     {                                                                        \
30         PyObject *_mod_##module = PyImport_ImportModule(IMPPREFIX #module);  \
31                                                                              \
32         if (_mod_##module != NULL) {                                         \
33             PyObject *_c_api =                                               \
34                 PyObject_GetAttrString(_mod_##module, PYGAMEAPI_LOCAL_ENTRY);\
35                                                                              \
36             Py_DECREF(_mod_##module);                                        \
37             if (_c_api != NULL && PyCapsule_CheckExact(_c_api)) {            \
38                 void **localptr = (void **)PyCapsule_GetPointer(             \
39                     _c_api, PG_CAPSULE_NAME(#module));                       \
40                 _PGSLOTS_ ## module = localptr;                              \
41             }                                                                \
42             Py_XDECREF(_c_api);                                              \
43         }                                                                    \
44     }
45
46 #define PYGAMEAPI_IS_IMPORTED(module) (_PGSLOTS_ ## module != NULL)
47
48 /*
49  * source file must include one of these in order to use _IMPORT_PYGAME_MODULE.
50  * this is set by import_pygame_*() functions.
51  * disable with NO_PYGAME_C_API
52  */
53 #define PYGAMEAPI_DEFINE_SLOTS(module) \
54     void ** _PGSLOTS_ ## module = NULL
55 #define PYGAMEAPI_EXTERN_SLOTS(module) \
56     extern void **_PGSLOTS_ ## module
57 #define PYGAMEAPI_GET_SLOT(module, index) \
58     _PGSLOTS_ ## module [(index)]
59
60 /*
61  * disabled API with NO_PYGAME_C_API; do nothing instead
62  */
63 #ifdef NO_PYGAME_C_API
64
65 #undef PYGAMEAPI_DEFINE_SLOTS
66 #undef PYGAMEAPI_EXTERN_SLOTS
67
68 #define PYGAMEAPI_DEFINE_SLOTS(module)
69 #define PYGAMEAPI_EXTERN_SLOTS(module)
70
71 /* intentionally leave this defined to cause a compiler error *
72 #define PYGAMEAPI_GET_SLOT(api_root, index)
73 #undef PYGAMEAPI_GET_SLOT*/
74
75 #undef _IMPORT_PYGAME_MODULE
76 #define _IMPORT_PYGAME_MODULE(module)
77
78 #endif /* NO_PYGAME_C_API */
79
80 #endif /* ~PGIMPORT_H */