Avoid memory allocation in some functions from 'ltests.c' · lua/lua@bfcf06d · GitHub
Skip to content

Commit bfcf06d

Browse files
committed
Avoid memory allocation in some functions from 'ltests.c'
To allow their use in memory tests, some functions in 'ltests.c' should never allocate memory. To avoid this allocation, the library registers the strings used for status codes, and keeps the variable '_WARN' always defined (with false instead of nil).
1 parent 0280407 commit bfcf06d

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

‎ltests.c‎

Lines changed: 20 additions & 7 deletions

‎testes/coroutine.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ do
184184
if not T then
185185
warn("@on")
186186
else -- test library
187-
assert(string.find(_WARN, "200")); _WARN = nil
187+
assert(string.find(_WARN, "200")); _WARN = false
188188
warn("@normal")
189189
end
190190
assert(st == false and coroutine.status(co) == "dead" and msg == 111)

‎testes/gc.lua‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ if T then
372372
warn("@on"); warn("@store")
373373
collectgarbage()
374374
assert(string.find(_WARN, "error in __gc metamethod"))
375-
assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = nil
375+
assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = false
376376
for i = 8, 10 do assert(s[i]) end
377377

378378
for i = 1, 5 do
@@ -481,7 +481,7 @@ if T then
481481
u = setmetatable({}, {__gc = function () error "@expected error" end})
482482
u = nil
483483
collectgarbage()
484-
assert(string.find(_WARN, "@expected error")); _WARN = nil
484+
assert(string.find(_WARN, "@expected error")); _WARN = false
485485
warn("@normal")
486486
end
487487

@@ -657,14 +657,14 @@ if T then
657657
n = n + 1
658658
assert(n == o[1])
659659
if n == 1 then
660-
_WARN = nil
660+
_WARN = false
661661
elseif n == 2 then
662662
assert(find(_WARN, "@expected warning"))
663663
lastmsg = _WARN -- get message from previous error (first 'o')
664664
else
665665
assert(lastmsg == _WARN) -- subsequent error messages are equal
666666
end
667-
warn("@store"); _WARN = nil
667+
warn("@store"); _WARN = false
668668
error"@expected warning"
669669
end}
670670
for i = 10, 1, -1 do

‎testes/locals.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ local function endwarn ()
337337
if not T then
338338
warn("@on") -- back to normal
339339
else
340-
assert(_WARN == nil)
340+
assert(_WARN == false)
341341
warn("@normal")
342342
end
343343
end
@@ -346,7 +346,7 @@ end
346346
local function checkwarn (msg)
347347
if T then
348348
assert(string.find(_WARN, msg))
349-
_WARN = nil -- reset variable to check next warning
349+
_WARN = false -- reset variable to check next warning
350350
end
351351
end
352352

‎testes/main.lua‎

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)