Skip to content

Commit

Permalink
fix: array handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 committed Jan 2, 2025
1 parent 144231d commit c9f5a20
Show file tree
Hide file tree
Showing 4 changed files with 8,334 additions and 1,796 deletions.
17 changes: 8 additions & 9 deletions codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def client_rpc_write(self, f):
f.write(
" rpc_write(0, &{param_name}, sizeof({param_type})) < 0 ||\n".format(
param_name=self.parameter.name,
param_type=self.parameter.name,
param_type=self.ptr.array_of.format(),
)
)
else:
Expand Down Expand Up @@ -243,11 +243,10 @@ def client_unified_copy(self, f, direction, error):
@property
def server_declaration(self) -> str:
if isinstance(self.ptr, Array):
c = self.ptr.const
self.ptr.const = False
# const[] isn't a valid part of a variable declaration
s = f" {self.ptr.format().replace("const[]", "")}* {self.parameter.name} = nullptr;\n"
self.ptr.const = c
c = self.ptr.array_of.const
self.ptr.array_of.const = False
s = f" {self.ptr.array_of.format()}* {self.parameter.name} = nullptr;\n"
self.ptr.array_of.const = c
else:
c = self.ptr.ptr_to.const
self.ptr.ptr_to.const = False
Expand Down Expand Up @@ -281,9 +280,9 @@ def server_rpc_read(self, f, index) -> Optional[str]:
)
elif isinstance(self.ptr, Array):
f.write(
" rpc_read(conn, &{param_name}, sizeof({param_type})) < 0 ||\n".format(
" rpc_read(conn, &{param_name}, sizeof({param_type}*)) < 0 ||\n".format(
param_name=self.parameter.name,
param_type=self.ptr.format().replace("[]", ""),
param_type=self.ptr.array_of.format(),
)
)
else:
Expand Down Expand Up @@ -690,7 +689,7 @@ def parse_annotation(annotation: str, params: list[Parameter]) -> list[tuple[Ope
))
elif isinstance(param.type, Array):
length_param = next(p for p in params if p.name == length_arg.split(":")[1])
if param.type.const:
if param.type.array_of.const:
recv = False
operations.append(ArrayOperation(
send=send,
Expand Down
Loading

0 comments on commit c9f5a20

Please sign in to comment.