From 7854c677fa4967d4990f91dde6be52f5b3b519ef Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 2 May 2021 22:11:05 +0200 Subject: [PATCH] FFI/ARM64/OSX: Fix vararg call handling. Thanks to Igor Munkin. (cherry picked from commit 521b367567dc5d91d7f9ae29c257998953e24e53) This patch fixes the issue introduced by commit 2e2fb8f6b5118e1a7996b76600c6ee98bfd5f203 ('OSX/iOS: Handle iOS simulator and ARM64 Macs.'). Within the mentioned commit LJ_TARGET_IOS define is set via Apple system header to enable several features (e.g. JIT and external unwinder) on ARM64 Macs, but its usage was not adjusted source-wide. This is done for FFI machinery within this commit. All LJ_TARGET_IOS uses in FFI sources are done with LJ_TARGET_ARM64 define being set, so we can simply replace these occurrences with LJ_TARGET_OSX. Igor Munkin: * added the description and the test for the problem Resolves tarantool/tarantool#6066 Part of tarantool/tarantool#5629 Relates to tarantool/tarantool#5983 Reported-by: Nikita Pettik Reviewed-by: Sergey Kaplun Reviewed-by: Sergey Ostanevich Signed-off-by: Igor Munkin --- .../lj-695-ffi-vararg-call.test.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/tarantool-tests/lj-695-ffi-vararg-call.test.lua diff --git a/test/tarantool-tests/lj-695-ffi-vararg-call.test.lua b/test/tarantool-tests/lj-695-ffi-vararg-call.test.lua new file mode 100644 index 0000000000..04be1998ab --- /dev/null +++ b/test/tarantool-tests/lj-695-ffi-vararg-call.test.lua @@ -0,0 +1,16 @@ +local tap = require('tap') + +local test = tap.test('lj-695-ffi-vararg-call') +test:plan(2) + +local ffi = require('ffi') +local str = ffi.new('char[256]') +ffi.cdef('int sprintf(char *str, const char *format, ...)') +local strlen = ffi.C.sprintf(str, 'try vararg function: %s:%.2f(%d) - %llu', + 'imun', 9, 9LL, -1ULL) + +local result = ffi.string(str) +test:is(#result, strlen) +test:is(result, 'try vararg function: imun:9.00(9) - 18446744073709551615') + +os.exit(test:check() and 0 or 1)