From c162647020c26de1d27064b488ca11525f1bc4bf Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Sat, 1 Apr 2023 09:26:02 +0530 Subject: fix(ext/ffi): crash when same reference struct is used in two fields (#18531) fix #17482 --- ext/ffi/00_ffi.js | 5 +++-- test_ffi/tests/test.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index c7ca21975..3664ae73b 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -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) { diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index 788faa93e..5e193e99f 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -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, { @@ -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: { -- cgit v1.2.3