Skip to content

c_p_pointer does not support pointers to structs with enum fields #1818

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

Closed
Tracked by #1802
dylon opened this issue May 16, 2023 · 0 comments · Fixed by #1823
Closed
Tracked by #1802

c_p_pointer does not support pointers to structs with enum fields #1818

dylon opened this issue May 16, 2023 · 0 comments · Fixed by #1823
Assignees

Comments

@dylon
Copy link

dylon commented May 16, 2023

With the workarounds I mention in #1814, I've hit another bug which is that I cannot use c_p_pointer on pointers to structs with enum fields:

from enum import Enum

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

from numpy import empty

class Value(Enum):
    TEN: i32 = 10

@dataclass
class Foo:
    value: Value

def bar(foo_ptr: CPtr) -> None:
    foo: Pointer[Foo] = c_p_pointer(foo_ptr, Foo)

def main() -> None:
    foo: Foo = Foo(Value.TEN)
    foo_ptr: CPtr = empty_c_void_p()
    p_c_pointer(pointer(foo), foo_ptr)
    bar(foo_ptr)

main()
$ python /var/tmp/main.py
Traceback (most recent call last):
  File "/var/tmp/main.py", line 23, in <module>
    main()
  File "/var/tmp/main.py", line 21, in main
    bar(foo_ptr)
  File "/var/tmp/main.py", line 15, in bar
    foo: Pointer[Foo] = c_p_pointer(foo_ptr, Foo)
  File "/home/dylon/Workspace/lpython/src/runtime/lpython/lpython.py", line 526, in c_p_pointer
    targettype_ptr = convert_type_to_ctype(targettype)
  File "/home/dylon/Workspace/lpython/src/runtime/lpython/lpython.py", line 262, in convert_type_to_ctype
    return convert_to_ctypes_Structure(arg)
  File "/home/dylon/Workspace/lpython/src/runtime/lpython/lpython.py", line 395, in convert_to_ctypes_Structure
    fields.append((name, convert_type_to_ctype(ltype_)))
  File "/home/dylon/Workspace/lpython/src/runtime/lpython/lpython.py", line 264, in convert_type_to_ctype
    raise NotImplementedError("Type %r not implemented" % arg)
NotImplementedError: Type <enum 'Value'> not implemented
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants