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

Skip to content

Feature request: pointers in emulation mode #1334

Closed
@certik

Description

@certik

This works with LPython:

def mystruct_set(mystruct: CPtr, k: i16) -> None:
    b: Pointer[mystruct]
    c_p_pointer(mystruct, b)
    b.k = k

But not in CPython mode, because "b" is not declared in c_p_pointer(mystruct, b):

UnboundLocalError: local variable 'b' referenced before assignment

Also the implementation of c_p_pointer makes no sense:

def c_p_pointer(cptr, targettype):
    return pointer(targettype)

As it needs to use the cptr pointer. Rather, the implementation must look something like this:

def mystruct_set(mystruct: CPtr, k: i16) -> None:
    struct_type = ctypes.POINTER(mystruct_type)
    newa = ctypes.cast(mystruct, struct_type)
    newa.contents.k = k

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions