From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 97BAF6ECE3; Wed, 13 Jul 2022 09:44:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 97BAF6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1657694657; bh=fzkM3eqLsTq9n7J04qkPUHnsyafKTssph9UhiRz+bH4=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wjWcSFsr8ZZKu67B6b7BFeHhJrD7tGGndoa8PMQ6dqSa+53k2sMi3nC3FUoHIZmpX hOANmY2moyxHiJADiNcFO3IwVzJAS7STFvianDxSWJuT2SEYfMK13Ha5vdTrkcHcnx fjnjSlMYckjkhgal3cxRJMYckUMWC/BLvYAT5FyU= Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2C4A86ECE3 for ; Wed, 13 Jul 2022 09:44:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2C4A86ECE3 Received: by smtp3.mail.ru with esmtpa (envelope-from ) id 1oBW6Y-0002qW-9K; Wed, 13 Jul 2022 09:44:14 +0300 To: Sergey Ostanevich , Igor Munkin Date: Wed, 13 Jul 2022 09:41:49 +0300 Message-Id: <20220713064149.523-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9BCA415BD41350256F688E2A4A7D167AAB4F58E22EA780020182A05F53808504082B998BE74C0AC3D3D4F4111DDC5E5AB2FF8644F687DEAE983BD23534EF1C784 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79145AB6E9E75F07EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063794BAA5DA89D799D78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E57DA5547D4F3676940F52956A4C9A00117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3238885582065B7B389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC81D471462564A2E19F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C3E12B096E30173B4C0837EA9F3D197644AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C31EBBAFDAEF65C2E6BA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE74ABCC139FF3F849B731C566533BA786AA5CC5B56E945C8DA X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C41E93BD56E7067354307CAA32FF218580205367B2BCC23E5BE4B1DCF4F027BDDDE7E65F06B2D3BF1CAD91A466A1DEF99B6ED91DBE5ABE359A3485EE9140A7D39DC234C8B12C006B7A65D5CC591E8E231C99B6E5D260F3BCDF21C92B735841FB2EB1881A6453793CE9C32612AADDFBE0615F364292A96AB711A71A35648BE338CE9510FB958DCE06DB58C12E6D310A6D5333F7A9E5587C79A693EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AE88D5ADEBE7C983069CABE67EC43E7CCD16E5ED4BDDE9844074DBED9695FCD067F89B5289226D441D7E09C32AA3244C23A8D58EB0BF7587688AFDCB877E1D0B55E75C8D0ED9F6EE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXgSkFNgPq7tMziL7ZclgSWU X-Mailru-Sender: 07FBBCF39629D1142254247A6196FF9B89C74E4C54104F743D4F4111DDC5E5ABBDDB26EEA8DAF3A6DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] From Lua 5.3: assert() accepts any type of error object. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall (cherry picked from commit a5a89ab586a3b5bb4f266949bbf3dc2b140e2374) This patch removes type restrictions for the second optional argument in `assert()` function. It allows to use different error objects in `assert()` and catches them via `pcall()`. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#7230 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-418-assert-any-type-full-ci Issue: https://github.com/LuaJIT/LuaJIT/issues/418 doc/extensions.html | 1 + src/lib_base.c | 10 +++++----- .../lj-418-assert-any-type.test.lua | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 test/tarantool-tests/lj-418-assert-any-type.test.lua diff --git a/doc/extensions.html b/doc/extensions.html index d7cc9693..e0f136e2 100644 --- a/doc/extensions.html +++ b/doc/extensions.html @@ -374,6 +374,7 @@ LuaJIT supports some extensions from Lua 5.3:
  • Unicode escape '\u{XX...}' embeds the UTF-8 encoding in string literals.
  • The argument table arg can be read (and modified) by LUA_INIT and -e chunks.
  • io.read() and file:read() accept formats with or without a leading *.
  • +
  • assert() accepts any type of error object.
  • table.move(a1, f, e, t [,a2]).
  • coroutine.isyieldable().
  • Lua/C API extensions: diff --git a/src/lib_base.c b/src/lib_base.c index 613a1859..83c7663c 100644 --- a/src/lib_base.c +++ b/src/lib_base.c @@ -42,13 +42,13 @@ LJLIB_ASM(assert) LJLIB_REC(.) { - GCstr *s; lj_lib_checkany(L, 1); - s = lj_lib_optstr(L, 2); - if (s) - lj_err_callermsg(L, strdata(s)); - else + if (L->top == L->base+1) lj_err_caller(L, LJ_ERR_ASSERT); + else if (tvisstr(L->base+1) || tvisnumber(L->base+1)) + lj_err_callermsg(L, strdata(lj_lib_checkstr(L, 2))); + else + lj_err_run(L); return FFH_UNREACHABLE; } diff --git a/test/tarantool-tests/lj-418-assert-any-type.test.lua b/test/tarantool-tests/lj-418-assert-any-type.test.lua new file mode 100644 index 00000000..37b88574 --- /dev/null +++ b/test/tarantool-tests/lj-418-assert-any-type.test.lua @@ -0,0 +1,14 @@ +local tap = require('tap') + +-- See also https://github.com/LuaJIT/LuaJIT/issues/418. +local test = tap.test('lj-418-asset-any-type') +test:plan(1) + +local retv = {} + +local st, obj = pcall(assert, false, retv) +assert(not st, 'pcall fails') + +test:ok(obj == retv, 'assert function take non-string argument') + +os.exit(test:check() and 0 or 1) -- 2.34.1