Skip to content

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

Closed
@dylon

Description

@dylon

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

Metadata

Metadata

Assignees

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