diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-04 16:40:18 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-04 16:40:18 -0300 |
commit | bfcf06d91a87b7ffb8c83e290db0cb6176a167f8 (patch) | |
tree | 0bcba905a2772e536c845e39e9eeed0c7330312c /testes/gc.lua | |
parent | 0280407fc54f9b6225139c5ac27326f98f0cf043 (diff) | |
download | lua-bfcf06d91a87b7ffb8c83e290db0cb6176a167f8.tar.gz lua-bfcf06d91a87b7ffb8c83e290db0cb6176a167f8.tar.bz2 lua-bfcf06d91a87b7ffb8c83e290db0cb6176a167f8.zip |
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).
Diffstat (limited to 'testes/gc.lua')
-rw-r--r-- | testes/gc.lua | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/testes/gc.lua b/testes/gc.lua index 91915c0b..80850f92 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -372,7 +372,7 @@ if T then | |||
372 | warn("@on"); warn("@store") | 372 | warn("@on"); warn("@store") |
373 | collectgarbage() | 373 | collectgarbage() |
374 | assert(string.find(_WARN, "error in __gc metamethod")) | 374 | assert(string.find(_WARN, "error in __gc metamethod")) |
375 | assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = nil | 375 | assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = false |
376 | for i = 8, 10 do assert(s[i]) end | 376 | for i = 8, 10 do assert(s[i]) end |
377 | 377 | ||
378 | for i = 1, 5 do | 378 | for i = 1, 5 do |
@@ -481,7 +481,7 @@ if T then | |||
481 | u = setmetatable({}, {__gc = function () error "@expected error" end}) | 481 | u = setmetatable({}, {__gc = function () error "@expected error" end}) |
482 | u = nil | 482 | u = nil |
483 | collectgarbage() | 483 | collectgarbage() |
484 | assert(string.find(_WARN, "@expected error")); _WARN = nil | 484 | assert(string.find(_WARN, "@expected error")); _WARN = false |
485 | warn("@normal") | 485 | warn("@normal") |
486 | end | 486 | end |
487 | 487 | ||
@@ -657,14 +657,14 @@ if T then | |||
657 | n = n + 1 | 657 | n = n + 1 |
658 | assert(n == o[1]) | 658 | assert(n == o[1]) |
659 | if n == 1 then | 659 | if n == 1 then |
660 | _WARN = nil | 660 | _WARN = false |
661 | elseif n == 2 then | 661 | elseif n == 2 then |
662 | assert(find(_WARN, "@expected warning")) | 662 | assert(find(_WARN, "@expected warning")) |
663 | lastmsg = _WARN -- get message from previous error (first 'o') | 663 | lastmsg = _WARN -- get message from previous error (first 'o') |
664 | else | 664 | else |
665 | assert(lastmsg == _WARN) -- subsequent error messages are equal | 665 | assert(lastmsg == _WARN) -- subsequent error messages are equal |
666 | end | 666 | end |
667 | warn("@store"); _WARN = nil | 667 | warn("@store"); _WARN = false |
668 | error"@expected warning" | 668 | error"@expected warning" |
669 | end} | 669 | end} |
670 | for i = 10, 1, -1 do | 670 | for i = 10, 1, -1 do |