Skip to content
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

Remove most SDL1/SDL2 compatibility c code #2823

Merged
merged 1 commit into from Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
366 changes: 2 additions & 364 deletions src_c/alphablit.c

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions src_c/base.c
Expand Up @@ -79,11 +79,9 @@ static PyObject *pgExc_BufferError = NULL;
static PyObject *pg_quit_functions = NULL;
static int pg_is_init = 0;
static int pg_sdl_was_init = 0;
#if IS_SDLv2
SDL_Window *pg_default_window = NULL;
pgSurfaceObject *pg_default_screen = NULL;
static char * pg_env_blend_alpha_SDL2 = NULL;
#endif /* IS_SDLv2 */

static void
pg_install_parachute(void);
Expand Down Expand Up @@ -164,7 +162,6 @@ static void
_pg_release_buffer_array(Py_buffer *);
static void
_pg_release_buffer_generic(Py_buffer *);
#if IS_SDLv2
static SDL_Window *
pg_GetDefaultWindow(void);
static void
Expand All @@ -175,29 +172,10 @@ static void
pg_SetDefaultWindowSurface(pgSurfaceObject *);
static char *
pg_EnvShouldBlendAlphaSDL2(void);
#endif /* IS_SDLv2 */

static int
pg_CheckSDLVersions(void) /*compare compiled to linked*/
{
#if IS_SDLv1
SDL_version compiled;
const SDL_version *linked;

SDL_VERSION(&compiled);
linked = SDL_Linked_Version();

/*only check the major and minor version numbers.
we will relax any differences in 'patch' version.*/

if (compiled.major != linked->major || compiled.minor != linked->minor) {
PyErr_Format(PyExc_RuntimeError,
"SDL compiled with version %d.%d.%d, linked to %d.%d.%d",
compiled.major, compiled.minor, compiled.patch,
linked->major, linked->minor, linked->patch);
return 0;
}
#else /* IS_SDLv2 */
SDL_version compiled;
SDL_version linked;

Expand All @@ -214,7 +192,6 @@ pg_CheckSDLVersions(void) /*compare compiled to linked*/
linked.major, linked.minor, linked.patch);
return 0;
}
#endif /* IS_SDLv2 */

return 1;
}
Expand Down Expand Up @@ -335,11 +312,7 @@ pg_init(PyObject *self)
IMPPREFIX "font",
IMPPREFIX "freetype",
IMPPREFIX "mixer",
#if IS_SDLv2
/* IMPPREFIX "_sdl2.controller", Is this required? Comment for now*/
#else
IMPPREFIX "cdrom",
#endif
NULL
};

Expand All @@ -355,9 +328,7 @@ pg_init(PyObject *self)
pg_sdl_was_init = SDL_Init(SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) == 0;
#endif

#if IS_SDLv2
pg_env_blend_alpha_SDL2 = SDL_getenv("PYGAME_BLEND_ALPHA_SDL2");
#endif /* IS_SDLv2 */

/* initialize all pygame modules */
for (i = 0; modnames[i]; i++) {
Expand Down Expand Up @@ -391,17 +362,10 @@ pg_atexit_quit(void)
static PyObject *
pg_get_sdl_version(PyObject *self)
{
#if IS_SDLv1
const SDL_version *v;

v = SDL_Linked_Version();
return Py_BuildValue("iii", v->major, v->minor, v->patch);
#else /* IS_SDLv2 */
SDL_version v;

SDL_GetVersion(&v);
return Py_BuildValue("iii", v.major, v.minor, v.patch);
#endif /* IS_SDLv2 */
}

static PyObject *
Expand All @@ -418,11 +382,7 @@ _pg_quit(void)

/* Put all the module names we want to quit in this array */
const char *modnames[] = {
#if IS_SDLv2
/* IMPPREFIX "_sdl2.controller", Is this required?, comment for now */
#else
IMPPREFIX "cdrom"
#endif
IMPPREFIX "mixer",
IMPPREFIX "freetype",
IMPPREFIX "font",
Expand Down Expand Up @@ -656,17 +616,7 @@ pg_RGBAFromObj(PyObject *obj, Uint8 *RGBA)
static PyObject *
pg_get_error(PyObject *self)
{
#if IS_SDLv1 && !defined(PYPY_VERSION)
/* SDL 1's encoding is ambiguous */
PyObject *obj;
if ((obj = PyUnicode_DecodeUTF8(SDL_GetError(),
strlen(SDL_GetError()), "strict")))
return obj;
PyErr_Clear();
return PyUnicode_DecodeLocale(SDL_GetError(), "surrogateescape");
#else /* IS_SDLv2 */
return Text_FromUTF8(SDL_GetError());
#endif /* IS_SDLv2 */
}

static PyObject *
Expand Down Expand Up @@ -1921,7 +1871,6 @@ _pg_typestr_as_format(PyObject *sp, char *format, Py_ssize_t *itemsize_p)
return 0;
}

#if IS_SDLv2
/*Default window(display)*/
static SDL_Window *
pg_GetDefaultWindow(void)
Expand Down Expand Up @@ -1966,7 +1915,6 @@ pg_EnvShouldBlendAlphaSDL2(void)
{
return pg_env_blend_alpha_SDL2;
}
#endif /* IS_SDLv2 */

/*error signal handlers(replacing SDL parachute)*/
static void
Expand Down Expand Up @@ -2205,16 +2153,12 @@ MODINIT_DEFINE(base)
c_api[16] = pgBuffer_Release;
c_api[17] = pgDict_AsBuffer;
c_api[18] = pgExc_BufferError;
#if IS_SDLv1
#define FILLED_SLOTS 19
#else /* IS_SDLv2 */
c_api[19] = pg_GetDefaultWindow;
c_api[20] = pg_SetDefaultWindow;
c_api[21] = pg_GetDefaultWindowSurface;
c_api[22] = pg_SetDefaultWindowSurface;
c_api[23] = pg_EnvShouldBlendAlphaSDL2;
#define FILLED_SLOTS 24
#endif /* IS_SDLv2 */

#if PYGAMEAPI_BASE_NUMSLOTS != FILLED_SLOTS
#error export slot count mismatch
Expand Down