immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,125 @@
1
+ /*
2
+ ** String formatting.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_STRFMT_H
7
+ #define _LJ_STRFMT_H
8
+
9
+ #include "lj_obj.h"
10
+
11
+ typedef uint32_t SFormat; /* Format indicator. */
12
+
13
+ /* Format parser state. */
14
+ typedef struct FormatState {
15
+ const uint8_t *p; /* Current format string pointer. */
16
+ const uint8_t *e; /* End of format string. */
17
+ const char *str; /* Returned literal string. */
18
+ MSize len; /* Size of literal string. */
19
+ } FormatState;
20
+
21
+ /* Format types (max. 16). */
22
+ typedef enum FormatType {
23
+ STRFMT_EOF, STRFMT_ERR, STRFMT_LIT,
24
+ STRFMT_INT, STRFMT_UINT, STRFMT_NUM, STRFMT_STR, STRFMT_CHAR, STRFMT_PTR
25
+ } FormatType;
26
+
27
+ /* Format subtypes (bits are reused). */
28
+ #define STRFMT_T_HEX 0x0010 /* STRFMT_UINT */
29
+ #define STRFMT_T_OCT 0x0020 /* STRFMT_UINT */
30
+ #define STRFMT_T_FP_A 0x0000 /* STRFMT_NUM */
31
+ #define STRFMT_T_FP_E 0x0010 /* STRFMT_NUM */
32
+ #define STRFMT_T_FP_F 0x0020 /* STRFMT_NUM */
33
+ #define STRFMT_T_FP_G 0x0030 /* STRFMT_NUM */
34
+ #define STRFMT_T_QUOTED 0x0010 /* STRFMT_STR */
35
+
36
+ /* Format flags. */
37
+ #define STRFMT_F_LEFT 0x0100
38
+ #define STRFMT_F_PLUS 0x0200
39
+ #define STRFMT_F_ZERO 0x0400
40
+ #define STRFMT_F_SPACE 0x0800
41
+ #define STRFMT_F_ALT 0x1000
42
+ #define STRFMT_F_UPPER 0x2000
43
+
44
+ /* Format indicator fields. */
45
+ #define STRFMT_SH_WIDTH 16
46
+ #define STRFMT_SH_PREC 24
47
+
48
+ #define STRFMT_TYPE(sf) ((FormatType)((sf) & 15))
49
+ #define STRFMT_WIDTH(sf) (((sf) >> STRFMT_SH_WIDTH) & 255u)
50
+ #define STRFMT_PREC(sf) ((((sf) >> STRFMT_SH_PREC) & 255u) - 1u)
51
+ #define STRFMT_FP(sf) (((sf) >> 4) & 3)
52
+
53
+ /* Formats for conversion characters. */
54
+ #define STRFMT_A (STRFMT_NUM|STRFMT_T_FP_A)
55
+ #define STRFMT_C (STRFMT_CHAR)
56
+ #define STRFMT_D (STRFMT_INT)
57
+ #define STRFMT_E (STRFMT_NUM|STRFMT_T_FP_E)
58
+ #define STRFMT_F (STRFMT_NUM|STRFMT_T_FP_F)
59
+ #define STRFMT_G (STRFMT_NUM|STRFMT_T_FP_G)
60
+ #define STRFMT_I STRFMT_D
61
+ #define STRFMT_O (STRFMT_UINT|STRFMT_T_OCT)
62
+ #define STRFMT_P (STRFMT_PTR)
63
+ #define STRFMT_Q (STRFMT_STR|STRFMT_T_QUOTED)
64
+ #define STRFMT_S (STRFMT_STR)
65
+ #define STRFMT_U (STRFMT_UINT)
66
+ #define STRFMT_X (STRFMT_UINT|STRFMT_T_HEX)
67
+
68
+ /* Maximum buffer sizes for conversions. */
69
+ #define STRFMT_MAXBUF_XINT (1+22) /* '0' prefix + uint64_t in octal. */
70
+ #define STRFMT_MAXBUF_INT (1+10) /* Sign + int32_t in decimal. */
71
+ #define STRFMT_MAXBUF_NUM LUAI_MAXNUMBER2STR
72
+ #define STRFMT_MAXBUF_PTR (2+2*sizeof(ptrdiff_t)) /* "0x" + hex ptr. */
73
+
74
+ /* Format parser. */
75
+ LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs);
76
+
77
+ static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len)
78
+ {
79
+ fs->p = (const uint8_t *)p;
80
+ fs->e = (const uint8_t *)p + len;
81
+ lua_assert(*fs->e == 0); /* Must be NUL-terminated (may have NULs inside). */
82
+ }
83
+
84
+ /* Raw conversions. */
85
+ LJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k);
86
+ LJ_FUNC char * LJ_FASTCALL lj_strfmt_wnum(char *p, cTValue *o);
87
+ LJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v);
88
+ LJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v);
89
+ LJ_FUNC const char *lj_strfmt_wstrnum(char *buf, cTValue *o, MSize *lenp);
90
+
91
+ /* Unformatted conversions to buffer. */
92
+ LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k);
93
+ #if LJ_HASJIT
94
+ LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o);
95
+ #endif
96
+ LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putptr(SBuf *sb, const void *v);
97
+ LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str);
98
+
99
+ /* Formatted conversions to buffer. */
100
+ LJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k);
101
+ LJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n);
102
+ LJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n);
103
+ LJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n);
104
+ LJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c);
105
+ LJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str);
106
+
107
+ /* Conversions to strings. */
108
+ LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k);
109
+ LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o);
110
+ LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o);
111
+ #if LJ_HASJIT
112
+ LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c);
113
+ #endif
114
+ LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o);
115
+
116
+ /* Internal string formatting. */
117
+ LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt,
118
+ va_list argp);
119
+ LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)
120
+ #ifdef __GNUC__
121
+ __attribute__ ((format (printf, 2, 3)))
122
+ #endif
123
+ ;
124
+
125
+ #endif
@@ -0,0 +1,547 @@
1
+ /*
2
+ ** String scanning.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #include <math.h>
7
+
8
+ #define lj_strscan_c
9
+ #define LUA_CORE
10
+
11
+ #include "lj_obj.h"
12
+ #include "lj_char.h"
13
+ #include "lj_strscan.h"
14
+
15
+ /* -- Scanning numbers ---------------------------------------------------- */
16
+
17
+ /*
18
+ ** Rationale for the builtin string to number conversion library:
19
+ **
20
+ ** It removes a dependency on libc's strtod(), which is a true portability
21
+ ** nightmare. Mainly due to the plethora of supported OS and toolchain
22
+ ** combinations. Sadly, the various implementations
23
+ ** a) are often buggy, incomplete (no hex floats) and/or imprecise,
24
+ ** b) sometimes crash or hang on certain inputs,
25
+ ** c) return non-standard NaNs that need to be filtered out, and
26
+ ** d) fail if the locale-specific decimal separator is not a dot,
27
+ ** which can only be fixed with atrocious workarounds.
28
+ **
29
+ ** Also, most of the strtod() implementations are hopelessly bloated,
30
+ ** which is not just an I-cache hog, but a problem for static linkage
31
+ ** on embedded systems, too.
32
+ **
33
+ ** OTOH the builtin conversion function is very compact. Even though it
34
+ ** does a lot more, like parsing long longs, octal or imaginary numbers
35
+ ** and returning the result in different formats:
36
+ ** a) It needs less than 3 KB (!) of machine code (on x64 with -Os),
37
+ ** b) it doesn't perform any dynamic allocation and,
38
+ ** c) it needs only around 600 bytes of stack space.
39
+ **
40
+ ** The builtin function is faster than strtod() for typical inputs, e.g.
41
+ ** "123", "1.5" or "1e6". Arguably, it's slower for very large exponents,
42
+ ** which are not very common (this could be fixed, if needed).
43
+ **
44
+ ** And most importantly, the builtin function is equally precise on all
45
+ ** platforms. It correctly converts and rounds any input to a double.
46
+ ** If this is not the case, please send a bug report -- but PLEASE verify
47
+ ** that the implementation you're comparing to is not the culprit!
48
+ **
49
+ ** The implementation quickly pre-scans the entire string first and
50
+ ** handles simple integers on-the-fly. Otherwise, it dispatches to the
51
+ ** base-specific parser. Hex and octal is straightforward.
52
+ **
53
+ ** Decimal to binary conversion uses a fixed-length circular buffer in
54
+ ** base 100. Some simple cases are handled directly. For other cases, the
55
+ ** number in the buffer is up-scaled or down-scaled until the integer part
56
+ ** is in the proper range. Then the integer part is rounded and converted
57
+ ** to a double which is finally rescaled to the result. Denormals need
58
+ ** special treatment to prevent incorrect 'double rounding'.
59
+ */
60
+
61
+ /* Definitions for circular decimal digit buffer (base 100 = 2 digits/byte). */
62
+ #define STRSCAN_DIG 1024
63
+ #define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */
64
+ #define STRSCAN_DDIG (STRSCAN_DIG/2)
65
+ #define STRSCAN_DMASK (STRSCAN_DDIG-1)
66
+
67
+ /* Helpers for circular buffer. */
68
+ #define DNEXT(a) (((a)+1) & STRSCAN_DMASK)
69
+ #define DPREV(a) (((a)-1) & STRSCAN_DMASK)
70
+ #define DLEN(lo, hi) ((int32_t)(((lo)-(hi)) & STRSCAN_DMASK))
71
+
72
+ #define casecmp(c, k) (((c) | 0x20) == k)
73
+
74
+ /* Final conversion to double. */
75
+ static void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg)
76
+ {
77
+ double n;
78
+
79
+ /* Avoid double rounding for denormals. */
80
+ if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) {
81
+ /* NYI: all of this generates way too much code on 32 bit CPUs. */
82
+ #if defined(__GNUC__) && LJ_64
83
+ int32_t b = (int32_t)(__builtin_clzll(x)^63);
84
+ #else
85
+ int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) :
86
+ (int32_t)lj_fls((uint32_t)x);
87
+ #endif
88
+ if ((int32_t)b + ex2 <= -1023 && (int32_t)b + ex2 >= -1075) {
89
+ uint64_t rb = (uint64_t)1 << (-1075-ex2);
90
+ if ((x & rb) && ((x & (rb+rb+rb-1)))) x += rb+rb;
91
+ x = (x & ~(rb+rb-1));
92
+ }
93
+ }
94
+
95
+ /* Convert to double using a signed int64_t conversion, then rescale. */
96
+ lua_assert((int64_t)x >= 0);
97
+ n = (double)(int64_t)x;
98
+ if (neg) n = -n;
99
+ if (ex2) n = ldexp(n, ex2);
100
+ o->n = n;
101
+ }
102
+
103
+ /* Parse hexadecimal number. */
104
+ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o,
105
+ StrScanFmt fmt, uint32_t opt,
106
+ int32_t ex2, int32_t neg, uint32_t dig)
107
+ {
108
+ uint64_t x = 0;
109
+ uint32_t i;
110
+
111
+ /* Scan hex digits. */
112
+ for (i = dig > 16 ? 16 : dig ; i; i--, p++) {
113
+ uint32_t d = (*p != '.' ? *p : *++p); if (d > '9') d += 9;
114
+ x = (x << 4) + (d & 15);
115
+ }
116
+
117
+ /* Summarize rounding-effect of excess digits. */
118
+ for (i = 16; i < dig; i++, p++)
119
+ x |= ((*p != '.' ? *p : *++p) != '0'), ex2 += 4;
120
+
121
+ /* Format-specific handling. */
122
+ switch (fmt) {
123
+ case STRSCAN_INT:
124
+ if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
125
+ o->i = neg ? -(int32_t)x : (int32_t)x;
126
+ return STRSCAN_INT; /* Fast path for 32 bit integers. */
127
+ }
128
+ if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }
129
+ /* fallthrough */
130
+ case STRSCAN_U32:
131
+ if (dig > 8) return STRSCAN_ERROR;
132
+ o->i = neg ? -(int32_t)x : (int32_t)x;
133
+ return STRSCAN_U32;
134
+ case STRSCAN_I64:
135
+ case STRSCAN_U64:
136
+ if (dig > 16) return STRSCAN_ERROR;
137
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
138
+ return fmt;
139
+ default:
140
+ break;
141
+ }
142
+
143
+ /* Reduce range, then convert to double. */
144
+ if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }
145
+ strscan_double(x, o, ex2, neg);
146
+ return fmt;
147
+ }
148
+
149
+ /* Parse octal number. */
150
+ static StrScanFmt strscan_oct(const uint8_t *p, TValue *o,
151
+ StrScanFmt fmt, int32_t neg, uint32_t dig)
152
+ {
153
+ uint64_t x = 0;
154
+
155
+ /* Scan octal digits. */
156
+ if (dig > 22 || (dig == 22 && *p > '1')) return STRSCAN_ERROR;
157
+ while (dig-- > 0) {
158
+ if (!(*p >= '0' && *p <= '7')) return STRSCAN_ERROR;
159
+ x = (x << 3) + (*p++ & 7);
160
+ }
161
+
162
+ /* Format-specific handling. */
163
+ switch (fmt) {
164
+ case STRSCAN_INT:
165
+ if (x >= 0x80000000u+neg) fmt = STRSCAN_U32;
166
+ /* fallthrough */
167
+ case STRSCAN_U32:
168
+ if ((x >> 32)) return STRSCAN_ERROR;
169
+ o->i = neg ? -(int32_t)x : (int32_t)x;
170
+ break;
171
+ default:
172
+ case STRSCAN_I64:
173
+ case STRSCAN_U64:
174
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
175
+ break;
176
+ }
177
+ return fmt;
178
+ }
179
+
180
+ /* Parse decimal number. */
181
+ static StrScanFmt strscan_dec(const uint8_t *p, TValue *o,
182
+ StrScanFmt fmt, uint32_t opt,
183
+ int32_t ex10, int32_t neg, uint32_t dig)
184
+ {
185
+ uint8_t xi[STRSCAN_DDIG], *xip = xi;
186
+
187
+ if (dig) {
188
+ uint32_t i = dig;
189
+ if (i > STRSCAN_MAXDIG) {
190
+ ex10 += (int32_t)(i - STRSCAN_MAXDIG);
191
+ i = STRSCAN_MAXDIG;
192
+ }
193
+ /* Scan unaligned leading digit. */
194
+ if (((ex10^i) & 1))
195
+ *xip++ = ((*p != '.' ? *p : *++p) & 15), i--, p++;
196
+ /* Scan aligned double-digits. */
197
+ for ( ; i > 1; i -= 2) {
198
+ uint32_t d = 10 * ((*p != '.' ? *p : *++p) & 15); p++;
199
+ *xip++ = d + ((*p != '.' ? *p : *++p) & 15); p++;
200
+ }
201
+ /* Scan and realign trailing digit. */
202
+ if (i) *xip++ = 10 * ((*p != '.' ? *p : *++p) & 15), ex10--, dig++, p++;
203
+
204
+ /* Summarize rounding-effect of excess digits. */
205
+ if (dig > STRSCAN_MAXDIG) {
206
+ do {
207
+ if ((*p != '.' ? *p : *++p) != '0') { xip[-1] |= 1; break; }
208
+ p++;
209
+ } while (--dig > STRSCAN_MAXDIG);
210
+ dig = STRSCAN_MAXDIG;
211
+ } else { /* Simplify exponent. */
212
+ while (ex10 > 0 && dig <= 18) *xip++ = 0, ex10 -= 2, dig += 2;
213
+ }
214
+ } else { /* Only got zeros. */
215
+ ex10 = 0;
216
+ xi[0] = 0;
217
+ }
218
+
219
+ /* Fast path for numbers in integer format (but handles e.g. 1e6, too). */
220
+ if (dig <= 20 && ex10 == 0) {
221
+ uint8_t *xis;
222
+ uint64_t x = xi[0];
223
+ double n;
224
+ for (xis = xi+1; xis < xip; xis++) x = x * 100 + *xis;
225
+ if (!(dig == 20 && (xi[0] > 18 || (int64_t)x >= 0))) { /* No overflow? */
226
+ /* Format-specific handling. */
227
+ switch (fmt) {
228
+ case STRSCAN_INT:
229
+ if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
230
+ o->i = neg ? -(int32_t)x : (int32_t)x;
231
+ return STRSCAN_INT; /* Fast path for 32 bit integers. */
232
+ }
233
+ if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; }
234
+ /* fallthrough */
235
+ case STRSCAN_U32:
236
+ if ((x >> 32) != 0) return STRSCAN_ERROR;
237
+ o->i = neg ? -(int32_t)x : (int32_t)x;
238
+ return STRSCAN_U32;
239
+ case STRSCAN_I64:
240
+ case STRSCAN_U64:
241
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
242
+ return fmt;
243
+ default:
244
+ plainnumber: /* Fast path for plain numbers < 2^63. */
245
+ if ((int64_t)x < 0) break;
246
+ n = (double)(int64_t)x;
247
+ if (neg) n = -n;
248
+ o->n = n;
249
+ return fmt;
250
+ }
251
+ }
252
+ }
253
+
254
+ /* Slow non-integer path. */
255
+ if (fmt == STRSCAN_INT) {
256
+ if ((opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;
257
+ fmt = STRSCAN_NUM;
258
+ } else if (fmt > STRSCAN_INT) {
259
+ return STRSCAN_ERROR;
260
+ }
261
+ {
262
+ uint32_t hi = 0, lo = (uint32_t)(xip-xi);
263
+ int32_t ex2 = 0, idig = (int32_t)lo + (ex10 >> 1);
264
+
265
+ lua_assert(lo > 0 && (ex10 & 1) == 0);
266
+
267
+ /* Handle simple overflow/underflow. */
268
+ if (idig > 310/2) { if (neg) setminfV(o); else setpinfV(o); return fmt; }
269
+ else if (idig < -326/2) { o->n = neg ? -0.0 : 0.0; return fmt; }
270
+
271
+ /* Scale up until we have at least 17 or 18 integer part digits. */
272
+ while (idig < 9 && idig < DLEN(lo, hi)) {
273
+ uint32_t i, cy = 0;
274
+ ex2 -= 6;
275
+ for (i = DPREV(lo); ; i = DPREV(i)) {
276
+ uint32_t d = (xi[i] << 6) + cy;
277
+ cy = (((d >> 2) * 5243) >> 17); d = d - cy * 100; /* Div/mod 100. */
278
+ xi[i] = (uint8_t)d;
279
+ if (i == hi) break;
280
+ if (d == 0 && i == DPREV(lo)) lo = i;
281
+ }
282
+ if (cy) {
283
+ hi = DPREV(hi);
284
+ if (xi[DPREV(lo)] == 0) lo = DPREV(lo);
285
+ else if (hi == lo) { lo = DPREV(lo); xi[DPREV(lo)] |= xi[lo]; }
286
+ xi[hi] = (uint8_t)cy; idig++;
287
+ }
288
+ }
289
+
290
+ /* Scale down until no more than 17 or 18 integer part digits remain. */
291
+ while (idig > 9) {
292
+ uint32_t i = hi, cy = 0;
293
+ ex2 += 6;
294
+ do {
295
+ cy += xi[i];
296
+ xi[i] = (cy >> 6);
297
+ cy = 100 * (cy & 0x3f);
298
+ if (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--;
299
+ i = DNEXT(i);
300
+ } while (i != lo);
301
+ while (cy) {
302
+ if (hi == lo) { xi[DPREV(lo)] |= 1; break; }
303
+ xi[lo] = (cy >> 6); lo = DNEXT(lo);
304
+ cy = 100 * (cy & 0x3f);
305
+ }
306
+ }
307
+
308
+ /* Collect integer part digits and convert to rescaled double. */
309
+ {
310
+ uint64_t x = xi[hi];
311
+ uint32_t i;
312
+ for (i = DNEXT(hi); --idig > 0 && i != lo; i = DNEXT(i))
313
+ x = x * 100 + xi[i];
314
+ if (i == lo) {
315
+ while (--idig >= 0) x = x * 100;
316
+ } else { /* Gather round bit from remaining digits. */
317
+ x <<= 1; ex2--;
318
+ do {
319
+ if (xi[i]) { x |= 1; break; }
320
+ i = DNEXT(i);
321
+ } while (i != lo);
322
+ }
323
+ strscan_double(x, o, ex2, neg);
324
+ }
325
+ }
326
+ return fmt;
327
+ }
328
+
329
+ /* Parse binary number. */
330
+ static StrScanFmt strscan_bin(const uint8_t *p, TValue *o,
331
+ StrScanFmt fmt, uint32_t opt,
332
+ int32_t ex2, int32_t neg, uint32_t dig)
333
+ {
334
+ uint64_t x = 0;
335
+ uint32_t i;
336
+
337
+ if (ex2 || dig > 64) return STRSCAN_ERROR;
338
+
339
+ /* Scan binary digits. */
340
+ for (i = dig; i; i--, p++) {
341
+ if ((*p & ~1) != '0') return STRSCAN_ERROR;
342
+ x = (x << 1) | (*p & 1);
343
+ }
344
+
345
+ /* Format-specific handling. */
346
+ switch (fmt) {
347
+ case STRSCAN_INT:
348
+ if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
349
+ o->i = neg ? -(int32_t)x : (int32_t)x;
350
+ return STRSCAN_INT; /* Fast path for 32 bit integers. */
351
+ }
352
+ if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }
353
+ /* fallthrough */
354
+ case STRSCAN_U32:
355
+ if (dig > 32) return STRSCAN_ERROR;
356
+ o->i = neg ? -(int32_t)x : (int32_t)x;
357
+ return STRSCAN_U32;
358
+ case STRSCAN_I64:
359
+ case STRSCAN_U64:
360
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
361
+ return fmt;
362
+ default:
363
+ break;
364
+ }
365
+
366
+ /* Reduce range, then convert to double. */
367
+ if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }
368
+ strscan_double(x, o, ex2, neg);
369
+ return fmt;
370
+ }
371
+
372
+ /* Scan string containing a number. Returns format. Returns value in o. */
373
+ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt)
374
+ {
375
+ int32_t neg = 0;
376
+
377
+ /* Remove leading space, parse sign and non-numbers. */
378
+ if (LJ_UNLIKELY(!lj_char_isdigit(*p))) {
379
+ while (lj_char_isspace(*p)) p++;
380
+ if (*p == '+' || *p == '-') neg = (*p++ == '-');
381
+ if (LJ_UNLIKELY(*p >= 'A')) { /* Parse "inf", "infinity" or "nan". */
382
+ TValue tmp;
383
+ setnanV(&tmp);
384
+ if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'f')) {
385
+ if (neg) setminfV(&tmp); else setpinfV(&tmp);
386
+ p += 3;
387
+ if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'i') &&
388
+ casecmp(p[3],'t') && casecmp(p[4],'y')) p += 5;
389
+ } else if (casecmp(p[0],'n') && casecmp(p[1],'a') && casecmp(p[2],'n')) {
390
+ p += 3;
391
+ }
392
+ while (lj_char_isspace(*p)) p++;
393
+ if (*p) return STRSCAN_ERROR;
394
+ o->u64 = tmp.u64;
395
+ return STRSCAN_NUM;
396
+ }
397
+ }
398
+
399
+ /* Parse regular number. */
400
+ {
401
+ StrScanFmt fmt = STRSCAN_INT;
402
+ int cmask = LJ_CHAR_DIGIT;
403
+ int base = (opt & STRSCAN_OPT_C) && *p == '0' ? 0 : 10;
404
+ const uint8_t *sp, *dp = NULL;
405
+ uint32_t dig = 0, hasdig = 0, x = 0;
406
+ int32_t ex = 0;
407
+
408
+ /* Determine base and skip leading zeros. */
409
+ if (LJ_UNLIKELY(*p <= '0')) {
410
+ if (*p == '0') {
411
+ if (casecmp(p[1], 'x'))
412
+ base = 16, cmask = LJ_CHAR_XDIGIT, p += 2;
413
+ else if (casecmp(p[1], 'b'))
414
+ base = 2, cmask = LJ_CHAR_DIGIT, p += 2;
415
+ }
416
+ for ( ; ; p++) {
417
+ if (*p == '0') {
418
+ hasdig = 1;
419
+ } else if (*p == '.') {
420
+ if (dp) return STRSCAN_ERROR;
421
+ dp = p;
422
+ } else {
423
+ break;
424
+ }
425
+ }
426
+ }
427
+
428
+ /* Preliminary digit and decimal point scan. */
429
+ for (sp = p; ; p++) {
430
+ if (LJ_LIKELY(lj_char_isa(*p, cmask))) {
431
+ x = x * 10 + (*p & 15); /* For fast path below. */
432
+ dig++;
433
+ } else if (*p == '.') {
434
+ if (dp) return STRSCAN_ERROR;
435
+ dp = p;
436
+ } else {
437
+ break;
438
+ }
439
+ }
440
+ if (!(hasdig | dig)) return STRSCAN_ERROR;
441
+
442
+ /* Handle decimal point. */
443
+ if (dp) {
444
+ fmt = STRSCAN_NUM;
445
+ if (dig) {
446
+ ex = (int32_t)(dp-(p-1)); dp = p-1;
447
+ while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */
448
+ if (base == 16) ex *= 4;
449
+ }
450
+ }
451
+
452
+ /* Parse exponent. */
453
+ if (base >= 10 && casecmp(*p, (uint32_t)(base == 16 ? 'p' : 'e'))) {
454
+ uint32_t xx;
455
+ int negx = 0;
456
+ fmt = STRSCAN_NUM; p++;
457
+ if (*p == '+' || *p == '-') negx = (*p++ == '-');
458
+ if (!lj_char_isdigit(*p)) return STRSCAN_ERROR;
459
+ xx = (*p++ & 15);
460
+ while (lj_char_isdigit(*p)) {
461
+ if (xx < 65536) xx = xx * 10 + (*p & 15);
462
+ p++;
463
+ }
464
+ ex += negx ? -(int32_t)xx : (int32_t)xx;
465
+ }
466
+
467
+ /* Parse suffix. */
468
+ if (*p) {
469
+ /* I (IMAG), U (U32), LL (I64), ULL/LLU (U64), L (long), UL/LU (ulong). */
470
+ /* NYI: f (float). Not needed until cp_number() handles non-integers. */
471
+ if (casecmp(*p, 'i')) {
472
+ if (!(opt & STRSCAN_OPT_IMAG)) return STRSCAN_ERROR;
473
+ p++; fmt = STRSCAN_IMAG;
474
+ } else if (fmt == STRSCAN_INT) {
475
+ if (casecmp(*p, 'u')) p++, fmt = STRSCAN_U32;
476
+ if (casecmp(*p, 'l')) {
477
+ p++;
478
+ if (casecmp(*p, 'l')) p++, fmt += STRSCAN_I64 - STRSCAN_INT;
479
+ else if (!(opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;
480
+ else if (sizeof(long) == 8) fmt += STRSCAN_I64 - STRSCAN_INT;
481
+ }
482
+ if (casecmp(*p, 'u') && (fmt == STRSCAN_INT || fmt == STRSCAN_I64))
483
+ p++, fmt += STRSCAN_U32 - STRSCAN_INT;
484
+ if ((fmt == STRSCAN_U32 && !(opt & STRSCAN_OPT_C)) ||
485
+ (fmt >= STRSCAN_I64 && !(opt & STRSCAN_OPT_LL)))
486
+ return STRSCAN_ERROR;
487
+ }
488
+ while (lj_char_isspace(*p)) p++;
489
+ if (*p) return STRSCAN_ERROR;
490
+ }
491
+
492
+ /* Fast path for decimal 32 bit integers. */
493
+ if (fmt == STRSCAN_INT && base == 10 &&
494
+ (dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) {
495
+ int32_t y = neg ? -(int32_t)x : (int32_t)x;
496
+ if ((opt & STRSCAN_OPT_TONUM)) {
497
+ o->n = (double)y;
498
+ return STRSCAN_NUM;
499
+ } else {
500
+ o->i = y;
501
+ return STRSCAN_INT;
502
+ }
503
+ }
504
+
505
+ /* Dispatch to base-specific parser. */
506
+ if (base == 0 && !(fmt == STRSCAN_NUM || fmt == STRSCAN_IMAG))
507
+ return strscan_oct(sp, o, fmt, neg, dig);
508
+ if (base == 16)
509
+ fmt = strscan_hex(sp, o, fmt, opt, ex, neg, dig);
510
+ else if (base == 2)
511
+ fmt = strscan_bin(sp, o, fmt, opt, ex, neg, dig);
512
+ else
513
+ fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig);
514
+
515
+ /* Try to convert number to integer, if requested. */
516
+ if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) {
517
+ double n = o->n;
518
+ int32_t i = lj_num2int(n);
519
+ if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; }
520
+ }
521
+ return fmt;
522
+ }
523
+ }
524
+
525
+ int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o)
526
+ {
527
+ StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o,
528
+ STRSCAN_OPT_TONUM);
529
+ lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM);
530
+ return (fmt != STRSCAN_ERROR);
531
+ }
532
+
533
+ #if LJ_DUALNUM
534
+ int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o)
535
+ {
536
+ StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o,
537
+ STRSCAN_OPT_TOINT);
538
+ lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT);
539
+ if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM);
540
+ return (fmt != STRSCAN_ERROR);
541
+ }
542
+ #endif
543
+
544
+ #undef DNEXT
545
+ #undef DPREV
546
+ #undef DLEN
547
+