ffi: preserve strings during reentrant calls · nodejs/node@aa3f168 · GitHub
Skip to content

Commit aa3f168

Browse files
trivikraduh95
authored andcommitted
ffi: preserve strings during reentrant calls
Cache temporary string conversion buffers by wrapper and active call depth. This prevents nested FFI calls from overwriting or replacing buffers still in use by an outer native call. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.6-sol PR-URL: #64551 Fixes: #64550 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 870f499 commit aa3f168

3 files changed

Lines changed: 103 additions & 27 deletions

File tree

lib/internal/ffi/fast-api.js

Lines changed: 68 additions & 27 deletions

test/ffi/fixture_library/ffi_test_library.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ FFI_EXPORT void call_void_callback(VoidCallback callback) {
333333
}
334334
}
335335

336+
FFI_EXPORT int32_t string_survives_callback(const char* str,
337+
VoidCallback callback) {
338+
if (callback) {
339+
callback();
340+
}
341+
342+
return str && strcmp(str, "outer string") == 0;
343+
}
344+
336345
FFI_EXPORT void call_string_callback(StringCallback callback, const char* str) {
337346
if (callback) {
338347
callback(str);

test/ffi/test-ffi-fast-buffer.js

Lines changed: 26 additions & 0 deletions

0 commit comments

Comments
 (0)