big.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. print "testing string length overflow"
  2. local longs = string.rep("\0", 2^25)
  3. local function catter (i)
  4. return assert(loadstring(
  5. string.format("return function(a) return a%s end",
  6. string.rep("..a", i-1))))()
  7. end
  8. rep129 = catter(129)
  9. local a, b = pcall(rep129, longs)
  10. print(b)
  11. assert(not a and string.find(b, "overflow"))
  12. print('+')
  13. require "checktable"
  14. --[[ lots of empty lines (to force SETLINEW)
  15. --]]
  16. a,b = nil,nil
  17. while not b do
  18. if a then
  19. b = { -- lots of strings (to force JMPW and PUSHCONSTANTW)
  20. "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9", "n10",
  21. "n11", "n12", "j301", "j302", "j303", "j304", "j305", "j306", "j307", "j308",
  22. "j309", "a310", "n311", "n312", "n313", "n314", "n315", "n316", "n317", "n318",
  23. "n319", "n320", "n321", "n322", "n323", "n324", "n325", "n326", "n327", "n328",
  24. "a329", "n330", "n331", "n332", "n333", "n334", "n335", "n336", "n337", "n338",
  25. "n339", "n340", "n341", "z342", "n343", "n344", "n345", "n346", "n347", "n348",
  26. "n349", "n350", "n351", "n352", "r353", "n354", "n355", "n356", "n357", "n358",
  27. "n359", "n360", "n361", "n362", "n363", "n364", "n365", "n366", "z367", "n368",
  28. "n369", "n370", "n371", "n372", "n373", "n374", "n375", "a376", "n377", "n378",
  29. "n379", "n380", "n381", "n382", "n383", "n384", "n385", "n386", "n387", "n388",
  30. "n389", "n390", "n391", "n392", "n393", "n394", "n395", "n396", "n397", "n398",
  31. "n399", "n400", "n13", "n14", "n15", "n16", "n17", "n18", "n19", "n20",
  32. "n21", "n22", "n23", "a24", "n25", "n26", "n27", "n28", "n29", "j30",
  33. "n31", "n32", "n33", "n34", "n35", "n36", "n37", "n38", "n39", "n40",
  34. "n41", "n42", "n43", "n44", "n45", "n46", "n47", "n48", "n49", "n50",
  35. "n51", "n52", "n53", "n54", "n55", "n56", "n57", "n58", "n59", "n60",
  36. "n61", "n62", "n63", "n64", "n65", "a66", "z67", "n68", "n69", "n70",
  37. "n71", "n72", "n73", "n74", "n75", "n76", "n77", "n78", "n79", "n80",
  38. "n81", "n82", "n83", "n84", "n85", "n86", "n87", "n88", "n89", "n90",
  39. "n91", "n92", "n93", "n94", "n95", "n96", "n97", "n98", "n99", "n100",
  40. "n201", "n202", "n203", "n204", "n205", "n206", "n207", "n208", "n209", "n210",
  41. "n211", "n212", "n213", "n214", "n215", "n216", "n217", "n218", "n219", "n220",
  42. "n221", "n222", "n223", "n224", "n225", "n226", "n227", "n228", "n229", "n230",
  43. "n231", "n232", "n233", "n234", "n235", "n236", "n237", "n238", "n239", "a240",
  44. "a241", "a242", "a243", "a244", "a245", "a246", "a247", "a248", "a249", "n250",
  45. "n251", "n252", "n253", "n254", "n255", "n256", "n257", "n258", "n259", "n260",
  46. "n261", "n262", "n263", "n264", "n265", "n266", "n267", "n268", "n269", "n270",
  47. "n271", "n272", "n273", "n274", "n275", "n276", "n277", "n278", "n279", "n280",
  48. "n281", "n282", "n283", "n284", "n285", "n286", "n287", "n288", "n289", "n290",
  49. "n291", "n292", "n293", "n294", "n295", "n296", "n297", "n298", "n299"
  50. ; x=23}
  51. else a = 1 end
  52. end
  53. assert(b.x == 23)
  54. print('+')
  55. stat(b)
  56. repeat
  57. a = {
  58. n1 = 1.5, n2 = 2.5, n3 = 3.5, n4 = 4.5, n5 = 5.5, n6 = 6.5, n7 = 7.5,
  59. n8 = 8.5, n9 = 9.5, n10 = 10.5, n11 = 11.5, n12 = 12.5,
  60. j301 = 301.5, j302 = 302.5, j303 = 303.5, j304 = 304.5, j305 = 305.5,
  61. j306 = 306.5, j307 = 307.5, j308 = 308.5, j309 = 309.5, a310 = 310.5,
  62. n311 = 311.5, n312 = 312.5, n313 = 313.5, n314 = 314.5, n315 = 315.5,
  63. n316 = 316.5, n317 = 317.5, n318 = 318.5, n319 = 319.5, n320 = 320.5,
  64. n321 = 321.5, n322 = 322.5, n323 = 323.5, n324 = 324.5, n325 = 325.5,
  65. n326 = 326.5, n327 = 327.5, n328 = 328.5, a329 = 329.5, n330 = 330.5,
  66. n331 = 331.5, n332 = 332.5, n333 = 333.5, n334 = 334.5, n335 = 335.5,
  67. n336 = 336.5, n337 = 337.5, n338 = 338.5, n339 = 339.5, n340 = 340.5,
  68. n341 = 341.5, z342 = 342.5, n343 = 343.5, n344 = 344.5, n345 = 345.5,
  69. n346 = 346.5, n347 = 347.5, n348 = 348.5, n349 = 349.5, n350 = 350.5,
  70. n351 = 351.5, n352 = 352.5, r353 = 353.5, n354 = 354.5, n355 = 355.5,
  71. n356 = 356.5, n357 = 357.5, n358 = 358.5, n359 = 359.5, n360 = 360.5,
  72. n361 = 361.5, n362 = 362.5, n363 = 363.5, n364 = 364.5, n365 = 365.5,
  73. n366 = 366.5, z367 = 367.5, n368 = 368.5, n369 = 369.5, n370 = 370.5,
  74. n371 = 371.5, n372 = 372.5, n373 = 373.5, n374 = 374.5, n375 = 375.5,
  75. a376 = 376.5, n377 = 377.5, n378 = 378.5, n379 = 379.5, n380 = 380.5,
  76. n381 = 381.5, n382 = 382.5, n383 = 383.5, n384 = 384.5, n385 = 385.5,
  77. n386 = 386.5, n387 = 387.5, n388 = 388.5, n389 = 389.5, n390 = 390.5,
  78. n391 = 391.5, n392 = 392.5, n393 = 393.5, n394 = 394.5, n395 = 395.5,
  79. n396 = 396.5, n397 = 397.5, n398 = 398.5, n399 = 399.5, n400 = 400.5,
  80. n13 = 13.5, n14 = 14.5, n15 = 15.5, n16 = 16.5, n17 = 17.5,
  81. n18 = 18.5, n19 = 19.5, n20 = 20.5, n21 = 21.5, n22 = 22.5,
  82. n23 = 23.5, a24 = 24.5, n25 = 25.5, n26 = 26.5, n27 = 27.5,
  83. n28 = 28.5, n29 = 29.5, j30 = 30.5, n31 = 31.5, n32 = 32.5,
  84. n33 = 33.5, n34 = 34.5, n35 = 35.5, n36 = 36.5, n37 = 37.5,
  85. n38 = 38.5, n39 = 39.5, n40 = 40.5, n41 = 41.5, n42 = 42.5,
  86. n43 = 43.5, n44 = 44.5, n45 = 45.5, n46 = 46.5, n47 = 47.5,
  87. n48 = 48.5, n49 = 49.5, n50 = 50.5, n51 = 51.5, n52 = 52.5,
  88. n53 = 53.5, n54 = 54.5, n55 = 55.5, n56 = 56.5, n57 = 57.5,
  89. n58 = 58.5, n59 = 59.5, n60 = 60.5, n61 = 61.5, n62 = 62.5,
  90. n63 = 63.5, n64 = 64.5, n65 = 65.5, a66 = 66.5, z67 = 67.5,
  91. n68 = 68.5, n69 = 69.5, n70 = 70.5, n71 = 71.5, n72 = 72.5,
  92. n73 = 73.5, n74 = 74.5, n75 = 75.5, n76 = 76.5, n77 = 77.5,
  93. n78 = 78.5, n79 = 79.5, n80 = 80.5, n81 = 81.5, n82 = 82.5,
  94. n83 = 83.5, n84 = 84.5, n85 = 85.5, n86 = 86.5, n87 = 87.5,
  95. n88 = 88.5, n89 = 89.5, n90 = 90.5, n91 = 91.5, n92 = 92.5,
  96. n93 = 93.5, n94 = 94.5, n95 = 95.5, n96 = 96.5, n97 = 97.5,
  97. n98 = 98.5, n99 = 99.5, n100 = 100.5, n201 = 201.5, n202 = 202.5,
  98. n203 = 203.5, n204 = 204.5, n205 = 205.5, n206 = 206.5, n207 = 207.5,
  99. n208 = 208.5, n209 = 209.5, n210 = 210.5, n211 = 211.5, n212 = 212.5,
  100. n213 = 213.5, n214 = 214.5, n215 = 215.5, n216 = 216.5, n217 = 217.5,
  101. n218 = 218.5, n219 = 219.5, n220 = 220.5, n221 = 221.5, n222 = 222.5,
  102. n223 = 223.5, n224 = 224.5, n225 = 225.5, n226 = 226.5, n227 = 227.5,
  103. n228 = 228.5, n229 = 229.5, n230 = 230.5, n231 = 231.5, n232 = 232.5,
  104. n233 = 233.5, n234 = 234.5, n235 = 235.5, n236 = 236.5, n237 = 237.5,
  105. n238 = 238.5, n239 = 239.5, a240 = 240.5, a241 = 241.5, a242 = 242.5,
  106. a243 = 243.5, a244 = 244.5, a245 = 245.5, a246 = 246.5, a247 = 247.5,
  107. a248 = 248.5, a249 = 249.5, n250 = 250.5, n251 = 251.5, n252 = 252.5,
  108. n253 = 253.5, n254 = 254.5, n255 = 255.5, n256 = 256.5, n257 = 257.5,
  109. n258 = 258.5, n259 = 259.5, n260 = 260.5, n261 = 261.5, n262 = 262.5,
  110. n263 = 263.5, n264 = 264.5, n265 = 265.5, n266 = 266.5, n267 = 267.5,
  111. n268 = 268.5, n269 = 269.5, n270 = 270.5, n271 = 271.5, n272 = 272.5,
  112. n273 = 273.5, n274 = 274.5, n275 = 275.5, n276 = 276.5, n277 = 277.5,
  113. n278 = 278.5, n279 = 279.5, n280 = 280.5, n281 = 281.5, n282 = 282.5,
  114. n283 = 283.5, n284 = 284.5, n285 = 285.5, n286 = 286.5, n287 = 287.5,
  115. n288 = 288.5, n289 = 289.5, n290 = 290.5, n291 = 291.5, n292 = 292.5,
  116. n293 = 293.5, n294 = 294.5, n295 = 295.5, n296 = 296.5, n297 = 297.5,
  117. n298 = 298.5, n299 = 299.5, j300 = 300} or 1
  118. until 1
  119. assert(a.n299 == 299.5)
  120. xxx = 1
  121. assert(xxx == 1)
  122. stat(a)
  123. function a:findfield (f)
  124. local i,v = next(self, nil)
  125. while i ~= f do
  126. if not i then return end
  127. i,v = next(self, i)
  128. end
  129. return v
  130. end
  131. local ii = 0
  132. i = 1
  133. while b[i] do
  134. local r = a:findfield(b[i]);
  135. assert(a[b[i]] == r)
  136. ii = math.max(ii,i)
  137. i = i+1
  138. end
  139. assert(ii == 299)
  140. function xxxx (x) coroutine.yield('b'); return ii+x end
  141. assert(xxxx(10) == 309)
  142. a = nil
  143. b = nil
  144. a1 = nil
  145. print("tables with table indices:")
  146. i = 1; a={}
  147. while i <= 1023 do a[{}] = i; i=i+1 end
  148. stat(a)
  149. a = nil
  150. print("tables with function indices:")
  151. a={}
  152. for i=1,511 do local x; a[function () return x end] = i end
  153. stat(a)
  154. a = nil
  155. print'OK'
  156. return 'a'