diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-04-23 17:57:42 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-04-23 17:57:42 -0300 |
| commit | 3228a97c6a953dcf397944161bb64b12f1ff5384 (patch) | |
| tree | 6497f6f8e93ba3bb381c0b48aed71646fca3f9b0 /testes | |
| parent | 0c16a42d61d08266033ff63bc5dfade6312b7359 (diff) | |
| download | lua-3228a97c6a953dcf397944161bb64b12f1ff5384.tar.gz lua-3228a97c6a953dcf397944161bb64b12f1ff5384.tar.bz2 lua-3228a97c6a953dcf397944161bb64b12f1ff5384.zip | |
Bug: 'lua_load' does not preserve the stack
'lua_load' does not preserve the stack through the calls to the
reader function, as it should. Immediately after the first call (to
detect whether chunk is binary) it adds stuff, and it also adds a new
table when starting the compilation of each new function.
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/calls.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 0dacb85a..cd4510a2 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -372,6 +372,32 @@ do -- another bug (in 5.4.0) | |||
| 372 | end | 372 | end |
| 373 | 373 | ||
| 374 | 374 | ||
| 375 | if T then | ||
| 376 | -- check stack level when calling reader function | ||
| 377 | local function get (str) | ||
| 378 | local pos = 0 | ||
| 379 | local level = nil | ||
| 380 | return function () | ||
| 381 | pos = pos + 1 | ||
| 382 | local c = string.sub(str, pos, pos) | ||
| 383 | local newlevel = T.stacklevel() | ||
| 384 | if not level then | ||
| 385 | level = newlevel | ||
| 386 | else | ||
| 387 | assert(level == newlevel) | ||
| 388 | end | ||
| 389 | return #c > 0 and c or nil | ||
| 390 | end | ||
| 391 | end | ||
| 392 | |||
| 393 | local str = "local function foo () end; return 121" | ||
| 394 | assert(assert(load(get(str)))() == 121) | ||
| 395 | |||
| 396 | str = string.dump(load(str)) | ||
| 397 | assert(assert(load(get(str)))() == 121) | ||
| 398 | end | ||
| 399 | |||
| 400 | |||
| 375 | x = string.dump(load("x = 1; return x")) | 401 | x = string.dump(load("x = 1; return x")) |
| 376 | a = assert(load(read1(x), nil, "b")) | 402 | a = assert(load(read1(x), nil, "b")) |
| 377 | assert(a() == 1 and _G.x == 1) | 403 | assert(a() == 1 and _G.x == 1) |
