Skip to content

Commit c4d1a64

Browse files
committed
Fix struct_02 test
1 parent fb00846 commit c4d1a64

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ RUN(NAME test_bool_binop LABELS cpython llvm c)
568568
RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST)
569569
RUN(NAME structs_01 LABELS cpython llvm c)
570570
RUN(NAME structs_02 LABELS cpython llvm c)
571+
RUN(NAME structs_02b LABELS cpython llvm c)
571572
RUN(NAME structs_03 LABELS llvm c)
572573
RUN(NAME structs_04 LABELS cpython llvm c)
573574
RUN(NAME structs_05 LABELS cpython llvm c)

integration_tests/bindc_09.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Value(Enum):
88
ONE: i32 = 1
99
FIVE: i32 = 5
1010

11+
@ccallable
1112
@dataclass
1213
class Foo:
1314
value: Value

integration_tests/structs_02.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def f(a: CPtr) -> None:
1717
y = a2.y
1818
assert x == 3
1919
assert f64(y) == 3.25
20-
a2 = c_p_pointer(a, A)
21-
print(a, a2, pointer(a1))
2220

2321
def g():
2422
b: CPtr = empty_c_void_p()

integration_tests/structs_02b.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from lpython import (i32, f32, dataclass, CPtr, Pointer, c_p_pointer, pointer,
2+
ccallable, empty_c_void_p, f64, ccall, sizeof, i64)
3+
4+
@ccall
5+
def _lfortran_malloc(size: i32) -> CPtr:
6+
pass
7+
8+
def alloc(buf_size:i64) -> CPtr:
9+
return _lfortran_malloc(i32(buf_size))
10+
11+
@ccallable
12+
@dataclass
13+
class A:
14+
x: i32
15+
y: f32
16+
17+
@ccallable
18+
def f(a: CPtr) -> None:
19+
x: i32
20+
y: f32
21+
a1: A = A(3, f32(3.25))
22+
a2: Pointer[A]
23+
a2 = pointer(a1)
24+
print(a2, pointer(a1))
25+
x = a2.x
26+
y = a2.y
27+
assert x == 3
28+
assert f64(y) == 3.25
29+
a2 = c_p_pointer(a, A)
30+
print(a, a2, pointer(a1))
31+
print(a2.x, a2.y)
32+
assert a2.x == 5
33+
assert a2.y == f32(6.0)
34+
35+
def g():
36+
b: CPtr = alloc(sizeof(A))
37+
b2: Pointer[A] = c_p_pointer(b, A)
38+
b2.x = 5
39+
b2.y = f32(6)
40+
f(b)
41+
42+
g()

0 commit comments

Comments
 (0)