<!DOCTYPE html>
<html data-lt-installed="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="padding-bottom: 1px;">
<p>Branch:
<a class="moz-txt-link-freetext" href="https://github.com/tarantool/luajit/tree/ligurio/gh-1279-recording-getmetatable">https://github.com/tarantool/luajit/tree/ligurio/gh-1279-recording-getmetatable</a></p>
<p>LJ issue: <a class="moz-txt-link-freetext" href="https://github.com/LuaJIT/LuaJIT/issues/1279">https://github.com/LuaJIT/LuaJIT/issues/1279</a></p>
<p><br>
</p>
<div class="moz-cite-prefix">On 07.11.2024 13:51, Sergey Bronnikov
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:76c9c163c365aec70741162ab83fdfa6385a9118.1730976041.git.sergeyb@tarantool.org">
<pre class="moz-quote-pre" wrap="">From: Sergey Bronnikov <a class="moz-txt-link-rfc2396E" href="mailto:sergeyb@tarantool.org"><sergeyb@tarantool.org></a>
The patch fixes a problem with recording `getmetatable()`
for I/O object: recording of `getmetatable` call with a file
descriptors represented by userdata object `UDTYPE_IO_FILE`
(like `io.stdout`) leads to violation of assertion in
`rec_check_slots`.
Note, the problem was fixed upstream in different manner, see
commit 5141cbc20c43
("Fix compiliation of getmetatable() for UDTYPE_IO_FILE.").
---
src/lj_record.c | 2 +-
...-incorrect-recording-getmetatable.test.lua | 21 +++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua
diff --git a/src/lj_record.c b/src/lj_record.c
index cc97bdf9..7181b72a 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -990,7 +990,7 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
int udtype = udataV(&ix->tabv)->udtype;
mt = tabref(udataV(&ix->tabv)->metatable);
/* The metatables of special userdata objects are treated as immutable. */
- if (udtype != UDTYPE_USERDATA) {
+ if (udtype > UDTYPE_IO_FILE) {
cTValue *mo;
if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) {
/* Specialize to the C library namespace object. */
diff --git a/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua
new file mode 100644
index 00000000..8bf22ca7
--- /dev/null
+++ b/test/tarantool-tests/lj-1279-incorrect-recording-getmetatable.test.lua
@@ -0,0 +1,21 @@
+local tap = require('tap')
+
+local test = tap.test('lj-1279-incorrect-recording-getmetatable')
+test:plan(1)
+
+-- A test file to demonstrate an incorrect recording of
+-- getmetatable() for I/O handlers.
+-- <a class="moz-txt-link-freetext" href="https://github.com/LuaJIT/LuaJIT/issues/1279">https://github.com/LuaJIT/LuaJIT/issues/1279</a>
+
+jit.opt.start("hotloop=1")
+
+local obj = io.stdout
+local getmetatable = getmetatable
+
+for _ = 1, 4 do
+ _ = getmetatable(obj)
+end
+
+test:ok(true, 'getmetatable() recording is correct')
+
+test:done(true)
</pre>
</blockquote>
</body>
<lt-container></lt-container>
</html>