Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pointer(.) of struct array causes CPython to yield error, "Type dtype('O') not implemented" #1817

Open
@dylon

Description

@dylon

If I pass an array of structs to pointer, it fails with the error, "NotImplementedError: Type dtype('O') not implemented"

from lpython import CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p, pointer

from numpy import empty

@dataclass
class Foo:
    pass

def main() -> None:
    foos: Foo[1] = empty(1, dtype=Foo)
    pointer(foos)

main()
$ python /var/tmp/main.py
Traceback (most recent call last):
  File "/var/tmp/main.py", line 13, in <module>
    main()
  File "/var/tmp/main.py", line 11, in main
    pointer(foos)
  File "/home/dylon/Workspace/lpython/src/runtime/lpython/lpython.py", line 446, in pointer
    return x.ctypes.data_as(ctypes.POINTER(convert_numpy_dtype_to_ctype(x.dtype)))
  File "/home/dylon/Workspace/lpython/src/runtime/lpython/lpython.py", line 291, in convert_numpy_dtype_to_ctype
    raise NotImplementedError("Type %r not implemented" % arg)
NotImplementedError: Type dtype('O') not implemented

A solution seems to be to add the dtype to convert_numpy_dtype_to_ctype:

elif arg == np.void or arg == np.dtype('O'):
    return ctypes.c_void_p

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions