pygame / src / mask.h

#include <Python.h>
#include "bitmask.h"

#define PYGAMEAPI_MASK_NUMSLOTS 1
#define PYGAMEAPI_LOCAL_ENTRY "_PYGAME_C_API"

typedef struct {
  PyObject_HEAD
  bitmask_t *mask;
} PyMaskObject;

#define PyMask_AsBitmap(x) (((PyMaskObject*)x)->mask)

#ifndef PYGAMEAPI_MASK_INTERNAL

#define PyMask_Type     (*(PyTypeObject*)PyMASK_C_API[0])
#define PyMask_Check(x) ((x)->ob_type == &PyMask_Type)

#define import_pygame_mask() {                                                                 \
	PyObject *module = PyImport_ImportModule(IMPPREFIX "mask");                               \
	if (module != NULL) {                                                                  \
		PyObject *dict  = PyModule_GetDict(module);                                    \
		PyObject *c_api = PyDict_GetItemString(dict, PYGAMEAPI_LOCAL_ENTRY);           \
		if(PyCObject_Check(c_api)) {                                                   \
			void** localptr = (void**) PyCObject_AsVoidPtr(c_api);                 \
			memcpy(PyMASK_C_API, localptr, sizeof(void*)*PYGAMEAPI_MASK_NUMSLOTS); \
		} Py_DECREF(module);                                                           \
	}                                                                                      \
}

#endif /* !defined(PYGAMEAPI_MASK_INTERNAL) */

static void* PyMASK_C_API[PYGAMEAPI_MASK_NUMSLOTS] = {NULL};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.