Skip to content

Commit

Permalink
Fix struct_02 test
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Jul 9, 2023
1 parent fb00846 commit c4d1a64
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ RUN(NAME test_bool_binop LABELS cpython llvm c)
RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST)
RUN(NAME structs_01 LABELS cpython llvm c)
RUN(NAME structs_02 LABELS cpython llvm c)
RUN(NAME structs_02b LABELS cpython llvm c)
RUN(NAME structs_03 LABELS llvm c)
RUN(NAME structs_04 LABELS cpython llvm c)
RUN(NAME structs_05 LABELS cpython llvm c)
Expand Down
1 change: 1 addition & 0 deletions integration_tests/bindc_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Value(Enum):
ONE: i32 = 1
FIVE: i32 = 5

@ccallable
@dataclass
class Foo:
value: Value
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/structs_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def f(a: CPtr) -> None:
y = a2.y
assert x == 3
assert f64(y) == 3.25
a2 = c_p_pointer(a, A)
print(a, a2, pointer(a1))

def g():
b: CPtr = empty_c_void_p()
Expand Down
42 changes: 42 additions & 0 deletions integration_tests/structs_02b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from lpython import (i32, f32, dataclass, CPtr, Pointer, c_p_pointer, pointer,
ccallable, empty_c_void_p, f64, ccall, sizeof, i64)

@ccall
def _lfortran_malloc(size: i32) -> CPtr:
pass

def alloc(buf_size:i64) -> CPtr:
return _lfortran_malloc(i32(buf_size))

@ccallable
@dataclass
class A:
x: i32
y: f32

@ccallable
def f(a: CPtr) -> None:
x: i32
y: f32
a1: A = A(3, f32(3.25))
a2: Pointer[A]
a2 = pointer(a1)
print(a2, pointer(a1))
x = a2.x
y = a2.y
assert x == 3
assert f64(y) == 3.25
a2 = c_p_pointer(a, A)
print(a, a2, pointer(a1))
print(a2.x, a2.y)
assert a2.x == 5
assert a2.y == f32(6.0)

def g():
b: CPtr = alloc(sizeof(A))
b2: Pointer[A] = c_p_pointer(b, A)
b2.x = 5
b2.y = f32(6)
f(b)

g()

0 comments on commit c4d1a64

Please sign in to comment.