py-sdl / py-sdl2

Python ctypes wrapper around SDL2
Other
304 stars 49 forks source link

Accessing the original ctypes function pointers broke again #254

Closed ell1e closed 1 year ago

ell1e commented 1 year ago

What doesn't work? This used to work:

#!/usr/bin/python3

import ctypes

def bla():
    import sdl2.sdlttf as sdlttf
    sdlttf_funcs = {}
    from sdl2.sdlttf import _funcs as sdlttf_funcs_module
    try:
        from sdl2.sdlttf import _funcs as sdlttf_funcs_module
        sdlttf_funcs["TTF_SizeUTF8"] = \
            sdlttf_funcs_module["TTF_SizeUTF8"]
    except ImportError:
        sdlttf_funcs["TTF_SizeUTF8"] = \
            sdlttf.TTF_SizeUTF8
    print("TEST TYPE: " + str(
        (sdlttf_funcs["TTF_SizeUTF8"],
        type(sdlttf_funcs["TTF_SizeUTF8"]))))
    _sdl_TextSize_utf8_addrint = (
        ctypes.addressof(
        sdlttf_funcs["TTF_SizeUTF8"]))

Now it no longer does. Also, the new _funcdefs is a list? How would I be expected to get it out of there? I'm a little confused, and my pile of try/excepts for multiple library versions is starting to get a bit long too.

How To Reproduce See above.

Platform (if relevant):

Additional context

ell1e commented 1 year ago

Ah, I guess I am supposed to use _ctypes now. You should add in _funcs = _ctypes with maybe some hack that prints out a deprecation warning, maybe. These things just changing is really confusing and also makes it hard to support multiple library versions cleanly.

Edit: also my apologies for being grumpy. I've just been at this point with PySDL2 about 4 times and it gets a little old at some point.

a-hurst commented 1 year ago

Hi @ell1e, apologies for breaking the workaround you were using! As you can see in the release notes for PySDL2 0.9.12, I've made sdl2._ctypes an official and stable part of the API specifically for your use-case, so hopefully you shouldn't have any other problems with this going forward.