Skip to content

Commit b39a2cb

Browse files
authored
Merge pull request #2144 from certik/err
Give a C interoperability error for module structs also
2 parents 2ae4640 + ade9e79 commit b39a2cb

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
27352735
throw SemanticAbort();
27362736
}
27372737
if (ASR::is_a<ASR::Struct_t>(*asr_alloc_type)) {
2738-
ASR::symbol_t *sym = ASR::down_cast<ASR::Struct_t>(asr_alloc_type)->m_derived_type;
2738+
ASR::symbol_t *sym = ASRUtils::symbol_get_past_external(ASR::down_cast<ASR::Struct_t>(asr_alloc_type)->m_derived_type);
27392739
if (ASR::is_a<ASR::StructType_t>(*sym)) {
27402740
ASR::StructType_t *st = ASR::down_cast<ASR::StructType_t>(sym);
27412741
if (st->m_abi != ASR::abiType::BindC) {

tests/errors/bindc_10e.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from lpython import (i64, i16, CPtr, c_p_pointer, Pointer, sizeof, packed,
2-
dataclass, ccallable, ccall, i32)
1+
from lpython import i64, i16, CPtr, c_p_pointer, Pointer, sizeof, ccall, i32
2+
from bindc_10e_mod import S
33

44
@ccall
55
def _lfortran_malloc(size: i32) -> CPtr:
@@ -9,14 +9,6 @@ def _lfortran_malloc(size: i32) -> CPtr:
99
def alloc(buf_size:i64) -> CPtr:
1010
return _lfortran_malloc(i32(buf_size))
1111

12-
13-
@packed
14-
@dataclass
15-
class S:
16-
a: i16
17-
b: i64
18-
19-
2012
def main():
2113
p1: CPtr = alloc(sizeof(S))
2214
print(p1)

tests/errors/bindc_10e_mod.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from lpython import packed, dataclass, i16, i64
2+
3+
@packed
4+
@dataclass
5+
class S:
6+
a: i16
7+
b: i64

tests/reference/asr-bindc_10e-8b10394.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"basename": "asr-bindc_10e-8b10394",
33
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
44
"infile": "tests/errors/bindc_10e.py",
5-
"infile_hash": "36d1b5d366716d6a601db544fe8ff32aba76518181e71a98a4e6500c",
5+
"infile_hash": "fa023d4ad17e426f778a99326998e6dbeac5428fa252974a39a3219d",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-bindc_10e-8b10394.stderr",
11-
"stderr_hash": "7686dd8c9b718548d301e28d39cd15a85b00030172c5658b38a75af5",
11+
"stderr_hash": "9ea4ff2c8a8789057456196deb5772e4b3a2dffadbd10ecfe5f15f29",
1212
"returncode": 2
1313
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
semantic error: The struct in c_p_pointer must be C interoperable
2-
--> tests/errors/bindc_10e.py:23:38
2+
--> tests/errors/bindc_10e.py:15:38
33
|
4-
23 | p2: Pointer[S] = c_p_pointer(p1, S)
4+
15 | p2: Pointer[S] = c_p_pointer(p1, S)
55
| ^ not C interoperable
6+
7+
--> tests/errors/bindc_10e_mod.py:5:1 - 7:10
68
|
7-
15 | class S:
9+
5 | class S:
810
| ~~~~~~~~...
911
...
1012
|
11-
17 | b: i64
13+
7 | b: i64
1214
| ...~~~~~~~~~~ help: add the @ccallable decorator to this struct to make it C interoperable

0 commit comments

Comments
 (0)