script_core 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (529) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -57
  3. data/.ruby-version +1 -1
  4. data/Gemfile +2 -2
  5. data/README.md +7 -1
  6. data/ext/enterprise_script_service/Rakefile +1 -1
  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 +149 -0
  138. data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +55 -0
  139. data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
  140. data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
  141. data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
  142. data/ext/enterprise_script_service/mruby/.gitignore +3 -0
  143. data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
  144. data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
  145. data/ext/enterprise_script_service/mruby/.travis.yml +7 -10
  146. data/ext/enterprise_script_service/mruby/.yamllint +8 -0
  147. data/ext/enterprise_script_service/mruby/AUTHORS +4 -0
  148. data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
  149. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
  150. data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
  151. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  152. data/ext/enterprise_script_service/mruby/Makefile +1 -1
  153. data/ext/enterprise_script_service/mruby/README.md +5 -11
  154. data/ext/enterprise_script_service/mruby/Rakefile +18 -108
  155. data/ext/enterprise_script_service/mruby/TODO.md +17 -0
  156. data/ext/enterprise_script_service/mruby/appveyor.yml +29 -26
  157. data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
  158. data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
  159. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +4 -21
  160. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +4 -4
  161. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +3 -20
  162. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +4 -21
  163. data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
  164. data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
  165. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_android_armeabi_v7a_neon_hard.rb → build_config/android_armeabi_v7a_neon_hard.rb} +0 -15
  166. data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
  167. data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
  168. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +4 -21
  169. data/ext/enterprise_script_service/mruby/{appveyor_config.rb → build_config/ci/gcc-clang.rb} +11 -8
  170. data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
  171. data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
  172. data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
  173. data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
  174. data/ext/enterprise_script_service/mruby/build_config/dreamcast_shelf.rb +94 -0
  175. data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
  176. data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
  177. data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
  178. data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
  179. data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
  180. data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
  181. data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
  182. data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
  183. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +142 -49
  184. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
  185. data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
  186. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +53 -30
  187. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
  188. data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
  189. data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
  190. data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
  191. data/ext/enterprise_script_service/mruby/doc/opcode.md +102 -103
  192. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
  193. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
  194. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
  195. data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
  196. data/ext/enterprise_script_service/mruby/include/mrbconf.h +88 -66
  197. data/ext/enterprise_script_service/mruby/include/mruby.h +160 -104
  198. data/ext/enterprise_script_service/mruby/include/mruby/array.h +27 -6
  199. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +80 -46
  200. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
  201. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +76 -55
  202. data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
  203. data/ext/enterprise_script_service/mruby/include/mruby/common.h +14 -1
  204. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +20 -6
  205. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  206. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +18 -52
  207. data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
  208. data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
  209. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
  210. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
  211. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +74 -14
  212. data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -1
  213. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +19 -9
  214. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +37 -63
  215. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
  216. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +29 -24
  217. data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
  218. data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
  219. data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
  220. data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
  221. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +93 -21
  222. data/ext/enterprise_script_service/mruby/include/mruby/string.h +12 -16
  223. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
  224. data/ext/enterprise_script_service/mruby/include/mruby/value.h +60 -59
  225. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
  226. data/ext/enterprise_script_service/mruby/include/mruby/version.h +25 -6
  227. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -72
  228. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +71 -78
  229. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
  230. data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
  231. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +84 -32
  232. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
  233. data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
  234. data/ext/enterprise_script_service/mruby/lib/mruby/source.rb +3 -1
  235. data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
  236. data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
  237. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -81
  238. data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
  239. data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
  240. data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
  241. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -32
  242. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +10 -12
  243. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +0 -13
  244. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +30 -18
  245. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
  246. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
  247. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
  248. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
  249. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
  250. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -4
  251. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
  252. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +6 -2
  253. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
  254. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
  255. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +46 -35
  256. data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
  257. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
  258. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +41 -28
  259. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
  260. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -2
  261. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +26 -6
  262. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
  263. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +6 -2
  264. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
  265. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
  266. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +7 -1
  267. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +495 -436
  268. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
  269. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
  270. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +637 -220
  271. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +13734 -0
  272. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +20 -23
  273. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +2 -2
  274. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +9 -9
  275. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
  276. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
  277. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
  278. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
  279. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +3 -3
  280. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +19 -238
  281. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +21 -0
  282. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +19 -15
  283. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +31 -5
  284. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
  285. data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +5 -6
  286. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
  287. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +39 -7
  288. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +2 -8
  289. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
  290. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file_constants.rb +0 -16
  291. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +9 -14
  292. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +107 -59
  293. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +22 -38
  294. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +417 -203
  295. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +20 -12
  296. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +33 -2
  297. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +58 -50
  298. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +13 -14
  299. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
  300. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
  301. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +56 -73
  302. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +13 -4
  303. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
  304. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +80 -78
  305. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
  306. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
  307. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +8 -16
  308. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -13
  309. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
  310. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
  311. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
  312. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
  313. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +120 -67
  314. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
  315. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +65 -26
  316. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +34 -21
  317. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
  318. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
  319. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
  320. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
  321. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +21 -43
  322. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
  323. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +12 -20
  324. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
  325. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
  326. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
  327. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +5 -5
  328. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
  329. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/mrbgem.rake +1 -1
  330. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
  331. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/sockettest.c +3 -2
  332. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +161 -93
  333. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +9 -25
  334. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
  335. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +17 -14
  336. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
  337. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +23 -36
  338. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +7 -6
  339. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  340. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
  341. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
  342. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +17 -44
  343. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
  344. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +37 -41
  345. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
  346. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
  347. data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
  348. data/ext/enterprise_script_service/mruby/mrblib/00class.rb +10 -0
  349. data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
  350. data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
  351. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
  352. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +3 -23
  353. data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
  354. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
  355. data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
  356. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
  357. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
  358. data/ext/enterprise_script_service/mruby/src/array.c +67 -90
  359. data/ext/enterprise_script_service/mruby/src/backtrace.c +18 -19
  360. data/ext/enterprise_script_service/mruby/src/class.c +819 -211
  361. data/ext/enterprise_script_service/mruby/src/codedump.c +226 -197
  362. data/ext/enterprise_script_service/mruby/src/debug.c +14 -11
  363. data/ext/enterprise_script_service/mruby/src/dump.c +470 -207
  364. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  365. data/ext/enterprise_script_service/mruby/src/error.c +94 -20
  366. data/ext/enterprise_script_service/mruby/src/etc.c +56 -39
  367. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +103 -27
  368. data/ext/enterprise_script_service/mruby/src/gc.c +86 -349
  369. data/ext/enterprise_script_service/mruby/src/hash.c +1058 -723
  370. data/ext/enterprise_script_service/mruby/src/kernel.c +78 -226
  371. data/ext/enterprise_script_service/mruby/src/load.c +215 -159
  372. data/ext/enterprise_script_service/mruby/src/numeric.c +400 -382
  373. data/ext/enterprise_script_service/mruby/src/object.c +115 -90
  374. data/ext/enterprise_script_service/mruby/src/print.c +31 -6
  375. data/ext/enterprise_script_service/mruby/src/proc.c +56 -45
  376. data/ext/enterprise_script_service/mruby/src/range.c +49 -33
  377. data/ext/enterprise_script_service/mruby/src/state.c +58 -42
  378. data/ext/enterprise_script_service/mruby/src/string.c +151 -156
  379. data/ext/enterprise_script_service/mruby/src/symbol.c +132 -66
  380. data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
  381. data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
  382. data/ext/enterprise_script_service/mruby/src/vm.c +655 -645
  383. data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
  384. data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
  385. data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
  386. data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
  387. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +64 -61
  388. data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
  389. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
  390. data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
  391. data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
  392. data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
  393. data/ext/enterprise_script_service/mruby/tasks/toolchains/android.rake +46 -1
  394. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +8 -7
  395. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +13 -17
  396. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +21 -25
  397. data/ext/enterprise_script_service/mruby/test/assert.rb +5 -4
  398. data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
  399. data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
  400. data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
  401. data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
  402. data/ext/enterprise_script_service/mruby/test/t/ensure.rb +8 -26
  403. data/ext/enterprise_script_service/mruby/test/t/exception.rb +2 -2
  404. data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
  405. data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
  406. data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
  407. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +16 -25
  408. data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
  409. data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
  410. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
  411. data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
  412. data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
  413. data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
  414. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
  415. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
  416. data/ext/enterprise_script_service/mruby_config.rb +2 -5
  417. data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
  418. data/ext/enterprise_script_service/msgpack/.github/depends/boost.sh +56 -0
  419. data/ext/enterprise_script_service/msgpack/.github/workflows/coverage.yml +62 -0
  420. data/ext/enterprise_script_service/msgpack/.github/workflows/gha.yml +304 -0
  421. data/ext/enterprise_script_service/msgpack/CHANGELOG.md +11 -0
  422. data/ext/enterprise_script_service/msgpack/CMakeLists.txt +82 -39
  423. data/ext/enterprise_script_service/msgpack/Files.cmake +22 -12
  424. data/ext/enterprise_script_service/msgpack/QUICKSTART-C.md +26 -29
  425. data/ext/enterprise_script_service/msgpack/README.md +3 -2
  426. data/ext/enterprise_script_service/msgpack/appveyor.yml +6 -2
  427. data/ext/enterprise_script_service/msgpack/ci/build_cmake.sh +3 -1
  428. data/ext/enterprise_script_service/msgpack/cmake/CodeCoverage.cmake +55 -0
  429. data/ext/enterprise_script_service/msgpack/codecov.yml +36 -0
  430. data/ext/enterprise_script_service/msgpack/example/CMakeLists.txt +9 -5
  431. data/ext/enterprise_script_service/msgpack/example/boost/CMakeLists.txt +1 -1
  432. data/ext/enterprise_script_service/msgpack/example/c/CMakeLists.txt +17 -6
  433. data/ext/enterprise_script_service/msgpack/example/c/boundary.c +296 -0
  434. data/ext/enterprise_script_service/msgpack/example/c/jsonconv.c +419 -0
  435. data/ext/enterprise_script_service/msgpack/example/c/simple_c.c +1 -1
  436. data/ext/enterprise_script_service/msgpack/example/cpp03/CMakeLists.txt +3 -3
  437. data/ext/enterprise_script_service/msgpack/example/cpp11/CMakeLists.txt +2 -2
  438. data/ext/enterprise_script_service/msgpack/example/x3/CMakeLists.txt +2 -2
  439. data/ext/enterprise_script_service/msgpack/include/msgpack/pack.h +24 -1
  440. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +5 -4
  441. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/boost/optional.hpp +4 -4
  442. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp +8 -8
  443. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/map.hpp +4 -4
  444. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector.hpp +4 -4
  445. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_char.hpp +8 -8
  446. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_unsigned_char.hpp +8 -8
  447. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +4 -4
  448. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/unpack.hpp +6 -6
  449. data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
  450. data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +4 -4
  451. data/ext/enterprise_script_service/msgpack/make_file_list.sh +38 -11
  452. data/ext/enterprise_script_service/msgpack/src/vrefbuffer.c +6 -0
  453. data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +86 -64
  454. data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +4 -0
  455. data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +4 -0
  456. data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +4 -0
  457. data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +4 -1
  458. data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +4 -0
  459. data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +4 -0
  460. data/ext/enterprise_script_service/msgpack/test/buffer.cpp +4 -47
  461. data/ext/enterprise_script_service/msgpack/test/buffer_c.cpp +148 -0
  462. data/ext/enterprise_script_service/msgpack/test/carray.cpp +4 -0
  463. data/ext/enterprise_script_service/msgpack/test/cases.cpp +8 -4
  464. data/ext/enterprise_script_service/msgpack/test/convert.cpp +8 -4
  465. data/ext/enterprise_script_service/msgpack/test/fixint.cpp +4 -0
  466. data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +4 -0
  467. data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +4 -0
  468. data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +4 -0
  469. data/ext/enterprise_script_service/msgpack/test/json.cpp +4 -0
  470. data/ext/enterprise_script_service/msgpack/test/limit.cpp +8 -4
  471. data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +4 -0
  472. data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +159 -0
  473. data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +4 -0
  474. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +32 -27
  475. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +4 -0
  476. data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +4 -0
  477. data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +4 -1
  478. data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +4 -0
  479. data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +4 -0
  480. data/ext/enterprise_script_service/msgpack/test/object.cpp +4 -1
  481. data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +12 -8
  482. data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +30 -26
  483. data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +4 -0
  484. data/ext/enterprise_script_service/msgpack/test/raw.cpp +4 -0
  485. data/ext/enterprise_script_service/msgpack/test/reference.cpp +4 -0
  486. data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +4 -0
  487. data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +4 -0
  488. data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +4 -0
  489. data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +4 -0
  490. data/ext/enterprise_script_service/msgpack/test/streaming.cpp +8 -4
  491. data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +4 -0
  492. data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +4 -0
  493. data/ext/enterprise_script_service/msgpack/test/user_class.cpp +16 -12
  494. data/ext/enterprise_script_service/msgpack/test/version.cpp +4 -0
  495. data/ext/enterprise_script_service/msgpack/test/visitor.cpp +4 -0
  496. data/ext/enterprise_script_service/msgpack/test/zone.cpp +4 -0
  497. data/lib/script_core/engine.rb +24 -5
  498. data/lib/script_core/executable.rb +4 -3
  499. data/lib/script_core/version.rb +1 -1
  500. data/lib/tasks/script_core.rake +3 -1
  501. data/script_core.gemspec +1 -2
  502. data/spec/dummy/app/lib/script_engine.rb +64 -5
  503. data/spec/script_core_spec.rb +13 -0
  504. metadata +123 -61
  505. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +0 -559
  506. data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +0 -570
  507. data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +0 -562
  508. data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +0 -562
  509. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +0 -562
  510. data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +0 -542
  511. data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +0 -559
  512. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +0 -559
  513. data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +0 -626
  514. data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +0 -626
  515. data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +0 -558
  516. data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +0 -692
  517. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +0 -559
  518. data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_whitelist.tests +0 -32
  519. data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_blacklist.tests +0 -32
  520. data/ext/enterprise_script_service/mruby/TODO +0 -8
  521. data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
  522. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
  523. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
  524. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
  525. data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
  526. data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
  527. data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
  528. data/ext/enterprise_script_service/mruby/travis_config.rb +0 -54
  529. data/ext/enterprise_script_service/msgpack/.travis.yml +0 -258
@@ -11,6 +11,7 @@
11
11
  #include "mruby/variable.h"
12
12
  #include "mruby/ext/io.h"
13
13
  #include "mruby/error.h"
14
+ #include "mruby/presym.h"
14
15
 
15
16
  #include <sys/types.h>
16
17
  #include <sys/stat.h>
@@ -18,6 +19,7 @@
18
19
  #if defined(_WIN32) || defined(_WIN64)
19
20
  #include <winsock.h>
20
21
  #include <io.h>
22
+ #include <basetsd.h>
21
23
  #define open _open
22
24
  #define close _close
23
25
  #define dup _dup
@@ -31,14 +33,27 @@
31
33
  typedef long ftime_t;
32
34
  typedef long fsuseconds_t;
33
35
  typedef int fmode_t;
36
+ typedef int mrb_io_read_write_size;
37
+ #ifndef MRB_MINGW32_LEGACY
38
+ #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) && \
39
+ !defined(__have_typedef_ssize_t)
40
+ typedef SSIZE_T ssize_t;
41
+ #endif
42
+ #endif
43
+
44
+ #ifndef O_TMPFILE
45
+ #define O_TMPFILE O_TEMPORARY
46
+ #endif
34
47
 
35
48
  #else
36
49
  #include <sys/wait.h>
50
+ #include <sys/time.h>
37
51
  #include <unistd.h>
38
52
  typedef size_t fsize_t;
39
53
  typedef time_t ftime_t;
40
54
  typedef suseconds_t fsuseconds_t;
41
55
  typedef mode_t fmode_t;
56
+ typedef ssize_t mrb_io_read_write_size;
42
57
  #endif
43
58
 
44
59
  #ifdef _MSC_VER
@@ -48,9 +63,14 @@ typedef mrb_int pid_t;
48
63
  #include <fcntl.h>
49
64
 
50
65
  #include <errno.h>
51
- #include <stdio.h>
52
66
  #include <string.h>
53
67
 
68
+ #define OPEN_ACCESS_MODE_FLAGS (O_RDONLY | O_WRONLY | O_RDWR)
69
+ #define OPEN_RDONLY_P(f) ((mrb_bool)(((f) & OPEN_ACCESS_MODE_FLAGS) == O_RDONLY))
70
+ #define OPEN_WRONLY_P(f) ((mrb_bool)(((f) & OPEN_ACCESS_MODE_FLAGS) == O_WRONLY))
71
+ #define OPEN_RDWR_P(f) ((mrb_bool)(((f) & OPEN_ACCESS_MODE_FLAGS) == O_RDWR))
72
+ #define OPEN_READABLE_P(f) ((mrb_bool)(OPEN_RDONLY_P(f) || OPEN_RDWR_P(f)))
73
+ #define OPEN_WRITABLE_P(f) ((mrb_bool)(OPEN_WRONLY_P(f) || OPEN_RDWR_P(f)))
54
74
 
55
75
  static void mrb_io_free(mrb_state *mrb, void *ptr);
56
76
  struct mrb_data_type mrb_io_type = { "IO", mrb_io_free };
@@ -58,7 +78,7 @@ struct mrb_data_type mrb_io_type = { "IO", mrb_io_free };
58
78
 
59
79
  static struct mrb_io *io_get_open_fptr(mrb_state *mrb, mrb_value self);
60
80
  static int mrb_io_modestr_to_flags(mrb_state *mrb, const char *modestr);
61
- static int mrb_io_flags_to_modenum(mrb_state *mrb, int flags);
81
+ static int mrb_io_mode_to_flags(mrb_state *mrb, mrb_value mode);
62
82
  static void fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int quiet);
63
83
 
64
84
  static struct mrb_io *
@@ -83,47 +103,50 @@ io_set_process_status(mrb_state *mrb, pid_t pid, int status)
83
103
  mrb_value v;
84
104
 
85
105
  c_status = NULL;
86
- if (mrb_class_defined(mrb, "Process")) {
87
- c_process = mrb_module_get(mrb, "Process");
88
- if (mrb_const_defined(mrb, mrb_obj_value(c_process), mrb_intern_cstr(mrb, "Status"))) {
89
- c_status = mrb_class_get_under(mrb, c_process, "Status");
106
+ if (mrb_class_defined_id(mrb, MRB_SYM(Process))) {
107
+ c_process = mrb_module_get_id(mrb, MRB_SYM(Process));
108
+ if (mrb_const_defined(mrb, mrb_obj_value(c_process), MRB_SYM(Status))) {
109
+ c_status = mrb_class_get_under_id(mrb, c_process, MRB_SYM(Status));
90
110
  }
91
111
  }
92
112
  if (c_status != NULL) {
93
- v = mrb_funcall(mrb, mrb_obj_value(c_status), "new", 2, mrb_fixnum_value(pid), mrb_fixnum_value(status));
113
+ v = mrb_funcall_id(mrb, mrb_obj_value(c_status), MRB_SYM(new), 2, mrb_fixnum_value(pid), mrb_fixnum_value(status));
94
114
  } else {
95
115
  v = mrb_fixnum_value(WEXITSTATUS(status));
96
116
  }
97
- mrb_gv_set(mrb, mrb_intern_cstr(mrb, "$?"), v);
117
+ mrb_gv_set(mrb, mrb_intern_lit(mrb, "$?"), v);
98
118
  }
99
119
 
100
120
  static int
101
121
  mrb_io_modestr_to_flags(mrb_state *mrb, const char *mode)
102
122
  {
103
- int flags = 0;
123
+ int flags;
104
124
  const char *m = mode;
105
125
 
106
126
  switch (*m++) {
107
127
  case 'r':
108
- flags |= FMODE_READABLE;
128
+ flags = O_RDONLY;
109
129
  break;
110
130
  case 'w':
111
- flags |= FMODE_WRITABLE | FMODE_CREATE | FMODE_TRUNC;
131
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
112
132
  break;
113
133
  case 'a':
114
- flags |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE;
134
+ flags = O_WRONLY | O_CREAT | O_APPEND;
115
135
  break;
116
136
  default:
117
137
  mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode);
138
+ flags = 0; /* not reached */
118
139
  }
119
140
 
120
141
  while (*m) {
121
142
  switch (*m++) {
122
143
  case 'b':
123
- flags |= FMODE_BINMODE;
144
+ #ifdef O_BINARY
145
+ flags |= O_BINARY;
146
+ #endif
124
147
  break;
125
148
  case '+':
126
- flags |= FMODE_READWRITE;
149
+ flags = (flags & ~OPEN_ACCESS_MODE_FLAGS) | O_RDWR;
127
150
  break;
128
151
  case ':':
129
152
  /* XXX: PASSTHROUGH*/
@@ -136,38 +159,72 @@ mrb_io_modestr_to_flags(mrb_state *mrb, const char *mode)
136
159
  }
137
160
 
138
161
  static int
139
- mrb_io_flags_to_modenum(mrb_state *mrb, int flags)
162
+ mrb_io_mode_to_flags(mrb_state *mrb, mrb_value mode)
140
163
  {
141
- int modenum = 0;
142
-
143
- switch(flags & (FMODE_READABLE|FMODE_WRITABLE|FMODE_READWRITE)) {
144
- case FMODE_READABLE:
145
- modenum = O_RDONLY;
146
- break;
147
- case FMODE_WRITABLE:
148
- modenum = O_WRONLY;
149
- break;
150
- case FMODE_READWRITE:
151
- modenum = O_RDWR;
152
- break;
153
- }
154
-
155
- if (flags & FMODE_APPEND) {
156
- modenum |= O_APPEND;
157
- }
158
- if (flags & FMODE_TRUNC) {
159
- modenum |= O_TRUNC;
164
+ if (mrb_nil_p(mode)) {
165
+ return mrb_io_modestr_to_flags(mrb, "r");
160
166
  }
161
- if (flags & FMODE_CREATE) {
162
- modenum |= O_CREAT;
167
+ else if (mrb_string_p(mode)) {
168
+ return mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
163
169
  }
170
+ else {
171
+ int flags = 0;
172
+ mrb_int flags0 = mrb_int(mrb, mode);
173
+
174
+ switch (flags0 & MRB_O_ACCMODE) {
175
+ case MRB_O_RDONLY:
176
+ flags |= O_RDONLY;
177
+ break;
178
+ case MRB_O_WRONLY:
179
+ flags |= O_WRONLY;
180
+ break;
181
+ case MRB_O_RDWR:
182
+ flags |= O_RDWR;
183
+ break;
184
+ default:
185
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %v", mode);
186
+ }
187
+
188
+ if (flags0 & MRB_O_APPEND) flags |= O_APPEND;
189
+ if (flags0 & MRB_O_CREAT) flags |= O_CREAT;
190
+ if (flags0 & MRB_O_EXCL) flags |= O_EXCL;
191
+ if (flags0 & MRB_O_TRUNC) flags |= O_TRUNC;
192
+ #ifdef O_NONBLOCK
193
+ if (flags0 & MRB_O_NONBLOCK) flags |= O_NONBLOCK;
194
+ #endif
195
+ #ifdef O_NOCTTY
196
+ if (flags0 & MRB_O_NOCTTY) flags |= O_NOCTTY;
197
+ #endif
164
198
  #ifdef O_BINARY
165
- if (flags & FMODE_BINMODE) {
166
- modenum |= O_BINARY;
167
- }
199
+ if (flags0 & MRB_O_BINARY) flags |= O_BINARY;
200
+ #endif
201
+ #ifdef O_SHARE_DELETE
202
+ if (flags0 & MRB_O_SHARE_DELETE) flags |= O_SHARE_DELETE;
203
+ #endif
204
+ #ifdef O_SYNC
205
+ if (flags0 & MRB_O_SYNC) flags |= O_SYNC;
206
+ #endif
207
+ #ifdef O_DSYNC
208
+ if (flags0 & MRB_O_DSYNC) flags |= O_DSYNC;
209
+ #endif
210
+ #ifdef O_RSYNC
211
+ if (flags0 & MRB_O_RSYNC) flags |= O_RSYNC;
212
+ #endif
213
+ #ifdef O_NOFOLLOW
214
+ if (flags0 & MRB_O_NOFOLLOW) flags |= O_NOFOLLOW;
215
+ #endif
216
+ #ifdef O_NOATIME
217
+ if (flags0 & MRB_O_NOATIME) flags |= O_NOATIME;
218
+ #endif
219
+ #ifdef O_DIRECT
220
+ if (flags0 & MRB_O_DIRECT) flags |= O_DIRECT;
221
+ #endif
222
+ #ifdef O_TMPFILE
223
+ if (flags0 & MRB_O_TMPFILE) flags |= O_TMPFILE;
168
224
  #endif
169
225
 
170
- return modenum;
226
+ return flags;
227
+ }
171
228
  }
172
229
 
173
230
  static void
@@ -270,20 +327,20 @@ mrb_io_alloc(mrb_state *mrb)
270
327
  #define NOFILE 64
271
328
  #endif
272
329
 
330
+ #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
331
+ # define mrb_io_s_popen mrb_notimplement_m
332
+ #else
273
333
  static int
274
- option_to_fd(mrb_state *mrb, mrb_value hash, const char *key)
334
+ option_to_fd(mrb_state *mrb, mrb_value v)
275
335
  {
276
- mrb_value opt;
277
-
278
- if (!mrb_hash_p(hash)) return -1;
279
- opt = mrb_hash_fetch(mrb, hash, mrb_symbol_value(mrb_intern_static(mrb, key, strlen(key))), mrb_nil_value());
280
- if (mrb_nil_p(opt)) return -1;
336
+ if (mrb_undef_p(v)) return -1;
337
+ if (mrb_nil_p(v)) return -1;
281
338
 
282
- switch (mrb_type(opt)) {
339
+ switch (mrb_type(v)) {
283
340
  case MRB_TT_DATA: /* IO */
284
- return mrb_io_fileno(mrb, opt);
285
- case MRB_TT_FIXNUM:
286
- return (int)mrb_fixnum(opt);
341
+ return mrb_io_fileno(mrb, v);
342
+ case MRB_TT_INTEGER:
343
+ return (int)mrb_integer(v);
287
344
  default:
288
345
  mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong exec redirect action");
289
346
  break;
@@ -291,16 +348,42 @@ option_to_fd(mrb_state *mrb, mrb_value hash, const char *key)
291
348
  return -1; /* never reached */
292
349
  }
293
350
 
351
+ static mrb_value
352
+ mrb_io_s_popen_args(mrb_state *mrb, mrb_value klass,
353
+ const char **cmd, int *flags, int *doexec,
354
+ int *opt_in, int *opt_out, int *opt_err)
355
+ {
356
+ mrb_value mode = mrb_nil_value();
357
+ struct { mrb_value opt_in, opt_out, opt_err; } kv;
358
+ mrb_sym knames[3] = {MRB_SYM(in), MRB_SYM(out), MRB_SYM(err)};
359
+ const mrb_kwargs kw = {
360
+ 3, 0,
361
+ knames,
362
+ &kv.opt_in,
363
+ NULL,
364
+ };
365
+
366
+ mrb_get_args(mrb, "z|o:", cmd, &mode, &kw);
367
+
368
+ *flags = mrb_io_mode_to_flags(mrb, mode);
369
+ *doexec = (strcmp("-", *cmd) != 0);
370
+ *opt_in = option_to_fd(mrb, kv.opt_in);
371
+ *opt_out = option_to_fd(mrb, kv.opt_out);
372
+ *opt_err = option_to_fd(mrb, kv.opt_err);
373
+
374
+ return mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
375
+ }
376
+
294
377
  #ifdef _WIN32
295
- mrb_value
378
+ static mrb_value
296
379
  mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
297
380
  {
298
- mrb_value cmd, io;
299
- mrb_value mode = mrb_str_new_cstr(mrb, "r");
300
- mrb_value opt = mrb_hash_new(mrb);
381
+ mrb_value io;
382
+ int doexec;
383
+ int opt_in, opt_out, opt_err;
384
+ const char *cmd;
301
385
 
302
386
  struct mrb_io *fptr;
303
- const char *pname;
304
387
  int pid = 0, flags;
305
388
  STARTUPINFO si;
306
389
  PROCESS_INFORMATION pi;
@@ -309,37 +392,26 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
309
392
  HANDLE ifd[2];
310
393
  HANDLE ofd[2];
311
394
 
312
- int doexec;
313
- int opt_in, opt_out, opt_err;
314
-
315
395
  ifd[0] = INVALID_HANDLE_VALUE;
316
396
  ifd[1] = INVALID_HANDLE_VALUE;
317
397
  ofd[0] = INVALID_HANDLE_VALUE;
318
398
  ofd[1] = INVALID_HANDLE_VALUE;
319
399
 
320
- mrb_get_args(mrb, "S|SH", &cmd, &mode, &opt);
321
- io = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
322
-
323
- pname = RSTRING_CSTR(mrb, cmd);
324
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
325
-
326
- doexec = (strcmp("-", pname) != 0);
327
- opt_in = option_to_fd(mrb, opt, "in");
328
- opt_out = option_to_fd(mrb, opt, "out");
329
- opt_err = option_to_fd(mrb, opt, "err");
400
+ io = mrb_io_s_popen_args(mrb, klass, &cmd, &flags, &doexec,
401
+ &opt_in, &opt_out, &opt_err);
330
402
 
331
403
  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
332
404
  saAttr.bInheritHandle = TRUE;
333
405
  saAttr.lpSecurityDescriptor = NULL;
334
406
 
335
- if (flags & FMODE_READABLE) {
407
+ if (OPEN_READABLE_P(flags)) {
336
408
  if (!CreatePipe(&ofd[0], &ofd[1], &saAttr, 0)
337
409
  || !SetHandleInformation(ofd[0], HANDLE_FLAG_INHERIT, 0)) {
338
410
  mrb_sys_fail(mrb, "pipe");
339
411
  }
340
412
  }
341
413
 
342
- if (flags & FMODE_WRITABLE) {
414
+ if (OPEN_WRITABLE_P(flags)) {
343
415
  if (!CreatePipe(&ifd[0], &ifd[1], &saAttr, 0)
344
416
  || !SetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0)) {
345
417
  mrb_sys_fail(mrb, "pipe");
@@ -353,21 +425,21 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
353
425
  si.dwFlags |= STARTF_USESHOWWINDOW;
354
426
  si.wShowWindow = SW_HIDE;
355
427
  si.dwFlags |= STARTF_USESTDHANDLES;
356
- if (flags & FMODE_READABLE) {
428
+ if (OPEN_READABLE_P(flags)) {
357
429
  si.hStdOutput = ofd[1];
358
430
  si.hStdError = ofd[1];
359
431
  }
360
- if (flags & FMODE_WRITABLE) {
432
+ if (OPEN_WRITABLE_P(flags)) {
361
433
  si.hStdInput = ifd[0];
362
434
  }
363
435
  if (!CreateProcess(
364
- NULL, (char*)pname, NULL, NULL,
436
+ NULL, (char*)cmd, NULL, NULL,
365
437
  TRUE, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi)) {
366
438
  CloseHandle(ifd[0]);
367
439
  CloseHandle(ifd[1]);
368
440
  CloseHandle(ofd[0]);
369
441
  CloseHandle(ofd[1]);
370
- mrb_raisef(mrb, E_IO_ERROR, "command not found: %v", cmd);
442
+ mrb_raisef(mrb, E_IO_ERROR, "command not found: %s", cmd);
371
443
  }
372
444
  CloseHandle(pi.hThread);
373
445
  CloseHandle(ifd[0]);
@@ -375,56 +447,39 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
375
447
  pid = pi.dwProcessId;
376
448
  }
377
449
 
378
- mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
450
+ mrb_iv_set(mrb, io, mrb_intern_lit(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
379
451
 
380
452
  fptr = mrb_io_alloc(mrb);
381
453
  fptr->fd = _open_osfhandle((intptr_t)ofd[0], 0);
382
454
  fptr->fd2 = _open_osfhandle((intptr_t)ifd[1], 0);
383
455
  fptr->pid = pid;
384
- fptr->readable = ((flags & FMODE_READABLE) != 0);
385
- fptr->writable = ((flags & FMODE_WRITABLE) != 0);
456
+ fptr->readable = OPEN_READABLE_P(flags);
457
+ fptr->writable = OPEN_WRITABLE_P(flags);
386
458
  fptr->sync = 0;
387
459
 
388
460
  DATA_TYPE(io) = &mrb_io_type;
389
461
  DATA_PTR(io) = fptr;
390
462
  return io;
391
463
  }
392
- #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
393
- mrb_value
394
- mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
395
- {
396
- mrb_raise(mrb, E_NOTIMP_ERROR, "IO#popen is not supported on the platform");
397
- return mrb_false_value();
398
- }
399
464
  #else
400
- mrb_value
465
+ static mrb_value
401
466
  mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
402
467
  {
403
- mrb_value cmd, io, result;
404
- mrb_value mode = mrb_str_new_cstr(mrb, "r");
405
- mrb_value opt = mrb_hash_new(mrb);
468
+ mrb_value io, result;
469
+ int doexec;
470
+ int opt_in, opt_out, opt_err;
471
+ const char *cmd;
406
472
 
407
473
  struct mrb_io *fptr;
408
- const char *pname;
409
474
  int pid, flags, fd, write_fd = -1;
410
475
  int pr[2] = { -1, -1 };
411
476
  int pw[2] = { -1, -1 };
412
- int doexec;
413
477
  int saved_errno;
414
- int opt_in, opt_out, opt_err;
415
478
 
416
- mrb_get_args(mrb, "S|SH", &cmd, &mode, &opt);
417
- io = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
479
+ io = mrb_io_s_popen_args(mrb, klass, &cmd, &flags, &doexec,
480
+ &opt_in, &opt_out, &opt_err);
418
481
 
419
- pname = RSTRING_CSTR(mrb, cmd);
420
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
421
-
422
- doexec = (strcmp("-", pname) != 0);
423
- opt_in = option_to_fd(mrb, opt, "in");
424
- opt_out = option_to_fd(mrb, opt, "out");
425
- opt_err = option_to_fd(mrb, opt, "err");
426
-
427
- if (flags & FMODE_READABLE) {
482
+ if (OPEN_READABLE_P(flags)) {
428
483
  if (pipe(pr) == -1) {
429
484
  mrb_sys_fail(mrb, "pipe");
430
485
  }
@@ -432,7 +487,7 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
432
487
  mrb_fd_cloexec(mrb, pr[1]);
433
488
  }
434
489
 
435
- if (flags & FMODE_WRITABLE) {
490
+ if (OPEN_WRITABLE_P(flags)) {
436
491
  if (pipe(pw) == -1) {
437
492
  if (pr[0] != -1) close(pr[0]);
438
493
  if (pr[1] != -1) close(pr[1]);
@@ -461,14 +516,14 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
461
516
  if (opt_err != -1) {
462
517
  dup2(opt_err, 2);
463
518
  }
464
- if (flags & FMODE_READABLE) {
519
+ if (OPEN_READABLE_P(flags)) {
465
520
  close(pr[0]);
466
521
  if (pr[1] != 1) {
467
522
  dup2(pr[1], 1);
468
523
  close(pr[1]);
469
524
  }
470
525
  }
471
- if (flags & FMODE_WRITABLE) {
526
+ if (OPEN_WRITABLE_P(flags)) {
472
527
  close(pw[1]);
473
528
  if (pw[0] != 0) {
474
529
  dup2(pw[0], 0);
@@ -479,20 +534,20 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
479
534
  for (fd = 3; fd < NOFILE; fd++) {
480
535
  close(fd);
481
536
  }
482
- mrb_proc_exec(pname);
483
- mrb_raisef(mrb, E_IO_ERROR, "command not found: %v", cmd);
537
+ mrb_proc_exec(cmd);
538
+ mrb_raisef(mrb, E_IO_ERROR, "command not found: %s", cmd);
484
539
  _exit(127);
485
540
  }
486
541
  result = mrb_nil_value();
487
542
  break;
488
543
 
489
544
  default: /* parent */
490
- if ((flags & FMODE_READABLE) && (flags & FMODE_WRITABLE)) {
545
+ if (OPEN_RDWR_P(flags)) {
491
546
  close(pr[1]);
492
547
  fd = pr[0];
493
548
  close(pw[0]);
494
549
  write_fd = pw[1];
495
- } else if (flags & FMODE_READABLE) {
550
+ } else if (OPEN_RDONLY_P(flags)) {
496
551
  close(pr[1]);
497
552
  fd = pr[0];
498
553
  } else {
@@ -500,14 +555,14 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
500
555
  fd = pw[1];
501
556
  }
502
557
 
503
- mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
558
+ mrb_iv_set(mrb, io, mrb_intern_lit(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
504
559
 
505
560
  fptr = mrb_io_alloc(mrb);
506
561
  fptr->fd = fd;
507
562
  fptr->fd2 = write_fd;
508
563
  fptr->pid = pid;
509
- fptr->readable = ((flags & FMODE_READABLE) != 0);
510
- fptr->writable = ((flags & FMODE_WRITABLE) != 0);
564
+ fptr->readable = OPEN_READABLE_P(flags);
565
+ fptr->writable = OPEN_WRITABLE_P(flags);
511
566
  fptr->sync = 0;
512
567
 
513
568
  DATA_TYPE(io) = &mrb_io_type;
@@ -517,11 +572,11 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
517
572
 
518
573
  case -1: /* error */
519
574
  saved_errno = errno;
520
- if (flags & FMODE_READABLE) {
575
+ if (OPEN_READABLE_P(flags)) {
521
576
  close(pr[0]);
522
577
  close(pr[1]);
523
578
  }
524
- if (flags & FMODE_WRITABLE) {
579
+ if (OPEN_WRITABLE_P(flags)) {
525
580
  close(pw[0]);
526
581
  close(pw[1]);
527
582
  }
@@ -531,7 +586,8 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
531
586
  }
532
587
  return result;
533
588
  }
534
- #endif
589
+ #endif /* _WIN32 */
590
+ #endif /* TARGET_OS_IPHONE */
535
591
 
536
592
  static int
537
593
  mrb_dup(mrb_state *mrb, int fd, mrb_bool *failed)
@@ -547,16 +603,15 @@ mrb_dup(mrb_state *mrb, int fd, mrb_bool *failed)
547
603
  return new_fd;
548
604
  }
549
605
 
550
- mrb_value
606
+ static mrb_value
551
607
  mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
552
608
  {
553
- mrb_value orig;
609
+ mrb_value orig = mrb_get_arg1(mrb);
554
610
  mrb_value buf;
555
611
  struct mrb_io *fptr_copy;
556
612
  struct mrb_io *fptr_orig;
557
613
  mrb_bool failed = TRUE;
558
614
 
559
- mrb_get_args(mrb, "o", &orig);
560
615
  fptr_orig = io_get_open_fptr(mrb, orig);
561
616
  fptr_copy = (struct mrb_io *)DATA_PTR(copy);
562
617
  if (fptr_orig == fptr_copy) return copy;
@@ -569,8 +624,8 @@ mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
569
624
  DATA_TYPE(copy) = &mrb_io_type;
570
625
  DATA_PTR(copy) = fptr_copy;
571
626
 
572
- buf = mrb_iv_get(mrb, orig, mrb_intern_cstr(mrb, "@buf"));
573
- mrb_iv_set(mrb, copy, mrb_intern_cstr(mrb, "@buf"), buf);
627
+ buf = mrb_iv_get(mrb, orig, mrb_intern_lit(mrb, "@buf"));
628
+ mrb_iv_set(mrb, copy, mrb_intern_lit(mrb, "@buf"), buf);
574
629
 
575
630
  fptr_copy->fd = mrb_dup(mrb, fptr_orig->fd, &failed);
576
631
  if (failed) {
@@ -596,7 +651,44 @@ mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
596
651
  return copy;
597
652
  }
598
653
 
599
- mrb_value
654
+ static void
655
+ check_file_descriptor(mrb_state *mrb, mrb_int fd)
656
+ {
657
+ struct stat sb;
658
+ int fdi = (int)fd;
659
+
660
+ #if MRB_INT_MIN < INT_MIN || MRB_INT_MAX > INT_MAX
661
+ if (fdi != fd) {
662
+ goto badfd;
663
+ }
664
+ #endif
665
+
666
+ #ifdef _WIN32
667
+ {
668
+ DWORD err;
669
+ int len = sizeof(err);
670
+
671
+ if (getsockopt(fdi, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0) {
672
+ return;
673
+ }
674
+ }
675
+
676
+ if (fdi < 0 || fdi > _getmaxstdio()) {
677
+ goto badfd;
678
+ }
679
+ #endif /* _WIN32 */
680
+
681
+ if (fstat(fdi, &sb) != 0) {
682
+ goto badfd;
683
+ }
684
+
685
+ return;
686
+
687
+ badfd:
688
+ mrb_sys_fail(mrb, "bad file descriptor");
689
+ }
690
+
691
+ static mrb_value
600
692
  mrb_io_initialize(mrb_state *mrb, mrb_value io)
601
693
  {
602
694
  struct mrb_io *fptr;
@@ -606,7 +698,16 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
606
698
 
607
699
  mode = opt = mrb_nil_value();
608
700
 
609
- mrb_get_args(mrb, "i|So", &fd, &mode, &opt);
701
+ mrb_get_args(mrb, "i|oo", &fd, &mode, &opt);
702
+ switch (fd) {
703
+ case 0: /* STDIN_FILENO */
704
+ case 1: /* STDOUT_FILENO */
705
+ case 2: /* STDERR_FILENO */
706
+ break;
707
+ default:
708
+ check_file_descriptor(mrb, fd);
709
+ break;
710
+ }
610
711
  if (mrb_nil_p(mode)) {
611
712
  mode = mrb_str_new_cstr(mrb, "r");
612
713
  }
@@ -614,9 +715,9 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
614
715
  opt = mrb_hash_new(mrb);
615
716
  }
616
717
 
617
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
718
+ flags = mrb_io_mode_to_flags(mrb, mode);
618
719
 
619
- mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
720
+ mrb_iv_set(mrb, io, mrb_intern_lit(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
620
721
 
621
722
  fptr = (struct mrb_io *)DATA_PTR(io);
622
723
  if (fptr != NULL) {
@@ -629,8 +730,8 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
629
730
  DATA_PTR(io) = fptr;
630
731
 
631
732
  fptr->fd = (int)fd;
632
- fptr->readable = ((flags & FMODE_READABLE) != 0);
633
- fptr->writable = ((flags & FMODE_WRITABLE) != 0);
733
+ fptr->readable = OPEN_READABLE_P(flags);
734
+ fptr->writable = OPEN_WRITABLE_P(flags);
634
735
  fptr->sync = 0;
635
736
  return io;
636
737
  }
@@ -698,7 +799,7 @@ fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int quiet)
698
799
  }
699
800
  }
700
801
 
701
- mrb_value
802
+ static mrb_value
702
803
  mrb_io_check_readable(mrb_state *mrb, mrb_value self)
703
804
  {
704
805
  struct mrb_io *fptr = io_get_open_fptr(mrb, self);
@@ -708,7 +809,7 @@ mrb_io_check_readable(mrb_state *mrb, mrb_value self)
708
809
  return mrb_nil_value();
709
810
  }
710
811
 
711
- mrb_value
812
+ static mrb_value
712
813
  mrb_io_isatty(mrb_state *mrb, mrb_value self)
713
814
  {
714
815
  struct mrb_io *fptr;
@@ -719,7 +820,7 @@ mrb_io_isatty(mrb_state *mrb, mrb_value self)
719
820
  return mrb_true_value();
720
821
  }
721
822
 
722
- mrb_value
823
+ static mrb_value
723
824
  mrb_io_s_for_fd(mrb_state *mrb, mrb_value klass)
724
825
  {
725
826
  struct RClass *c = mrb_class_ptr(klass);
@@ -732,7 +833,7 @@ mrb_io_s_for_fd(mrb_state *mrb, mrb_value klass)
732
833
  return mrb_io_initialize(mrb, obj);
733
834
  }
734
835
 
735
- mrb_value
836
+ static mrb_value
736
837
  mrb_io_s_sysclose(mrb_state *mrb, mrb_value klass)
737
838
  {
738
839
  mrb_int fd;
@@ -743,7 +844,7 @@ mrb_io_s_sysclose(mrb_state *mrb, mrb_value klass)
743
844
  return mrb_fixnum_value(0);
744
845
  }
745
846
 
746
- int
847
+ static int
747
848
  mrb_cloexec_open(mrb_state *mrb, const char *pathname, mrb_int flags, mrb_int mode)
748
849
  {
749
850
  int fd, retry = FALSE;
@@ -778,39 +879,55 @@ reopen:
778
879
  return fd;
779
880
  }
780
881
 
781
- mrb_value
882
+ static mrb_value
782
883
  mrb_io_s_sysopen(mrb_state *mrb, mrb_value klass)
783
884
  {
784
885
  mrb_value path = mrb_nil_value();
785
886
  mrb_value mode = mrb_nil_value();
786
887
  mrb_int fd, perm = -1;
787
888
  const char *pat;
788
- int flags, modenum;
889
+ int flags;
789
890
 
790
- mrb_get_args(mrb, "S|Si", &path, &mode, &perm);
791
- if (mrb_nil_p(mode)) {
792
- mode = mrb_str_new_cstr(mrb, "r");
793
- }
891
+ mrb_get_args(mrb, "S|oi", &path, &mode, &perm);
794
892
  if (perm < 0) {
795
893
  perm = 0666;
796
894
  }
797
895
 
798
896
  pat = RSTRING_CSTR(mrb, path);
799
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
800
- modenum = mrb_io_flags_to_modenum(mrb, flags);
801
- fd = mrb_cloexec_open(mrb, pat, modenum, perm);
897
+ flags = mrb_io_mode_to_flags(mrb, mode);
898
+ fd = mrb_cloexec_open(mrb, pat, flags, perm);
802
899
  return mrb_fixnum_value(fd);
803
900
  }
804
901
 
805
- mrb_value
902
+ static mrb_value mrb_io_sysread_common(mrb_state *mrb,
903
+ mrb_io_read_write_size (*readfunc)(int, void *, fsize_t, off_t),
904
+ mrb_value io, mrb_value buf, mrb_int maxlen, off_t offset);
905
+
906
+ static mrb_io_read_write_size
907
+ mrb_sysread_dummy(int fd, void *buf, fsize_t nbytes, off_t offset)
908
+ {
909
+ return (mrb_io_read_write_size)read(fd, buf, nbytes);
910
+ }
911
+
912
+ static mrb_value
806
913
  mrb_io_sysread(mrb_state *mrb, mrb_value io)
807
914
  {
808
- struct mrb_io *fptr;
809
915
  mrb_value buf = mrb_nil_value();
810
916
  mrb_int maxlen;
811
- int ret;
812
917
 
813
918
  mrb_get_args(mrb, "i|S", &maxlen, &buf);
919
+
920
+ return mrb_io_sysread_common(mrb, mrb_sysread_dummy, io, buf, maxlen, 0);
921
+ }
922
+
923
+ static mrb_value
924
+ mrb_io_sysread_common(mrb_state *mrb,
925
+ mrb_io_read_write_size (*readfunc)(int, void *, fsize_t, off_t),
926
+ mrb_value io, mrb_value buf, mrb_int maxlen, off_t offset)
927
+ {
928
+ struct mrb_io *fptr;
929
+ int ret;
930
+
814
931
  if (maxlen < 0) {
815
932
  mrb_raise(mrb, E_ARGUMENT_ERROR, "negative expanding string size");
816
933
  }
@@ -824,7 +941,8 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
824
941
 
825
942
  if (RSTRING_LEN(buf) != maxlen) {
826
943
  buf = mrb_str_resize(mrb, buf, maxlen);
827
- } else {
944
+ }
945
+ else {
828
946
  mrb_str_modify(mrb, RSTRING(buf));
829
947
  }
830
948
 
@@ -832,29 +950,20 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
832
950
  if (!fptr->readable) {
833
951
  mrb_raise(mrb, E_IO_ERROR, "not opened for reading");
834
952
  }
835
- ret = read(fptr->fd, RSTRING_PTR(buf), (fsize_t)maxlen);
836
- switch (ret) {
837
- case 0: /* EOF */
838
- if (maxlen == 0) {
839
- buf = mrb_str_new_cstr(mrb, "");
840
- } else {
841
- mrb_raise(mrb, E_EOF_ERROR, "sysread failed: End of File");
842
- }
843
- break;
844
- case -1: /* Error */
845
- mrb_sys_fail(mrb, "sysread failed");
846
- break;
847
- default:
848
- if (RSTRING_LEN(buf) != ret) {
849
- buf = mrb_str_resize(mrb, buf, ret);
850
- }
851
- break;
953
+ ret = readfunc(fptr->fd, RSTRING_PTR(buf), (fsize_t)maxlen, offset);
954
+ if (ret < 0) {
955
+ mrb_sys_fail(mrb, "sysread failed");
956
+ }
957
+ if (RSTRING_LEN(buf) != ret) {
958
+ buf = mrb_str_resize(mrb, buf, ret);
959
+ }
960
+ if (ret == 0 && maxlen > 0) {
961
+ mrb_raise(mrb, E_EOF_ERROR, "sysread failed: End of File");
852
962
  }
853
-
854
963
  return buf;
855
964
  }
856
965
 
857
- mrb_value
966
+ static mrb_value
858
967
  mrb_io_sysseek(mrb_state *mrb, mrb_value io)
859
968
  {
860
969
  struct mrb_io *fptr;
@@ -872,21 +981,22 @@ mrb_io_sysseek(mrb_state *mrb, mrb_value io)
872
981
  mrb_sys_fail(mrb, "sysseek");
873
982
  }
874
983
  if (pos > MRB_INT_MAX) {
875
- #ifndef MRB_WITHOUT_FLOAT
984
+ #ifndef MRB_NO_FLOAT
876
985
  return mrb_float_value(mrb, (mrb_float)pos);
877
986
  #else
878
- mrb_raise(mrb, E_IO_ERROR, "sysseek reached too far for MRB_WITHOUT_FLOAT");
987
+ mrb_raise(mrb, E_IO_ERROR, "sysseek reached too far for MRB_NO_FLOAT");
879
988
  #endif
880
989
  } else {
881
- return mrb_fixnum_value(pos);
990
+ return mrb_int_value(mrb, pos);
882
991
  }
883
992
  }
884
993
 
885
- mrb_value
886
- mrb_io_syswrite(mrb_state *mrb, mrb_value io)
994
+ static mrb_value
995
+ mrb_io_syswrite_common(mrb_state *mrb,
996
+ mrb_io_read_write_size (*writefunc)(int, const void *, fsize_t, off_t),
997
+ mrb_value io, mrb_value buf, off_t offset)
887
998
  {
888
999
  struct mrb_io *fptr;
889
- mrb_value str, buf;
890
1000
  int fd, length;
891
1001
 
892
1002
  fptr = io_get_open_fptr(mrb, io);
@@ -894,23 +1004,36 @@ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
894
1004
  mrb_raise(mrb, E_IO_ERROR, "not opened for writing");
895
1005
  }
896
1006
 
897
- mrb_get_args(mrb, "S", &str);
898
- buf = str;
899
-
900
1007
  if (fptr->fd2 == -1) {
901
1008
  fd = fptr->fd;
902
1009
  } else {
903
1010
  fd = fptr->fd2;
904
1011
  }
905
- length = write(fd, RSTRING_PTR(buf), (fsize_t)RSTRING_LEN(buf));
1012
+ length = writefunc(fd, RSTRING_PTR(buf), (fsize_t)RSTRING_LEN(buf), offset);
906
1013
  if (length == -1) {
907
1014
  mrb_sys_fail(mrb, 0);
908
1015
  }
909
1016
 
910
- return mrb_fixnum_value(length);
1017
+ return mrb_int_value(mrb, (mrb_int)length);
1018
+ }
1019
+
1020
+ static mrb_io_read_write_size
1021
+ mrb_syswrite_dummy(int fd, const void *buf, fsize_t nbytes, off_t offset)
1022
+ {
1023
+ return (mrb_io_read_write_size)write(fd, buf, nbytes);
1024
+ }
1025
+
1026
+ static mrb_value
1027
+ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
1028
+ {
1029
+ mrb_value buf;
1030
+
1031
+ mrb_get_args(mrb, "S", &buf);
1032
+
1033
+ return mrb_io_syswrite_common(mrb, mrb_syswrite_dummy, io, buf, 0);
911
1034
  }
912
1035
 
913
- mrb_value
1036
+ static mrb_value
914
1037
  mrb_io_close(mrb_state *mrb, mrb_value self)
915
1038
  {
916
1039
  struct mrb_io *fptr;
@@ -919,7 +1042,7 @@ mrb_io_close(mrb_state *mrb, mrb_value self)
919
1042
  return mrb_nil_value();
920
1043
  }
921
1044
 
922
- mrb_value
1045
+ static mrb_value
923
1046
  mrb_io_close_write(mrb_state *mrb, mrb_value self)
924
1047
  {
925
1048
  struct mrb_io *fptr;
@@ -930,7 +1053,7 @@ mrb_io_close_write(mrb_state *mrb, mrb_value self)
930
1053
  return mrb_nil_value();
931
1054
  }
932
1055
 
933
- mrb_value
1056
+ static mrb_value
934
1057
  mrb_io_closed(mrb_state *mrb, mrb_value io)
935
1058
  {
936
1059
  struct mrb_io *fptr;
@@ -942,7 +1065,7 @@ mrb_io_closed(mrb_state *mrb, mrb_value io)
942
1065
  return mrb_true_value();
943
1066
  }
944
1067
 
945
- mrb_value
1068
+ static mrb_value
946
1069
  mrb_io_pid(mrb_state *mrb, mrb_value io)
947
1070
  {
948
1071
  struct mrb_io *fptr;
@@ -961,12 +1084,12 @@ time2timeval(mrb_state *mrb, mrb_value time)
961
1084
  struct timeval t = { 0, 0 };
962
1085
 
963
1086
  switch (mrb_type(time)) {
964
- case MRB_TT_FIXNUM:
965
- t.tv_sec = (ftime_t)mrb_fixnum(time);
1087
+ case MRB_TT_INTEGER:
1088
+ t.tv_sec = (ftime_t)mrb_integer(time);
966
1089
  t.tv_usec = 0;
967
1090
  break;
968
1091
 
969
- #ifndef MRB_WITHOUT_FLOAT
1092
+ #ifndef MRB_NO_FLOAT
970
1093
  case MRB_TT_FLOAT:
971
1094
  t.tv_sec = (ftime_t)mrb_float(time);
972
1095
  t.tv_usec = (fsuseconds_t)((mrb_float(time) - t.tv_sec) * 1000000.0);
@@ -983,7 +1106,7 @@ time2timeval(mrb_state *mrb, mrb_value time)
983
1106
  static int
984
1107
  mrb_io_read_data_pending(mrb_state *mrb, mrb_value io)
985
1108
  {
986
- mrb_value buf = mrb_iv_get(mrb, io, mrb_intern_cstr(mrb, "@buf"));
1109
+ mrb_value buf = mrb_iv_get(mrb, io, mrb_intern_lit(mrb, "@buf"));
987
1110
  if (mrb_string_p(buf) && RSTRING_LEN(buf) > 0) {
988
1111
  return 1;
989
1112
  }
@@ -1005,7 +1128,7 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
1005
1128
  }
1006
1129
 
1007
1130
  r = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
1008
- mrb_iv_set(mrb, r, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
1131
+ mrb_iv_set(mrb, r, mrb_intern_lit(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
1009
1132
  fptr_r = mrb_io_alloc(mrb);
1010
1133
  fptr_r->fd = pipes[0];
1011
1134
  fptr_r->readable = 1;
@@ -1015,7 +1138,7 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
1015
1138
  DATA_PTR(r) = fptr_r;
1016
1139
 
1017
1140
  w = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
1018
- mrb_iv_set(mrb, w, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
1141
+ mrb_iv_set(mrb, w, mrb_intern_lit(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
1019
1142
  fptr_w = mrb_io_alloc(mrb);
1020
1143
  fptr_w->fd = pipes[1];
1021
1144
  fptr_w->readable = 0;
@@ -1031,7 +1154,7 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
1031
1154
  static mrb_value
1032
1155
  mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1033
1156
  {
1034
- mrb_value *argv;
1157
+ const mrb_value *argv;
1035
1158
  mrb_int argc;
1036
1159
  mrb_value read, read_io, write, except, timeout, list;
1037
1160
  struct timeval *tp, timerec;
@@ -1076,6 +1199,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1076
1199
  for (i = 0; i < RARRAY_LEN(read); i++) {
1077
1200
  read_io = RARRAY_PTR(read)[i];
1078
1201
  fptr = io_get_open_fptr(mrb, read_io);
1202
+ if (fptr->fd >= FD_SETSIZE) continue;
1079
1203
  FD_SET(fptr->fd, rp);
1080
1204
  if (mrb_io_read_data_pending(mrb, read_io)) {
1081
1205
  pending++;
@@ -1098,6 +1222,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1098
1222
  FD_ZERO(wp);
1099
1223
  for (i = 0; i < RARRAY_LEN(write); i++) {
1100
1224
  fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]);
1225
+ if (fptr->fd >= FD_SETSIZE) continue;
1101
1226
  FD_SET(fptr->fd, wp);
1102
1227
  if (max < fptr->fd)
1103
1228
  max = fptr->fd;
@@ -1117,6 +1242,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1117
1242
  FD_ZERO(ep);
1118
1243
  for (i = 0; i < RARRAY_LEN(except); i++) {
1119
1244
  fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]);
1245
+ if (fptr->fd >= FD_SETSIZE) continue;
1120
1246
  FD_SET(fptr->fd, ep);
1121
1247
  if (max < fptr->fd)
1122
1248
  max = fptr->fd;
@@ -1205,10 +1331,10 @@ mrb_io_fileno_m(mrb_state *mrb, mrb_value io)
1205
1331
  return mrb_fixnum_value(fd);
1206
1332
  }
1207
1333
 
1208
- mrb_value
1334
+ #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
1335
+ static mrb_value
1209
1336
  mrb_io_close_on_exec_p(mrb_state *mrb, mrb_value self)
1210
1337
  {
1211
- #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
1212
1338
  struct mrb_io *fptr;
1213
1339
  int ret;
1214
1340
 
@@ -1222,17 +1348,15 @@ mrb_io_close_on_exec_p(mrb_state *mrb, mrb_value self)
1222
1348
  if ((ret = fcntl(fptr->fd, F_GETFD)) == -1) mrb_sys_fail(mrb, "F_GETFD failed");
1223
1349
  if (!(ret & FD_CLOEXEC)) return mrb_false_value();
1224
1350
  return mrb_true_value();
1225
-
1351
+ }
1226
1352
  #else
1227
- mrb_raise(mrb, E_NOTIMP_ERROR, "IO#close_on_exec? is not supported on the platform");
1228
- return mrb_false_value();
1353
+ # define mrb_io_close_on_exec_p mrb_notimplement_m
1229
1354
  #endif
1230
- }
1231
1355
 
1232
- mrb_value
1356
+ #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
1357
+ static mrb_value
1233
1358
  mrb_io_set_close_on_exec(mrb_state *mrb, mrb_value self)
1234
1359
  {
1235
- #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
1236
1360
  struct mrb_io *fptr;
1237
1361
  int flag, ret;
1238
1362
  mrb_bool b;
@@ -1259,13 +1383,12 @@ mrb_io_set_close_on_exec(mrb_state *mrb, mrb_value self)
1259
1383
  }
1260
1384
 
1261
1385
  return mrb_bool_value(b);
1386
+ }
1262
1387
  #else
1263
- mrb_raise(mrb, E_NOTIMP_ERROR, "IO#close_on_exec= is not supported on the platform");
1264
- return mrb_nil_value();
1388
+ # define mrb_io_set_close_on_exec mrb_notimplement_m
1265
1389
  #endif
1266
- }
1267
1390
 
1268
- mrb_value
1391
+ static mrb_value
1269
1392
  mrb_io_set_sync(mrb_state *mrb, mrb_value self)
1270
1393
  {
1271
1394
  struct mrb_io *fptr;
@@ -1277,7 +1400,7 @@ mrb_io_set_sync(mrb_state *mrb, mrb_value self)
1277
1400
  return mrb_bool_value(b);
1278
1401
  }
1279
1402
 
1280
- mrb_value
1403
+ static mrb_value
1281
1404
  mrb_io_sync(mrb_state *mrb, mrb_value self)
1282
1405
  {
1283
1406
  struct mrb_io *fptr;
@@ -1285,15 +1408,55 @@ mrb_io_sync(mrb_state *mrb, mrb_value self)
1285
1408
  return mrb_bool_value(fptr->sync);
1286
1409
  }
1287
1410
 
1411
+ #ifndef MRB_WITH_IO_PREAD_PWRITE
1412
+ # define mrb_io_pread mrb_notimplement_m
1413
+ # define mrb_io_pwrite mrb_notimplement_m
1414
+ #else
1415
+ static off_t
1416
+ value2off(mrb_state *mrb, mrb_value offv)
1417
+ {
1418
+ return (off_t)mrb_int(mrb, offv);
1419
+ }
1420
+
1421
+ /*
1422
+ * call-seq:
1423
+ * pread(maxlen, offset, outbuf = "") -> outbuf
1424
+ */
1425
+ static mrb_value
1426
+ mrb_io_pread(mrb_state *mrb, mrb_value io)
1427
+ {
1428
+ mrb_value buf = mrb_nil_value();
1429
+ mrb_value off;
1430
+ mrb_int maxlen;
1431
+
1432
+ mrb_get_args(mrb, "io|S!", &maxlen, &off, &buf);
1433
+
1434
+ return mrb_io_sysread_common(mrb, pread, io, buf, maxlen, value2off(mrb, off));
1435
+ }
1436
+
1437
+ /*
1438
+ * call-seq:
1439
+ * pwrite(buffer, offset) -> wrote_bytes
1440
+ */
1288
1441
  static mrb_value
1289
- io_bufread(mrb_state *mrb, mrb_value self)
1442
+ mrb_io_pwrite(mrb_state *mrb, mrb_value io)
1290
1443
  {
1291
- mrb_value str, str2;
1292
- mrb_int len, newlen;
1444
+ mrb_value buf, off;
1445
+
1446
+ mrb_get_args(mrb, "So", &buf, &off);
1447
+
1448
+ return mrb_io_syswrite_common(mrb, pwrite, io, buf, value2off(mrb, off));
1449
+ }
1450
+ #endif /* MRB_WITH_IO_PREAD_PWRITE */
1451
+
1452
+ static mrb_value
1453
+ io_bufread(mrb_state *mrb, mrb_value str, mrb_int len)
1454
+ {
1455
+ mrb_value str2;
1456
+ mrb_int newlen;
1293
1457
  struct RString *s;
1294
1458
  char *p;
1295
1459
 
1296
- mrb_get_args(mrb, "Si", &str, &len);
1297
1460
  s = RSTRING(str);
1298
1461
  mrb_str_modify(mrb, s);
1299
1462
  p = RSTR_PTR(s);
@@ -1306,6 +1469,54 @@ io_bufread(mrb_state *mrb, mrb_value self)
1306
1469
  return str2;
1307
1470
  }
1308
1471
 
1472
+ static mrb_value
1473
+ mrb_io_bufread(mrb_state *mrb, mrb_value self)
1474
+ {
1475
+ mrb_value str;
1476
+ mrb_int len;
1477
+
1478
+ mrb_get_args(mrb, "Si", &str, &len);
1479
+ return io_bufread(mrb, str, len);
1480
+ }
1481
+
1482
+ static mrb_value
1483
+ mrb_io_readchar(mrb_state *mrb, mrb_value self)
1484
+ {
1485
+ mrb_value buf;
1486
+ mrb_int len = 1;
1487
+ #ifdef MRB_UTF8_STRING
1488
+ unsigned char c;
1489
+ #endif
1490
+
1491
+ mrb_get_args(mrb, "S", &buf);
1492
+ mrb_assert(RSTRING_LEN(buf) > 0);
1493
+ mrb_assert(RSTRING_PTR(buf) != NULL);
1494
+ mrb_str_modify(mrb, RSTRING(buf));
1495
+ #ifdef MRB_UTF8_STRING
1496
+ c = RSTRING_PTR(buf)[0];
1497
+ if (c & 0x80) {
1498
+ len = mrb_utf8len(RSTRING_PTR(buf), RSTRING_END(buf));
1499
+ if (len == 1 && RSTRING_LEN(buf) < 4) { /* partial UTF-8 */
1500
+ mrb_int blen = RSTRING_LEN(buf);
1501
+ ssize_t n;
1502
+
1503
+ struct mrb_io *fptr = (struct mrb_io*)io_get_open_fptr(mrb, self);
1504
+
1505
+ if (!fptr->readable) {
1506
+ mrb_raise(mrb, E_IO_ERROR, "not opened for reading");
1507
+ }
1508
+ /* refill the buffer */
1509
+ mrb_str_resize(mrb, buf, 4096);
1510
+ n = read(fptr->fd, RSTRING_PTR(buf)+blen, 4096-blen);
1511
+ if (n < 0) mrb_sys_fail(mrb, "sysread failed");
1512
+ mrb_str_resize(mrb, buf, blen+n);
1513
+ }
1514
+ len = mrb_utf8len(RSTRING_PTR(buf), RSTRING_END(buf));
1515
+ }
1516
+ #endif
1517
+ return io_bufread(mrb, buf, len);
1518
+ }
1519
+
1309
1520
  void
1310
1521
  mrb_init_io(mrb_state *mrb)
1311
1522
  {
@@ -1340,6 +1551,9 @@ mrb_init_io(mrb_state *mrb)
1340
1551
  mrb_define_method(mrb, io, "closed?", mrb_io_closed, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
1341
1552
  mrb_define_method(mrb, io, "pid", mrb_io_pid, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
1342
1553
  mrb_define_method(mrb, io, "fileno", mrb_io_fileno_m, MRB_ARGS_NONE());
1554
+ mrb_define_method(mrb, io, "pread", mrb_io_pread, MRB_ARGS_ANY()); /* ruby 2.5 feature */
1555
+ mrb_define_method(mrb, io, "pwrite", mrb_io_pwrite, MRB_ARGS_ANY()); /* ruby 2.5 feature */
1343
1556
 
1344
- mrb_define_class_method(mrb, io, "_bufread", io_bufread, MRB_ARGS_REQ(2));
1557
+ mrb_define_method(mrb, io, "_readchar", mrb_io_readchar, MRB_ARGS_REQ(1));
1558
+ mrb_define_class_method(mrb, io, "_bufread", mrb_io_bufread, MRB_ARGS_REQ(2));
1345
1559
  }