1+
12/*
23 pygame-ce - Python Game Library
34 Copyright (C) 2000-2001 Pete Shinners
1920 Pete Shinners
20212122*/
23+ #define NO_PYGAME_C_API
24+ #define PYGAMEAPI_BASE_INTERNAL
25+
2226#include "base.h"
2327
28+ PG_PixelFormatEnum pg_default_convert_format = 0 ;
29+
2430/* Custom exceptions */
25- PyObject * pgExc_BufferError = NULL ;
31+ static PyObject * pgExc_BufferError = NULL ;
2632
2733/* Only one instance of the state per process. */
28- PyObject * pg_quit_functions = NULL ;
29- int pg_is_init = 0 ;
30- int pg_sdl_was_init = 0 ;
34+ static PyObject * pg_quit_functions = NULL ;
35+ static int pg_is_init = 0 ;
36+ static int pg_sdl_was_init = 0 ;
3137SDL_Window * pg_default_window = NULL ;
3238pgSurfaceObject * pg_default_screen = NULL ;
33- int pg_env_blend_alpha_SDL2 = 0 ;
34-
35- void
36- pg_install_parachute (void );
37- void
38- pg_uninstall_parachute (void );
39- void
40- pg_atexit_quit (void );
41- int
42- pgGetArrayStruct (PyObject * , PyObject * * , PyArrayInterface * * );
43- PyObject *
44- pgArrayStruct_AsDict (PyArrayInterface * );
45- PyObject *
46- pgBuffer_AsArrayInterface (Py_buffer * );
47- PyObject *
48- pgBuffer_AsArrayStruct (Py_buffer * );
49- int
50- _pg_buffer_is_byteswapped (Py_buffer * );
51- void
52- pgBuffer_Release (pg_buffer * );
53- int
54- pgObject_GetBuffer (PyObject * , pg_buffer * , int );
55- inline PyObject *
56- pgObject_getRectHelper (PyObject * , PyObject * const * , Py_ssize_t , PyObject * ,
57- char * );
58- int
59- pgGetArrayInterface (PyObject * * , PyObject * );
60- int
61- pgArrayStruct_AsBuffer (pg_buffer * , PyObject * , PyArrayInterface * , int );
62- int
63- _pg_arraystruct_as_buffer (Py_buffer * , PyObject * , PyArrayInterface * , int );
64- int
65- _pg_arraystruct_to_format (char * , PyArrayInterface * , int );
66- int
67- pgDict_AsBuffer (pg_buffer * , PyObject * , int );
68- int
69- _pg_shape_check (PyObject * );
70- int
71- _pg_typestr_check (PyObject * );
72- int
73- _pg_strides_check (PyObject * );
74- int
75- _pg_data_check (PyObject * );
76- int
77- _pg_is_int_tuple (PyObject * );
78- int
79- _pg_values_as_buffer (Py_buffer * , int , PyObject * , PyObject * , PyObject * ,
80- PyObject * );
81- int
82- _pg_int_tuple_as_ssize_arr (PyObject * , Py_ssize_t * );
83- int
84- _pg_typestr_as_format (PyObject * , char * , Py_ssize_t * );
85- PyObject *
86- pg_view_get_typestr_obj (Py_buffer * );
87- PyObject *
88- pg_view_get_shape_obj (Py_buffer * );
89- PyObject *
90- pg_view_get_strides_obj (Py_buffer * );
91- PyObject *
92- pg_view_get_data_obj (Py_buffer * );
93- char
94- _pg_as_arrayinter_typekind (Py_buffer * );
95- char
96- _pg_as_arrayinter_byteorder (Py_buffer * );
97- int
98- _pg_as_arrayinter_flags (Py_buffer * );
99- pgCapsuleInterface *
100- _pg_new_capsuleinterface (Py_buffer * );
101- void
102- _pg_capsule_PyMem_Free (PyObject * );
103- PyObject *
104- _pg_shape_as_tuple (PyArrayInterface * );
105- PyObject *
106- _pg_typekind_as_str (PyArrayInterface * );
107- PyObject *
108- _pg_strides_as_tuple (PyArrayInterface * );
109- PyObject *
110- _pg_data_as_tuple (PyArrayInterface * );
111- PyObject *
112- pg_get_array_interface (PyObject * , PyObject * );
113- void
114- _pg_release_buffer_array (Py_buffer * );
115- void
116- _pg_release_buffer_generic (Py_buffer * );
117- SDL_Window *
118- pg_GetDefaultWindow (void );
119- void
120- pg_SetDefaultWindow (SDL_Window * );
121- pgSurfaceObject *
122- pg_GetDefaultWindowSurface (void );
123- void
124- pg_SetDefaultWindowSurface (pgSurfaceObject * );
125- int
126- pg_EnvShouldBlendAlphaSDL2 (void );
39+ static int pg_env_blend_alpha_SDL2 = 0 ;
12740
12841/* compare compiled to linked, raise python error on incompatibility */
12942int
@@ -347,7 +260,7 @@ pg_get_sdl_version(PyObject *self, PyObject *args, PyObject *kwargs)
347260 SDL_VERSION (& version );
348261#endif
349262
350- char * keywords [] = {"linked" , NULL };
263+ static char * keywords [] = {"linked" , NULL };
351264
352265 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|p" , keywords , & linked )) {
353266 return NULL ; /* Exception already set. */
@@ -645,105 +558,6 @@ pg_TwoFloatsFromObj(PyObject *obj, float *val1, float *val2)
645558 return 1 ;
646559}
647560
648- inline int
649- pg_DoubleFromObj (PyObject * obj , double * val )
650- {
651- if (PyFloat_Check (obj )) {
652- * val = PyFloat_AS_DOUBLE (obj );
653- return 1 ;
654- }
655-
656- * val = (double )PyLong_AsLong (obj );
657- if (PyErr_Occurred ()) {
658- PyErr_Clear ();
659- return 0 ;
660- }
661-
662- return 1 ;
663- }
664-
665- /*Assumes obj is a Sequence, internal or conscious use only*/
666- inline int
667- _pg_DoubleFromObjIndex (PyObject * obj , int index , double * val )
668- {
669- int result = 0 ;
670-
671- PyObject * item = PySequence_ITEM (obj , index );
672- if (!item ) {
673- PyErr_Clear ();
674- return 0 ;
675- }
676- result = pg_DoubleFromObj (item , val );
677- Py_DECREF (item );
678-
679- return result ;
680- }
681-
682- inline int
683- pg_TwoDoublesFromObj (PyObject * obj , double * val1 , double * val2 )
684- {
685- Py_ssize_t length ;
686- /*Faster path for tuples and lists*/
687- if (pgSequenceFast_Check (obj )) {
688- length = PySequence_Fast_GET_SIZE (obj );
689- PyObject * * f_arr = PySequence_Fast_ITEMS (obj );
690- if (length == 2 ) {
691- if (!pg_DoubleFromObj (f_arr [0 ], val1 ) ||
692- !pg_DoubleFromObj (f_arr [1 ], val2 )) {
693- return 0 ;
694- }
695- }
696- else if (length == 1 ) {
697- /* Handle case of ((x, y), ) 'nested sequence' */
698- return pg_TwoDoublesFromObj (f_arr [0 ], val1 , val2 );
699- }
700- else {
701- return 0 ;
702- }
703- }
704- else if (PySequence_Check (obj )) {
705- length = PySequence_Length (obj );
706- if (length == 2 ) {
707- if (!_pg_DoubleFromObjIndex (obj , 0 , val1 )) {
708- return 0 ;
709- }
710- if (!_pg_DoubleFromObjIndex (obj , 1 , val2 )) {
711- return 0 ;
712- }
713- }
714- else if (length == 1 && !PyUnicode_Check (obj )) {
715- /* Handle case of ((x, y), ) 'nested sequence' */
716- PyObject * tmp = PySequence_ITEM (obj , 0 );
717- int ret = pg_TwoDoublesFromObj (tmp , val1 , val2 );
718- Py_DECREF (tmp );
719- return ret ;
720- }
721- else {
722- PyErr_Clear ();
723- return 0 ;
724- }
725- }
726- else {
727- return 0 ;
728- }
729-
730- return 1 ;
731- }
732-
733- inline int
734- pg_TwoDoublesFromFastcallArgs (PyObject * const * args , Py_ssize_t nargs ,
735- double * val1 , double * val2 )
736- {
737- if (nargs == 1 && pg_TwoDoublesFromObj (args [0 ], val1 , val2 )) {
738- return 1 ;
739- }
740- else if (nargs == 2 && pg_DoubleFromObj (args [0 ], val1 ) &&
741- pg_DoubleFromObj (args [1 ], val2 )) {
742- return 1 ;
743- }
744- return 0 ;
745- }
746-
747561int
748562pg_UintFromObj (PyObject * obj , Uint32 * val )
749563{
@@ -1334,32 +1148,6 @@ pgObject_GetBuffer(PyObject *obj, pg_buffer *pg_view_p, int flags)
13341148 return 0 ;
13351149}
13361150
1337- inline PyObject *
1338- pgObject_getRectHelper (PyObject * rect , PyObject * const * args , Py_ssize_t nargs ,
1339- PyObject * kwnames , char * type )
1340- {
1341- if (nargs > 0 ) {
1342- Py_DECREF (rect );
1343- return PyErr_Format (PyExc_TypeError ,
1344- "get_%s only accepts keyword arguments" , type );
1345- }
1346-
1347- if (rect && kwnames ) {
1348- Py_ssize_t i , sequence_len ;
1349- PyObject * * sequence_items ;
1350- sequence_items = PySequence_Fast_ITEMS (kwnames );
1351- sequence_len = PyTuple_GET_SIZE (kwnames );
1352-
1353- for (i = 0 ; i < sequence_len ; ++ i ) {
1354- if ((PyObject_SetAttr (rect , sequence_items [i ], args [i ]) == -1 )) {
1355- Py_DECREF (rect );
1356- return NULL ;
1357- }
1358- }
1359- }
1360- return rect ;
1361- }
1362-
13631151void
13641152pgBuffer_Release (pg_buffer * pg_view_p )
13651153{
@@ -1399,15 +1187,15 @@ _pg_buffer_is_byteswapped(Py_buffer *view)
13991187 switch (view -> format [0 ]) {
14001188 case '<' :
14011189#if SDL_BYTEORDER == SDL_LIL_ENDIAN
1402- /* Use macros to make analyzer happy */
1190+ /* Use macros to make static analyzer happy */
14031191 return 0 ;
14041192#else
14051193 return 1 ;
14061194#endif
14071195 case '>' :
14081196 case '!' :
14091197#if SDL_BYTEORDER == SDL_BIG_ENDIAN
1410- /* Use macros to make analyzer happy */
1198+ /* Use macros to make static analyzer happy */
14111199 return 0 ;
14121200#else
14131201 return 1 ;
@@ -2154,8 +1942,6 @@ pg_SetDefaultWindowSurface(pgSurfaceObject *screen)
21541942 pg_default_screen = screen ;
21551943}
21561944
2157- PG_PixelFormatEnum pg_default_convert_format = 0 ;
2158-
21591945PG_PixelFormatEnum
21601946pg_GetDefaultConvertFormat (void )
21611947{
@@ -2216,7 +2002,7 @@ pygame_parachute(int sig)
22162002#endif
22172003}
22182004
2219- int fatal_signals [] = {
2005+ static int fatal_signals [] = {
22202006 SIGSEGV ,
22212007#ifdef SIGBUS
22222008 SIGBUS ,
@@ -2230,7 +2016,7 @@ int fatal_signals[] = {
22302016 0 /*end of list*/
22312017};
22322018
2233- int parachute_installed = 0 ;
2019+ static int parachute_installed = 0 ;
22342020void
22352021pg_install_parachute (void )
22362022{
@@ -2279,7 +2065,7 @@ pg_uninstall_parachute(void)
22792065
22802066/* bind functions to python */
22812067
2282- PyMethodDef _base_methods [] = {
2068+ static PyMethodDef _base_methods [] = {
22832069 {"init" , (PyCFunction )pg_init , METH_NOARGS , DOC_INIT },
22842070 {"quit" , (PyCFunction )pg_quit , METH_NOARGS , DOC_QUIT },
22852071 {"get_init" , (PyCFunction )pg_base_get_init , METH_NOARGS , DOC_GETINIT },
@@ -2298,8 +2084,8 @@ PyMethodDef _base_methods[] = {
22982084#if defined(BUILD_STATIC ) && defined(NO_PYGAME_C_API )
22992085// in case of wasm+dynamic loading it could be a trampoline in the globals
23002086// generated at runtime.
2301- // when building make global accessible symbol directly.
2302- PyObject * pgExc_SDLError ;
2087+ // when building static make global accessible symbol directly.
2088+ static PyObject * pgExc_SDLError ;
23032089#endif
23042090
23052091MODINIT_DEFINE (base )
@@ -2310,17 +2096,17 @@ MODINIT_DEFINE(base)
23102096 // only pointer via C-api will be used, no need to keep global.
23112097 PyObject * pgExc_SDLError ;
23122098#endif
2313- void * c_api [PYGAMEAPI_BASE_NUMSLOTS ];
2314-
2315- struct PyModuleDef _module = {PyModuleDef_HEAD_INIT ,
2316- "base" ,
2317- "" ,
2318- -1 ,
2319- _base_methods ,
2320- NULL ,
2321- NULL ,
2322- NULL ,
2323- NULL };
2099+ static void * c_api [PYGAMEAPI_BASE_NUMSLOTS ];
2100+
2101+ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT ,
2102+ "base" ,
2103+ "" ,
2104+ -1 ,
2105+ _base_methods ,
2106+ NULL ,
2107+ NULL ,
2108+ NULL ,
2109+ NULL };
23242110
23252111 /* import need modules. Do this first so if there is an error
23262112 the module is not loaded.
0 commit comments