Skip to content

Commit 5ef7466

Browse files
authored
fix: array handling (#73)
1 parent 144231d commit 5ef7466

File tree

4 files changed

+8334
-1796
lines changed

4 files changed

+8334
-1796
lines changed

codegen/codegen.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def client_rpc_write(self, f):
197197
f.write(
198198
" rpc_write(0, &{param_name}, sizeof({param_type})) < 0 ||\n".format(
199199
param_name=self.parameter.name,
200-
param_type=self.parameter.name,
200+
param_type=self.ptr.array_of.format(),
201201
)
202202
)
203203
else:
@@ -243,11 +243,10 @@ def client_unified_copy(self, f, direction, error):
243243
@property
244244
def server_declaration(self) -> str:
245245
if isinstance(self.ptr, Array):
246-
c = self.ptr.const
247-
self.ptr.const = False
248-
# const[] isn't a valid part of a variable declaration
249-
s = f" {self.ptr.format().replace("const[]", "")}* {self.parameter.name} = nullptr;\n"
250-
self.ptr.const = c
246+
c = self.ptr.array_of.const
247+
self.ptr.array_of.const = False
248+
s = f" {self.ptr.array_of.format()}* {self.parameter.name} = nullptr;\n"
249+
self.ptr.array_of.const = c
251250
else:
252251
c = self.ptr.ptr_to.const
253252
self.ptr.ptr_to.const = False
@@ -281,9 +280,9 @@ def server_rpc_read(self, f, index) -> Optional[str]:
281280
)
282281
elif isinstance(self.ptr, Array):
283282
f.write(
284-
" rpc_read(conn, &{param_name}, sizeof({param_type})) < 0 ||\n".format(
283+
" rpc_read(conn, &{param_name}, sizeof({param_type}*)) < 0 ||\n".format(
285284
param_name=self.parameter.name,
286-
param_type=self.ptr.format().replace("[]", ""),
285+
param_type=self.ptr.array_of.format(),
287286
)
288287
)
289288
else:
@@ -690,7 +689,7 @@ def parse_annotation(annotation: str, params: list[Parameter]) -> list[tuple[Ope
690689
))
691690
elif isinstance(param.type, Array):
692691
length_param = next(p for p in params if p.name == length_arg.split(":")[1])
693-
if param.type.const:
692+
if param.type.array_of.const:
694693
recv = False
695694
operations.append(ArrayOperation(
696695
send=send,

0 commit comments

Comments
 (0)