Skip to content

Commit

Permalink
fix(ext/ffi): crash when same reference struct is used in two fields (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
DjDeveloperr committed Apr 1, 2023
1 parent bafffa9 commit c162647
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ function getTypeSizeAndAlignment(type, cache = new SafeMap()) {
size += fieldSize;
}
size = MathCeil(size / alignment) * alignment;
cache.set(type, size);
return [size, alignment];
const result = [size, alignment];
cache.set(type, result);
return result;
}

switch (type) {
Expand Down
3 changes: 2 additions & 1 deletion test_ffi/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const Point = ["f64", "f64"];
const Size = ["f64", "f64"];
const Rect = ["f64", "f64", "f64", "f64"];
const RectNested = [{ struct: Point }, { struct: Size }];
const RectNestedCached = [{ struct: Size }, { struct: Size }];
const Mixed = ["u8", "f32", { struct: Rect }, "usize", { struct: ["u32", "u32"] }];

const dylib = Deno.dlopen(libPath, {
Expand Down Expand Up @@ -264,7 +265,7 @@ const dylib = Deno.dlopen(libPath, {
result: { struct: RectNested },
},
print_rect: {
parameters: [{ struct: Rect }],
parameters: [{ struct: RectNestedCached }],
result: "void",
},
print_rect_async: {
Expand Down

0 comments on commit c162647

Please sign in to comment.