@@ -52,10 +52,10 @@ typedef enum {
52
52
} SurfViewKind ;
53
53
54
54
/* To avoid problems with non-const Py_buffer format field */
55
- static char FormatUint8 [] = "B" ;
56
- static char FormatUint16 [] = "=H" ;
57
- static char FormatUint24 [] = "3x" ;
58
- static char FormatUint32 [] = "=I" ;
55
+ #define FormatUint8 "B"
56
+ #define FormatUint16 "=H"
57
+ #define FormatUint24 "3x"
58
+ #define FormatUint32 "=I"
59
59
60
60
typedef struct pg_bufferinternal_s {
61
61
PyObject * consumer_ref ; /* A weak reference to a bufferproxy object */
@@ -4596,69 +4596,53 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
4596
4596
4597
4597
static PyMethodDef _surface_methods [] = {{NULL , NULL , 0 , NULL }};
4598
4598
4599
- MODINIT_DEFINE (surface )
4599
+ int
4600
+ exec_surface (PyObject * module )
4600
4601
{
4601
- PyObject * module , * apiobj ;
4602
- static void * c_api [PYGAMEAPI_SURFACE_NUMSLOTS ];
4603
-
4604
- static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT ,
4605
- "surface" ,
4606
- DOC_SURFACE ,
4607
- -1 ,
4608
- _surface_methods ,
4609
- NULL ,
4610
- NULL ,
4611
- NULL ,
4612
- NULL };
4613
-
4614
4602
/* imported needed apis; Do this first so if there is an error
4615
4603
the module is not loaded.
4616
4604
*/
4617
4605
import_pygame_base ();
4618
4606
if (PyErr_Occurred ()) {
4619
- return NULL ;
4607
+ return -1 ;
4620
4608
}
4621
4609
import_pygame_color ();
4622
4610
if (PyErr_Occurred ()) {
4623
- return NULL ;
4611
+ return -1 ;
4624
4612
}
4625
4613
import_pygame_rect ();
4626
4614
if (PyErr_Occurred ()) {
4627
- return NULL ;
4615
+ return -1 ;
4628
4616
}
4629
4617
import_pygame_bufferproxy ();
4630
4618
if (PyErr_Occurred ()) {
4631
- return NULL ;
4619
+ return -1 ;
4632
4620
}
4633
4621
_IMPORT_PYGAME_MODULE (surflock );
4634
4622
if (PyErr_Occurred ()) {
4635
- return NULL ;
4623
+ return -1 ;
4636
4624
}
4637
4625
4638
4626
/* type preparation */
4639
4627
if (PyType_Ready (& pgSurface_Type ) < 0 ) {
4640
- return NULL ;
4628
+ return -1 ;
4641
4629
}
4642
4630
4643
- /* create the module */
4644
- module = PyModule_Create (& _module );
4645
- if (module == NULL ) {
4646
- return NULL ;
4647
- }
4631
+ PyObject * apiobj ;
4632
+ static void * c_api [PYGAMEAPI_SURFACE_NUMSLOTS ];
4633
+
4648
4634
if (pg_warn_simd_at_runtime_but_uncompiled () < 0 ) {
4649
- Py_DECREF (module );
4650
- return NULL ;
4635
+ return -1 ;
4651
4636
}
4637
+
4652
4638
if (PyModule_AddObjectRef (module , "SurfaceType" ,
4653
4639
(PyObject * )& pgSurface_Type )) {
4654
- Py_DECREF (module );
4655
- return NULL ;
4640
+ return -1 ;
4656
4641
}
4657
4642
4658
4643
if (PyModule_AddObjectRef (module , "Surface" ,
4659
4644
(PyObject * )& pgSurface_Type )) {
4660
- Py_DECREF (module );
4661
- return NULL ;
4645
+ return -1 ;
4662
4646
}
4663
4647
4664
4648
/* export the c api */
@@ -4667,14 +4651,40 @@ MODINIT_DEFINE(surface)
4667
4651
c_api [2 ] = pgSurface_Blit ;
4668
4652
c_api [3 ] = pgSurface_SetSurface ;
4669
4653
apiobj = encapsulate_api (c_api , "surface" );
4670
- if (PyModule_AddObject (module , PYGAMEAPI_LOCAL_ENTRY , apiobj )) {
4671
- Py_XDECREF (apiobj );
4672
- Py_DECREF (module );
4673
- return NULL ;
4654
+ if (PyModule_Add (module , PYGAMEAPI_LOCAL_ENTRY , apiobj ) < 0 ) {
4655
+ return -1 ;
4674
4656
}
4657
+
4675
4658
if (PyModule_AddObjectRef (module , "_dict" , pgSurface_Type .tp_dict )) {
4676
- Py_DECREF (module );
4677
- return NULL ;
4659
+ return -1 ;
4678
4660
}
4679
- return module ;
4661
+
4662
+ return 0 ;
4663
+ }
4664
+
4665
+ MODINIT_DEFINE (surface )
4666
+ {
4667
+ static PyModuleDef_Slot surf_slots [] = {
4668
+ {Py_mod_exec , & exec_surface },
4669
+ #if PY_VERSION_HEX >= 0x030c0000
4670
+ {Py_mod_multiple_interpreters ,
4671
+ Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED }, // TODO: see if this can
4672
+ // be supported later
4673
+ #endif
4674
+ #if PY_VERSION_HEX >= 0x030d0000
4675
+ {Py_mod_gil , Py_MOD_GIL_USED }, // TODO: support this later
4676
+ #endif
4677
+ {0 , NULL }};
4678
+
4679
+ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT ,
4680
+ "surface" ,
4681
+ DOC_SURFACE ,
4682
+ 0 ,
4683
+ _surface_methods ,
4684
+ surf_slots ,
4685
+ NULL ,
4686
+ NULL ,
4687
+ NULL };
4688
+
4689
+ return PyModuleDef_Init (& _module );
4680
4690
}
0 commit comments