Use generated ctypes wrappers in Python/C API tests#16068
Open
jakelishman wants to merge 3 commits intoQiskit:mainfrom
Open
Use generated ctypes wrappers in Python/C API tests#16068jakelishman wants to merge 3 commits intoQiskit:mainfrom
ctypes wrappers in Python/C API tests#16068jakelishman wants to merge 3 commits intoQiskit:mainfrom
Conversation
This is minor code reorganisation to avoid the `cext` build script getting out of hand; we're about to add an extra `ctypes`-like backend to it, which coudl do with being in its own module.
Collaborator
|
One or more of the following people are relevant to this code:
|
This is similar to how Python exposes its own C API through `ctypes` as `ctypes.pythonapi`. It's unlikely to be immediately useful as a feature for downstream users, but it simplifies the process of us testing our own code from Python space. I had originally hoped / thought that `numba` would support calling these `ctypes` functions, but while `numba` (as of current version 0.65) does have support for calling `ctypes` functions defined purely in terms of primitive non-pointer integral types, it doesn't yet support `ctypes.py_object` or arbitrary pointers.
Now we have generated `ctypes` wrappers, we don't need to manually redefine the wrapper objects. With the argument type definitions being more structured now, it is simpler to specify out variables with the pointed-to type, then pass it with `ctypes.byref`, rather than trying to construct the reference type and pass it by value; the strict pointer-type matching of `ctypes` makes `byref` more reliable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now we have generated
ctypeswrappers, we don't need to manually redefine the wrapper objects. With the argument type definitions being more structured now, it is simpler to specify out variables with the pointed-to type, then pass it withctypes.byref, rather than trying to construct the reference type and pass it by value; the strict pointer-type matching ofctypesmakesbyrefmore reliable.AI/LLM disclosure