mask.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include <Python.h>
  2. #include "bitmask.h"
  3. #define PYGAMEAPI_MASK_NUMSLOTS 1
  4. #define PYGAMEAPI_LOCAL_ENTRY "_PYGAME_C_API"
  5. typedef struct {
  6. PyObject_HEAD
  7. bitmask_t *mask;
  8. } PyMaskObject;
  9. #define PyMask_AsBitmap(x) (((PyMaskObject*)x)->mask)
  10. #ifndef PYGAMEAPI_MASK_INTERNAL
  11. #define PyMask_Type (*(PyTypeObject*)PyMASK_C_API[0])
  12. #define PyMask_Check(x) ((x)->ob_type == &PyMask_Type)
  13. #define import_pygame_mask() { \
  14. PyObject *module = PyImport_ImportModule(IMPPREFIX "mask"); \
  15. if (module != NULL) { \
  16. PyObject *dict = PyModule_GetDict(module); \
  17. PyObject *c_api = PyDict_GetItemString(dict, PYGAMEAPI_LOCAL_ENTRY); \
  18. if(PyCObject_Check(c_api)) { \
  19. void** localptr = (void**) PyCObject_AsVoidPtr(c_api); \
  20. memcpy(PyMASK_C_API, localptr, sizeof(void*)*PYGAMEAPI_MASK_NUMSLOTS); \
  21. } Py_DECREF(module); \
  22. } \
  23. }
  24. #endif /* !defined(PYGAMEAPI_MASK_INTERNAL) */
  25. static void* PyMASK_C_API[PYGAMEAPI_MASK_NUMSLOTS] = {NULL};