script_core 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -1
  3. data/ext/enterprise_script_service/libseccomp/.travis.yml +3 -5
  4. data/ext/enterprise_script_service/libseccomp/CHANGELOG +10 -0
  5. data/ext/enterprise_script_service/libseccomp/CREDITS +3 -0
  6. data/ext/enterprise_script_service/libseccomp/README.md +18 -0
  7. data/ext/enterprise_script_service/libseccomp/configure.ac +1 -1
  8. data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +7 -0
  9. data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +16 -0
  10. data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +16 -0
  11. data/ext/enterprise_script_service/libseccomp/tests/.gitignore +1 -0
  12. data/ext/enterprise_script_service/libseccomp/tests/15-basic-resolver.c +3 -3
  13. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.c +48 -0
  14. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.py +38 -0
  15. data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.tests +11 -0
  16. data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +6 -3
  17. data/ext/enterprise_script_service/libseccomp/tests/regression +4 -0
  18. data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -3
  19. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +2 -0
  20. data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +106 -0
  21. data/ext/enterprise_script_service/mruby/.github/workflows/main.yml +24 -0
  22. data/ext/enterprise_script_service/mruby/.gitignore +3 -0
  23. data/ext/enterprise_script_service/mruby/.travis.yml +6 -9
  24. data/ext/enterprise_script_service/mruby/AUTHORS +1 -0
  25. data/ext/enterprise_script_service/mruby/Doxyfile +1 -1
  26. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  27. data/ext/enterprise_script_service/mruby/README.md +6 -2
  28. data/ext/enterprise_script_service/mruby/appveyor.yml +9 -12
  29. data/ext/enterprise_script_service/mruby/appveyor_config.rb +9 -0
  30. data/ext/enterprise_script_service/mruby/build_config.rb +6 -6
  31. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +6 -2
  32. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +1 -1
  33. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +4 -8
  34. data/ext/enterprise_script_service/mruby/doc/limitations.md +10 -10
  35. data/ext/enterprise_script_service/mruby/doc/opcode.md +108 -95
  36. data/ext/enterprise_script_service/mruby/examples/targets/build_config_ArduinoDue.rb +2 -2
  37. data/ext/enterprise_script_service/mruby/examples/targets/build_config_IntelEdison.rb +2 -2
  38. data/ext/enterprise_script_service/mruby/examples/targets/build_config_IntelGalileo.rb +2 -2
  39. data/ext/enterprise_script_service/mruby/examples/targets/build_config_RX630.rb +2 -2
  40. data/ext/enterprise_script_service/mruby/examples/targets/build_config_chipKITMax32.rb +2 -2
  41. data/ext/enterprise_script_service/mruby/examples/targets/build_config_dreamcast_shelf.rb +108 -0
  42. data/ext/enterprise_script_service/mruby/include/mrbconf.h +10 -7
  43. data/ext/enterprise_script_service/mruby/include/mruby.h +11 -9
  44. data/ext/enterprise_script_service/mruby/include/mruby/array.h +4 -0
  45. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +11 -2
  46. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +0 -9
  47. data/ext/enterprise_script_service/mruby/include/mruby/common.h +10 -0
  48. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +11 -3
  49. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +1 -17
  50. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +10 -0
  51. data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -1
  52. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +23 -5
  53. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +1 -0
  54. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +3 -2
  55. data/ext/enterprise_script_service/mruby/include/mruby/string.h +2 -1
  56. data/ext/enterprise_script_service/mruby/include/mruby/value.h +7 -12
  57. data/ext/enterprise_script_service/mruby/include/mruby/version.h +4 -4
  58. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +2 -30
  59. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +21 -46
  60. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +9 -0
  61. data/ext/enterprise_script_service/mruby/lib/mruby/source.rb +3 -1
  62. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +7 -0
  63. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +0 -31
  64. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +0 -13
  65. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +5 -2
  66. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +0 -1
  67. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +5 -1
  68. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +5 -1
  69. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +7 -11
  70. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +0 -1
  71. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +6 -2
  72. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +6 -2
  73. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +6 -1
  74. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +76 -48
  75. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +107 -32
  76. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +13153 -0
  77. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +13 -15
  78. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +3 -3
  79. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +2 -213
  80. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +21 -0
  81. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +1 -3
  82. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +39 -7
  83. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +2 -8
  84. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file_constants.rb +0 -16
  85. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +7 -12
  86. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +76 -30
  87. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +9 -10
  88. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +323 -120
  89. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +18 -12
  90. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +32 -0
  91. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +57 -49
  92. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +15 -17
  93. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +9 -0
  94. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +1 -1
  95. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +3 -12
  96. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +113 -10
  97. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +5 -1
  98. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +2 -2
  99. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +9 -9
  100. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +1 -1
  101. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/mrbgem.rake +1 -1
  102. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/sockettest.c +3 -2
  103. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +61 -24
  104. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +5 -23
  105. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +3 -3
  106. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +1 -1
  107. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +1 -0
  108. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +6 -5
  109. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +3 -3
  110. data/ext/enterprise_script_service/mruby/src/array.c +11 -0
  111. data/ext/enterprise_script_service/mruby/src/backtrace.c +2 -2
  112. data/ext/enterprise_script_service/mruby/src/class.c +26 -11
  113. data/ext/enterprise_script_service/mruby/src/codedump.c +4 -0
  114. data/ext/enterprise_script_service/mruby/src/debug.c +8 -5
  115. data/ext/enterprise_script_service/mruby/src/dump.c +3 -65
  116. data/ext/enterprise_script_service/mruby/src/error.c +57 -5
  117. data/ext/enterprise_script_service/mruby/src/etc.c +13 -4
  118. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +98 -21
  119. data/ext/enterprise_script_service/mruby/src/gc.c +10 -275
  120. data/ext/enterprise_script_service/mruby/src/hash.c +5 -6
  121. data/ext/enterprise_script_service/mruby/src/kernel.c +2 -2
  122. data/ext/enterprise_script_service/mruby/src/load.c +56 -30
  123. data/ext/enterprise_script_service/mruby/src/numeric.c +22 -10
  124. data/ext/enterprise_script_service/mruby/src/object.c +12 -4
  125. data/ext/enterprise_script_service/mruby/src/print.c +27 -3
  126. data/ext/enterprise_script_service/mruby/src/proc.c +21 -1
  127. data/ext/enterprise_script_service/mruby/src/state.c +34 -11
  128. data/ext/enterprise_script_service/mruby/src/string.c +69 -35
  129. data/ext/enterprise_script_service/mruby/src/symbol.c +12 -10
  130. data/ext/enterprise_script_service/mruby/src/vm.c +21 -30
  131. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +19 -22
  132. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +1 -1
  133. data/ext/enterprise_script_service/mruby/tasks/toolchains/android.rake +46 -1
  134. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +3 -3
  135. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +6 -6
  136. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +8 -8
  137. data/ext/enterprise_script_service/mruby/test/assert.rb +5 -4
  138. data/ext/enterprise_script_service/mruby/test/t/ensure.rb +8 -26
  139. data/ext/enterprise_script_service/mruby/test/t/exception.rb +2 -2
  140. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +8 -24
  141. data/ext/enterprise_script_service/mruby/travis_config.rb +0 -14
  142. data/ext/enterprise_script_service/msgpack/.github/depends/boost.sh +56 -0
  143. data/ext/enterprise_script_service/msgpack/.github/workflows/coverage.yml +62 -0
  144. data/ext/enterprise_script_service/msgpack/.github/workflows/gha.yml +304 -0
  145. data/ext/enterprise_script_service/msgpack/CHANGELOG.md +11 -0
  146. data/ext/enterprise_script_service/msgpack/CMakeLists.txt +82 -39
  147. data/ext/enterprise_script_service/msgpack/Files.cmake +22 -12
  148. data/ext/enterprise_script_service/msgpack/QUICKSTART-C.md +26 -29
  149. data/ext/enterprise_script_service/msgpack/README.md +3 -2
  150. data/ext/enterprise_script_service/msgpack/appveyor.yml +6 -2
  151. data/ext/enterprise_script_service/msgpack/ci/build_cmake.sh +3 -1
  152. data/ext/enterprise_script_service/msgpack/cmake/CodeCoverage.cmake +55 -0
  153. data/ext/enterprise_script_service/msgpack/codecov.yml +36 -0
  154. data/ext/enterprise_script_service/msgpack/example/CMakeLists.txt +9 -5
  155. data/ext/enterprise_script_service/msgpack/example/boost/CMakeLists.txt +1 -1
  156. data/ext/enterprise_script_service/msgpack/example/c/CMakeLists.txt +17 -6
  157. data/ext/enterprise_script_service/msgpack/example/c/boundary.c +296 -0
  158. data/ext/enterprise_script_service/msgpack/example/c/jsonconv.c +419 -0
  159. data/ext/enterprise_script_service/msgpack/example/c/simple_c.c +1 -1
  160. data/ext/enterprise_script_service/msgpack/example/cpp03/CMakeLists.txt +3 -3
  161. data/ext/enterprise_script_service/msgpack/example/cpp11/CMakeLists.txt +2 -2
  162. data/ext/enterprise_script_service/msgpack/example/x3/CMakeLists.txt +2 -2
  163. data/ext/enterprise_script_service/msgpack/include/msgpack/pack.h +24 -1
  164. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +5 -4
  165. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/boost/optional.hpp +4 -4
  166. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp +8 -8
  167. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/map.hpp +4 -4
  168. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector.hpp +4 -4
  169. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_char.hpp +8 -8
  170. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_unsigned_char.hpp +8 -8
  171. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +4 -4
  172. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/unpack.hpp +6 -6
  173. data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
  174. data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +4 -4
  175. data/ext/enterprise_script_service/msgpack/make_file_list.sh +38 -11
  176. data/ext/enterprise_script_service/msgpack/src/vrefbuffer.c +6 -0
  177. data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +86 -64
  178. data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +4 -0
  179. data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +4 -0
  180. data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +4 -0
  181. data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +4 -1
  182. data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +4 -0
  183. data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +4 -0
  184. data/ext/enterprise_script_service/msgpack/test/buffer.cpp +4 -47
  185. data/ext/enterprise_script_service/msgpack/test/buffer_c.cpp +148 -0
  186. data/ext/enterprise_script_service/msgpack/test/carray.cpp +4 -0
  187. data/ext/enterprise_script_service/msgpack/test/cases.cpp +8 -4
  188. data/ext/enterprise_script_service/msgpack/test/convert.cpp +8 -4
  189. data/ext/enterprise_script_service/msgpack/test/fixint.cpp +4 -0
  190. data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +4 -0
  191. data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +4 -0
  192. data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +4 -0
  193. data/ext/enterprise_script_service/msgpack/test/json.cpp +4 -0
  194. data/ext/enterprise_script_service/msgpack/test/limit.cpp +8 -4
  195. data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +4 -0
  196. data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +159 -0
  197. data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +4 -0
  198. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +32 -27
  199. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +4 -0
  200. data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +4 -0
  201. data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +4 -1
  202. data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +4 -0
  203. data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +4 -0
  204. data/ext/enterprise_script_service/msgpack/test/object.cpp +4 -1
  205. data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +12 -8
  206. data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +30 -26
  207. data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +4 -0
  208. data/ext/enterprise_script_service/msgpack/test/raw.cpp +4 -0
  209. data/ext/enterprise_script_service/msgpack/test/reference.cpp +4 -0
  210. data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +4 -0
  211. data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +4 -0
  212. data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +4 -0
  213. data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +4 -0
  214. data/ext/enterprise_script_service/msgpack/test/streaming.cpp +8 -4
  215. data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +4 -0
  216. data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +4 -0
  217. data/ext/enterprise_script_service/msgpack/test/user_class.cpp +16 -12
  218. data/ext/enterprise_script_service/msgpack/test/version.cpp +4 -0
  219. data/ext/enterprise_script_service/msgpack/test/visitor.cpp +4 -0
  220. data/ext/enterprise_script_service/msgpack/test/zone.cpp +4 -0
  221. data/lib/script_core/version.rb +1 -1
  222. data/script_core.gemspec +1 -1
  223. metadata +23 -9
  224. data/ext/enterprise_script_service/msgpack/.travis.yml +0 -258
@@ -913,7 +913,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
913
913
  {
914
914
  mrb_value **var;
915
915
  mrb_int *pl;
916
- mrb_bool nocopy = altmode || argv_on_stack ? TRUE : FALSE;
916
+ mrb_bool nocopy = (altmode || !argv_on_stack) ? TRUE : FALSE;
917
917
 
918
918
  var = va_arg(ap, mrb_value**);
919
919
  pl = va_arg(ap, mrb_int*);
@@ -1242,33 +1242,45 @@ mrb_mod_dummy_visibility(mrb_state *mrb, mrb_value mod)
1242
1242
  return mod;
1243
1243
  }
1244
1244
 
1245
- MRB_API mrb_value
1246
- mrb_singleton_class(mrb_state *mrb, mrb_value v)
1245
+ /* returns mrb_class_ptr(mrb_singleton_class()) */
1246
+ /* except that it return NULL for immediate values */
1247
+ MRB_API struct RClass*
1248
+ mrb_singleton_class_ptr(mrb_state *mrb, mrb_value v)
1247
1249
  {
1248
1250
  struct RBasic *obj;
1249
1251
 
1250
1252
  switch (mrb_type(v)) {
1251
1253
  case MRB_TT_FALSE:
1252
1254
  if (mrb_nil_p(v))
1253
- return mrb_obj_value(mrb->nil_class);
1254
- return mrb_obj_value(mrb->false_class);
1255
+ return mrb->nil_class;
1256
+ return mrb->false_class;
1255
1257
  case MRB_TT_TRUE:
1256
- return mrb_obj_value(mrb->true_class);
1258
+ return mrb->true_class;
1257
1259
  case MRB_TT_CPTR:
1258
- return mrb_obj_value(mrb->object_class);
1260
+ return mrb->object_class;
1259
1261
  case MRB_TT_SYMBOL:
1260
1262
  case MRB_TT_FIXNUM:
1261
1263
  #ifndef MRB_WITHOUT_FLOAT
1262
1264
  case MRB_TT_FLOAT:
1263
1265
  #endif
1264
- mrb_raise(mrb, E_TYPE_ERROR, "can't define singleton");
1265
- return mrb_nil_value(); /* not reached */
1266
+ return NULL;
1266
1267
  default:
1267
1268
  break;
1268
1269
  }
1269
1270
  obj = mrb_basic_ptr(v);
1270
1271
  prepare_singleton_class(mrb, obj);
1271
- return mrb_obj_value(obj->c);
1272
+ return obj->c;
1273
+ }
1274
+
1275
+ MRB_API mrb_value
1276
+ mrb_singleton_class(mrb_state *mrb, mrb_value v)
1277
+ {
1278
+ struct RClass *c = mrb_singleton_class_ptr(mrb, v);
1279
+
1280
+ if (c == NULL) {
1281
+ mrb_raise(mrb, E_TYPE_ERROR, "can't define singleton");
1282
+ }
1283
+ return mrb_obj_value(c);
1272
1284
  }
1273
1285
 
1274
1286
  MRB_API void
@@ -1716,7 +1728,10 @@ mrb_class_real(struct RClass* cl)
1716
1728
  MRB_API const char*
1717
1729
  mrb_class_name(mrb_state *mrb, struct RClass* c)
1718
1730
  {
1719
- mrb_value name = class_name_str(mrb, c);
1731
+ mrb_value name;
1732
+
1733
+ if (c == NULL) return NULL;
1734
+ name = class_name_str(mrb, c);
1720
1735
  return RSTRING_PTR(name);
1721
1736
  }
1722
1737
 
@@ -130,6 +130,10 @@ codedump(mrb_state *mrb, mrb_irep *irep)
130
130
  printf("OP_LOADI\tR%d\t-%d\t", a, b);
131
131
  print_lv_a(mrb, irep, a);
132
132
  break;
133
+ CASE(OP_LOADI16, BS):
134
+ printf("OP_LOADI16\tR%d\t%d\t", a, (int)(int16_t)b);
135
+ print_lv_a(mrb, irep, a);
136
+ break;
133
137
  CASE(OP_LOADI__1, B):
134
138
  printf("OP_LOADI__1\tR%d\t\t", a);
135
139
  print_lv_a(mrb, irep, a);
@@ -204,11 +204,14 @@ mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d)
204
204
 
205
205
  if (!d) { return; }
206
206
 
207
- for (i = 0; i < d->flen; ++i) {
208
- mrb_assert(d->files[i]);
209
- mrb_free(mrb, d->files[i]->lines.ptr);
210
- mrb_free(mrb, d->files[i]);
207
+ if (d->files) {
208
+ for (i = 0; i < d->flen; ++i) {
209
+ if (d->files[i]) {
210
+ mrb_free(mrb, d->files[i]->lines.ptr);
211
+ mrb_free(mrb, d->files[i]);
212
+ }
213
+ }
214
+ mrb_free(mrb, d->files);
211
215
  }
212
- mrb_free(mrb, d->files);
213
216
  mrb_free(mrb, d);
214
217
  }
@@ -13,9 +13,6 @@
13
13
  #include <mruby/numeric.h>
14
14
  #include <mruby/debug.h>
15
15
 
16
- #define FLAG_BYTEORDER_NATIVE 2
17
- #define FLAG_BYTEORDER_NONATIVE 0
18
-
19
16
  #ifndef MRB_WITHOUT_FLOAT
20
17
  #ifdef MRB_USE_FLOAT
21
18
  #define MRB_FLOAT_FMT "%.9g"
@@ -709,22 +706,7 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t *bin, uint8
709
706
  uint16_t crc;
710
707
  uint32_t offset;
711
708
 
712
- switch (flags & DUMP_ENDIAN_NAT) {
713
- endian_big:
714
- case DUMP_ENDIAN_BIG:
715
- memcpy(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident));
716
- break;
717
- endian_little:
718
- case DUMP_ENDIAN_LIL:
719
- memcpy(header->binary_ident, RITE_BINARY_IDENT_LIL, sizeof(header->binary_ident));
720
- break;
721
-
722
- case DUMP_ENDIAN_NAT:
723
- if (bigendian_p()) goto endian_big;
724
- goto endian_little;
725
- break;
726
- }
727
-
709
+ memcpy(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident));
728
710
  memcpy(header->binary_version, RITE_BINARY_FORMAT_VER, sizeof(header->binary_version));
729
711
  memcpy(header->compiler_name, RITE_COMPILER_NAME, sizeof(header->compiler_name));
730
712
  memcpy(header->compiler_version, RITE_COMPILER_VERSION, sizeof(header->compiler_version));
@@ -764,21 +746,6 @@ lv_defined_p(mrb_irep *irep)
764
746
  return FALSE;
765
747
  }
766
748
 
767
- static uint8_t
768
- dump_flags(uint8_t flags, uint8_t native)
769
- {
770
- if (native == FLAG_BYTEORDER_NATIVE) {
771
- if ((flags & DUMP_ENDIAN_NAT) == 0) {
772
- return (flags & DUMP_DEBUG_INFO) | DUMP_ENDIAN_NAT;
773
- }
774
- return flags;
775
- }
776
- if ((flags & DUMP_ENDIAN_NAT) == 0) {
777
- return (flags & DUMP_DEBUG_INFO) | DUMP_ENDIAN_BIG;
778
- }
779
- return flags;
780
- }
781
-
782
749
  static int
783
750
  dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size)
784
751
  {
@@ -870,7 +837,7 @@ error_exit:
870
837
  int
871
838
  mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size)
872
839
  {
873
- return dump_irep(mrb, irep, dump_flags(flags, FLAG_BYTEORDER_NONATIVE), bin, bin_size);
840
+ return dump_irep(mrb, irep, flags, bin, bin_size);
874
841
  }
875
842
 
876
843
  #ifndef MRB_DISABLE_STDIO
@@ -886,7 +853,7 @@ mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE* fp)
886
853
  return MRB_DUMP_INVALID_ARGUMENT;
887
854
  }
888
855
 
889
- result = dump_irep(mrb, irep, dump_flags(flags, FLAG_BYTEORDER_NONATIVE), &bin, &bin_size);
856
+ result = dump_irep(mrb, irep, flags, &bin, &bin_size);
890
857
  if (result == MRB_DUMP_OK) {
891
858
  if (fwrite(bin, sizeof(bin[0]), bin_size, fp) != bin_size) {
892
859
  result = MRB_DUMP_WRITE_FAULT;
@@ -897,20 +864,6 @@ mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE* fp)
897
864
  return result;
898
865
  }
899
866
 
900
- static mrb_bool
901
- dump_bigendian_p(uint8_t flags)
902
- {
903
- switch (flags & DUMP_ENDIAN_NAT) {
904
- case DUMP_ENDIAN_BIG:
905
- return TRUE;
906
- case DUMP_ENDIAN_LIL:
907
- return FALSE;
908
- default:
909
- case DUMP_ENDIAN_NAT:
910
- return bigendian_p();
911
- }
912
- }
913
-
914
867
  int
915
868
  mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, const char *initname)
916
869
  {
@@ -921,23 +874,8 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, con
921
874
  if (fp == NULL || initname == NULL || initname[0] == '\0') {
922
875
  return MRB_DUMP_INVALID_ARGUMENT;
923
876
  }
924
- flags = dump_flags(flags, FLAG_BYTEORDER_NATIVE);
925
877
  result = dump_irep(mrb, irep, flags, &bin, &bin_size);
926
878
  if (result == MRB_DUMP_OK) {
927
- if (!dump_bigendian_p(flags)) {
928
- if (fprintf(fp, "/* dumped in little endian order.\n"
929
- " use `mrbc -E` option for big endian CPU. */\n") < 0) {
930
- mrb_free(mrb, bin);
931
- return MRB_DUMP_WRITE_FAULT;
932
- }
933
- }
934
- else {
935
- if (fprintf(fp, "/* dumped in big endian order.\n"
936
- " use `mrbc -e` option for better performance on little endian CPU. */\n") < 0) {
937
- mrb_free(mrb, bin);
938
- return MRB_DUMP_WRITE_FAULT;
939
- }
940
- }
941
879
  if (fprintf(fp, "#include <stdint.h>\n") < 0) { /* for uint8_t under at least Darwin */
942
880
  mrb_free(mrb, bin);
943
881
  return MRB_DUMP_WRITE_FAULT;
@@ -185,6 +185,16 @@ mrb_exc_set(mrb_state *mrb, mrb_value exc)
185
185
  }
186
186
  }
187
187
 
188
+ static mrb_noreturn void
189
+ exc_throw(mrb_state *mrb, mrb_value exc)
190
+ {
191
+ if (!mrb->jmp) {
192
+ mrb_p(mrb, exc);
193
+ abort();
194
+ }
195
+ MRB_THROW(mrb->jmp);
196
+ }
197
+
188
198
  MRB_API mrb_noreturn void
189
199
  mrb_exc_raise(mrb_state *mrb, mrb_value exc)
190
200
  {
@@ -197,11 +207,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc)
197
207
  }
198
208
  mrb_exc_set(mrb, exc);
199
209
  }
200
- if (!mrb->jmp) {
201
- mrb_p(mrb, exc);
202
- abort();
203
- }
204
- MRB_THROW(mrb->jmp);
210
+ exc_throw(mrb, exc);
205
211
  }
206
212
 
207
213
  MRB_API mrb_noreturn void
@@ -550,6 +556,52 @@ mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max)
550
556
  #undef FMT
551
557
  }
552
558
 
559
+ void mrb_core_init_printabort(void);
560
+
561
+ int
562
+ mrb_core_init_protect(mrb_state *mrb, void (*body)(mrb_state *, void *), void *opaque)
563
+ {
564
+ struct mrb_jmpbuf *prev_jmp = mrb->jmp;
565
+ struct mrb_jmpbuf c_jmp;
566
+ int err = 1;
567
+
568
+ MRB_TRY(&c_jmp) {
569
+ mrb->jmp = &c_jmp;
570
+ body(mrb, opaque);
571
+ err = 0;
572
+ } MRB_CATCH(&c_jmp) {
573
+ if (mrb->exc) {
574
+ mrb_p(mrb, mrb_obj_value(mrb->exc));
575
+ mrb->exc = NULL;
576
+ }
577
+ else {
578
+ mrb_core_init_printabort();
579
+ }
580
+ } MRB_END_EXC(&c_jmp);
581
+
582
+ mrb->jmp = prev_jmp;
583
+
584
+ return err;
585
+ }
586
+
587
+ mrb_noreturn void
588
+ mrb_core_init_abort(mrb_state *mrb)
589
+ {
590
+ mrb->exc = NULL;
591
+ exc_throw(mrb, mrb_nil_value());
592
+ }
593
+
594
+ mrb_noreturn void
595
+ mrb_raise_nomemory(mrb_state *mrb)
596
+ {
597
+ if (mrb->nomem_err) {
598
+ mrb_exc_raise(mrb, mrb_obj_value(mrb->nomem_err));
599
+ }
600
+ else {
601
+ mrb_core_init_abort(mrb);
602
+ }
603
+ }
604
+
553
605
  void
554
606
  mrb_init_exception(mrb_state *mrb)
555
607
  {
@@ -140,7 +140,13 @@ mrb_obj_id(mrb_value obj)
140
140
  }
141
141
  }
142
142
 
143
+ #if defined(MRB_NAN_BOXING) && defined(MRB_64BIT)
144
+ #define mrb_xxx_boxing_cptr_value mrb_nan_boxing_cptr_value
145
+ #endif
146
+
143
147
  #ifdef MRB_WORD_BOXING
148
+ #define mrb_xxx_boxing_cptr_value mrb_word_boxing_cptr_value
149
+
144
150
  #ifndef MRB_WITHOUT_FLOAT
145
151
  MRB_API mrb_value
146
152
  mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f)
@@ -164,17 +170,20 @@ mrb_word_boxing_float_pool(mrb_state *mrb, mrb_float f)
164
170
  return mrb_obj_value(nf);
165
171
  }
166
172
  #endif /* MRB_WITHOUT_FLOAT */
173
+ #endif /* MRB_WORD_BOXING */
167
174
 
175
+ #if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_64BIT))
168
176
  MRB_API mrb_value
169
- mrb_word_boxing_cptr_value(mrb_state *mrb, void *p)
177
+ mrb_xxx_boxing_cptr_value(mrb_state *mrb, void *p)
170
178
  {
171
179
  mrb_value v;
180
+ struct RCptr *cptr = (struct RCptr*)mrb_obj_alloc(mrb, MRB_TT_CPTR, mrb->object_class);
172
181
 
173
- v.value.p = mrb_obj_alloc(mrb, MRB_TT_CPTR, mrb->object_class);
174
- v.value.vp->p = p;
182
+ SET_OBJ_VALUE(v, cptr);
183
+ cptr->p = p;
175
184
  return v;
176
185
  }
177
- #endif /* MRB_WORD_BOXING */
186
+ #endif
178
187
 
179
188
  #if defined _MSC_VER && _MSC_VER < 1900
180
189
 
@@ -37,9 +37,19 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
37
  #include <mruby.h>
38
38
  #include <mruby/string.h>
39
39
 
40
+ struct fmt_args;
41
+
42
+ typedef void output_func(struct fmt_args *f, const char *s, size_t l);
43
+
40
44
  struct fmt_args {
41
45
  mrb_state *mrb;
42
- mrb_value str;
46
+ output_func *output;
47
+ void *opaque;
48
+ };
49
+
50
+ struct mrb_cstr {
51
+ char *buf;
52
+ size_t len;
43
53
  };
44
54
 
45
55
  #define MAX(a,b) ((a)>(b) ? (a) : (b))
@@ -54,15 +64,44 @@ struct fmt_args {
54
64
  #define PAD_POS (1U<<(' '-' '))
55
65
  #define MARK_POS (1U<<('+'-' '))
56
66
 
67
+ #define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS)
68
+
69
+ static output_func strcat_value;
70
+ static output_func strcat_cstr;
71
+
72
+ static void
73
+ strcat_value(struct fmt_args *f, const char *s, size_t l)
74
+ {
75
+ mrb_value str = *(mrb_value*)f->opaque;
76
+ mrb_str_cat(f->mrb, str, s, l);
77
+ }
78
+
79
+ static void
80
+ strcat_cstr(struct fmt_args *f, const char *s, size_t l)
81
+ {
82
+ struct mrb_cstr *cstr = (struct mrb_cstr*)f->opaque;
83
+
84
+ if (l > cstr->len) {
85
+ mrb_state *mrb = f->mrb;
86
+
87
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "string buffer too small");
88
+ }
89
+
90
+ memcpy(cstr->buf, s, l);
91
+
92
+ cstr->buf += l;
93
+ cstr->len -= l;
94
+ }
95
+
57
96
  static void
58
97
  out(struct fmt_args *f, const char *s, size_t l)
59
98
  {
60
- mrb_str_cat(f->mrb, f->str, s, l);
99
+ f->output(f, s, l);
61
100
  }
62
101
 
63
102
  #define PAD_SIZE 256
64
103
  static void
65
- pad(struct fmt_args *f, char c, ptrdiff_t w, ptrdiff_t l, uint8_t fl)
104
+ pad(struct fmt_args *f, char c, ptrdiff_t w, ptrdiff_t l, uint32_t fl)
66
105
  {
67
106
  char pad[PAD_SIZE];
68
107
  if (fl & (LEFT_ADJ | ZERO_PAD) || l >= w) return;
@@ -92,7 +131,7 @@ typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)
92
131
  #endif
93
132
 
94
133
  static int
95
- fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
134
+ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t w, ptrdiff_t p, uint32_t fl, int t)
96
135
  {
97
136
  uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion
98
137
  + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion
@@ -117,11 +156,11 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
117
156
  if (!isfinite(y)) {
118
157
  const char *ss = (t&32)?"inf":"INF";
119
158
  if (y!=y) ss=(t&32)?"nan":"NAN";
120
- pad(f, ' ', 0, 3+pl, fl&~ZERO_PAD);
159
+ pad(f, ' ', w, 3+pl, fl&~ZERO_PAD);
121
160
  out(f, prefix, pl);
122
161
  out(f, ss, 3);
123
- pad(f, ' ', 0, 3+pl, fl^LEFT_ADJ);
124
- return 3+(int)pl;
162
+ pad(f, ' ', w, 3+pl, fl^LEFT_ADJ);
163
+ return (int)MAX(w, 3+pl);
125
164
  }
126
165
 
127
166
  y = frexp((double)y, &e2) * 2;
@@ -169,14 +208,14 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
169
208
  else
170
209
  l = (s-buf) + (ebuf-estr);
171
210
 
172
- pad(f, ' ', 0, pl+l, fl);
211
+ pad(f, ' ', w, pl+l, fl);
173
212
  out(f, prefix, pl);
174
- pad(f, '0', 0, pl+l, fl^ZERO_PAD);
213
+ pad(f, '0', w, pl+l, fl^ZERO_PAD);
175
214
  out(f, buf, s-buf);
176
215
  pad(f, '0', l-(ebuf-estr)-(s-buf), 0, 0);
177
216
  out(f, estr, ebuf-estr);
178
- pad(f, ' ', 0, pl+l, fl^LEFT_ADJ);
179
- return (int)pl+(int)l;
217
+ pad(f, ' ', w, pl+l, fl^LEFT_ADJ);
218
+ return (int)MAX(w, pl+l);
180
219
  }
181
220
  if (p<0) p=6;
182
221
 
@@ -288,9 +327,9 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
288
327
  l += ebuf-estr;
289
328
  }
290
329
 
291
- pad(f, ' ', 0, pl+l, fl);
330
+ pad(f, ' ', w, pl+l, fl);
292
331
  out(f, prefix, pl);
293
- pad(f, '0', 0, pl+l, fl^ZERO_PAD);
332
+ pad(f, '0', w, pl+l, fl^ZERO_PAD);
294
333
 
295
334
  if ((t|32)=='f') {
296
335
  if (a>r) a=r;
@@ -325,21 +364,33 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
325
364
  out(f, estr, ebuf-estr);
326
365
  }
327
366
 
328
- pad(f, ' ', 0, pl+l, fl^LEFT_ADJ);
367
+ pad(f, ' ', w, pl+l, fl^LEFT_ADJ);
329
368
 
330
- return (int)pl+(int)l;
369
+ return (int)MAX(w, pl+l);
331
370
  }
332
371
 
333
372
  static int
334
373
  fmt_core(struct fmt_args *f, const char *fmt, mrb_float flo)
335
374
  {
336
- ptrdiff_t p;
375
+ ptrdiff_t w, p;
376
+ uint32_t fl;
337
377
 
338
378
  if (*fmt != '%') {
339
379
  return -1;
340
380
  }
341
381
  ++fmt;
342
382
 
383
+ /* Read modifier flags */
384
+ for (fl=0; (unsigned)*fmt-' '<32 && (FLAGMASK&(1U<<(*fmt-' '))); fmt++)
385
+ fl |= 1U<<(*fmt-' ');
386
+
387
+ /* - and 0 flags are mutually exclusive */
388
+ if (fl & LEFT_ADJ) fl &= ~ZERO_PAD;
389
+
390
+ for (w = 0; ISDIGIT(*fmt); ++fmt) {
391
+ w = 10 * w + (*fmt - '0');
392
+ }
393
+
343
394
  if (*fmt == '.') {
344
395
  ++fmt;
345
396
  for (p = 0; ISDIGIT(*fmt); ++fmt) {
@@ -353,29 +404,49 @@ fmt_core(struct fmt_args *f, const char *fmt, mrb_float flo)
353
404
  switch (*fmt) {
354
405
  case 'e': case 'f': case 'g': case 'a':
355
406
  case 'E': case 'F': case 'G': case 'A':
356
- return fmt_fp(f, flo, p, 0, *fmt);
407
+ return fmt_fp(f, flo, w, p, fl, *fmt);
357
408
  default:
358
409
  return -1;
359
410
  }
360
411
  }
361
412
 
362
- mrb_value
413
+ MRB_API mrb_value
363
414
  mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt)
364
415
  {
365
416
  struct fmt_args f;
417
+ mrb_value str = mrb_str_new_capa(mrb, 24);
366
418
 
367
419
  f.mrb = mrb;
368
- f.str = mrb_str_new_capa(mrb, 24);
420
+ f.output = strcat_value;
421
+ f.opaque = (void*)&str;
369
422
  if (fmt_core(&f, fmt, mrb_float(flo)) < 0) {
370
423
  mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid format string");
371
424
  }
372
- return f.str;
425
+ return str;
426
+ }
427
+
428
+ MRB_API int
429
+ mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float fval)
430
+ {
431
+ struct fmt_args f;
432
+ struct mrb_cstr cstr;
433
+
434
+ cstr.buf = buf;
435
+ cstr.len = len - 1; /* reserve NUL terminator */
436
+ f.mrb = mrb;
437
+ f.output = strcat_cstr;
438
+ f.opaque = (void*)&cstr;
439
+ if (fmt_core(&f, fmt, fval) < 0) {
440
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid format string");
441
+ }
442
+ *cstr.buf = '\0';
443
+ return (int)(cstr.buf - buf);
373
444
  }
374
445
  #else /* MRB_DISABLE_STDIO || _WIN32 || _WIN64 */
375
446
  #include <mruby.h>
376
447
  #include <stdio.h>
377
448
 
378
- mrb_value
449
+ MRB_API mrb_value
379
450
  mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt)
380
451
  {
381
452
  char buf[25];
@@ -383,5 +454,11 @@ mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt)
383
454
  snprintf(buf, sizeof(buf), fmt, mrb_float(flo));
384
455
  return mrb_str_new_cstr(mrb, buf);
385
456
  }
457
+
458
+ MRB_API int
459
+ mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float fval)
460
+ {
461
+ return snprintf(buf, len, fmt, fval);
462
+ }
386
463
  #endif /* MRB_DISABLE_STDIO || _WIN32 || _WIN64 */
387
464
  #endif