Uh oh!
There was an error while loading. Please reload this page.
Add lower_bounds in CPtrToPointer - #1822
Conversation
| 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 |
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.
Closes#1798