Hello, thanks for the patch! LGTM Sergey On 7/21/26 10:59, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Magnus Wibeck. > > (cherry picked from commit d508715ab657261e8437a52c1b1966c20ab1631d) > > In LuaJIT the second `fp:seek()` argument (offset) doesn't coerce from a > string to an integer value, unlike PUC-Rio Lua 5.1 does. > > This patch adds missing coercion. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#12880 > --- > > Branch:https://github.com/tarantool/luajit/tree/skaplun/lj-1343-fseek-offset-coercion > Related issues: > *https://github.com/LuaJIT/LuaJIT/issues/1343 > *https://github.com/tarantool/tarantool/issues/12880 > > src/Makefile.dep.original | 2 +- > src/lib_io.c | 4 +++- > .../lj-1343-fseek-offset-coercion.test.lua | 23 +++++++++++++++++++ > 3 files changed, 27 insertions(+), 2 deletions(-) > create mode 100644 test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua > > diff --git a/src/Makefile.dep.original b/src/Makefile.dep.original > index 436685f5..acc6b3ba 100644 > --- a/src/Makefile.dep.original > +++ b/src/Makefile.dep.original > @@ -21,7 +21,7 @@ lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ > lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lmisclib.h lj_arch.h > lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ > lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_state.h \ > - lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h > + lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h lj_strscan.h lj_libdef.h > lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ > lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \ > lj_state.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \ > diff --git a/src/lib_io.c b/src/lib_io.c > index ef39e535..2d0abf78 100644 > --- a/src/lib_io.c > +++ b/src/lib_io.c > @@ -25,6 +25,7 @@ > #include "lj_strfmt.h" > #include "lj_ff.h" > #include "lj_lib.h" > +#include "lj_strscan.h" > > /* Userdata payload for I/O file. */ > typedef struct IOFileUD { > @@ -317,13 +318,14 @@ LJLIB_CF(io_method_seek) > FILE *fp = io_tofile(L)->fp; > int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end"); > int64_t ofs = 0; > - cTValue *o; > + TValue *o; > int res; > if (opt == 0) opt = SEEK_SET; > else if (opt == 1) opt = SEEK_CUR; > else if (opt == 2) opt = SEEK_END; > o = L->base+2; > if (o < L->top) { > + if (tvisstr(o)) lj_strscan_num(strV(o), o); > if (tvisint(o)) > ofs = (int64_t)intV(o); > else if (tvisnum(o)) > diff --git a/test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua b/test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua > new file mode 100644 > index 00000000..fdfc6ce5 > --- /dev/null > +++ b/test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua > @@ -0,0 +1,23 @@ > +local tap = require('tap') > + > +-- The test file to demonstrate LuaJIT's missing coercion for the > +-- `io.fseek()` offset argument. > +-- See also:https://github.com/LuaJIT/LuaJIT/issues/1343. > + > +local test = tap.test('lj-1343-fseek-offset-coercion') > + > +test:plan(2) > + > +local f = io.tmpfile() > + > +f:write('12345') > + > +f:seek('set', 0) > +f:seek('set', '1') > +test:is(f:read('*all'), '2345', 'base coercion test') > + > +f:seek('set', 0) > +f:seek('set', '1.9') > +test:is(f:read('*all'), '2345', 'coercion test for non-integer value') > + > +test:done(true)