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
@@ -130,6 +130,10 @@ codedump(mrb_state *mrb, mrb_irep *irep)
130
130
  printf("OP_LOADI\tR%d\t-%d\t", a, b);
131
131
  print_lv_a(mrb, irep, a);
132
132
  break;
133
+ CASE(OP_LOADI16, BS):
134
+ printf("OP_LOADI16\tR%d\t%d\t", a, (int)(int16_t)b);
135
+ print_lv_a(mrb, irep, a);
136
+ break;
133
137
  CASE(OP_LOADI__1, B):
134
138
  printf("OP_LOADI__1\tR%d\t\t", a);
135
139
  print_lv_a(mrb, irep, a);
@@ -204,11 +204,14 @@ mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d)
204
204
 
205
205
  if (!d) { return; }
206
206
 
207
- for (i = 0; i < d->flen; ++i) {
208
- mrb_assert(d->files[i]);
209
- mrb_free(mrb, d->files[i]->lines.ptr);
210
- mrb_free(mrb, d->files[i]);
207
+ if (d->files) {
208
+ for (i = 0; i < d->flen; ++i) {
209
+ if (d->files[i]) {
210
+ mrb_free(mrb, d->files[i]->lines.ptr);
211
+ mrb_free(mrb, d->files[i]);
212
+ }
213
+ }
214
+ mrb_free(mrb, d->files);
211
215
  }
212
- mrb_free(mrb, d->files);
213
216
  mrb_free(mrb, d);
214
217
  }
@@ -13,9 +13,6 @@
13
13
  #include <mruby/numeric.h>
14
14
  #include <mruby/debug.h>
15
15
 
16
- #define FLAG_BYTEORDER_NATIVE 2
17
- #define FLAG_BYTEORDER_NONATIVE 0
18
-
19
16
  #ifndef MRB_WITHOUT_FLOAT
20
17
  #ifdef MRB_USE_FLOAT
21
18
  #define MRB_FLOAT_FMT "%.9g"
@@ -709,22 +706,7 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t *bin, uint8
709
706
  uint16_t crc;
710
707
  uint32_t offset;
711
708
 
712
- switch (flags & DUMP_ENDIAN_NAT) {
713
- endian_big:
714
- case DUMP_ENDIAN_BIG:
715
- memcpy(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident));
716
- break;
717
- endian_little:
718
- case DUMP_ENDIAN_LIL:
719
- memcpy(header->binary_ident, RITE_BINARY_IDENT_LIL, sizeof(header->binary_ident));
720
- break;
721
-
722
- case DUMP_ENDIAN_NAT:
723
- if (bigendian_p()) goto endian_big;
724
- goto endian_little;
725
- break;
726
- }
727
-
709
+ memcpy(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident));
728
710
  memcpy(header->binary_version, RITE_BINARY_FORMAT_VER, sizeof(header->binary_version));
729
711
  memcpy(header->compiler_name, RITE_COMPILER_NAME, sizeof(header->compiler_name));
730
712
  memcpy(header->compiler_version, RITE_COMPILER_VERSION, sizeof(header->compiler_version));
@@ -764,21 +746,6 @@ lv_defined_p(mrb_irep *irep)
764
746
  return FALSE;
765
747
  }
766
748
 
767
- static uint8_t
768
- dump_flags(uint8_t flags, uint8_t native)
769
- {
770
- if (native == FLAG_BYTEORDER_NATIVE) {
771
- if ((flags & DUMP_ENDIAN_NAT) == 0) {
772
- return (flags & DUMP_DEBUG_INFO) | DUMP_ENDIAN_NAT;
773
- }
774
- return flags;
775
- }
776
- if ((flags & DUMP_ENDIAN_NAT) == 0) {
777
- return (flags & DUMP_DEBUG_INFO) | DUMP_ENDIAN_BIG;
778
- }
779
- return flags;
780
- }
781
-
782
749
  static int
783
750
  dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size)
784
751
  {
@@ -870,7 +837,7 @@ error_exit:
870
837
  int
871
838
  mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size)
872
839
  {
873
- return dump_irep(mrb, irep, dump_flags(flags, FLAG_BYTEORDER_NONATIVE), bin, bin_size);
840
+ return dump_irep(mrb, irep, flags, bin, bin_size);
874
841
  }
875
842
 
876
843
  #ifndef MRB_DISABLE_STDIO
@@ -886,7 +853,7 @@ mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE* fp)
886
853
  return MRB_DUMP_INVALID_ARGUMENT;
887
854
  }
888
855
 
889
- result = dump_irep(mrb, irep, dump_flags(flags, FLAG_BYTEORDER_NONATIVE), &bin, &bin_size);
856
+ result = dump_irep(mrb, irep, flags, &bin, &bin_size);
890
857
  if (result == MRB_DUMP_OK) {
891
858
  if (fwrite(bin, sizeof(bin[0]), bin_size, fp) != bin_size) {
892
859
  result = MRB_DUMP_WRITE_FAULT;
@@ -897,20 +864,6 @@ mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE* fp)
897
864
  return result;
898
865
  }
899
866
 
900
- static mrb_bool
901
- dump_bigendian_p(uint8_t flags)
902
- {
903
- switch (flags & DUMP_ENDIAN_NAT) {
904
- case DUMP_ENDIAN_BIG:
905
- return TRUE;
906
- case DUMP_ENDIAN_LIL:
907
- return FALSE;
908
- default:
909
- case DUMP_ENDIAN_NAT:
910
- return bigendian_p();
911
- }
912
- }
913
-
914
867
  int
915
868
  mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, const char *initname)
916
869
  {
@@ -921,23 +874,8 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, con
921
874
  if (fp == NULL || initname == NULL || initname[0] == '\0') {
922
875
  return MRB_DUMP_INVALID_ARGUMENT;
923
876
  }
924
- flags = dump_flags(flags, FLAG_BYTEORDER_NATIVE);
925
877
  result = dump_irep(mrb, irep, flags, &bin, &bin_size);
926
878
  if (result == MRB_DUMP_OK) {
927
- if (!dump_bigendian_p(flags)) {
928
- if (fprintf(fp, "/* dumped in little endian order.\n"
929
- " use `mrbc -E` option for big endian CPU. */\n") < 0) {
930
- mrb_free(mrb, bin);
931
- return MRB_DUMP_WRITE_FAULT;
932
- }
933
- }
934
- else {
935
- if (fprintf(fp, "/* dumped in big endian order.\n"
936
- " use `mrbc -e` option for better performance on little endian CPU. */\n") < 0) {
937
- mrb_free(mrb, bin);
938
- return MRB_DUMP_WRITE_FAULT;
939
- }
940
- }
941
879
  if (fprintf(fp, "#include <stdint.h>\n") < 0) { /* for uint8_t under at least Darwin */
942
880
  mrb_free(mrb, bin);
943
881
  return MRB_DUMP_WRITE_FAULT;
@@ -160,9 +160,8 @@ set_backtrace(mrb_state *mrb, mrb_value exc, mrb_value backtrace)
160
160
  static mrb_value
161
161
  exc_set_backtrace(mrb_state *mrb, mrb_value exc)
162
162
  {
163
- mrb_value backtrace;
163
+ mrb_value backtrace = mrb_get_arg1(mrb);
164
164
 
165
- mrb_get_args(mrb, "o", &backtrace);
166
165
  set_backtrace(mrb, exc, backtrace);
167
166
  return backtrace;
168
167
  }
@@ -185,6 +184,16 @@ mrb_exc_set(mrb_state *mrb, mrb_value exc)
185
184
  }
186
185
  }
187
186
 
187
+ static mrb_noreturn void
188
+ exc_throw(mrb_state *mrb, mrb_value exc)
189
+ {
190
+ if (!mrb->jmp) {
191
+ mrb_p(mrb, exc);
192
+ abort();
193
+ }
194
+ MRB_THROW(mrb->jmp);
195
+ }
196
+
188
197
  MRB_API mrb_noreturn void
189
198
  mrb_exc_raise(mrb_state *mrb, mrb_value exc)
190
199
  {
@@ -197,11 +206,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc)
197
206
  }
198
207
  mrb_exc_set(mrb, exc);
199
208
  }
200
- if (!mrb->jmp) {
201
- mrb_p(mrb, exc);
202
- abort();
203
- }
204
- MRB_THROW(mrb->jmp);
209
+ exc_throw(mrb, exc);
205
210
  }
206
211
 
207
212
  MRB_API mrb_noreturn void
@@ -550,6 +555,52 @@ mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max)
550
555
  #undef FMT
551
556
  }
552
557
 
558
+ void mrb_core_init_printabort(void);
559
+
560
+ int
561
+ mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state *, void *), void *opaque)
562
+ {
563
+ struct mrb_jmpbuf *prev_jmp = mrb->jmp;
564
+ struct mrb_jmpbuf c_jmp;
565
+ int err = 1;
566
+
567
+ MRB_TRY(&c_jmp) {
568
+ mrb->jmp = &c_jmp;
569
+ body(mrb, opaque);
570
+ err = 0;
571
+ } MRB_CATCH(&c_jmp) {
572
+ if (mrb->exc) {
573
+ mrb_p(mrb, mrb_obj_value(mrb->exc));
574
+ mrb->exc = NULL;
575
+ }
576
+ else {
577
+ mrb_core_init_printabort();
578
+ }
579
+ } MRB_END_EXC(&c_jmp);
580
+
581
+ mrb->jmp = prev_jmp;
582
+
583
+ return err;
584
+ }
585
+
586
+ mrb_noreturn void
587
+ mrb_core_init_abort(mrb_state *mrb)
588
+ {
589
+ mrb->exc = NULL;
590
+ exc_throw(mrb, mrb_nil_value());
591
+ }
592
+
593
+ mrb_noreturn void
594
+ mrb_raise_nomemory(mrb_state *mrb)
595
+ {
596
+ if (mrb->nomem_err) {
597
+ mrb_exc_raise(mrb, mrb_obj_value(mrb->nomem_err));
598
+ }
599
+ else {
600
+ mrb_core_init_abort(mrb);
601
+ }
602
+ }
603
+
553
604
  void
554
605
  mrb_init_exception(mrb_state *mrb)
555
606
  {
@@ -132,7 +132,6 @@ mrb_obj_id(mrb_value obj)
132
132
  case MRB_TT_HASH:
133
133
  case MRB_TT_RANGE:
134
134
  case MRB_TT_EXCEPTION:
135
- case MRB_TT_FILE:
136
135
  case MRB_TT_DATA:
137
136
  case MRB_TT_ISTRUCT:
138
137
  default:
@@ -140,7 +139,13 @@ mrb_obj_id(mrb_value obj)
140
139
  }
141
140
  }
142
141
 
142
+ #if defined(MRB_NAN_BOXING) && defined(MRB_64BIT)
143
+ #define mrb_xxx_boxing_cptr_value mrb_nan_boxing_cptr_value
144
+ #endif
145
+
143
146
  #ifdef MRB_WORD_BOXING
147
+ #define mrb_xxx_boxing_cptr_value mrb_word_boxing_cptr_value
148
+
144
149
  #ifndef MRB_WITHOUT_FLOAT
145
150
  MRB_API mrb_value
146
151
  mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f)
@@ -164,17 +169,20 @@ mrb_word_boxing_float_pool(mrb_state *mrb, mrb_float f)
164
169
  return mrb_obj_value(nf);
165
170
  }
166
171
  #endif /* MRB_WITHOUT_FLOAT */
172
+ #endif /* MRB_WORD_BOXING */
167
173
 
174
+ #if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_64BIT))
168
175
  MRB_API mrb_value
169
- mrb_word_boxing_cptr_value(mrb_state *mrb, void *p)
176
+ mrb_xxx_boxing_cptr_value(mrb_state *mrb, void *p)
170
177
  {
171
178
  mrb_value v;
179
+ struct RCptr *cptr = (struct RCptr*)mrb_obj_alloc(mrb, MRB_TT_CPTR, mrb->object_class);
172
180
 
173
- v.value.p = mrb_obj_alloc(mrb, MRB_TT_CPTR, mrb->object_class);
174
- v.value.vp->p = p;
181
+ SET_OBJ_VALUE(v, cptr);
182
+ cptr->p = p;
175
183
  return v;
176
184
  }
177
- #endif /* MRB_WORD_BOXING */
185
+ #endif
178
186
 
179
187
  #if defined _MSC_VER && _MSC_VER < 1900
180
188
 
@@ -37,9 +37,19 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
37
  #include <mruby.h>
38
38
  #include <mruby/string.h>
39
39
 
40
+ struct fmt_args;
41
+
42
+ typedef void output_func(struct fmt_args *f, const char *s, size_t l);
43
+
40
44
  struct fmt_args {
41
45
  mrb_state *mrb;
42
- mrb_value str;
46
+ output_func *output;
47
+ void *opaque;
48
+ };
49
+
50
+ struct mrb_cstr {
51
+ char *buf;
52
+ size_t len;
43
53
  };
44
54
 
45
55
  #define MAX(a,b) ((a)>(b) ? (a) : (b))
@@ -54,15 +64,44 @@ struct fmt_args {
54
64
  #define PAD_POS (1U<<(' '-' '))
55
65
  #define MARK_POS (1U<<('+'-' '))
56
66
 
67
+ #define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS)
68
+
69
+ static output_func strcat_value;
70
+ static output_func strcat_cstr;
71
+
72
+ static void
73
+ strcat_value(struct fmt_args *f, const char *s, size_t l)
74
+ {
75
+ mrb_value str = *(mrb_value*)f->opaque;
76
+ mrb_str_cat(f->mrb, str, s, l);
77
+ }
78
+
79
+ static void
80
+ strcat_cstr(struct fmt_args *f, const char *s, size_t l)
81
+ {
82
+ struct mrb_cstr *cstr = (struct mrb_cstr*)f->opaque;
83
+
84
+ if (l > cstr->len) {
85
+ mrb_state *mrb = f->mrb;
86
+
87
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "string buffer too small");
88
+ }
89
+
90
+ memcpy(cstr->buf, s, l);
91
+
92
+ cstr->buf += l;
93
+ cstr->len -= l;
94
+ }
95
+
57
96
  static void
58
97
  out(struct fmt_args *f, const char *s, size_t l)
59
98
  {
60
- mrb_str_cat(f->mrb, f->str, s, l);
99
+ f->output(f, s, l);
61
100
  }
62
101
 
63
102
  #define PAD_SIZE 256
64
103
  static void
65
- pad(struct fmt_args *f, char c, ptrdiff_t w, ptrdiff_t l, uint8_t fl)
104
+ pad(struct fmt_args *f, char c, ptrdiff_t w, ptrdiff_t l, uint32_t fl)
66
105
  {
67
106
  char pad[PAD_SIZE];
68
107
  if (fl & (LEFT_ADJ | ZERO_PAD) || l >= w) return;
@@ -92,7 +131,7 @@ typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)
92
131
  #endif
93
132
 
94
133
  static int
95
- fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
134
+ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t w, ptrdiff_t p, uint32_t fl, int t)
96
135
  {
97
136
  uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion
98
137
  + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion
@@ -117,11 +156,11 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
117
156
  if (!isfinite(y)) {
118
157
  const char *ss = (t&32)?"inf":"INF";
119
158
  if (y!=y) ss=(t&32)?"nan":"NAN";
120
- pad(f, ' ', 0, 3+pl, fl&~ZERO_PAD);
159
+ pad(f, ' ', w, 3+pl, fl&~ZERO_PAD);
121
160
  out(f, prefix, pl);
122
161
  out(f, ss, 3);
123
- pad(f, ' ', 0, 3+pl, fl^LEFT_ADJ);
124
- return 3+(int)pl;
162
+ pad(f, ' ', w, 3+pl, fl^LEFT_ADJ);
163
+ return (int)MAX(w, 3+pl);
125
164
  }
126
165
 
127
166
  y = frexp((double)y, &e2) * 2;
@@ -169,14 +208,14 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
169
208
  else
170
209
  l = (s-buf) + (ebuf-estr);
171
210
 
172
- pad(f, ' ', 0, pl+l, fl);
211
+ pad(f, ' ', w, pl+l, fl);
173
212
  out(f, prefix, pl);
174
- pad(f, '0', 0, pl+l, fl^ZERO_PAD);
213
+ pad(f, '0', w, pl+l, fl^ZERO_PAD);
175
214
  out(f, buf, s-buf);
176
215
  pad(f, '0', l-(ebuf-estr)-(s-buf), 0, 0);
177
216
  out(f, estr, ebuf-estr);
178
- pad(f, ' ', 0, pl+l, fl^LEFT_ADJ);
179
- return (int)pl+(int)l;
217
+ pad(f, ' ', w, pl+l, fl^LEFT_ADJ);
218
+ return (int)MAX(w, pl+l);
180
219
  }
181
220
  if (p<0) p=6;
182
221
 
@@ -288,9 +327,9 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
288
327
  l += ebuf-estr;
289
328
  }
290
329
 
291
- pad(f, ' ', 0, pl+l, fl);
330
+ pad(f, ' ', w, pl+l, fl);
292
331
  out(f, prefix, pl);
293
- pad(f, '0', 0, pl+l, fl^ZERO_PAD);
332
+ pad(f, '0', w, pl+l, fl^ZERO_PAD);
294
333
 
295
334
  if ((t|32)=='f') {
296
335
  if (a>r) a=r;
@@ -325,21 +364,33 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
325
364
  out(f, estr, ebuf-estr);
326
365
  }
327
366
 
328
- pad(f, ' ', 0, pl+l, fl^LEFT_ADJ);
367
+ pad(f, ' ', w, pl+l, fl^LEFT_ADJ);
329
368
 
330
- return (int)pl+(int)l;
369
+ return (int)MAX(w, pl+l);
331
370
  }
332
371
 
333
372
  static int
334
373
  fmt_core(struct fmt_args *f, const char *fmt, mrb_float flo)
335
374
  {
336
- ptrdiff_t p;
375
+ ptrdiff_t w, p;
376
+ uint32_t fl;
337
377
 
338
378
  if (*fmt != '%') {
339
379
  return -1;
340
380
  }
341
381
  ++fmt;
342
382
 
383
+ /* Read modifier flags */
384
+ for (fl=0; (unsigned)*fmt-' '<32 && (FLAGMASK&(1U<<(*fmt-' '))); fmt++)
385
+ fl |= 1U<<(*fmt-' ');
386
+
387
+ /* - and 0 flags are mutually exclusive */
388
+ if (fl & LEFT_ADJ) fl &= ~ZERO_PAD;
389
+
390
+ for (w = 0; ISDIGIT(*fmt); ++fmt) {
391
+ w = 10 * w + (*fmt - '0');
392
+ }
393
+
343
394
  if (*fmt == '.') {
344
395
  ++fmt;
345
396
  for (p = 0; ISDIGIT(*fmt); ++fmt) {
@@ -353,29 +404,49 @@ fmt_core(struct fmt_args *f, const char *fmt, mrb_float flo)
353
404
  switch (*fmt) {
354
405
  case 'e': case 'f': case 'g': case 'a':
355
406
  case 'E': case 'F': case 'G': case 'A':
356
- return fmt_fp(f, flo, p, 0, *fmt);
407
+ return fmt_fp(f, flo, w, p, fl, *fmt);
357
408
  default:
358
409
  return -1;
359
410
  }
360
411
  }
361
412
 
362
- mrb_value
413
+ MRB_API mrb_value
363
414
  mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt)
364
415
  {
365
416
  struct fmt_args f;
417
+ mrb_value str = mrb_str_new_capa(mrb, 24);
366
418
 
367
419
  f.mrb = mrb;
368
- f.str = mrb_str_new_capa(mrb, 24);
420
+ f.output = strcat_value;
421
+ f.opaque = (void*)&str;
369
422
  if (fmt_core(&f, fmt, mrb_float(flo)) < 0) {
370
423
  mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid format string");
371
424
  }
372
- return f.str;
425
+ return str;
426
+ }
427
+
428
+ MRB_API int
429
+ mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float fval)
430
+ {
431
+ struct fmt_args f;
432
+ struct mrb_cstr cstr;
433
+
434
+ cstr.buf = buf;
435
+ cstr.len = len - 1; /* reserve NUL terminator */
436
+ f.mrb = mrb;
437
+ f.output = strcat_cstr;
438
+ f.opaque = (void*)&cstr;
439
+ if (fmt_core(&f, fmt, fval) < 0) {
440
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid format string");
441
+ }
442
+ *cstr.buf = '\0';
443
+ return (int)(cstr.buf - buf);
373
444
  }
374
445
  #else /* MRB_DISABLE_STDIO || _WIN32 || _WIN64 */
375
446
  #include <mruby.h>
376
447
  #include <stdio.h>
377
448
 
378
- mrb_value
449
+ MRB_API mrb_value
379
450
  mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt)
380
451
  {
381
452
  char buf[25];
@@ -383,5 +454,11 @@ mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt)
383
454
  snprintf(buf, sizeof(buf), fmt, mrb_float(flo));
384
455
  return mrb_str_new_cstr(mrb, buf);
385
456
  }
457
+
458
+ MRB_API int
459
+ mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float fval)
460
+ {
461
+ return snprintf(buf, len, fmt, fval);
462
+ }
386
463
  #endif /* MRB_DISABLE_STDIO || _WIN32 || _WIN64 */
387
464
  #endif