Skip to content

Commit

Permalink
Rework pg_EnvShouldBlendAlphaSDL2 for SDL3
Browse files Browse the repository at this point in the history
SDL_getenv now returns a const char* instead of a char*, so rather than worry about propagating that through or casting it away, lets just have pg_EnvShouldBlendAlphaSDL2 return an int, and have the callers evaluate that instead of evaluating whether a char* is NULL or not. This requires no changes to the callers.
  • Loading branch information
Starbuck5 committed Oct 31, 2024
1 parent 4d6a8e3 commit 5827924
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src_c/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int pg_is_init = 0;
static int pg_sdl_was_init = 0;
SDL_Window *pg_default_window = NULL;
pgSurfaceObject *pg_default_screen = NULL;
static char *pg_env_blend_alpha_SDL2 = NULL;
static int pg_env_blend_alpha_SDL2 = 0;

static void
pg_install_parachute(void);
Expand Down Expand Up @@ -170,7 +170,7 @@ static pgSurfaceObject *
pg_GetDefaultWindowSurface(void);
static void
pg_SetDefaultWindowSurface(pgSurfaceObject *);
static char *
static int
pg_EnvShouldBlendAlphaSDL2(void);

/* compare compiled to linked, raise python error on incompatibility */
Expand Down Expand Up @@ -347,7 +347,7 @@ pg_init(PyObject *self, PyObject *_null)
pg_sdl_was_init = SDL_Init(PG_INIT_TIMER | PG_INIT_NOPARACHUTE) == 0;
#endif

pg_env_blend_alpha_SDL2 = SDL_getenv("PYGAME_BLEND_ALPHA_SDL2");
pg_env_blend_alpha_SDL2 = SDL_getenv("PYGAME_BLEND_ALPHA_SDL2") != NULL;

/* initialize all pygame modules */
for (i = 0; modnames[i]; i++) {
Expand Down Expand Up @@ -2096,7 +2096,7 @@ pg_SetDefaultConvertFormat(Uint32 format)
return pg_default_convert_format; // returns for NULL error checking
}

static char *
static int
pg_EnvShouldBlendAlphaSDL2(void)
{
return pg_env_blend_alpha_SDL2;
Expand Down
2 changes: 1 addition & 1 deletion src_c/include/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ typedef struct pg_bufferinfo_s {
(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(base, 22))

#define pg_EnvShouldBlendAlphaSDL2 \
(*(char *(*)(void))PYGAMEAPI_GET_SLOT(base, 23))
(*(int (*)(void))PYGAMEAPI_GET_SLOT(base, 23))

#define pg_GetDefaultConvertFormat \
(*(SDL_PixelFormat * (*)(void)) PYGAMEAPI_GET_SLOT(base, 27))
Expand Down

0 comments on commit 5827924

Please sign in to comment.