4 /* Prefix when initializing module */
6 /* Prefix when importing module */
7 #define IMPPREFIX "pygame."
11 /* On Symbian there is no pygame package. The extensions are built-in or in
15 #define MODPREFIX "pygame_"
16 #define IMPPREFIX "pygame_"
18 #endif /* __SYMBIAN32__ */
22 #define PYGAMEAPI_LOCAL_ENTRY "_PYGAME_C_API"
23 #define PG_CAPSULE_NAME(m) (IMPPREFIX m "." PYGAMEAPI_LOCAL_ENTRY)
26 * fill API slots defined by PYGAMEAPI_DEFINE_SLOTS/PYGAMEAPI_EXTERN_SLOTS
28 #define _IMPORT_PYGAME_MODULE(module) \
30 PyObject *_mod_##module = PyImport_ImportModule(IMPPREFIX #module); \
32 if (_mod_##module != NULL) { \
34 PyObject_GetAttrString(_mod_##module, PYGAMEAPI_LOCAL_ENTRY);\
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; \
46 #define PYGAMEAPI_IS_IMPORTED(module) (_PGSLOTS_ ## module != NULL)
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
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)]
61 * disabled API with NO_PYGAME_C_API; do nothing instead
63 #ifdef NO_PYGAME_C_API
65 #undef PYGAMEAPI_DEFINE_SLOTS
66 #undef PYGAMEAPI_EXTERN_SLOTS
68 #define PYGAMEAPI_DEFINE_SLOTS(module)
69 #define PYGAMEAPI_EXTERN_SLOTS(module)
71 /* intentionally leave this defined to cause a compiler error *
72 #define PYGAMEAPI_GET_SLOT(api_root, index)
73 #undef PYGAMEAPI_GET_SLOT*/
75 #undef _IMPORT_PYGAME_MODULE
76 #define _IMPORT_PYGAME_MODULE(module)
78 #endif /* NO_PYGAME_C_API */
80 #endif /* ~PGIMPORT_H */