Skip to content

Surface multiphase init #3354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 55 additions & 45 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ typedef enum {
} SurfViewKind;

/* To avoid problems with non-const Py_buffer format field */
static char FormatUint8[] = "B";
static char FormatUint16[] = "=H";
static char FormatUint24[] = "3x";
static char FormatUint32[] = "=I";
#define FormatUint8 "B"
#define FormatUint16 "=H"
#define FormatUint24 "3x"
#define FormatUint32 "=I"

typedef struct pg_bufferinternal_s {
PyObject *consumer_ref; /* A weak reference to a bufferproxy object */
Expand Down Expand Up @@ -4597,17 +4597,63 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,

static PyMethodDef _surface_methods[] = {{NULL, NULL, 0, NULL}};

MODINIT_DEFINE(surface)
int
exec_surface(PyObject *module)
{
PyObject *module, *apiobj;
PyObject *apiobj;
static void *c_api[PYGAMEAPI_SURFACE_NUMSLOTS];

if (pg_warn_simd_at_runtime_but_uncompiled() < 0) {
return -1;
}

if (PyModule_AddObjectRef(module, "SurfaceType",
(PyObject *)&pgSurface_Type)) {
return -1;
}

if (PyModule_AddObjectRef(module, "Surface",
(PyObject *)&pgSurface_Type)) {
return -1;
}

/* export the c api */
c_api[0] = &pgSurface_Type;
c_api[1] = pgSurface_New2;
c_api[2] = pgSurface_Blit;
c_api[3] = pgSurface_SetSurface;
apiobj = encapsulate_api(c_api, "surface");
if (PyModule_Add(module, PYGAMEAPI_LOCAL_ENTRY, apiobj) < 0) {
return -1;
}

if (PyModule_AddObjectRef(module, "_dict", pgSurface_Type.tp_dict)) {
return -1;
}

return 0;
}

MODINIT_DEFINE(surface)
{
static PyModuleDef_Slot surf_slots[] = {
{Py_mod_exec, &exec_surface},
#if PY_VERSION_HEX >= 0x030c0000
{Py_mod_multiple_interpreters,
Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED}, // TODO: see if this can
// be supported later
#endif
#if PY_VERSION_HEX >= 0x030d0000
{Py_mod_gil, Py_MOD_GIL_USED}, // TODO: support this later
#endif
{0, NULL}};

static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
"surface",
DOC_SURFACE,
-1,
0,
_surface_methods,
NULL,
surf_slots,
NULL,
NULL,
NULL};
Expand Down Expand Up @@ -4641,41 +4687,5 @@ MODINIT_DEFINE(surface)
return NULL;
}

/* create the module */
module = PyModule_Create(&_module);
if (module == NULL) {
return NULL;
}
if (pg_warn_simd_at_runtime_but_uncompiled() < 0) {
Py_DECREF(module);
return NULL;
}
if (PyModule_AddObjectRef(module, "SurfaceType",
(PyObject *)&pgSurface_Type)) {
Py_DECREF(module);
return NULL;
}

if (PyModule_AddObjectRef(module, "Surface",
(PyObject *)&pgSurface_Type)) {
Py_DECREF(module);
return NULL;
}

/* export the c api */
c_api[0] = &pgSurface_Type;
c_api[1] = pgSurface_New2;
c_api[2] = pgSurface_Blit;
c_api[3] = pgSurface_SetSurface;
apiobj = encapsulate_api(c_api, "surface");
if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) {
Py_XDECREF(apiobj);
Py_DECREF(module);
return NULL;
}
if (PyModule_AddObjectRef(module, "_dict", pgSurface_Type.tp_dict)) {
Py_DECREF(module);
return NULL;
}
return module;
return PyModuleDef_Init(&_module);
}
Loading