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
@@ -5,14 +5,8 @@
5
5
 
6
6
  spec.cc.include_paths << "#{build.root}/src"
7
7
 
8
- case RUBY_PLATFORM
9
- when /mingw|mswin|msys/
10
- spec.linker.libraries += ['Ws2_32']
11
- #spec.cc.include_paths += ["C:/Windows/system/include"]
12
- spec.linker.library_paths += ["C:/Windows/system"]
13
- end
14
- if build.kind_of?(MRuby::CrossBuild) && %w(x86_64-w64-mingw32 i686-w64-mingw32).include?(build.host_target)
15
- spec.linker.libraries += ['ws2_32']
8
+ if for_windows?
9
+ spec.linker.libraries << "ws2_32"
16
10
  end
17
11
  spec.add_test_dependency 'mruby-time', core: 'mruby-time'
18
12
  end
@@ -1,21 +1,5 @@
1
1
  class File
2
2
  module Constants
3
- RDONLY = 0
4
- WRONLY = 1
5
- RDWR = 2
6
- NONBLOCK = 4
7
- APPEND = 8
8
-
9
- BINARY = 0
10
- SYNC = 128
11
- NOFOLLOW = 256
12
- CREAT = 512
13
- TRUNC = 1024
14
- EXCL = 2048
15
-
16
- NOCTTY = 131072
17
- DSYNC = 4194304
18
-
19
3
  FNM_SYSCASE = 0
20
4
  FNM_NOESCAPE = 1
21
5
  FNM_PATHNAME = 2
@@ -170,21 +170,16 @@ def seek(i, whence = SEEK_SET)
170
170
  end
171
171
 
172
172
  def _read_buf
173
- return @buf if @buf && @buf.bytesize >= 4 # maximum UTF-8 character is 4 bytes
174
- @buf ||= ""
175
- begin
176
- @buf += sysread(BUF_SIZE)
177
- rescue EOFError => e
178
- raise e if @buf.empty?
179
- end
173
+ return @buf if @buf && @buf.bytesize > 0
174
+ sysread(BUF_SIZE, @buf)
180
175
  end
181
176
 
182
177
  def ungetc(substr)
183
178
  raise TypeError.new "expect String, got #{substr.class}" unless substr.is_a?(String)
184
179
  if @buf.empty?
185
- @buf = substr.dup
180
+ @buf.replace(substr)
186
181
  else
187
- @buf = substr + @buf
182
+ @buf[0,0] = substr
188
183
  end
189
184
  nil
190
185
  end
@@ -288,15 +283,15 @@ def gets(*args)
288
283
 
289
284
  def readchar
290
285
  _read_buf
291
- c = @buf[0]
292
- @buf[0] = ""
293
- c
286
+ _readchar(@buf)
294
287
  end
295
288
 
296
289
  def getc
297
290
  begin
298
291
  readchar
299
292
  rescue EOFError
293
+ c = @buf[0]
294
+ @buf[0,1]="" if c
300
295
  nil
301
296
  end
302
297
  end
@@ -48,6 +48,7 @@
48
48
  #if defined(_WIN32) || defined(_WIN64)
49
49
  #define PATH_SEPARATOR ";"
50
50
  #define FILE_ALT_SEPARATOR "\\"
51
+ #define VOLUME_SEPARATOR ":"
51
52
  #else
52
53
  #define PATH_SEPARATOR ":"
53
54
  #endif
@@ -88,7 +89,7 @@ flock(int fd, int operation) {
88
89
  }
89
90
  #endif
90
91
 
91
- mrb_value
92
+ static mrb_value
92
93
  mrb_file_s_umask(mrb_state *mrb, mrb_value klass)
93
94
  {
94
95
  #if defined(_WIN32) || defined(_WIN64)
@@ -264,7 +265,7 @@ mrb_file_realpath(mrb_state *mrb, mrb_value klass)
264
265
  return result;
265
266
  }
266
267
 
267
- mrb_value
268
+ static mrb_value
268
269
  mrb_file__getwd(mrb_state *mrb, mrb_value klass)
269
270
  {
270
271
  mrb_value path;
@@ -279,12 +280,59 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass)
279
280
  return path;
280
281
  }
281
282
 
283
+ #ifdef _WIN32
284
+ #define IS_FILESEP(x) (x == (*(char*)(FILE_SEPARATOR)) || x == (*(char*)(FILE_ALT_SEPARATOR)))
285
+ #define IS_VOLSEP(x) (x == (*(char*)(VOLUME_SEPARATOR)))
286
+ #define IS_DEVICEID(x) (x == '.' || x == '?')
287
+ #define CHECK_UNCDEV_PATH (IS_FILESEP(path[0]) && IS_FILESEP(path[1]))
288
+
289
+ static int
290
+ is_absolute_traditional_path(const char *path, size_t len)
291
+ {
292
+ if (len < 3) return 0;
293
+ return (ISALPHA(path[0]) && IS_VOLSEP(path[1]) && IS_FILESEP(path[2]));
294
+ }
295
+
296
+ static int
297
+ is_aboslute_unc_path(const char *path, size_t len) {
298
+ if (len < 2) return 0;
299
+ return (CHECK_UNCDEV_PATH && !IS_DEVICEID(path[2]));
300
+ }
301
+
302
+ static int
303
+ is_absolute_device_path(const char *path, size_t len) {
304
+ if (len < 4) return 0;
305
+ return (CHECK_UNCDEV_PATH && IS_DEVICEID(path[2]) && IS_FILESEP(path[3]));
306
+ }
307
+
282
308
  static int
283
309
  mrb_file_is_absolute_path(const char *path)
284
310
  {
285
- return (path[0] == '/');
311
+ size_t len = strlen(path);
312
+ if (IS_FILESEP(path[0])) return 1;
313
+ if (len > 0)
314
+ return (
315
+ is_absolute_traditional_path(path, len) ||
316
+ is_aboslute_unc_path(path, len) ||
317
+ is_absolute_device_path(path, len)
318
+ );
319
+ else
320
+ return 0;
286
321
  }
287
322
 
323
+ #undef IS_FILESEP
324
+ #undef IS_VOLSEP
325
+ #undef IS_DEVICEID
326
+ #undef CHECK_UNCDEV_PATH
327
+
328
+ #else
329
+ static int
330
+ mrb_file_is_absolute_path(const char *path)
331
+ {
332
+ return (path[0] == *(char*)(FILE_SEPARATOR));
333
+ }
334
+ #endif
335
+
288
336
  static mrb_value
289
337
  mrb_file__gethome(mrb_state *mrb, mrb_value klass)
290
338
  {
@@ -319,7 +367,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
319
367
  path = mrb_str_new_cstr(mrb, home);
320
368
  mrb_locale_free(home);
321
369
  return path;
322
- #else
370
+ #else /* _WIN32 */
323
371
  argc = mrb_get_argc(mrb);
324
372
  if (argc == 0) {
325
373
  home = getenv("USERPROFILE");
@@ -353,7 +401,7 @@ mrb_file_mtime(mrb_state *mrb, mrb_value self)
353
401
  return mrb_funcall(mrb, obj, "at", 1, mrb_fixnum_value(st.st_mtime));
354
402
  }
355
403
 
356
- mrb_value
404
+ static mrb_value
357
405
  mrb_file_flock(mrb_state *mrb, mrb_value self)
358
406
  {
359
407
  #if defined(sun)
@@ -402,15 +450,15 @@ mrb_file_size(mrb_state *mrb, mrb_value self)
402
450
  #ifdef MRB_WITHOUT_FLOAT
403
451
  mrb_raise(mrb, E_RUNTIME_ERROR, "File#size too large for MRB_WITHOUT_FLOAT");
404
452
  #else
405
- return mrb_float_value(mrb, st.st_size);
453
+ return mrb_float_value(mrb, (mrb_float)st.st_size);
406
454
  #endif
407
455
  }
408
456
 
409
- return mrb_fixnum_value(st.st_size);
457
+ return mrb_fixnum_value((mrb_int)st.st_size);
410
458
  }
411
459
 
412
460
  static int
413
- mrb_ftruncate(int fd, int64_t length)
461
+ mrb_ftruncate(int fd, mrb_int length)
414
462
  {
415
463
  #ifndef _WIN32
416
464
  return ftruncate(fd, (off_t)length);
@@ -443,32 +491,11 @@ static mrb_value
443
491
  mrb_file_truncate(mrb_state *mrb, mrb_value self)
444
492
  {
445
493
  int fd;
446
- int64_t length;
447
- mrb_value lenv;
494
+ mrb_int length;
495
+ mrb_value lenv = mrb_get_arg1(mrb);
448
496
 
449
497
  fd = mrb_io_fileno(mrb, self);
450
- mrb_get_args(mrb, "o", &lenv);
451
- switch (mrb_type(lenv)) {
452
- #ifndef MRB_WITHOUT_FLOAT
453
- case MRB_TT_FLOAT:
454
- {
455
- mrb_float lenf = mrb_float(lenv);
456
- if (lenf > INT64_MAX) {
457
- mrb_raise(mrb, E_ARGUMENT_ERROR, "length too large");
458
- }
459
- length = (int64_t)lenf;
460
- }
461
- break;
462
- #endif
463
- case MRB_TT_FIXNUM:
464
- default:
465
- {
466
- mrb_int leni = mrb_int(mrb, lenv);
467
- length = (int64_t)leni;
468
- }
469
- break;
470
- }
471
-
498
+ length = mrb_int(mrb, lenv);
472
499
  if (mrb_ftruncate(fd, length) != 0) {
473
500
  mrb_raise(mrb, E_IO_ERROR, "ftruncate failed");
474
501
  }
@@ -599,4 +626,22 @@ mrb_init_file(mrb_state *mrb)
599
626
  #endif
600
627
  mrb_define_const(mrb, cnst, "NULL", mrb_str_new_cstr(mrb, NULL_FILE));
601
628
 
629
+ mrb_define_const(mrb, cnst, "RDONLY", mrb_fixnum_value(MRB_O_RDONLY));
630
+ mrb_define_const(mrb, cnst, "WRONLY", mrb_fixnum_value(MRB_O_WRONLY));
631
+ mrb_define_const(mrb, cnst, "RDWR", mrb_fixnum_value(MRB_O_RDWR));
632
+ mrb_define_const(mrb, cnst, "APPEND", mrb_fixnum_value(MRB_O_APPEND));
633
+ mrb_define_const(mrb, cnst, "CREAT", mrb_fixnum_value(MRB_O_CREAT));
634
+ mrb_define_const(mrb, cnst, "EXCL", mrb_fixnum_value(MRB_O_EXCL));
635
+ mrb_define_const(mrb, cnst, "TRUNC", mrb_fixnum_value(MRB_O_TRUNC));
636
+ mrb_define_const(mrb, cnst, "NONBLOCK", mrb_fixnum_value(MRB_O_NONBLOCK));
637
+ mrb_define_const(mrb, cnst, "NOCTTY", mrb_fixnum_value(MRB_O_NOCTTY));
638
+ mrb_define_const(mrb, cnst, "BINARY", mrb_fixnum_value(MRB_O_BINARY));
639
+ mrb_define_const(mrb, cnst, "SHARE_DELETE", mrb_fixnum_value(MRB_O_SHARE_DELETE));
640
+ mrb_define_const(mrb, cnst, "SYNC", mrb_fixnum_value(MRB_O_SYNC));
641
+ mrb_define_const(mrb, cnst, "DSYNC", mrb_fixnum_value(MRB_O_DSYNC));
642
+ mrb_define_const(mrb, cnst, "RSYNC", mrb_fixnum_value(MRB_O_RSYNC));
643
+ mrb_define_const(mrb, cnst, "NOFOLLOW", mrb_fixnum_value(MRB_O_NOFOLLOW));
644
+ mrb_define_const(mrb, cnst, "NOATIME", mrb_fixnum_value(MRB_O_NOATIME));
645
+ mrb_define_const(mrb, cnst, "DIRECT", mrb_fixnum_value(MRB_O_DIRECT));
646
+ mrb_define_const(mrb, cnst, "TMPFILE", mrb_fixnum_value(MRB_O_TMPFILE));
602
647
  }
@@ -28,7 +28,6 @@
28
28
  #include <fcntl.h>
29
29
 
30
30
  #include <errno.h>
31
- #include <stdio.h>
32
31
  #include <stdlib.h>
33
32
  #include <string.h>
34
33
 
@@ -86,7 +85,7 @@ mrb_lstat(mrb_state *mrb, mrb_value obj, struct stat *st)
86
85
  * File.directory?(".")
87
86
  */
88
87
 
89
- mrb_value
88
+ static mrb_value
90
89
  mrb_filetest_s_directory_p(mrb_state *mrb, mrb_value klass)
91
90
  {
92
91
  #ifndef S_ISDIR
@@ -94,9 +93,7 @@ mrb_filetest_s_directory_p(mrb_state *mrb, mrb_value klass)
94
93
  #endif
95
94
 
96
95
  struct stat st;
97
- mrb_value obj;
98
-
99
- mrb_get_args(mrb, "o", &obj);
96
+ mrb_value obj = mrb_get_arg1(mrb);
100
97
 
101
98
  if (mrb_stat(mrb, obj, &st) < 0)
102
99
  return mrb_false_value();
@@ -113,7 +110,7 @@ mrb_filetest_s_directory_p(mrb_state *mrb, mrb_value klass)
113
110
  * Returns <code>true</code> if the named file is a pipe.
114
111
  */
115
112
 
116
- mrb_value
113
+ static mrb_value
117
114
  mrb_filetest_s_pipe_p(mrb_state *mrb, mrb_value klass)
118
115
  {
119
116
  #if defined(_WIN32) || defined(_WIN64)
@@ -125,9 +122,7 @@ mrb_filetest_s_pipe_p(mrb_state *mrb, mrb_value klass)
125
122
  # endif
126
123
 
127
124
  struct stat st;
128
- mrb_value obj;
129
-
130
- mrb_get_args(mrb, "o", &obj);
125
+ mrb_value obj = mrb_get_arg1(mrb);
131
126
 
132
127
  if (mrb_stat(mrb, obj, &st) < 0)
133
128
  return mrb_false_value();
@@ -146,7 +141,7 @@ mrb_filetest_s_pipe_p(mrb_state *mrb, mrb_value klass)
146
141
  * Returns <code>true</code> if the named file is a symbolic link.
147
142
  */
148
143
 
149
- mrb_value
144
+ static mrb_value
150
145
  mrb_filetest_s_symlink_p(mrb_state *mrb, mrb_value klass)
151
146
  {
152
147
  #if defined(_WIN32) || defined(_WIN64)
@@ -168,9 +163,7 @@ mrb_filetest_s_symlink_p(mrb_state *mrb, mrb_value klass)
168
163
 
169
164
  #ifdef S_ISLNK
170
165
  struct stat st;
171
- mrb_value obj;
172
-
173
- mrb_get_args(mrb, "o", &obj);
166
+ mrb_value obj = mrb_get_arg1(mrb);
174
167
 
175
168
  if (mrb_lstat(mrb, obj, &st) == -1)
176
169
  return mrb_false_value();
@@ -189,7 +182,7 @@ mrb_filetest_s_symlink_p(mrb_state *mrb, mrb_value klass)
189
182
  * Returns <code>true</code> if the named file is a socket.
190
183
  */
191
184
 
192
- mrb_value
185
+ static mrb_value
193
186
  mrb_filetest_s_socket_p(mrb_state *mrb, mrb_value klass)
194
187
  {
195
188
  #if defined(_WIN32) || defined(_WIN64)
@@ -211,9 +204,7 @@ mrb_filetest_s_socket_p(mrb_state *mrb, mrb_value klass)
211
204
 
212
205
  #ifdef S_ISSOCK
213
206
  struct stat st;
214
- mrb_value obj;
215
-
216
- mrb_get_args(mrb, "o", &obj);
207
+ mrb_value obj = mrb_get_arg1(mrb);
217
208
 
218
209
  if (mrb_stat(mrb, obj, &st) < 0)
219
210
  return mrb_false_value();
@@ -233,13 +224,12 @@ mrb_filetest_s_socket_p(mrb_state *mrb, mrb_value klass)
233
224
  * Return <code>true</code> if the named file exists.
234
225
  */
235
226
 
236
- mrb_value
227
+ static mrb_value
237
228
  mrb_filetest_s_exist_p(mrb_state *mrb, mrb_value klass)
238
229
  {
239
230
  struct stat st;
240
- mrb_value obj;
231
+ mrb_value obj = mrb_get_arg1(mrb);
241
232
 
242
- mrb_get_args(mrb, "o", &obj);
243
233
  if (mrb_stat(mrb, obj, &st) < 0)
244
234
  return mrb_false_value();
245
235
 
@@ -254,7 +244,7 @@ mrb_filetest_s_exist_p(mrb_state *mrb, mrb_value klass)
254
244
  * regular file.
255
245
  */
256
246
 
257
- mrb_value
247
+ static mrb_value
258
248
  mrb_filetest_s_file_p(mrb_state *mrb, mrb_value klass)
259
249
  {
260
250
  #ifndef S_ISREG
@@ -262,9 +252,7 @@ mrb_filetest_s_file_p(mrb_state *mrb, mrb_value klass)
262
252
  #endif
263
253
 
264
254
  struct stat st;
265
- mrb_value obj;
266
-
267
- mrb_get_args(mrb, "o", &obj);
255
+ mrb_value obj = mrb_get_arg1(mrb);
268
256
 
269
257
  if (mrb_stat(mrb, obj, &st) < 0)
270
258
  return mrb_false_value();
@@ -282,13 +270,11 @@ mrb_filetest_s_file_p(mrb_state *mrb, mrb_value klass)
282
270
  * a zero size.
283
271
  */
284
272
 
285
- mrb_value
273
+ static mrb_value
286
274
  mrb_filetest_s_zero_p(mrb_state *mrb, mrb_value klass)
287
275
  {
288
276
  struct stat st;
289
- mrb_value obj;
290
-
291
- mrb_get_args(mrb, "o", &obj);
277
+ mrb_value obj = mrb_get_arg1(mrb);
292
278
 
293
279
  if (mrb_stat(mrb, obj, &st) < 0)
294
280
  return mrb_false_value();
@@ -307,13 +293,11 @@ mrb_filetest_s_zero_p(mrb_state *mrb, mrb_value klass)
307
293
  * _file_name_ can be an IO object.
308
294
  */
309
295
 
310
- mrb_value
296
+ static mrb_value
311
297
  mrb_filetest_s_size(mrb_state *mrb, mrb_value klass)
312
298
  {
313
299
  struct stat st;
314
- mrb_value obj;
315
-
316
- mrb_get_args(mrb, "o", &obj);
300
+ mrb_value obj = mrb_get_arg1(mrb);
317
301
 
318
302
  if (mrb_stat(mrb, obj, &st) < 0)
319
303
  mrb_sys_fail(mrb, "mrb_stat");
@@ -329,13 +313,11 @@ mrb_filetest_s_size(mrb_state *mrb, mrb_value klass)
329
313
  * file otherwise.
330
314
  */
331
315
 
332
- mrb_value
316
+ static mrb_value
333
317
  mrb_filetest_s_size_p(mrb_state *mrb, mrb_value klass)
334
318
  {
335
319
  struct stat st;
336
- mrb_value obj;
337
-
338
- mrb_get_args(mrb, "o", &obj);
320
+ mrb_value obj = mrb_get_arg1(mrb);
339
321
 
340
322
  if (mrb_stat(mrb, obj, &st) < 0)
341
323
  return mrb_nil_value();
@@ -31,14 +31,21 @@
31
31
  typedef long ftime_t;
32
32
  typedef long fsuseconds_t;
33
33
  typedef int fmode_t;
34
+ typedef int mrb_io_read_write_size;
35
+
36
+ #ifndef O_TMPFILE
37
+ #define O_TMPFILE O_TEMPORARY
38
+ #endif
34
39
 
35
40
  #else
36
41
  #include <sys/wait.h>
42
+ #include <sys/time.h>
37
43
  #include <unistd.h>
38
44
  typedef size_t fsize_t;
39
45
  typedef time_t ftime_t;
40
46
  typedef suseconds_t fsuseconds_t;
41
47
  typedef mode_t fmode_t;
48
+ typedef ssize_t mrb_io_read_write_size;
42
49
  #endif
43
50
 
44
51
  #ifdef _MSC_VER
@@ -48,9 +55,14 @@ typedef mrb_int pid_t;
48
55
  #include <fcntl.h>
49
56
 
50
57
  #include <errno.h>
51
- #include <stdio.h>
52
58
  #include <string.h>
53
59
 
60
+ #define OPEN_ACCESS_MODE_FLAGS (O_RDONLY | O_WRONLY | O_RDWR)
61
+ #define OPEN_RDONLY_P(f) ((mrb_bool)(((f) & OPEN_ACCESS_MODE_FLAGS) == O_RDONLY))
62
+ #define OPEN_WRONLY_P(f) ((mrb_bool)(((f) & OPEN_ACCESS_MODE_FLAGS) == O_WRONLY))
63
+ #define OPEN_RDWR_P(f) ((mrb_bool)(((f) & OPEN_ACCESS_MODE_FLAGS) == O_RDWR))
64
+ #define OPEN_READABLE_P(f) ((mrb_bool)(OPEN_RDONLY_P(f) || OPEN_RDWR_P(f)))
65
+ #define OPEN_WRITABLE_P(f) ((mrb_bool)(OPEN_WRONLY_P(f) || OPEN_RDWR_P(f)))
54
66
 
55
67
  static void mrb_io_free(mrb_state *mrb, void *ptr);
56
68
  struct mrb_data_type mrb_io_type = { "IO", mrb_io_free };
@@ -58,7 +70,7 @@ struct mrb_data_type mrb_io_type = { "IO", mrb_io_free };
58
70
 
59
71
  static struct mrb_io *io_get_open_fptr(mrb_state *mrb, mrb_value self);
60
72
  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);
73
+ static int mrb_io_mode_to_flags(mrb_state *mrb, mrb_value mode);
62
74
  static void fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int quiet);
63
75
 
64
76
  static struct mrb_io *
@@ -100,30 +112,33 @@ io_set_process_status(mrb_state *mrb, pid_t pid, int status)
100
112
  static int
101
113
  mrb_io_modestr_to_flags(mrb_state *mrb, const char *mode)
102
114
  {
103
- int flags = 0;
115
+ int flags;
104
116
  const char *m = mode;
105
117
 
106
118
  switch (*m++) {
107
119
  case 'r':
108
- flags |= FMODE_READABLE;
120
+ flags = O_RDONLY;
109
121
  break;
110
122
  case 'w':
111
- flags |= FMODE_WRITABLE | FMODE_CREATE | FMODE_TRUNC;
123
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
112
124
  break;
113
125
  case 'a':
114
- flags |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE;
126
+ flags = O_WRONLY | O_CREAT | O_APPEND;
115
127
  break;
116
128
  default:
117
129
  mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode);
130
+ flags = 0; /* not reached */
118
131
  }
119
132
 
120
133
  while (*m) {
121
134
  switch (*m++) {
122
135
  case 'b':
123
- flags |= FMODE_BINMODE;
136
+ #ifdef O_BINARY
137
+ flags |= O_BINARY;
138
+ #endif
124
139
  break;
125
140
  case '+':
126
- flags |= FMODE_READWRITE;
141
+ flags = (flags & ~OPEN_ACCESS_MODE_FLAGS) | O_RDWR;
127
142
  break;
128
143
  case ':':
129
144
  /* XXX: PASSTHROUGH*/
@@ -136,38 +151,72 @@ mrb_io_modestr_to_flags(mrb_state *mrb, const char *mode)
136
151
  }
137
152
 
138
153
  static int
139
- mrb_io_flags_to_modenum(mrb_state *mrb, int flags)
154
+ mrb_io_mode_to_flags(mrb_state *mrb, mrb_value mode)
140
155
  {
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;
156
+ if (mrb_nil_p(mode)) {
157
+ return mrb_io_modestr_to_flags(mrb, "r");
160
158
  }
161
- if (flags & FMODE_CREATE) {
162
- modenum |= O_CREAT;
159
+ else if (mrb_string_p(mode)) {
160
+ return mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
163
161
  }
162
+ else {
163
+ int flags = 0;
164
+ mrb_int flags0 = mrb_int(mrb, mode);
165
+
166
+ switch (flags0 & MRB_O_ACCMODE) {
167
+ case MRB_O_RDONLY:
168
+ flags |= O_RDONLY;
169
+ break;
170
+ case MRB_O_WRONLY:
171
+ flags |= O_WRONLY;
172
+ break;
173
+ case MRB_O_RDWR:
174
+ flags |= O_RDWR;
175
+ break;
176
+ default:
177
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %v", mode);
178
+ }
179
+
180
+ if (flags0 & MRB_O_APPEND) flags |= O_APPEND;
181
+ if (flags0 & MRB_O_CREAT) flags |= O_CREAT;
182
+ if (flags0 & MRB_O_EXCL) flags |= O_EXCL;
183
+ if (flags0 & MRB_O_TRUNC) flags |= O_TRUNC;
184
+ #ifdef O_NONBLOCK
185
+ if (flags0 & MRB_O_NONBLOCK) flags |= O_NONBLOCK;
186
+ #endif
187
+ #ifdef O_NOCTTY
188
+ if (flags0 & MRB_O_NOCTTY) flags |= O_NOCTTY;
189
+ #endif
164
190
  #ifdef O_BINARY
165
- if (flags & FMODE_BINMODE) {
166
- modenum |= O_BINARY;
167
- }
191
+ if (flags0 & MRB_O_BINARY) flags |= O_BINARY;
192
+ #endif
193
+ #ifdef O_SHARE_DELETE
194
+ if (flags0 & MRB_O_SHARE_DELETE) flags |= O_SHARE_DELETE;
195
+ #endif
196
+ #ifdef O_SYNC
197
+ if (flags0 & MRB_O_SYNC) flags |= O_SYNC;
198
+ #endif
199
+ #ifdef O_DSYNC
200
+ if (flags0 & MRB_O_DSYNC) flags |= O_DSYNC;
201
+ #endif
202
+ #ifdef O_RSYNC
203
+ if (flags0 & MRB_O_RSYNC) flags |= O_RSYNC;
204
+ #endif
205
+ #ifdef O_NOFOLLOW
206
+ if (flags0 & MRB_O_NOFOLLOW) flags |= O_NOFOLLOW;
207
+ #endif
208
+ #ifdef O_NOATIME
209
+ if (flags0 & MRB_O_NOATIME) flags |= O_NOATIME;
210
+ #endif
211
+ #ifdef O_DIRECT
212
+ if (flags0 & MRB_O_DIRECT) flags |= O_DIRECT;
213
+ #endif
214
+ #ifdef O_TMPFILE
215
+ if (flags0 & MRB_O_TMPFILE) flags |= O_TMPFILE;
168
216
  #endif
169
217
 
170
- return modenum;
218
+ return flags;
219
+ }
171
220
  }
172
221
 
173
222
  static void
@@ -292,7 +341,7 @@ option_to_fd(mrb_state *mrb, mrb_value hash, const char *key)
292
341
  }
293
342
 
294
343
  #ifdef _WIN32
295
- mrb_value
344
+ static mrb_value
296
345
  mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
297
346
  {
298
347
  mrb_value cmd, io;
@@ -317,11 +366,11 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
317
366
  ofd[0] = INVALID_HANDLE_VALUE;
318
367
  ofd[1] = INVALID_HANDLE_VALUE;
319
368
 
320
- mrb_get_args(mrb, "S|SH", &cmd, &mode, &opt);
369
+ mrb_get_args(mrb, "S|oH", &cmd, &mode, &opt);
321
370
  io = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
322
371
 
323
372
  pname = RSTRING_CSTR(mrb, cmd);
324
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
373
+ flags = mrb_io_mode_to_flags(mrb, mode);
325
374
 
326
375
  doexec = (strcmp("-", pname) != 0);
327
376
  opt_in = option_to_fd(mrb, opt, "in");
@@ -332,14 +381,14 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
332
381
  saAttr.bInheritHandle = TRUE;
333
382
  saAttr.lpSecurityDescriptor = NULL;
334
383
 
335
- if (flags & FMODE_READABLE) {
384
+ if (OPEN_READABLE_P(flags)) {
336
385
  if (!CreatePipe(&ofd[0], &ofd[1], &saAttr, 0)
337
386
  || !SetHandleInformation(ofd[0], HANDLE_FLAG_INHERIT, 0)) {
338
387
  mrb_sys_fail(mrb, "pipe");
339
388
  }
340
389
  }
341
390
 
342
- if (flags & FMODE_WRITABLE) {
391
+ if (OPEN_WRITABLE_P(flags)) {
343
392
  if (!CreatePipe(&ifd[0], &ifd[1], &saAttr, 0)
344
393
  || !SetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0)) {
345
394
  mrb_sys_fail(mrb, "pipe");
@@ -353,11 +402,11 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
353
402
  si.dwFlags |= STARTF_USESHOWWINDOW;
354
403
  si.wShowWindow = SW_HIDE;
355
404
  si.dwFlags |= STARTF_USESTDHANDLES;
356
- if (flags & FMODE_READABLE) {
405
+ if (OPEN_READABLE_P(flags)) {
357
406
  si.hStdOutput = ofd[1];
358
407
  si.hStdError = ofd[1];
359
408
  }
360
- if (flags & FMODE_WRITABLE) {
409
+ if (OPEN_WRITABLE_P(flags)) {
361
410
  si.hStdInput = ifd[0];
362
411
  }
363
412
  if (!CreateProcess(
@@ -381,8 +430,8 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
381
430
  fptr->fd = _open_osfhandle((intptr_t)ofd[0], 0);
382
431
  fptr->fd2 = _open_osfhandle((intptr_t)ifd[1], 0);
383
432
  fptr->pid = pid;
384
- fptr->readable = ((flags & FMODE_READABLE) != 0);
385
- fptr->writable = ((flags & FMODE_WRITABLE) != 0);
433
+ fptr->readable = OPEN_READABLE_P(flags);
434
+ fptr->writable = OPEN_WRITABLE_P(flags);
386
435
  fptr->sync = 0;
387
436
 
388
437
  DATA_TYPE(io) = &mrb_io_type;
@@ -390,14 +439,14 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
390
439
  return io;
391
440
  }
392
441
  #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
393
- mrb_value
442
+ static mrb_value
394
443
  mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
395
444
  {
396
445
  mrb_raise(mrb, E_NOTIMP_ERROR, "IO#popen is not supported on the platform");
397
446
  return mrb_false_value();
398
447
  }
399
448
  #else
400
- mrb_value
449
+ static mrb_value
401
450
  mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
402
451
  {
403
452
  mrb_value cmd, io, result;
@@ -413,18 +462,18 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
413
462
  int saved_errno;
414
463
  int opt_in, opt_out, opt_err;
415
464
 
416
- mrb_get_args(mrb, "S|SH", &cmd, &mode, &opt);
465
+ mrb_get_args(mrb, "S|oH", &cmd, &mode, &opt);
417
466
  io = mrb_obj_value(mrb_data_object_alloc(mrb, mrb_class_ptr(klass), NULL, &mrb_io_type));
418
467
 
419
468
  pname = RSTRING_CSTR(mrb, cmd);
420
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
469
+ flags = mrb_io_mode_to_flags(mrb, mode);
421
470
 
422
471
  doexec = (strcmp("-", pname) != 0);
423
472
  opt_in = option_to_fd(mrb, opt, "in");
424
473
  opt_out = option_to_fd(mrb, opt, "out");
425
474
  opt_err = option_to_fd(mrb, opt, "err");
426
475
 
427
- if (flags & FMODE_READABLE) {
476
+ if (OPEN_READABLE_P(flags)) {
428
477
  if (pipe(pr) == -1) {
429
478
  mrb_sys_fail(mrb, "pipe");
430
479
  }
@@ -432,7 +481,7 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
432
481
  mrb_fd_cloexec(mrb, pr[1]);
433
482
  }
434
483
 
435
- if (flags & FMODE_WRITABLE) {
484
+ if (OPEN_WRITABLE_P(flags)) {
436
485
  if (pipe(pw) == -1) {
437
486
  if (pr[0] != -1) close(pr[0]);
438
487
  if (pr[1] != -1) close(pr[1]);
@@ -461,14 +510,14 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
461
510
  if (opt_err != -1) {
462
511
  dup2(opt_err, 2);
463
512
  }
464
- if (flags & FMODE_READABLE) {
513
+ if (OPEN_READABLE_P(flags)) {
465
514
  close(pr[0]);
466
515
  if (pr[1] != 1) {
467
516
  dup2(pr[1], 1);
468
517
  close(pr[1]);
469
518
  }
470
519
  }
471
- if (flags & FMODE_WRITABLE) {
520
+ if (OPEN_WRITABLE_P(flags)) {
472
521
  close(pw[1]);
473
522
  if (pw[0] != 0) {
474
523
  dup2(pw[0], 0);
@@ -487,12 +536,12 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
487
536
  break;
488
537
 
489
538
  default: /* parent */
490
- if ((flags & FMODE_READABLE) && (flags & FMODE_WRITABLE)) {
539
+ if (OPEN_RDWR_P(flags)) {
491
540
  close(pr[1]);
492
541
  fd = pr[0];
493
542
  close(pw[0]);
494
543
  write_fd = pw[1];
495
- } else if (flags & FMODE_READABLE) {
544
+ } else if (OPEN_RDONLY_P(flags)) {
496
545
  close(pr[1]);
497
546
  fd = pr[0];
498
547
  } else {
@@ -506,8 +555,8 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
506
555
  fptr->fd = fd;
507
556
  fptr->fd2 = write_fd;
508
557
  fptr->pid = pid;
509
- fptr->readable = ((flags & FMODE_READABLE) != 0);
510
- fptr->writable = ((flags & FMODE_WRITABLE) != 0);
558
+ fptr->readable = OPEN_READABLE_P(flags);
559
+ fptr->writable = OPEN_WRITABLE_P(flags);
511
560
  fptr->sync = 0;
512
561
 
513
562
  DATA_TYPE(io) = &mrb_io_type;
@@ -517,11 +566,11 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
517
566
 
518
567
  case -1: /* error */
519
568
  saved_errno = errno;
520
- if (flags & FMODE_READABLE) {
569
+ if (OPEN_READABLE_P(flags)) {
521
570
  close(pr[0]);
522
571
  close(pr[1]);
523
572
  }
524
- if (flags & FMODE_WRITABLE) {
573
+ if (OPEN_WRITABLE_P(flags)) {
525
574
  close(pw[0]);
526
575
  close(pw[1]);
527
576
  }
@@ -547,16 +596,15 @@ mrb_dup(mrb_state *mrb, int fd, mrb_bool *failed)
547
596
  return new_fd;
548
597
  }
549
598
 
550
- mrb_value
599
+ static mrb_value
551
600
  mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
552
601
  {
553
- mrb_value orig;
602
+ mrb_value orig = mrb_get_arg1(mrb);
554
603
  mrb_value buf;
555
604
  struct mrb_io *fptr_copy;
556
605
  struct mrb_io *fptr_orig;
557
606
  mrb_bool failed = TRUE;
558
607
 
559
- mrb_get_args(mrb, "o", &orig);
560
608
  fptr_orig = io_get_open_fptr(mrb, orig);
561
609
  fptr_copy = (struct mrb_io *)DATA_PTR(copy);
562
610
  if (fptr_orig == fptr_copy) return copy;
@@ -596,7 +644,44 @@ mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
596
644
  return copy;
597
645
  }
598
646
 
599
- mrb_value
647
+ static void
648
+ check_file_descriptor(mrb_state *mrb, mrb_int fd)
649
+ {
650
+ struct stat sb;
651
+ int fdi = (int)fd;
652
+
653
+ #if MRB_INT_MIN < INT_MIN || MRB_INT_MAX > INT_MAX
654
+ if (fdi != fd) {
655
+ goto badfd;
656
+ }
657
+ #endif
658
+
659
+ #ifdef _WIN32
660
+ {
661
+ DWORD err;
662
+ int len = sizeof(err);
663
+
664
+ if (getsockopt(fdi, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0) {
665
+ return;
666
+ }
667
+ }
668
+
669
+ if (fdi < 0 || fdi > _getmaxstdio()) {
670
+ goto badfd;
671
+ }
672
+ #endif /* _WIN32 */
673
+
674
+ if (fstat(fdi, &sb) != 0) {
675
+ goto badfd;
676
+ }
677
+
678
+ return;
679
+
680
+ badfd:
681
+ mrb_sys_fail(mrb, "bad file descriptor");
682
+ }
683
+
684
+ static mrb_value
600
685
  mrb_io_initialize(mrb_state *mrb, mrb_value io)
601
686
  {
602
687
  struct mrb_io *fptr;
@@ -606,7 +691,8 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
606
691
 
607
692
  mode = opt = mrb_nil_value();
608
693
 
609
- mrb_get_args(mrb, "i|So", &fd, &mode, &opt);
694
+ mrb_get_args(mrb, "i|oo", &fd, &mode, &opt);
695
+ check_file_descriptor(mrb, fd);
610
696
  if (mrb_nil_p(mode)) {
611
697
  mode = mrb_str_new_cstr(mrb, "r");
612
698
  }
@@ -614,7 +700,7 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
614
700
  opt = mrb_hash_new(mrb);
615
701
  }
616
702
 
617
- flags = mrb_io_modestr_to_flags(mrb, RSTRING_CSTR(mrb, mode));
703
+ flags = mrb_io_mode_to_flags(mrb, mode);
618
704
 
619
705
  mrb_iv_set(mrb, io, mrb_intern_cstr(mrb, "@buf"), mrb_str_new_cstr(mrb, ""));
620
706
 
@@ -629,8 +715,8 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
629
715
  DATA_PTR(io) = fptr;
630
716
 
631
717
  fptr->fd = (int)fd;
632
- fptr->readable = ((flags & FMODE_READABLE) != 0);
633
- fptr->writable = ((flags & FMODE_WRITABLE) != 0);
718
+ fptr->readable = OPEN_READABLE_P(flags);
719
+ fptr->writable = OPEN_WRITABLE_P(flags);
634
720
  fptr->sync = 0;
635
721
  return io;
636
722
  }
@@ -698,7 +784,7 @@ fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int quiet)
698
784
  }
699
785
  }
700
786
 
701
- mrb_value
787
+ static mrb_value
702
788
  mrb_io_check_readable(mrb_state *mrb, mrb_value self)
703
789
  {
704
790
  struct mrb_io *fptr = io_get_open_fptr(mrb, self);
@@ -708,7 +794,7 @@ mrb_io_check_readable(mrb_state *mrb, mrb_value self)
708
794
  return mrb_nil_value();
709
795
  }
710
796
 
711
- mrb_value
797
+ static mrb_value
712
798
  mrb_io_isatty(mrb_state *mrb, mrb_value self)
713
799
  {
714
800
  struct mrb_io *fptr;
@@ -719,7 +805,7 @@ mrb_io_isatty(mrb_state *mrb, mrb_value self)
719
805
  return mrb_true_value();
720
806
  }
721
807
 
722
- mrb_value
808
+ static mrb_value
723
809
  mrb_io_s_for_fd(mrb_state *mrb, mrb_value klass)
724
810
  {
725
811
  struct RClass *c = mrb_class_ptr(klass);
@@ -732,7 +818,7 @@ mrb_io_s_for_fd(mrb_state *mrb, mrb_value klass)
732
818
  return mrb_io_initialize(mrb, obj);
733
819
  }
734
820
 
735
- mrb_value
821
+ static mrb_value
736
822
  mrb_io_s_sysclose(mrb_state *mrb, mrb_value klass)
737
823
  {
738
824
  mrb_int fd;
@@ -743,7 +829,7 @@ mrb_io_s_sysclose(mrb_state *mrb, mrb_value klass)
743
829
  return mrb_fixnum_value(0);
744
830
  }
745
831
 
746
- int
832
+ static int
747
833
  mrb_cloexec_open(mrb_state *mrb, const char *pathname, mrb_int flags, mrb_int mode)
748
834
  {
749
835
  int fd, retry = FALSE;
@@ -778,39 +864,55 @@ reopen:
778
864
  return fd;
779
865
  }
780
866
 
781
- mrb_value
867
+ static mrb_value
782
868
  mrb_io_s_sysopen(mrb_state *mrb, mrb_value klass)
783
869
  {
784
870
  mrb_value path = mrb_nil_value();
785
871
  mrb_value mode = mrb_nil_value();
786
872
  mrb_int fd, perm = -1;
787
873
  const char *pat;
788
- int flags, modenum;
874
+ int flags;
789
875
 
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
- }
876
+ mrb_get_args(mrb, "S|oi", &path, &mode, &perm);
794
877
  if (perm < 0) {
795
878
  perm = 0666;
796
879
  }
797
880
 
798
881
  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);
882
+ flags = mrb_io_mode_to_flags(mrb, mode);
883
+ fd = mrb_cloexec_open(mrb, pat, flags, perm);
802
884
  return mrb_fixnum_value(fd);
803
885
  }
804
886
 
805
- mrb_value
887
+ static mrb_value mrb_io_sysread_common(mrb_state *mrb,
888
+ mrb_io_read_write_size (*readfunc)(int, void *, fsize_t, off_t),
889
+ mrb_value io, mrb_value buf, mrb_int maxlen, off_t offset);
890
+
891
+ static mrb_io_read_write_size
892
+ mrb_sysread_dummy(int fd, void *buf, fsize_t nbytes, off_t offset)
893
+ {
894
+ return (mrb_io_read_write_size)read(fd, buf, nbytes);
895
+ }
896
+
897
+ static mrb_value
806
898
  mrb_io_sysread(mrb_state *mrb, mrb_value io)
807
899
  {
808
- struct mrb_io *fptr;
809
900
  mrb_value buf = mrb_nil_value();
810
901
  mrb_int maxlen;
811
- int ret;
812
902
 
813
903
  mrb_get_args(mrb, "i|S", &maxlen, &buf);
904
+
905
+ return mrb_io_sysread_common(mrb, mrb_sysread_dummy, io, buf, maxlen, 0);
906
+ }
907
+
908
+ static mrb_value
909
+ mrb_io_sysread_common(mrb_state *mrb,
910
+ mrb_io_read_write_size (*readfunc)(int, void *, fsize_t, off_t),
911
+ mrb_value io, mrb_value buf, mrb_int maxlen, off_t offset)
912
+ {
913
+ struct mrb_io *fptr;
914
+ int ret;
915
+
814
916
  if (maxlen < 0) {
815
917
  mrb_raise(mrb, E_ARGUMENT_ERROR, "negative expanding string size");
816
918
  }
@@ -824,7 +926,8 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
824
926
 
825
927
  if (RSTRING_LEN(buf) != maxlen) {
826
928
  buf = mrb_str_resize(mrb, buf, maxlen);
827
- } else {
929
+ }
930
+ else {
828
931
  mrb_str_modify(mrb, RSTRING(buf));
829
932
  }
830
933
 
@@ -832,29 +935,20 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io)
832
935
  if (!fptr->readable) {
833
936
  mrb_raise(mrb, E_IO_ERROR, "not opened for reading");
834
937
  }
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;
938
+ ret = readfunc(fptr->fd, RSTRING_PTR(buf), (fsize_t)maxlen, offset);
939
+ if (ret < 0) {
940
+ mrb_sys_fail(mrb, "sysread failed");
941
+ }
942
+ if (RSTRING_LEN(buf) != ret) {
943
+ buf = mrb_str_resize(mrb, buf, ret);
944
+ }
945
+ if (ret == 0 && maxlen > 0) {
946
+ mrb_raise(mrb, E_EOF_ERROR, "sysread failed: End of File");
852
947
  }
853
-
854
948
  return buf;
855
949
  }
856
950
 
857
- mrb_value
951
+ static mrb_value
858
952
  mrb_io_sysseek(mrb_state *mrb, mrb_value io)
859
953
  {
860
954
  struct mrb_io *fptr;
@@ -882,11 +976,12 @@ mrb_io_sysseek(mrb_state *mrb, mrb_value io)
882
976
  }
883
977
  }
884
978
 
885
- mrb_value
886
- mrb_io_syswrite(mrb_state *mrb, mrb_value io)
979
+ static mrb_value
980
+ mrb_io_syswrite_common(mrb_state *mrb,
981
+ mrb_io_read_write_size (*writefunc)(int, const void *, fsize_t, off_t),
982
+ mrb_value io, mrb_value buf, off_t offset)
887
983
  {
888
984
  struct mrb_io *fptr;
889
- mrb_value str, buf;
890
985
  int fd, length;
891
986
 
892
987
  fptr = io_get_open_fptr(mrb, io);
@@ -894,15 +989,12 @@ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
894
989
  mrb_raise(mrb, E_IO_ERROR, "not opened for writing");
895
990
  }
896
991
 
897
- mrb_get_args(mrb, "S", &str);
898
- buf = str;
899
-
900
992
  if (fptr->fd2 == -1) {
901
993
  fd = fptr->fd;
902
994
  } else {
903
995
  fd = fptr->fd2;
904
996
  }
905
- length = write(fd, RSTRING_PTR(buf), (fsize_t)RSTRING_LEN(buf));
997
+ length = writefunc(fd, RSTRING_PTR(buf), (fsize_t)RSTRING_LEN(buf), offset);
906
998
  if (length == -1) {
907
999
  mrb_sys_fail(mrb, 0);
908
1000
  }
@@ -910,7 +1002,23 @@ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
910
1002
  return mrb_fixnum_value(length);
911
1003
  }
912
1004
 
913
- mrb_value
1005
+ static mrb_io_read_write_size
1006
+ mrb_syswrite_dummy(int fd, const void *buf, fsize_t nbytes, off_t offset)
1007
+ {
1008
+ return (mrb_io_read_write_size)write(fd, buf, nbytes);
1009
+ }
1010
+
1011
+ static mrb_value
1012
+ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
1013
+ {
1014
+ mrb_value buf;
1015
+
1016
+ mrb_get_args(mrb, "S", &buf);
1017
+
1018
+ return mrb_io_syswrite_common(mrb, mrb_syswrite_dummy, io, buf, 0);
1019
+ }
1020
+
1021
+ static mrb_value
914
1022
  mrb_io_close(mrb_state *mrb, mrb_value self)
915
1023
  {
916
1024
  struct mrb_io *fptr;
@@ -919,7 +1027,7 @@ mrb_io_close(mrb_state *mrb, mrb_value self)
919
1027
  return mrb_nil_value();
920
1028
  }
921
1029
 
922
- mrb_value
1030
+ static mrb_value
923
1031
  mrb_io_close_write(mrb_state *mrb, mrb_value self)
924
1032
  {
925
1033
  struct mrb_io *fptr;
@@ -930,7 +1038,7 @@ mrb_io_close_write(mrb_state *mrb, mrb_value self)
930
1038
  return mrb_nil_value();
931
1039
  }
932
1040
 
933
- mrb_value
1041
+ static mrb_value
934
1042
  mrb_io_closed(mrb_state *mrb, mrb_value io)
935
1043
  {
936
1044
  struct mrb_io *fptr;
@@ -942,7 +1050,7 @@ mrb_io_closed(mrb_state *mrb, mrb_value io)
942
1050
  return mrb_true_value();
943
1051
  }
944
1052
 
945
- mrb_value
1053
+ static mrb_value
946
1054
  mrb_io_pid(mrb_state *mrb, mrb_value io)
947
1055
  {
948
1056
  struct mrb_io *fptr;
@@ -1076,6 +1184,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1076
1184
  for (i = 0; i < RARRAY_LEN(read); i++) {
1077
1185
  read_io = RARRAY_PTR(read)[i];
1078
1186
  fptr = io_get_open_fptr(mrb, read_io);
1187
+ if (fptr->fd >= FD_SETSIZE) continue;
1079
1188
  FD_SET(fptr->fd, rp);
1080
1189
  if (mrb_io_read_data_pending(mrb, read_io)) {
1081
1190
  pending++;
@@ -1098,6 +1207,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1098
1207
  FD_ZERO(wp);
1099
1208
  for (i = 0; i < RARRAY_LEN(write); i++) {
1100
1209
  fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]);
1210
+ if (fptr->fd >= FD_SETSIZE) continue;
1101
1211
  FD_SET(fptr->fd, wp);
1102
1212
  if (max < fptr->fd)
1103
1213
  max = fptr->fd;
@@ -1117,6 +1227,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass)
1117
1227
  FD_ZERO(ep);
1118
1228
  for (i = 0; i < RARRAY_LEN(except); i++) {
1119
1229
  fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]);
1230
+ if (fptr->fd >= FD_SETSIZE) continue;
1120
1231
  FD_SET(fptr->fd, ep);
1121
1232
  if (max < fptr->fd)
1122
1233
  max = fptr->fd;
@@ -1205,7 +1316,7 @@ mrb_io_fileno_m(mrb_state *mrb, mrb_value io)
1205
1316
  return mrb_fixnum_value(fd);
1206
1317
  }
1207
1318
 
1208
- mrb_value
1319
+ static mrb_value
1209
1320
  mrb_io_close_on_exec_p(mrb_state *mrb, mrb_value self)
1210
1321
  {
1211
1322
  #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
@@ -1229,7 +1340,7 @@ mrb_io_close_on_exec_p(mrb_state *mrb, mrb_value self)
1229
1340
  #endif
1230
1341
  }
1231
1342
 
1232
- mrb_value
1343
+ static mrb_value
1233
1344
  mrb_io_set_close_on_exec(mrb_state *mrb, mrb_value self)
1234
1345
  {
1235
1346
  #if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
@@ -1265,7 +1376,7 @@ mrb_io_set_close_on_exec(mrb_state *mrb, mrb_value self)
1265
1376
  #endif
1266
1377
  }
1267
1378
 
1268
- mrb_value
1379
+ static mrb_value
1269
1380
  mrb_io_set_sync(mrb_state *mrb, mrb_value self)
1270
1381
  {
1271
1382
  struct mrb_io *fptr;
@@ -1277,7 +1388,7 @@ mrb_io_set_sync(mrb_state *mrb, mrb_value self)
1277
1388
  return mrb_bool_value(b);
1278
1389
  }
1279
1390
 
1280
- mrb_value
1391
+ static mrb_value
1281
1392
  mrb_io_sync(mrb_state *mrb, mrb_value self)
1282
1393
  {
1283
1394
  struct mrb_io *fptr;
@@ -1285,15 +1396,55 @@ mrb_io_sync(mrb_state *mrb, mrb_value self)
1285
1396
  return mrb_bool_value(fptr->sync);
1286
1397
  }
1287
1398
 
1399
+ #ifndef MRB_WITH_IO_PREAD_PWRITE
1400
+ # define mrb_io_pread mrb_notimplement_m
1401
+ # define mrb_io_pwrite mrb_notimplement_m
1402
+ #else
1403
+ static off_t
1404
+ value2off(mrb_state *mrb, mrb_value offv)
1405
+ {
1406
+ return (off_t)mrb_int(mrb, offv);
1407
+ }
1408
+
1409
+ /*
1410
+ * call-seq:
1411
+ * pread(maxlen, offset, outbuf = "") -> outbuf
1412
+ */
1413
+ static mrb_value
1414
+ mrb_io_pread(mrb_state *mrb, mrb_value io)
1415
+ {
1416
+ mrb_value buf = mrb_nil_value();
1417
+ mrb_value off;
1418
+ mrb_int maxlen;
1419
+
1420
+ mrb_get_args(mrb, "io|S!", &maxlen, &off, &buf);
1421
+
1422
+ return mrb_io_sysread_common(mrb, pread, io, buf, maxlen, value2off(mrb, off));
1423
+ }
1424
+
1425
+ /*
1426
+ * call-seq:
1427
+ * pwrite(buffer, offset) -> wrote_bytes
1428
+ */
1429
+ static mrb_value
1430
+ mrb_io_pwrite(mrb_state *mrb, mrb_value io)
1431
+ {
1432
+ mrb_value buf, off;
1433
+
1434
+ mrb_get_args(mrb, "So", &buf, &off);
1435
+
1436
+ return mrb_io_syswrite_common(mrb, pwrite, io, buf, value2off(mrb, off));
1437
+ }
1438
+ #endif /* MRB_WITH_IO_PREAD_PWRITE */
1439
+
1288
1440
  static mrb_value
1289
- io_bufread(mrb_state *mrb, mrb_value self)
1441
+ io_bufread(mrb_state *mrb, mrb_value str, mrb_int len)
1290
1442
  {
1291
- mrb_value str, str2;
1292
- mrb_int len, newlen;
1443
+ mrb_value str2;
1444
+ mrb_int newlen;
1293
1445
  struct RString *s;
1294
1446
  char *p;
1295
1447
 
1296
- mrb_get_args(mrb, "Si", &str, &len);
1297
1448
  s = RSTRING(str);
1298
1449
  mrb_str_modify(mrb, s);
1299
1450
  p = RSTR_PTR(s);
@@ -1306,6 +1457,54 @@ io_bufread(mrb_state *mrb, mrb_value self)
1306
1457
  return str2;
1307
1458
  }
1308
1459
 
1460
+ static mrb_value
1461
+ mrb_io_bufread(mrb_state *mrb, mrb_value self)
1462
+ {
1463
+ mrb_value str;
1464
+ mrb_int len;
1465
+
1466
+ mrb_get_args(mrb, "Si", &str, &len);
1467
+ return io_bufread(mrb, str, len);
1468
+ }
1469
+
1470
+ static mrb_value
1471
+ mrb_io_readchar(mrb_state *mrb, mrb_value self)
1472
+ {
1473
+ mrb_value buf;
1474
+ mrb_int len = 1;
1475
+ #ifdef MRB_UTF8_STRING
1476
+ unsigned char c;
1477
+ #endif
1478
+
1479
+ mrb_get_args(mrb, "S", &buf);
1480
+ mrb_assert(RSTRING_LEN(buf) > 0);
1481
+ mrb_assert(RSTRING_PTR(buf) != NULL);
1482
+ mrb_str_modify(mrb, RSTRING(buf));
1483
+ #ifdef MRB_UTF8_STRING
1484
+ c = RSTRING_PTR(buf)[0];
1485
+ if (c & 0x80) {
1486
+ len = mrb_utf8len(RSTRING_PTR(buf), RSTRING_END(buf));
1487
+ if (len == 1 && RSTRING_LEN(buf) < 4) { /* partial UTF-8 */
1488
+ mrb_int blen = RSTRING_LEN(buf);
1489
+ ssize_t n;
1490
+
1491
+ struct mrb_io *fptr = (struct mrb_io*)io_get_open_fptr(mrb, self);
1492
+
1493
+ if (!fptr->readable) {
1494
+ mrb_raise(mrb, E_IO_ERROR, "not opened for reading");
1495
+ }
1496
+ /* refill the buffer */
1497
+ mrb_str_resize(mrb, buf, 4096);
1498
+ n = read(fptr->fd, RSTRING_PTR(buf)+blen, 4096-blen);
1499
+ if (n < 0) mrb_sys_fail(mrb, "sysread failed");
1500
+ mrb_str_resize(mrb, buf, blen+n);
1501
+ }
1502
+ len = mrb_utf8len(RSTRING_PTR(buf), RSTRING_END(buf));
1503
+ }
1504
+ #endif
1505
+ return io_bufread(mrb, buf, len);
1506
+ }
1507
+
1309
1508
  void
1310
1509
  mrb_init_io(mrb_state *mrb)
1311
1510
  {
@@ -1340,6 +1539,9 @@ mrb_init_io(mrb_state *mrb)
1340
1539
  mrb_define_method(mrb, io, "closed?", mrb_io_closed, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
1341
1540
  mrb_define_method(mrb, io, "pid", mrb_io_pid, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
1342
1541
  mrb_define_method(mrb, io, "fileno", mrb_io_fileno_m, MRB_ARGS_NONE());
1542
+ mrb_define_method(mrb, io, "pread", mrb_io_pread, MRB_ARGS_ANY()); /* ruby 2.5 feature */
1543
+ mrb_define_method(mrb, io, "pwrite", mrb_io_pwrite, MRB_ARGS_ANY()); /* ruby 2.5 feature */
1343
1544
 
1344
- mrb_define_class_method(mrb, io, "_bufread", io_bufread, MRB_ARGS_REQ(2));
1545
+ mrb_define_method(mrb, io, "_readchar", mrb_io_readchar, MRB_ARGS_REQ(1));
1546
+ mrb_define_class_method(mrb, io, "_bufread", mrb_io_bufread, MRB_ARGS_REQ(2));
1345
1547
  }