Skip to content

Commit bd98dae

Browse files
committed
Update gl_get_proc function
- SDL3 compat - Use WINFUNCTYPE (stdcall) on win32 - Use ctypes._FuncPointer in stubs
1 parent 9cf4797 commit bd98dae

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

buildconfig/stubs/pygame/display.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Iterable
2-
from typing import Optional, Union, overload, Literal, Any
2+
from ctypes import _FuncPointer
3+
from typing import Optional, Union, overload, Literal
34
from typing_extensions import deprecated # added in 3.13
45

56
from pygame.constants import FULLSCREEN
@@ -70,7 +71,7 @@ def mode_ok(
7071
) -> int: ...
7172
def gl_get_attribute(flag: int, /) -> int: ...
7273
def gl_set_attribute(flag: int, value: int, /) -> None: ...
73-
def gl_get_proc(proc_name: str) -> Any: ...
74+
def gl_get_proc(proc_name: str) -> _FuncPointer: ...
7475
def get_active() -> bool: ...
7576
def iconify() -> bool: ...
7677
def toggle_fullscreen() -> int: ...

src_c/display.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,7 @@ pg_message_box(PyObject *self, PyObject *arg, PyObject *kwargs)
29382938
return NULL;
29392939
}
29402940

2941-
static PyObject *pg_proc_from_address = NULL;
2941+
static PyObject *pg_gl_proc_from_address = NULL;
29422942

29432943
static PyObject *
29442944
pg_gl_get_proc(PyObject *self, PyObject *arg)
@@ -2951,19 +2951,24 @@ pg_gl_get_proc(PyObject *self, PyObject *arg)
29512951
return NULL;
29522952
}
29532953

2954-
void *proc_addr = SDL_GL_GetProcAddress(proc_name);
2954+
#if SDL_VERSION_ATLEAST(3, 0, 0)
2955+
SDL_FunctionPointer proc_addr;
2956+
#else
2957+
void *proc_addr;
2958+
#endif
2959+
proc_addr = SDL_GL_GetProcAddress(proc_name);
29552960
if (!proc_addr) {
29562961
return RAISE(pgExc_SDLError, SDL_GetError());
29572962
}
29582963
PyObject *proc_addr_obj = PyLong_FromVoidPtr(proc_addr);
29592964
if (!proc_addr_obj) {
29602965
return NULL;
29612966
}
2962-
if (!pg_proc_from_address) {
2967+
if (!pg_gl_proc_from_address) {
29632968
return RAISE(PyExc_TypeError, "'_proc_from_address' object is NULL");
29642969
}
29652970
PyObject *retv =
2966-
PyObject_CallFunction(pg_proc_from_address, "(O)", proc_addr_obj);
2971+
PyObject_CallFunction(pg_gl_proc_from_address, "(O)", proc_addr_obj);
29672972
Py_DECREF(proc_addr_obj);
29682973
return retv;
29692974
}
@@ -3102,9 +3107,9 @@ MODINIT_DEFINE(display)
31023107
return NULL;
31033108
}
31043109

3105-
pg_proc_from_address =
3106-
PyObject_GetAttrString(pg_ffi_module, "_proc_from_address");
3107-
if (!pg_proc_from_address) {
3110+
pg_gl_proc_from_address =
3111+
PyObject_GetAttrString(pg_ffi_module, "_gl_proc_from_address");
3112+
if (!pg_gl_proc_from_address) {
31083113
return NULL;
31093114
}
31103115
Py_DECREF(pg_ffi_module);

src_py/_ffi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import ctypes
2+
import sys
23

34

4-
def _proc_from_address(addr):
5+
def _gl_proc_from_address(addr):
6+
if sys.platform == "win32":
7+
# use __stdcall on win32
8+
return ctypes.WINFUNCTYPE(None)(addr)
59
return ctypes.CFUNCTYPE(None)(addr)

0 commit comments

Comments
 (0)