1
+
1
2
/*
2
3
pygame-ce - Python Game Library
3
4
Copyright (C) 2000-2001 Pete Shinners
19
20
Pete Shinners
20
21
pete@shinners.org
21
22
*/
23
+ #define NO_PYGAME_C_API
24
+ #define PYGAMEAPI_BASE_INTERNAL
25
+
22
26
#include "base.h"
23
27
28
+ PG_PixelFormatEnum pg_default_convert_format = 0 ;
29
+
24
30
/* Custom exceptions */
25
- PyObject * pgExc_BufferError = NULL ;
31
+ static PyObject * pgExc_BufferError = NULL ;
26
32
27
33
/* 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 ;
31
37
SDL_Window * pg_default_window = NULL ;
32
38
pgSurfaceObject * 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 ;
127
40
128
41
/* compare compiled to linked, raise python error on incompatibility */
129
42
int
@@ -347,7 +260,7 @@ pg_get_sdl_version(PyObject *self, PyObject *args, PyObject *kwargs)
347
260
SDL_VERSION (& version );
348
261
#endif
349
262
350
- char * keywords [] = {"linked" , NULL };
263
+ static char * keywords [] = {"linked" , NULL };
351
264
352
265
if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|p" , keywords , & linked )) {
353
266
return NULL ; /* Exception already set. */
@@ -645,105 +558,6 @@ pg_TwoFloatsFromObj(PyObject *obj, float *val1, float *val2)
645
558
return 1 ;
646
559
}
647
560
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
-
747
561
int
748
562
pg_UintFromObj (PyObject * obj , Uint32 * val )
749
563
{
@@ -1334,32 +1148,6 @@ pgObject_GetBuffer(PyObject *obj, pg_buffer *pg_view_p, int flags)
1334
1148
return 0 ;
1335
1149
}
1336
1150
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
-
1363
1151
void
1364
1152
pgBuffer_Release (pg_buffer * pg_view_p )
1365
1153
{
@@ -1399,15 +1187,15 @@ _pg_buffer_is_byteswapped(Py_buffer *view)
1399
1187
switch (view -> format [0 ]) {
1400
1188
case '<' :
1401
1189
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
1402
- /* Use macros to make analyzer happy */
1190
+ /* Use macros to make static analyzer happy */
1403
1191
return 0 ;
1404
1192
#else
1405
1193
return 1 ;
1406
1194
#endif
1407
1195
case '>' :
1408
1196
case '!' :
1409
1197
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
1410
- /* Use macros to make analyzer happy */
1198
+ /* Use macros to make static analyzer happy */
1411
1199
return 0 ;
1412
1200
#else
1413
1201
return 1 ;
@@ -2154,8 +1942,6 @@ pg_SetDefaultWindowSurface(pgSurfaceObject *screen)
2154
1942
pg_default_screen = screen ;
2155
1943
}
2156
1944
2157
- PG_PixelFormatEnum pg_default_convert_format = 0 ;
2158
-
2159
1945
PG_PixelFormatEnum
2160
1946
pg_GetDefaultConvertFormat (void )
2161
1947
{
@@ -2216,7 +2002,7 @@ pygame_parachute(int sig)
2216
2002
#endif
2217
2003
}
2218
2004
2219
- int fatal_signals [] = {
2005
+ static int fatal_signals [] = {
2220
2006
SIGSEGV ,
2221
2007
#ifdef SIGBUS
2222
2008
SIGBUS ,
@@ -2230,7 +2016,7 @@ int fatal_signals[] = {
2230
2016
0 /*end of list*/
2231
2017
};
2232
2018
2233
- int parachute_installed = 0 ;
2019
+ static int parachute_installed = 0 ;
2234
2020
void
2235
2021
pg_install_parachute (void )
2236
2022
{
@@ -2279,7 +2065,7 @@ pg_uninstall_parachute(void)
2279
2065
2280
2066
/* bind functions to python */
2281
2067
2282
- PyMethodDef _base_methods [] = {
2068
+ static PyMethodDef _base_methods [] = {
2283
2069
{"init" , (PyCFunction )pg_init , METH_NOARGS , DOC_INIT },
2284
2070
{"quit" , (PyCFunction )pg_quit , METH_NOARGS , DOC_QUIT },
2285
2071
{"get_init" , (PyCFunction )pg_base_get_init , METH_NOARGS , DOC_GETINIT },
@@ -2298,8 +2084,8 @@ PyMethodDef _base_methods[] = {
2298
2084
#if defined(BUILD_STATIC ) && defined(NO_PYGAME_C_API )
2299
2085
// in case of wasm+dynamic loading it could be a trampoline in the globals
2300
2086
// 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 ;
2303
2089
#endif
2304
2090
2305
2091
MODINIT_DEFINE (base )
@@ -2310,17 +2096,17 @@ MODINIT_DEFINE(base)
2310
2096
// only pointer via C-api will be used, no need to keep global.
2311
2097
PyObject * pgExc_SDLError ;
2312
2098
#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 };
2324
2110
2325
2111
/* import need modules. Do this first so if there is an error
2326
2112
the module is not loaded.
0 commit comments