Skip to content

Commit b63dabb

Browse files
committed
Merge branch 'main' of https://github.com/pygame-community/pygame-ce into SDL_JoystickSetLED
2 parents 21ca2b0 + a82eaef commit b63dabb

File tree

7 files changed

+137
-73
lines changed

7 files changed

+137
-73
lines changed

src_c/alphablit.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ blit_blend_premultiplied(SDL_BlitInfo *info);
6161
static int
6262
SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
6363
SDL_Rect *dstrect, int blend_flags);
64-
extern int
65-
SDL_RLESurface(SDL_Surface *surface);
66-
extern void
67-
SDL_UnRLESurface(SDL_Surface *surface, int recode);
6864

6965
static int
7066
SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,

src_c/include/pygame_mask.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,4 @@ typedef struct {
2929

3030
#define pgMask_AsBitmap(x) (((pgMaskObject *)x)->mask)
3131

32-
#ifndef PYGAMEAPI_MASK_INTERNAL
33-
34-
#include "pgimport.h"
35-
36-
PYGAMEAPI_DEFINE_SLOTS(mask);
37-
38-
#define pgMask_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(mask, 0))
39-
#define pgMask_Check(x) ((x)->ob_type == &pgMask_Type)
40-
41-
#define import_pygame_mask() _IMPORT_PYGAME_MODULE(mask)
42-
43-
#endif /* ~PYGAMEAPI_MASK_INTERNAL */
44-
4532
#endif /* ~PGMASK_H */

src_c/mask.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,8 +2667,7 @@ static PyMethodDef _mask_methods[] = {
26672667

26682668
MODINIT_DEFINE(mask)
26692669
{
2670-
PyObject *module, *apiobj;
2671-
static void *c_api[PYGAMEAPI_MASK_NUMSLOTS];
2670+
PyObject *module;
26722671

26732672
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
26742673
"mask",
@@ -2720,13 +2719,5 @@ MODINIT_DEFINE(mask)
27202719
return NULL;
27212720
}
27222721

2723-
/* export the c api */
2724-
c_api[0] = &pgMask_Type;
2725-
apiobj = encapsulate_api(c_api, "mask");
2726-
if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) {
2727-
Py_XDECREF(apiobj);
2728-
Py_DECREF(module);
2729-
return NULL;
2730-
}
27312722
return module;
27322723
}

src_c/mask.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
#define PGMASK_INTERNAL_H
33

44
#include "include/pygame_mask.h"
5-
#define PYGAMEAPI_MASK_NUMSLOTS 1
65

76
#endif /* ~PGMASK_INTERNAL_H */

src_c/static.c

Lines changed: 89 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ import_pygame_surface(void)
4949
{
5050
}
5151

52+
void
53+
import_pygame_window(void)
54+
{
55+
}
56+
5257
void
5358
import_pygame_geometry(void)
5459
{
@@ -59,6 +64,16 @@ import_pygame_color(void)
5964
{
6065
}
6166

67+
void
68+
import_pygame_font(void)
69+
{
70+
}
71+
72+
void
73+
import_pygame_freetype(void)
74+
{
75+
}
76+
6277
void
6378
import_pygame_bufferproxy(void)
6479
{
@@ -79,8 +94,22 @@ import_pygame_joystick(void)
7994
{
8095
}
8196

97+
#undef import_pygame_imageext
98+
#undef import_pygame_render
99+
#undef import_pygame_pixelarray
100+
82101
void
83-
import_pygame_window(void)
102+
import_pygame_imageext(void)
103+
{
104+
}
105+
106+
void
107+
import_pygame_render(void)
108+
{
109+
}
110+
111+
void
112+
import_pygame_pixelarray(void)
84113
{
85114
}
86115

@@ -198,24 +227,30 @@ void
198227
load_submodule(const char *parent, PyObject *mod, const char *alias)
199228
{
200229
char fqn[1024];
201-
snprintf(fqn, sizeof(fqn), "%s.%s", parent, alias);
202-
203-
PyObject *modules = PyImport_GetModuleDict();
204-
205-
PyObject *pmod = PyDict_GetItemString(modules, parent);
206-
207230
if (!mod) {
208-
snprintf(fqn, sizeof(fqn), "ERROR: %s.%s", parent, alias);
231+
snprintf(fqn, sizeof(fqn), "ERROR: PyInit_%s failed for %s.%s", alias,
232+
parent, alias);
209233
puts(fqn);
210234
PyErr_Print();
211235
PyErr_Clear();
212236
}
213237
else {
214-
PyDict_SetItemString(modules, fqn, mod);
215-
PyDict_SetItemString(PyModule_GetDict(mod), "__name__",
216-
PyUnicode_FromString(fqn));
217-
PyModule_AddObjectRef(pmod, alias, mod);
218-
Py_XDECREF(mod);
238+
snprintf(fqn, sizeof(fqn), "%s.%s", parent, alias);
239+
PyObject *modules = PyImport_GetModuleDict();
240+
241+
PyObject *pmod = PyDict_GetItemString(modules, parent);
242+
if (!pmod) {
243+
snprintf(fqn, sizeof(fqn), "ERROR: Parent %s not found for %s.%s",
244+
parent, parent, alias);
245+
puts(fqn);
246+
}
247+
else {
248+
PyDict_SetItemString(modules, fqn, mod);
249+
PyDict_SetItemString(PyModule_GetDict(mod), "__name__",
250+
PyUnicode_FromString(fqn));
251+
PyModule_AddObjectRef(pmod, alias, mod);
252+
Py_XDECREF(mod);
253+
}
219254
}
220255
}
221256

@@ -225,6 +260,7 @@ load_submodule_mphase(const char *parent, PyObject *mdef, PyObject *spec,
225260
{
226261
char fqn[1024];
227262
snprintf(fqn, sizeof(fqn), "%s.%s", parent, alias);
263+
228264
PyObject *modules = PyImport_GetModuleDict();
229265

230266
Py_DECREF(PyObject_GetAttrString(spec, "name"));
@@ -256,6 +292,7 @@ static PyObject *
256292
mod_pygame_import_cython(PyObject *self, PyObject *spec)
257293
{
258294
load_submodule_mphase("pygame._sdl2", PyInit_sdl2(), spec, "sdl2");
295+
259296
load_submodule_mphase("pygame._sdl2", PyInit_mixer(), spec, "mixer");
260297
#if defined(CONTROLLER_NOPYX)
261298
load_submodule("pygame._sdl2", PyInit_controller(), "controller");
@@ -288,47 +325,72 @@ PyInit_pygame_static()
288325
SDL_SetHint("SDL_EMSCRIPTEN_KEYBOARD_ELEMENT", "1");
289326

290327
load_submodule("pygame", PyInit_base(), "base");
328+
329+
//
291330
load_submodule("pygame", PyInit_constants(), "constants");
292-
load_submodule("pygame", PyInit_surflock(), "surflock");
293-
load_submodule("pygame", PyInit_rwobject(), "rwobject");
331+
//
294332
load_submodule("pygame", PyInit_pg_math(), "math");
295-
load_submodule("pygame", PyInit_display(), "display");
296-
load_submodule("pygame", PyInit_surface(), "surface");
297-
load_submodule("pygame", PyInit_system(), "system");
298-
load_submodule("pygame", PyInit_key(), "key");
299333

334+
// base, pygame.colordict
335+
load_submodule("pygame", PyInit_color(), "color");
336+
337+
// base
300338
load_submodule("pygame", PyInit_rect(), "rect");
339+
340+
// base, rect
301341
load_submodule("pygame", PyInit_geometry(), "geometry");
302-
load_submodule("pygame", PyInit_gfxdraw(), "gfxdraw");
303-
load_submodule("pygame", PyInit_pg_time(), "time");
304-
load_submodule("pygame", PyInit__freetype(), "_freetype");
305342

306-
load_submodule("pygame", PyInit_imageext(), "imageext");
343+
load_submodule("pygame", PyInit_bufferproxy(), "bufferproxy");
344+
load_submodule("pygame", PyInit_surflock(), "surflock");
345+
346+
// base, color, rect, bufferproxy, surflock
347+
load_submodule("pygame", PyInit_surface(), "surface");
348+
349+
load_submodule("pygame", PyInit_rwobject(), "rwobject");
307350

351+
// base, color, rect, bufferproxy, surflock, surface, rwobject
352+
load_submodule("pygame", PyInit_imageext(), "imageext");
353+
// base, color, rect, bufferproxy, surflock, surface, rwobject
308354
load_submodule("pygame", PyInit_image(), "image");
355+
356+
load_submodule("pygame", PyInit__freetype(), "_freetype");
309357
load_submodule("pygame", PyInit_font(), "font");
310358
load_submodule("pygame", PyInit_pixelcopy(), "pixelcopy");
311359
load_submodule("pygame", PyInit_newbuffer(), "newbuffer");
312360

313-
load_submodule("pygame", PyInit_color(), "color");
314-
load_submodule("pygame", PyInit_bufferproxy(), "bufferproxy");
361+
// base
362+
load_submodule("pygame", PyInit_joystick(), "joystick");
363+
// base, joystick
364+
load_submodule("pygame", PyInit_event(), "event");
365+
366+
// base, rect, event
367+
load_submodule("pygame", PyInit_key(), "key");
368+
// base, event
369+
load_submodule("pygame", PyInit_pg_time(), "time");
315370

316371
load_submodule("pygame", PyInit_transform(), "transform");
317372
load_submodule("pygame", PyInit_draw(), "draw");
318373

319374
load_submodule("pygame", PyInit_mask(), "mask");
320375
load_submodule("pygame", PyInit_mouse(), "mouse");
321-
load_submodule("pygame", PyInit_event(), "event");
322-
load_submodule("pygame", PyInit_joystick(), "joystick");
323376

324377
load_submodule("pygame", PyInit_pg_mixer(), "mixer");
325378
load_submodule("pygame.mixer", PyInit_mixer_music(), "music");
326379

380+
// base, color, rect, bufferproxy, surflock, surface
327381
load_submodule("pygame", PyInit_window(), "window");
382+
383+
// base, color, rect, surflock, surface, window
384+
load_submodule("pygame", PyInit_display(), "display");
328385
load_submodule("pygame", PyInit__render(), "_render");
329386

330387
load_submodule("pygame", PyInit_pixelarray(), "pixelarray");
331388

389+
// base, color, rect, bufferproxy, surflock, surface
390+
load_submodule("pygame", PyInit_gfxdraw(), "gfxdraw");
391+
392+
load_submodule("pygame", PyInit_system(), "system");
393+
332394
return PyModule_Create(&mod_pygame_static);
333395
}
334396

src_c/surface.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4630,11 +4630,11 @@ exec_surface(PyObject *module)
46304630

46314631
PyObject *apiobj;
46324632
static void *c_api[PYGAMEAPI_SURFACE_NUMSLOTS];
4633-
4633+
#ifndef BUILD_STATIC
46344634
if (pg_warn_simd_at_runtime_but_uncompiled() < 0) {
46354635
return -1;
46364636
}
4637-
4637+
#endif
46384638
if (PyModule_AddObjectRef(module, "SurfaceType",
46394639
(PyObject *)&pgSurface_Type)) {
46404640
return -1;
@@ -4664,6 +4664,7 @@ exec_surface(PyObject *module)
46644664

46654665
MODINIT_DEFINE(surface)
46664666
{
4667+
#ifndef BUILD_STATIC
46674668
static PyModuleDef_Slot surf_slots[] = {
46684669
{Py_mod_exec, &exec_surface},
46694670
#if PY_VERSION_HEX >= 0x030c0000
@@ -4675,16 +4676,32 @@ MODINIT_DEFINE(surface)
46754676
{Py_mod_gil, Py_MOD_GIL_USED}, // TODO: support this later
46764677
#endif
46774678
{0, NULL}};
4678-
4679+
#endif
46794680
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
46804681
"surface",
46814682
DOC_SURFACE,
46824683
0,
46834684
_surface_methods,
4685+
#ifndef BUILD_STATIC
46844686
surf_slots,
4687+
#else
4688+
NULL,
4689+
#endif
46854690
NULL,
46864691
NULL,
46874692
NULL};
4688-
4693+
#ifndef BUILD_STATIC
46894694
return PyModuleDef_Init(&_module);
4695+
#else
4696+
// in static mode with want surface module to be ready before python types
4697+
// are evaluated eg pygame.surface.Surface in sprite.py
4698+
PyObject *module = PyModule_Create(&_module);
4699+
if (module) {
4700+
if (exec_surface(module) != 0) {
4701+
Py_DECREF(module);
4702+
return NULL;
4703+
}
4704+
}
4705+
return module;
4706+
#endif
46904707
}

0 commit comments

Comments
 (0)