Add lower_bounds in CPtrToPointer#1822
Merged
certik merged 1 commit intolcompilers:mainfrom May 17, 2023
Merged
Conversation
czgdp1807
commented
May 17, 2023
| targettype_ptr = convert_type_to_ctype(targettype) | ||
| if isinstance(targettype, Array): | ||
| if py_is_dataclass(targettype._type): | ||
| return ctypes.cast(cptr.value, ctypes.py_object).value |
Collaborator
Author
There was a problem hiding this comment.
cptr.value is nothing but the address of foos: Foo[1] = empty(1, dtype=Foo). And ctypes.cast(cptr.value, ctypes.py_object).value just gives the original numpy array back, so effectively it becomes a pointer and you can easily make changes to it in other functions.
That's the only way forward if we want to keep using numpy arrays for arrays of dataclasses. If we can avoid using numpy arrays for dataclasses then we can define our own empty in lpython.py or in our own version of numpy.py. In our empty we can just create a ctypes.Structure array and return it via empty. For all the types like i32, etc we can keep calling numpy.empty. But I would not go for it unless extremely necessary.
This was referenced May 17, 2023
Closed
certik
approved these changes
May 17, 2023
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.
Closes #1798