Skip to content

Check dangling pointers: Add runtime check for c_p_pointer behaviour #676

Open
@Smit-create

Description

@Smit-create

I was testing pointers in lpython and used the following python code:

from ltypes import c_p_pointer, CPtr, pointer, i16, Pointer

def f():
    yq: CPtr
    yptr1: Pointer[i16[:]]
    y: i16[2]
    y[0] = 1
    y[1] = 2
    yptr1 = pointer(y)
    # This works
    print(yptr1[0], yptr1[1])
    assert yptr1[0] == 1
    assert yptr1[1] == 2
    c_p_pointer(yq, yptr1)

    # Shouldn't this work the same way as earlier?
    print(yptr1[0], yptr1[1])
f()

Running this I get:

% lpython expr.py && ./a.out
1 2
zsh: segmentation fault  ./a.out

Metadata

Metadata

Assignees

No one assigned

    Labels

    cLabel for C language related changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions