script_core 0.2.2 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (376) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +41 -45
  3. data/.travis.yml +2 -1
  4. data/Gemfile +3 -3
  5. data/README.md +7 -1
  6. data/bootstrap.sh +2 -2
  7. data/ext/enterprise_script_service/libseccomp/.travis.yml +24 -12
  8. data/ext/enterprise_script_service/libseccomp/CHANGELOG +32 -0
  9. data/ext/enterprise_script_service/libseccomp/CONTRIBUTING.md +37 -26
  10. data/ext/enterprise_script_service/libseccomp/CREDITS +11 -0
  11. data/ext/enterprise_script_service/libseccomp/README.md +21 -1
  12. data/ext/enterprise_script_service/libseccomp/configure.ac +13 -8
  13. data/ext/enterprise_script_service/libseccomp/doc/Makefile.am +6 -0
  14. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_api_get.3 +12 -2
  15. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_arch_add.3 +38 -6
  16. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_attr_set.3 +53 -2
  17. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_export_bpf.3 +20 -2
  18. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_init.3 +9 -2
  19. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_load.3 +32 -2
  20. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_merge.3 +16 -2
  21. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_alloc.3 +113 -0
  22. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_fd.3 +1 -0
  23. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_free.3 +1 -0
  24. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_id_valid.3 +1 -0
  25. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_receive.3 +1 -0
  26. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_respond.3 +1 -0
  27. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_rule_add.3 +64 -3
  28. data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_syscall_priority.3 +18 -3
  29. data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +19 -0
  30. data/ext/enterprise_script_service/libseccomp/include/seccomp.h.in +116 -0
  31. data/ext/enterprise_script_service/libseccomp/src/.gitignore +2 -0
  32. data/ext/enterprise_script_service/libseccomp/src/Makefile.am +31 -17
  33. data/ext/enterprise_script_service/libseccomp/src/api.c +254 -58
  34. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64.h +1 -9
  35. data/ext/enterprise_script_service/libseccomp/src/arch-arm.c +47 -2
  36. data/ext/enterprise_script_service/libseccomp/src/arch-arm.h +1 -9
  37. data/ext/enterprise_script_service/libseccomp/src/arch-gperf-generate +40 -0
  38. data/ext/enterprise_script_service/libseccomp/src/arch-mips.c +41 -4
  39. data/ext/enterprise_script_service/libseccomp/src/arch-mips.h +2 -10
  40. data/ext/enterprise_script_service/libseccomp/src/arch-mips64.c +41 -4
  41. data/ext/enterprise_script_service/libseccomp/src/arch-mips64.h +3 -11
  42. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32.c +41 -4
  43. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32.h +2 -10
  44. data/ext/enterprise_script_service/libseccomp/src/arch-parisc.h +1 -10
  45. data/ext/enterprise_script_service/libseccomp/src/arch-parisc64.c +3 -3
  46. data/ext/enterprise_script_service/libseccomp/src/arch-parisc64.h +29 -0
  47. data/ext/enterprise_script_service/libseccomp/src/arch-ppc.h +1 -9
  48. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64.c +606 -8
  49. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64.h +2 -10
  50. data/ext/enterprise_script_service/libseccomp/src/arch-riscv64.c +31 -0
  51. data/ext/enterprise_script_service/libseccomp/src/arch-riscv64.h +22 -0
  52. data/ext/enterprise_script_service/libseccomp/src/arch-s390.c +171 -12
  53. data/ext/enterprise_script_service/libseccomp/src/arch-s390.h +1 -17
  54. data/ext/enterprise_script_service/libseccomp/src/arch-s390x.c +166 -10
  55. data/ext/enterprise_script_service/libseccomp/src/arch-s390x.h +1 -20
  56. data/ext/enterprise_script_service/libseccomp/src/arch-syscall-dump.c +8 -1
  57. data/ext/enterprise_script_service/libseccomp/src/arch-syscall-validate +359 -143
  58. data/ext/enterprise_script_service/libseccomp/src/arch-x32.c +36 -2
  59. data/ext/enterprise_script_service/libseccomp/src/arch-x32.h +2 -10
  60. data/ext/enterprise_script_service/libseccomp/src/arch-x86.c +172 -10
  61. data/ext/enterprise_script_service/libseccomp/src/arch-x86.h +1 -14
  62. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64.h +1 -9
  63. data/ext/enterprise_script_service/libseccomp/src/arch.c +11 -3
  64. data/ext/enterprise_script_service/libseccomp/src/arch.h +7 -0
  65. data/ext/enterprise_script_service/libseccomp/src/db.c +268 -57
  66. data/ext/enterprise_script_service/libseccomp/src/db.h +16 -2
  67. data/ext/enterprise_script_service/libseccomp/src/gen_bpf.c +503 -148
  68. data/ext/enterprise_script_service/libseccomp/src/gen_bpf.h +2 -1
  69. data/ext/enterprise_script_service/libseccomp/src/gen_pfc.c +165 -37
  70. data/ext/enterprise_script_service/libseccomp/src/python/libseccomp.pxd +37 -1
  71. data/ext/enterprise_script_service/libseccomp/src/python/seccomp.pyx +295 -5
  72. data/ext/enterprise_script_service/libseccomp/src/syscalls.c +56 -0
  73. data/ext/enterprise_script_service/libseccomp/src/syscalls.csv +470 -0
  74. data/ext/enterprise_script_service/libseccomp/src/syscalls.h +62 -0
  75. data/ext/enterprise_script_service/libseccomp/src/syscalls.perf.template +82 -0
  76. data/ext/enterprise_script_service/libseccomp/src/system.c +196 -16
  77. data/ext/enterprise_script_service/libseccomp/src/system.h +68 -13
  78. data/ext/enterprise_script_service/libseccomp/tests/.gitignore +10 -2
  79. data/ext/enterprise_script_service/libseccomp/tests/06-sim-actions.tests +1 -1
  80. data/ext/enterprise_script_service/libseccomp/tests/11-basic-basic_errors.c +5 -5
  81. data/ext/enterprise_script_service/libseccomp/tests/13-basic-attrs.c +35 -1
  82. data/ext/enterprise_script_service/libseccomp/tests/13-basic-attrs.py +10 -1
  83. data/ext/enterprise_script_service/libseccomp/tests/15-basic-resolver.c +4 -3
  84. data/ext/enterprise_script_service/libseccomp/tests/16-sim-arch_basic.c +12 -0
  85. data/ext/enterprise_script_service/libseccomp/tests/16-sim-arch_basic.py +1 -0
  86. data/ext/enterprise_script_service/libseccomp/tests/{18-sim-basic_whitelist.c → 18-sim-basic_allowlist.c} +0 -0
  87. data/ext/enterprise_script_service/libseccomp/tests/{18-sim-basic_whitelist.py → 18-sim-basic_allowlist.py} +0 -0
  88. data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_allowlist.tests +32 -0
  89. data/ext/enterprise_script_service/libseccomp/tests/23-sim-arch_all_le_basic.c +3 -0
  90. data/ext/enterprise_script_service/libseccomp/tests/23-sim-arch_all_le_basic.py +1 -0
  91. data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.c +3 -0
  92. data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.py +1 -0
  93. data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.tests +33 -17
  94. data/ext/enterprise_script_service/libseccomp/tests/{34-sim-basic_blacklist.c → 34-sim-basic_denylist.c} +0 -0
  95. data/ext/enterprise_script_service/libseccomp/tests/{34-sim-basic_blacklist.py → 34-sim-basic_denylist.py} +0 -0
  96. data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_denylist.tests +32 -0
  97. data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.c +3 -0
  98. data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.py +1 -0
  99. data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.tests +25 -25
  100. data/ext/enterprise_script_service/libseccomp/tests/39-basic-api_level.c +24 -3
  101. data/ext/enterprise_script_service/libseccomp/tests/39-basic-api_level.py +16 -1
  102. data/ext/enterprise_script_service/libseccomp/tests/47-live-kill_process.c +3 -3
  103. data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.c +112 -0
  104. data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.py +60 -0
  105. data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.tests +11 -0
  106. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.c +48 -0
  107. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.py +38 -0
  108. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.tests +11 -0
  109. data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.c +156 -0
  110. data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.py +95 -0
  111. data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.tests +65 -0
  112. data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.c +128 -0
  113. data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.py +95 -0
  114. data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.tests +11 -0
  115. data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.c +134 -0
  116. data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.sh +46 -0
  117. data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.tests +11 -0
  118. data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.c +90 -0
  119. data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.py +65 -0
  120. data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.tests +11 -0
  121. data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.c +64 -0
  122. data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.py +46 -0
  123. data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.tests +11 -0
  124. data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.c +116 -0
  125. data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.py +61 -0
  126. data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.tests +11 -0
  127. data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +34 -10
  128. data/ext/enterprise_script_service/libseccomp/tests/regression +10 -3
  129. data/ext/enterprise_script_service/libseccomp/tests/util.c +3 -3
  130. data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -3
  131. data/ext/enterprise_script_service/libseccomp/tools/check-syntax +1 -1
  132. data/ext/enterprise_script_service/libseccomp/tools/scmp_arch_detect.c +3 -0
  133. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_disasm.c +4 -2
  134. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +4 -0
  135. data/ext/enterprise_script_service/libseccomp/tools/util.c +14 -12
  136. data/ext/enterprise_script_service/libseccomp/tools/util.h +7 -0
  137. data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +106 -0
  138. data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +51 -0
  139. data/ext/enterprise_script_service/mruby/.github/workflows/main.yml +24 -0
  140. data/ext/enterprise_script_service/mruby/.gitignore +3 -0
  141. data/ext/enterprise_script_service/mruby/.travis.yml +6 -9
  142. data/ext/enterprise_script_service/mruby/AUTHORS +1 -0
  143. data/ext/enterprise_script_service/mruby/Doxyfile +1 -1
  144. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  145. data/ext/enterprise_script_service/mruby/README.md +6 -2
  146. data/ext/enterprise_script_service/mruby/appveyor.yml +9 -12
  147. data/ext/enterprise_script_service/mruby/appveyor_config.rb +9 -0
  148. data/ext/enterprise_script_service/mruby/build_config.rb +6 -6
  149. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +6 -2
  150. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +1 -1
  151. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +4 -8
  152. data/ext/enterprise_script_service/mruby/doc/limitations.md +10 -10
  153. data/ext/enterprise_script_service/mruby/doc/opcode.md +108 -95
  154. data/ext/enterprise_script_service/mruby/examples/targets/build_config_ArduinoDue.rb +2 -2
  155. data/ext/enterprise_script_service/mruby/examples/targets/build_config_IntelEdison.rb +2 -2
  156. data/ext/enterprise_script_service/mruby/examples/targets/build_config_IntelGalileo.rb +2 -2
  157. data/ext/enterprise_script_service/mruby/examples/targets/build_config_RX630.rb +2 -2
  158. data/ext/enterprise_script_service/mruby/examples/targets/build_config_chipKITMax32.rb +2 -2
  159. data/ext/enterprise_script_service/mruby/examples/targets/build_config_dreamcast_shelf.rb +108 -0
  160. data/ext/enterprise_script_service/mruby/include/mrbconf.h +10 -7
  161. data/ext/enterprise_script_service/mruby/include/mruby.h +24 -9
  162. data/ext/enterprise_script_service/mruby/include/mruby/array.h +4 -0
  163. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +11 -2
  164. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +0 -10
  165. data/ext/enterprise_script_service/mruby/include/mruby/common.h +10 -0
  166. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +11 -3
  167. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +1 -17
  168. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +10 -0
  169. data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -1
  170. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +23 -5
  171. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +1 -0
  172. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +3 -2
  173. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +13 -8
  174. data/ext/enterprise_script_service/mruby/include/mruby/string.h +2 -1
  175. data/ext/enterprise_script_service/mruby/include/mruby/value.h +32 -41
  176. data/ext/enterprise_script_service/mruby/include/mruby/version.h +4 -4
  177. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +2 -30
  178. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +21 -46
  179. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +9 -0
  180. data/ext/enterprise_script_service/mruby/lib/mruby/source.rb +3 -1
  181. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +7 -0
  182. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +0 -31
  183. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +5 -8
  184. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +0 -13
  185. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +5 -2
  186. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +0 -1
  187. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +5 -1
  188. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +7 -3
  189. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +24 -21
  190. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +0 -1
  191. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +6 -2
  192. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +6 -2
  193. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +6 -1
  194. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +76 -48
  195. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +107 -32
  196. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +13153 -0
  197. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +13 -15
  198. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +1 -1
  199. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +1 -2
  200. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +3 -3
  201. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +3 -214
  202. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +21 -0
  203. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +1 -2
  204. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +1 -3
  205. data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +3 -4
  206. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +39 -7
  207. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +2 -8
  208. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file_constants.rb +0 -16
  209. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +7 -12
  210. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +77 -32
  211. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +18 -36
  212. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +324 -122
  213. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +18 -12
  214. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +32 -0
  215. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +57 -49
  216. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +6 -8
  217. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +15 -17
  218. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +9 -0
  219. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +4 -5
  220. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +3 -12
  221. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +0 -1
  222. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +113 -10
  223. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +6 -3
  224. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +2 -2
  225. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +1 -3
  226. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +1 -3
  227. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +9 -9
  228. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +1 -1
  229. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/mrbgem.rake +1 -1
  230. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/sockettest.c +3 -2
  231. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +62 -25
  232. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +5 -23
  233. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +4 -5
  234. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +5 -11
  235. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +1 -1
  236. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +1 -0
  237. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +11 -15
  238. data/ext/enterprise_script_service/mruby/mrblib/00class.rb +10 -0
  239. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +3 -3
  240. data/ext/enterprise_script_service/mruby/src/array.c +25 -11
  241. data/ext/enterprise_script_service/mruby/src/backtrace.c +2 -2
  242. data/ext/enterprise_script_service/mruby/src/class.c +48 -32
  243. data/ext/enterprise_script_service/mruby/src/codedump.c +4 -0
  244. data/ext/enterprise_script_service/mruby/src/debug.c +8 -5
  245. data/ext/enterprise_script_service/mruby/src/dump.c +3 -65
  246. data/ext/enterprise_script_service/mruby/src/error.c +58 -7
  247. data/ext/enterprise_script_service/mruby/src/etc.c +13 -5
  248. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +98 -21
  249. data/ext/enterprise_script_service/mruby/src/gc.c +15 -280
  250. data/ext/enterprise_script_service/mruby/src/hash.c +13 -21
  251. data/ext/enterprise_script_service/mruby/src/kernel.c +6 -9
  252. data/ext/enterprise_script_service/mruby/src/load.c +56 -30
  253. data/ext/enterprise_script_service/mruby/src/numeric.c +50 -70
  254. data/ext/enterprise_script_service/mruby/src/object.c +23 -5
  255. data/ext/enterprise_script_service/mruby/src/print.c +27 -3
  256. data/ext/enterprise_script_service/mruby/src/proc.c +26 -7
  257. data/ext/enterprise_script_service/mruby/src/range.c +4 -12
  258. data/ext/enterprise_script_service/mruby/src/state.c +34 -11
  259. data/ext/enterprise_script_service/mruby/src/string.c +93 -56
  260. data/ext/enterprise_script_service/mruby/src/symbol.c +13 -12
  261. data/ext/enterprise_script_service/mruby/src/vm.c +48 -53
  262. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +19 -22
  263. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +1 -1
  264. data/ext/enterprise_script_service/mruby/tasks/toolchains/android.rake +46 -1
  265. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +3 -3
  266. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +6 -6
  267. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +8 -8
  268. data/ext/enterprise_script_service/mruby/test/assert.rb +5 -4
  269. data/ext/enterprise_script_service/mruby/test/t/ensure.rb +8 -26
  270. data/ext/enterprise_script_service/mruby/test/t/exception.rb +2 -2
  271. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +15 -24
  272. data/ext/enterprise_script_service/mruby/travis_config.rb +0 -14
  273. data/ext/enterprise_script_service/msgpack/.github/depends/boost.sh +56 -0
  274. data/ext/enterprise_script_service/msgpack/.github/workflows/coverage.yml +62 -0
  275. data/ext/enterprise_script_service/msgpack/.github/workflows/gha.yml +304 -0
  276. data/ext/enterprise_script_service/msgpack/CHANGELOG.md +11 -0
  277. data/ext/enterprise_script_service/msgpack/CMakeLists.txt +82 -39
  278. data/ext/enterprise_script_service/msgpack/Files.cmake +22 -12
  279. data/ext/enterprise_script_service/msgpack/QUICKSTART-C.md +26 -29
  280. data/ext/enterprise_script_service/msgpack/README.md +3 -2
  281. data/ext/enterprise_script_service/msgpack/appveyor.yml +6 -2
  282. data/ext/enterprise_script_service/msgpack/ci/build_cmake.sh +3 -1
  283. data/ext/enterprise_script_service/msgpack/cmake/CodeCoverage.cmake +55 -0
  284. data/ext/enterprise_script_service/msgpack/codecov.yml +36 -0
  285. data/ext/enterprise_script_service/msgpack/example/CMakeLists.txt +9 -5
  286. data/ext/enterprise_script_service/msgpack/example/boost/CMakeLists.txt +1 -1
  287. data/ext/enterprise_script_service/msgpack/example/c/CMakeLists.txt +17 -6
  288. data/ext/enterprise_script_service/msgpack/example/c/boundary.c +296 -0
  289. data/ext/enterprise_script_service/msgpack/example/c/jsonconv.c +419 -0
  290. data/ext/enterprise_script_service/msgpack/example/c/simple_c.c +1 -1
  291. data/ext/enterprise_script_service/msgpack/example/cpp03/CMakeLists.txt +3 -3
  292. data/ext/enterprise_script_service/msgpack/example/cpp11/CMakeLists.txt +2 -2
  293. data/ext/enterprise_script_service/msgpack/example/x3/CMakeLists.txt +2 -2
  294. data/ext/enterprise_script_service/msgpack/include/msgpack/pack.h +24 -1
  295. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +5 -4
  296. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/boost/optional.hpp +4 -4
  297. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp +8 -8
  298. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/map.hpp +4 -4
  299. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector.hpp +4 -4
  300. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_char.hpp +8 -8
  301. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_unsigned_char.hpp +8 -8
  302. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +4 -4
  303. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/unpack.hpp +6 -6
  304. data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
  305. data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +4 -4
  306. data/ext/enterprise_script_service/msgpack/make_file_list.sh +38 -11
  307. data/ext/enterprise_script_service/msgpack/src/vrefbuffer.c +6 -0
  308. data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +86 -64
  309. data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +4 -0
  310. data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +4 -0
  311. data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +4 -0
  312. data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +4 -1
  313. data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +4 -0
  314. data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +4 -0
  315. data/ext/enterprise_script_service/msgpack/test/buffer.cpp +4 -47
  316. data/ext/enterprise_script_service/msgpack/test/buffer_c.cpp +148 -0
  317. data/ext/enterprise_script_service/msgpack/test/carray.cpp +4 -0
  318. data/ext/enterprise_script_service/msgpack/test/cases.cpp +8 -4
  319. data/ext/enterprise_script_service/msgpack/test/convert.cpp +8 -4
  320. data/ext/enterprise_script_service/msgpack/test/fixint.cpp +4 -0
  321. data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +4 -0
  322. data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +4 -0
  323. data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +4 -0
  324. data/ext/enterprise_script_service/msgpack/test/json.cpp +4 -0
  325. data/ext/enterprise_script_service/msgpack/test/limit.cpp +8 -4
  326. data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +4 -0
  327. data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +159 -0
  328. data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +4 -0
  329. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +32 -27
  330. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +4 -0
  331. data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +4 -0
  332. data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +4 -1
  333. data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +4 -0
  334. data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +4 -0
  335. data/ext/enterprise_script_service/msgpack/test/object.cpp +4 -1
  336. data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +12 -8
  337. data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +30 -26
  338. data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +4 -0
  339. data/ext/enterprise_script_service/msgpack/test/raw.cpp +4 -0
  340. data/ext/enterprise_script_service/msgpack/test/reference.cpp +4 -0
  341. data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +4 -0
  342. data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +4 -0
  343. data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +4 -0
  344. data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +4 -0
  345. data/ext/enterprise_script_service/msgpack/test/streaming.cpp +8 -4
  346. data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +4 -0
  347. data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +4 -0
  348. data/ext/enterprise_script_service/msgpack/test/user_class.cpp +16 -12
  349. data/ext/enterprise_script_service/msgpack/test/version.cpp +4 -0
  350. data/ext/enterprise_script_service/msgpack/test/visitor.cpp +4 -0
  351. data/ext/enterprise_script_service/msgpack/test/zone.cpp +4 -0
  352. data/lib/script_core/engine.rb +24 -5
  353. data/lib/script_core/executable.rb +4 -3
  354. data/lib/script_core/result.rb +1 -5
  355. data/lib/script_core/service_channel.rb +1 -0
  356. data/lib/script_core/version.rb +1 -1
  357. data/lib/tasks/script_core.rake +3 -1
  358. data/script_core.gemspec +2 -2
  359. data/spec/dummy/app/lib/script_engine.rb +64 -5
  360. metadata +68 -30
  361. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +0 -559
  362. data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +0 -570
  363. data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +0 -562
  364. data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +0 -562
  365. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +0 -562
  366. data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +0 -542
  367. data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +0 -559
  368. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +0 -559
  369. data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +0 -626
  370. data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +0 -626
  371. data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +0 -558
  372. data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +0 -692
  373. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +0 -559
  374. data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_whitelist.tests +0 -32
  375. data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_blacklist.tests +0 -32
  376. data/ext/enterprise_script_service/msgpack/.travis.yml +0 -258
@@ -47,6 +47,17 @@ mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
47
47
  mrb_value result;
48
48
 
49
49
  if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE;
50
+ #ifndef MRB_WITHOUT_FLOAT
51
+ /* value mixing with integer and float */
52
+ if (mrb_fixnum_p(obj1)) {
53
+ if (mrb_float_p(obj2) && (mrb_float)mrb_fixnum(obj1) == mrb_float(obj2))
54
+ return TRUE;
55
+ }
56
+ else if (mrb_float_p(obj1)) {
57
+ if (mrb_fixnum_p(obj2) && mrb_float(obj1) == (mrb_float)mrb_fixnum(obj2))
58
+ return TRUE;
59
+ }
60
+ #endif
50
61
  result = mrb_funcall(mrb, obj1, "==", 1, obj2);
51
62
  if (mrb_test(result)) return TRUE;
52
63
  return FALSE;
@@ -83,13 +94,17 @@ mrb_true(mrb_state *mrb, mrb_value obj)
83
94
  static mrb_value
84
95
  nil_to_s(mrb_state *mrb, mrb_value obj)
85
96
  {
86
- return mrb_str_new_frozen(mrb, 0, 0);
97
+ mrb_value str = mrb_str_new_frozen(mrb, 0, 0);
98
+ RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
99
+ return str;
87
100
  }
88
101
 
89
102
  static mrb_value
90
103
  nil_inspect(mrb_state *mrb, mrb_value obj)
91
104
  {
92
- return mrb_str_new_lit_frozen(mrb, "nil");
105
+ mrb_value str = mrb_str_new_lit_frozen(mrb, "nil");
106
+ RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
107
+ return str;
93
108
  }
94
109
 
95
110
  /***********************************************************************
@@ -150,7 +165,9 @@ true_xor(mrb_state *mrb, mrb_value obj)
150
165
  static mrb_value
151
166
  true_to_s(mrb_state *mrb, mrb_value obj)
152
167
  {
153
- return mrb_str_new_lit_frozen(mrb, "true");
168
+ mrb_value str = mrb_str_new_lit_frozen(mrb, "true");
169
+ RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
170
+ return str;
154
171
  }
155
172
 
156
173
  /* 15.2.5.3.4 */
@@ -257,7 +274,9 @@ false_or(mrb_state *mrb, mrb_value obj)
257
274
  static mrb_value
258
275
  false_to_s(mrb_state *mrb, mrb_value obj)
259
276
  {
260
- return mrb_str_new_lit_frozen(mrb, "false");
277
+ mrb_value str = mrb_str_new_lit_frozen(mrb, "false");
278
+ RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
279
+ return str;
261
280
  }
262
281
 
263
282
  void
@@ -358,7 +377,6 @@ static const struct types {
358
377
  {MRB_TT_STRING, "String"},
359
378
  {MRB_TT_RANGE, "Range"},
360
379
  /* {MRB_TT_BIGNUM, "Bignum"}, */
361
- {MRB_TT_FILE, "File"},
362
380
  {MRB_TT_DATA, "Data"}, /* internal use: wrapped C pointers */
363
381
  /* {MRB_TT_VARMAP, "Varmap"}, */ /* internal use: dynamic variables */
364
382
  /* {MRB_TT_NODE, "Node"}, */ /* internal use: syntax tree node */
@@ -7,24 +7,48 @@
7
7
  #include <mruby.h>
8
8
  #include <mruby/string.h>
9
9
  #include <mruby/variable.h>
10
+ #include <mruby/error.h>
11
+ #include <string.h>
10
12
 
11
13
  #ifndef MRB_DISABLE_STDIO
14
+ static void
15
+ printcstr(const char *str, size_t len, FILE *stream)
16
+ {
17
+ if (str) {
18
+ fwrite(str, len, 1, stream);
19
+ putc('\n', stream);
20
+ }
21
+ }
22
+
12
23
  static void
13
24
  printstr(mrb_value obj, FILE *stream)
14
25
  {
15
26
  if (mrb_string_p(obj)) {
16
- fwrite(RSTRING_PTR(obj), RSTRING_LEN(obj), 1, stream);
17
- putc('\n', stream);
27
+ printcstr(RSTRING_PTR(obj), RSTRING_LEN(obj), stream);
18
28
  }
19
29
  }
20
30
  #else
31
+ # define printcstr(str, len, stream) (void)0
21
32
  # define printstr(obj, stream) (void)0
22
33
  #endif
23
34
 
35
+ void
36
+ mrb_core_init_printabort(void)
37
+ {
38
+ static const char *str = "Failed mruby core initialization";
39
+ printcstr(str, strlen(str), stdout);
40
+ }
41
+
24
42
  MRB_API void
25
43
  mrb_p(mrb_state *mrb, mrb_value obj)
26
44
  {
27
- printstr(mrb_inspect(mrb, obj), stdout);
45
+ if (mrb_type(obj) == MRB_TT_EXCEPTION && mrb_obj_ptr(obj) == mrb->nomem_err) {
46
+ static const char *str = "Out of memory";
47
+ printcstr(str, strlen(str), stdout);
48
+ }
49
+ else {
50
+ printstr(mrb_inspect(mrb, obj), stdout);
51
+ }
28
52
  }
29
53
 
30
54
  MRB_API void
@@ -8,6 +8,7 @@
8
8
  #include <mruby/class.h>
9
9
  #include <mruby/proc.h>
10
10
  #include <mruby/opcode.h>
11
+ #include <mruby/data.h>
11
12
 
12
13
  static const mrb_code call_iseq[] = {
13
14
  OP_CALL,
@@ -46,7 +47,7 @@ env_new(mrb_state *mrb, mrb_int nlocals)
46
47
  int bidx;
47
48
 
48
49
  e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, NULL);
49
- MRB_ENV_SET_STACK_LEN(e, nlocals);
50
+ MRB_ENV_SET_LEN(e, nlocals);
50
51
  bidx = ci->argc;
51
52
  if (ci->argc < 0) bidx = 2;
52
53
  else bidx += 1;
@@ -121,8 +122,15 @@ mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const
121
122
  p->e.env = e = env_new(mrb, argc);
122
123
  p->flags |= MRB_PROC_ENVSET;
123
124
  mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)e);
124
- MRB_ENV_UNSHARE_STACK(e);
125
+ MRB_ENV_CLOSE(e);
126
+
127
+ /* NOTE: Prevents keeping invalid addresses when NoMemoryError is raised from `mrb_malloc()`. */
128
+ e->stack = NULL;
129
+ MRB_ENV_SET_LEN(e, 0);
130
+
125
131
  e->stack = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value) * argc);
132
+ MRB_ENV_SET_LEN(e, argc);
133
+
126
134
  if (argv) {
127
135
  for (i = 0; i < argc; ++i) {
128
136
  e->stack[i] = argv[i];
@@ -155,9 +163,9 @@ mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx)
155
163
  if (!e) {
156
164
  mrb_raise(mrb, E_TYPE_ERROR, "Can't get cfunc env from cfunc Proc without REnv.");
157
165
  }
158
- if (idx < 0 || MRB_ENV_STACK_LEN(e) <= idx) {
166
+ if (idx < 0 || MRB_ENV_LEN(e) <= idx) {
159
167
  mrb_raisef(mrb, E_INDEX_ERROR, "Env index out of range: %i (expected: 0 <= index < %i)",
160
- idx, MRB_ENV_STACK_LEN(e));
168
+ idx, MRB_ENV_LEN(e));
161
169
  }
162
170
 
163
171
  return e->stack[idx];
@@ -203,9 +211,8 @@ mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class)
203
211
  static mrb_value
204
212
  mrb_proc_init_copy(mrb_state *mrb, mrb_value self)
205
213
  {
206
- mrb_value proc;
214
+ mrb_value proc = mrb_get_arg1(mrb);
207
215
 
208
- mrb_get_args(mrb, "o", &proc);
209
216
  if (!mrb_proc_p(proc)) {
210
217
  mrb_raise(mrb, E_ARGUMENT_ERROR, "not a proc");
211
218
  }
@@ -286,14 +293,25 @@ mrb_proc_arity(const struct RProc *p)
286
293
  return arity;
287
294
  }
288
295
 
296
+ static void
297
+ tempirep_free(mrb_state *mrb, void *p)
298
+ {
299
+ if (p) mrb_irep_free(mrb, (mrb_irep *)p);
300
+ }
301
+
302
+ static const mrb_data_type tempirep_type = { "temporary irep", tempirep_free };
303
+
289
304
  void
290
305
  mrb_init_proc(mrb_state *mrb)
291
306
  {
292
307
  struct RProc *p;
293
308
  mrb_method_t m;
294
- mrb_irep *call_irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep));
309
+ struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
310
+ mrb_irep *call_irep;
295
311
  static const mrb_irep mrb_irep_zero = { 0 };
296
312
 
313
+ call_irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep));
314
+ irep_obj->data = call_irep;
297
315
  *call_irep = mrb_irep_zero;
298
316
  call_irep->flags = MRB_ISEQ_NO_FREE;
299
317
  call_irep->iseq = call_iseq;
@@ -305,6 +323,7 @@ mrb_init_proc(mrb_state *mrb)
305
323
  mrb_define_method(mrb, mrb->proc_class, "arity", proc_arity, MRB_ARGS_NONE());
306
324
 
307
325
  p = mrb_proc_new(mrb, call_irep);
326
+ irep_obj->data = NULL;
308
327
  MRB_METHOD_FROM_PROC(m, p);
309
328
  mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "call"), m);
310
329
  mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern_lit(mrb, "[]"), m);
@@ -182,11 +182,9 @@ range_eq(mrb_state *mrb, mrb_value range)
182
182
  {
183
183
  struct RRange *rr;
184
184
  struct RRange *ro;
185
- mrb_value obj;
185
+ mrb_value obj = mrb_get_arg1(mrb);
186
186
  mrb_bool v1, v2;
187
187
 
188
- mrb_get_args(mrb, "o", &obj);
189
-
190
188
  if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();
191
189
  if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) { /* same class? */
192
190
  return mrb_false_value();
@@ -211,13 +209,11 @@ range_eq(mrb_state *mrb, mrb_value range)
211
209
  static mrb_value
212
210
  range_include(mrb_state *mrb, mrb_value range)
213
211
  {
214
- mrb_value val;
212
+ mrb_value val = mrb_get_arg1(mrb);
215
213
  struct RRange *r = mrb_range_ptr(mrb, range);
216
214
  mrb_value beg, end;
217
215
  mrb_bool include_p;
218
216
 
219
- mrb_get_args(mrb, "o", &val);
220
-
221
217
  beg = RANGE_BEG(r);
222
218
  end = RANGE_END(r);
223
219
  include_p = r_le(mrb, beg, val) && /* beg <= val */
@@ -289,11 +285,9 @@ range_inspect(mrb_state *mrb, mrb_value range)
289
285
  static mrb_value
290
286
  range_eql(mrb_state *mrb, mrb_value range)
291
287
  {
292
- mrb_value obj;
288
+ mrb_value obj = mrb_get_arg1(mrb);
293
289
  struct RRange *r, *o;
294
290
 
295
- mrb_get_args(mrb, "o", &obj);
296
-
297
291
  if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();
298
292
  if (!mrb_obj_is_kind_of(mrb, obj, mrb->range_class)) return mrb_false_value();
299
293
  if (!mrb_range_p(obj)) return mrb_false_value();
@@ -312,11 +306,9 @@ range_eql(mrb_state *mrb, mrb_value range)
312
306
  static mrb_value
313
307
  range_initialize_copy(mrb_state *mrb, mrb_value copy)
314
308
  {
315
- mrb_value src;
309
+ mrb_value src = mrb_get_arg1(mrb);
316
310
  struct RRange *r;
317
311
 
318
- mrb_get_args(mrb, "o", &src);
319
-
320
312
  if (mrb_obj_equal(mrb, copy, src)) return copy;
321
313
  if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
322
314
  mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
@@ -19,11 +19,25 @@ void mrb_init_mrbgems(mrb_state*);
19
19
  void mrb_gc_init(mrb_state*, mrb_gc *gc);
20
20
  void mrb_gc_destroy(mrb_state*, mrb_gc *gc);
21
21
 
22
+ int mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state *, void *), void *opaque);
23
+
24
+ static void
25
+ init_gc_and_core(mrb_state *mrb, void *opaque)
26
+ {
27
+ static const struct mrb_context mrb_context_zero = { 0 };
28
+
29
+ mrb_gc_init(mrb, &mrb->gc);
30
+ mrb->c = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context));
31
+ *mrb->c = mrb_context_zero;
32
+ mrb->root_c = mrb->c;
33
+
34
+ mrb_init_core(mrb);
35
+ }
36
+
22
37
  MRB_API mrb_state*
23
38
  mrb_open_core(mrb_allocf f, void *ud)
24
39
  {
25
40
  static const mrb_state mrb_state_zero = { 0 };
26
- static const struct mrb_context mrb_context_zero = { 0 };
27
41
  mrb_state *mrb;
28
42
 
29
43
  if (f == NULL) f = mrb_default_allocf;
@@ -35,12 +49,10 @@ mrb_open_core(mrb_allocf f, void *ud)
35
49
  mrb->allocf = f;
36
50
  mrb->atexit_stack_len = 0;
37
51
 
38
- mrb_gc_init(mrb, &mrb->gc);
39
- mrb->c = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context));
40
- *mrb->c = mrb_context_zero;
41
- mrb->root_c = mrb->c;
42
-
43
- mrb_init_core(mrb);
52
+ if (mrb_core_init_protect(mrb, init_gc_and_core, NULL)) {
53
+ mrb_close(mrb);
54
+ return NULL;
55
+ }
44
56
 
45
57
  return mrb;
46
58
  }
@@ -65,6 +77,12 @@ mrb_open(void)
65
77
  return mrb;
66
78
  }
67
79
 
80
+ static void
81
+ init_mrbgems(mrb_state *mrb, void *opaque)
82
+ {
83
+ mrb_init_mrbgems(mrb);
84
+ }
85
+
68
86
  MRB_API mrb_state*
69
87
  mrb_open_allocf(mrb_allocf f, void *ud)
70
88
  {
@@ -75,7 +93,10 @@ mrb_open_allocf(mrb_allocf f, void *ud)
75
93
  }
76
94
 
77
95
  #ifndef DISABLE_GEMS
78
- mrb_init_mrbgems(mrb);
96
+ if (mrb_core_init_protect(mrb, init_mrbgems, NULL)) {
97
+ mrb_close(mrb);
98
+ return NULL;
99
+ }
79
100
  mrb_gc_arena_restore(mrb, 0);
80
101
  #endif
81
102
  return mrb;
@@ -131,9 +152,11 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
131
152
  }
132
153
  mrb_free(mrb, irep->pool);
133
154
  mrb_free(mrb, irep->syms);
134
- for (i=0; i<irep->rlen; i++) {
135
- if (irep->reps[i])
136
- mrb_irep_decref(mrb, irep->reps[i]);
155
+ if (irep->reps) {
156
+ for (i=0; i<irep->rlen; i++) {
157
+ if (irep->reps[i])
158
+ mrb_irep_decref(mrb, irep->reps[i]);
159
+ }
137
160
  }
138
161
  mrb_free(mrb, irep->reps);
139
162
  mrb_free(mrb, irep->lv);
@@ -10,6 +10,7 @@
10
10
 
11
11
  #ifndef MRB_WITHOUT_FLOAT
12
12
  #include <float.h>
13
+ #include <math.h>
13
14
  #endif
14
15
  #include <limits.h>
15
16
  #include <stddef.h>
@@ -300,8 +301,8 @@ static const char utf8len_codepage[256] =
300
301
  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1,
301
302
  };
302
303
 
303
- static mrb_int
304
- utf8len(const char* p, const char* e)
304
+ mrb_int
305
+ mrb_utf8len(const char* p, const char* e)
305
306
  {
306
307
  mrb_int len;
307
308
  mrb_int i;
@@ -317,14 +318,14 @@ utf8len(const char* p, const char* e)
317
318
  }
318
319
 
319
320
  mrb_int
320
- mrb_utf8_len(const char *str, mrb_int byte_len)
321
+ mrb_utf8_strlen(const char *str, mrb_int byte_len)
321
322
  {
322
323
  mrb_int total = 0;
323
324
  const char *p = str;
324
325
  const char *e = p + byte_len;
325
326
 
326
327
  while (p < e) {
327
- p += utf8len(p, e);
328
+ p += mrb_utf8len(p, e);
328
329
  total++;
329
330
  }
330
331
  return total;
@@ -340,7 +341,7 @@ utf8_strlen(mrb_value str)
340
341
  return byte_len;
341
342
  }
342
343
  else {
343
- mrb_int utf8_len = mrb_utf8_len(RSTR_PTR(s), byte_len);
344
+ mrb_int utf8_len = mrb_utf8_strlen(RSTR_PTR(s), byte_len);
344
345
  if (byte_len == utf8_len) RSTR_SET_ASCII_FLAG(s);
345
346
  return utf8_len;
346
347
  }
@@ -361,7 +362,7 @@ chars2bytes(mrb_value s, mrb_int off, mrb_int idx)
361
362
  const char *e = RSTRING_END(s);
362
363
 
363
364
  for (b=i=0; p<e && i<idx; i++) {
364
- n = utf8len(p, e);
365
+ n = mrb_utf8len(p, e);
365
366
  b += n;
366
367
  p += n;
367
368
  }
@@ -378,7 +379,7 @@ bytes2chars(char *p, mrb_int len, mrb_int bi)
378
379
  mrb_int i;
379
380
 
380
381
  for (i = 0; p < pivot; i ++) {
381
- p += utf8len(p, e);
382
+ p += mrb_utf8len(p, e);
382
383
  }
383
384
  if (p != pivot) return -1;
384
385
  return i;
@@ -399,7 +400,7 @@ char_adjust(const char *beg, const char *end, const char *ptr)
399
400
  while (p > beg) {
400
401
  p --;
401
402
  if ((*p & 0xc0) != 0x80) {
402
- int clen = utf8len(p, end);
403
+ int clen = mrb_utf8len(p, end);
403
404
  if (clen > ptr - p) return p;
404
405
  break;
405
406
  }
@@ -462,10 +463,10 @@ str_index_str_by_char_search(mrb_state *mrb, const char *p, const char *pend, co
462
463
  }
463
464
 
464
465
  pivot = p + qstable[(unsigned char)p[slen - 1]];
465
- if (pivot > pend || pivot < p /* overflowed */) { return -1; }
466
+ if (pivot >= pend || pivot < p /* overflowed */) { return -1; }
466
467
 
467
468
  do {
468
- p += utf8len(p, pend);
469
+ p += mrb_utf8len(p, pend);
469
470
  off ++;
470
471
  } while (p < pivot);
471
472
  }
@@ -484,7 +485,7 @@ str_index_str_by_char(mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int pos)
484
485
 
485
486
  for (; pos > 0; pos --) {
486
487
  if (pend - p < 1) { return -1; }
487
- p += utf8len(p, pend);
488
+ p += mrb_utf8len(p, pend);
488
489
  }
489
490
 
490
491
  if (slen < 1) { return off; }
@@ -503,25 +504,45 @@ str_index_str_by_char(mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int pos)
503
504
  #define str_index_str_by_char(mrb, str, sub, pos) str_index_str(mrb, str, sub, pos)
504
505
  #endif
505
506
 
507
+ #ifndef MRB_QS_SHORT_STRING_LENGTH
508
+ #define MRB_QS_SHORT_STRING_LENGTH 2048
509
+ #endif
510
+
506
511
  static inline mrb_int
507
512
  mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mrb_int n)
508
513
  {
509
- const unsigned char *x = xs, *xe = xs + m;
510
- const unsigned char *y = ys;
511
- int i;
512
- ptrdiff_t qstable[256];
514
+ if (n + m < MRB_QS_SHORT_STRING_LENGTH) {
515
+ const unsigned char *y = ys;
516
+ const unsigned char *ye = ys+n-m+1;
513
517
 
514
- /* Preprocessing */
515
- for (i = 0; i < 256; ++i)
516
- qstable[i] = m + 1;
517
- for (; x < xe; ++x)
518
- qstable[*x] = xe - x;
519
- /* Searching */
520
- for (; y + m <= ys + n; y += *(qstable + y[m])) {
521
- if (*xs == *y && memcmp(xs, y, m) == 0)
522
- return (mrb_int)(y - ys);
518
+ for (;;) {
519
+ y = (const unsigned char*)memchr(y, xs[0], (size_t)(ye-y));
520
+ if (y == NULL) return -1;
521
+ if (memcmp(xs, y, m) == 0) {
522
+ return (mrb_int)(y - ys);
523
+ }
524
+ y++;
525
+ }
526
+ return -1;
527
+ }
528
+ else {
529
+ const unsigned char *x = xs, *xe = xs + m;
530
+ const unsigned char *y = ys;
531
+ int i;
532
+ ptrdiff_t qstable[256];
533
+
534
+ /* Preprocessing */
535
+ for (i = 0; i < 256; ++i)
536
+ qstable[i] = m + 1;
537
+ for (; x < xe; ++x)
538
+ qstable[*x] = xe - x;
539
+ /* Searching */
540
+ for (; y + m <= ys + n; y += *(qstable + y[m])) {
541
+ if (*xs == *y && memcmp(xs, y, m) == 0)
542
+ return (mrb_int)(y - ys);
543
+ }
544
+ return -1;
523
545
  }
524
- return -1;
525
546
  }
526
547
 
527
548
  static mrb_int
@@ -1040,10 +1061,9 @@ mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2)
1040
1061
  static mrb_value
1041
1062
  mrb_str_cmp_m(mrb_state *mrb, mrb_value str1)
1042
1063
  {
1043
- mrb_value str2;
1064
+ mrb_value str2 = mrb_get_arg1(mrb);
1044
1065
  mrb_int result;
1045
1066
 
1046
- mrb_get_args(mrb, "o", &str2);
1047
1067
  if (!mrb_string_p(str2)) {
1048
1068
  return mrb_nil_value();
1049
1069
  }
@@ -1085,9 +1105,7 @@ mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2)
1085
1105
  static mrb_value
1086
1106
  mrb_str_equal_m(mrb_state *mrb, mrb_value str1)
1087
1107
  {
1088
- mrb_value str2;
1089
-
1090
- mrb_get_args(mrb, "o", &str2);
1108
+ mrb_value str2 = mrb_get_arg1(mrb);
1091
1109
 
1092
1110
  return mrb_bool_value(mrb_str_equal(mrb, str1, str2));
1093
1111
  }
@@ -1341,7 +1359,7 @@ str_escape(mrb_state *mrb, mrb_value str, mrb_bool inspect)
1341
1359
  unsigned char c, cc;
1342
1360
  #ifdef MRB_UTF8_STRING
1343
1361
  if (inspect) {
1344
- mrb_int clen = utf8len(p, pend);
1362
+ mrb_int clen = mrb_utf8len(p, pend);
1345
1363
  if (clen > 1) {
1346
1364
  mrb_int i;
1347
1365
 
@@ -1644,7 +1662,7 @@ mrb_str_chop_bang(mrb_state *mrb, mrb_value str)
1644
1662
  const char* t = RSTR_PTR(s), *p = t;
1645
1663
  const char* e = p + RSTR_LEN(s);
1646
1664
  while (p<e) {
1647
- mrb_int clen = utf8len(p, e);
1665
+ mrb_int clen = mrb_utf8len(p, e);
1648
1666
  if (p + clen>=e) break;
1649
1667
  p += clen;
1650
1668
  }
@@ -1770,10 +1788,9 @@ mrb_str_empty_p(mrb_state *mrb, mrb_value self)
1770
1788
  static mrb_value
1771
1789
  mrb_str_eql(mrb_state *mrb, mrb_value self)
1772
1790
  {
1773
- mrb_value str2;
1791
+ mrb_value str2 = mrb_get_arg1(mrb);
1774
1792
  mrb_bool eql_p;
1775
1793
 
1776
- mrb_get_args(mrb, "o", &str2);
1777
1794
  eql_p = (mrb_string_p(str2)) && str_eql(mrb, self, str2);
1778
1795
 
1779
1796
  return mrb_bool_value(eql_p);
@@ -2016,7 +2033,7 @@ mrb_str_reverse_bang(mrb_state *mrb, mrb_value str)
2016
2033
  p = RSTR_PTR(s);
2017
2034
  e = p + RSTR_LEN(s);
2018
2035
  while (p<e) {
2019
- mrb_int clen = utf8len(p, e);
2036
+ mrb_int clen = mrb_utf8len(p, e);
2020
2037
  str_reverse(p, p + clen - 1);
2021
2038
  p += clen;
2022
2039
  }
@@ -2491,16 +2508,18 @@ mrb_str_to_i(mrb_state *mrb, mrb_value self)
2491
2508
  double
2492
2509
  mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck)
2493
2510
  {
2494
- char buf[DBL_DIG * 4 + 10];
2495
- const char *p = s;
2511
+ char buf[DBL_DIG * 4 + 20];
2512
+ const char *p = s, *p2;
2496
2513
  const char *pend = p + len;
2497
2514
  char *end;
2498
2515
  char *n;
2499
2516
  char prev = 0;
2500
2517
  double d;
2518
+ mrb_bool dot = FALSE;
2501
2519
 
2502
2520
  if (!p) return 0.0;
2503
- while (ISSPACE(*p)) p++;
2521
+ while (p<pend && ISSPACE(*p)) p++;
2522
+ p2 = p;
2504
2523
 
2505
2524
  if (pend - p > 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
2506
2525
  mrb_value x;
@@ -2515,21 +2534,27 @@ mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck)
2515
2534
  }
2516
2535
  while (p < pend) {
2517
2536
  if (!*p) {
2518
- if (badcheck && p < pend) {
2537
+ if (badcheck) {
2519
2538
  mrb_raise(mrb, E_ARGUMENT_ERROR, "string for Float contains null byte");
2520
2539
  /* not reached */
2521
2540
  }
2522
2541
  pend = p;
2523
- p = s;
2542
+ p = p2;
2543
+ goto nocopy;
2544
+ }
2545
+ if (!badcheck && *p == ' ') {
2546
+ pend = p;
2547
+ p = p2;
2524
2548
  goto nocopy;
2525
2549
  }
2526
2550
  if (*p == '_') break;
2527
2551
  p++;
2528
2552
  }
2529
- p = s;
2553
+ p = p2;
2530
2554
  n = buf;
2531
2555
  while (p < pend) {
2532
2556
  char c = *p++;
2557
+ if (c == '.') dot = TRUE;
2533
2558
  if (c == '_') {
2534
2559
  /* remove an underscore between digits */
2535
2560
  if (n == buf || !ISDIGIT(prev) || p == pend) {
@@ -2539,6 +2564,11 @@ mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck)
2539
2564
  }
2540
2565
  else if (badcheck && prev == '_' && !ISDIGIT(c)) goto bad;
2541
2566
  else {
2567
+ const char *bend = buf+sizeof(buf)-1;
2568
+ if (n==bend) { /* buffer overflow */
2569
+ if (dot) break; /* cut off remaining fractions */
2570
+ return INFINITY;
2571
+ }
2542
2572
  *n++ = c;
2543
2573
  }
2544
2574
  prev = c;
@@ -2725,7 +2755,7 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
2725
2755
  MRB_API mrb_value
2726
2756
  mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr)
2727
2757
  {
2728
- return mrb_str_cat(mrb, str, ptr, strlen(ptr));
2758
+ return mrb_str_cat(mrb, str, ptr, ptr ? strlen(ptr) : 0);
2729
2759
  }
2730
2760
 
2731
2761
  MRB_API mrb_value
@@ -2855,25 +2885,32 @@ mrb_str_setbyte(mrb_state *mrb, mrb_value str)
2855
2885
  static mrb_value
2856
2886
  mrb_str_byteslice(mrb_state *mrb, mrb_value str)
2857
2887
  {
2858
- mrb_value a1, a2;
2888
+ mrb_value a1;
2859
2889
  mrb_int str_len = RSTRING_LEN(str), beg, len;
2860
2890
  mrb_bool empty = TRUE;
2861
2891
 
2862
- if (mrb_get_args(mrb, "o|o", &a1, &a2) == 2) {
2863
- beg = mrb_fixnum(mrb_to_int(mrb, a1));
2864
- len = mrb_fixnum(mrb_to_int(mrb, a2));
2865
- }
2866
- else if (mrb_range_p(a1)) {
2867
- if (mrb_range_beg_len(mrb, a1, &beg, &len, str_len, TRUE) != MRB_RANGE_OK) {
2868
- return mrb_nil_value();
2892
+ len = mrb_get_argc(mrb);
2893
+ switch (len) {
2894
+ case 2:
2895
+ mrb_get_args(mrb, "ii", &beg, &len);
2896
+ break;
2897
+ case 1:
2898
+ a1 = mrb_get_arg1(mrb);
2899
+ if (mrb_range_p(a1)) {
2900
+ if (mrb_range_beg_len(mrb, a1, &beg, &len, str_len, TRUE) != MRB_RANGE_OK) {
2901
+ return mrb_nil_value();
2902
+ }
2869
2903
  }
2904
+ else {
2905
+ beg = mrb_fixnum(mrb_to_int(mrb, a1));
2906
+ len = 1;
2907
+ empty = FALSE;
2908
+ }
2909
+ break;
2910
+ default:
2911
+ mrb_argnum_error(mrb, len, 1, 2);
2912
+ break;
2870
2913
  }
2871
- else {
2872
- beg = mrb_fixnum(mrb_to_int(mrb, a1));
2873
- len = 1;
2874
- empty = FALSE;
2875
- }
2876
-
2877
2914
  if (mrb_str_beg_len(str_len, &beg, &len) && (empty || len != 0)) {
2878
2915
  return mrb_str_byte_subseq(mrb, str, beg, len);
2879
2916
  }