-
Notifications
You must be signed in to change notification settings - Fork 27
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
Allow passing capsules for draw callbacks #130
Conversation
This is neat. |
This allow defining the callbacks in C modules and passing the pointers as Python objects.
Should |
I wondered about that too, but it seems to work without a change. I guess because |
I'm just worried that the callback code will have to deal with unpacking the capsule. If it requires a Python C API call that would be unfortunate. |
Good point. |
Can capsules interoperate with ctypes pointers? It's a bit unclear to me how compatible the two are. |
I think they should work, PyCapsule is essentially wrapping an integer in a Python object. The problem, I think, will be that there is no Python API for dealing with PyCapsule’s, only a C-API. |
I think ctypes.pythonapi exposes the Python API, including PyCapsule, not sure if that's what you're after. |
found this on https://stackoverflow.com/a/65057267 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and works well in FontGoggles. Some tests would be nice, but we can do that later.
Testing would be good indeed, but I was hesitant to look into it because it will need some compiled native code and I have no idea how to pull that for tsets. |
Could it be |
I don’t know, I’m apparently not a Cython expert. @anthrotype probably has some ideas. |
maybe you could define some dummy move_to, line_to etc. methods inside the main .pyx module (or a new extension module that's only for testing but that complicates the setup), then from inside the pure-python test module you use ctypes to |
I tried just for fun to load the uharfbuzz extension via ctypes, looks like it works In [1]: import ctypes
In [2]: import uharfbuzz._harfbuzz
In [3]: uharfbuzz._harfbuzz.__file__
Out[3]: '/Users/clupo/Github/nanoemoji/.venv/lib/python3.10/site-packages/uharfbuzz/_harfbuzz.cpython-310-darwin.so'
In [4]: lib = ctypes.cdll.LoadLibrary(uharfbuzz._harfbuzz.__file__)
In [5]: hb_version_string = lib.hb_version_string
In [6]: hb_version_string.restype = ctypes.c_char_p
In [7]: hb_version_string.argtypes = ()
In [8]: hb_version_string()
Out[8]: b'5.0.0' I think the dummy move_to, line_to, etc. for testing should be defined as |
Thanks, I’ll give this a try. |
This allow defining the callbacks in C modules and passing the pointers as Python objects.