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
@@ -201,6 +201,8 @@ gettimeofday_time(void)
201
201
 
202
202
  #define objects(p) ((RVALUE *)p->objects)
203
203
 
204
+ mrb_noreturn void mrb_raise_nomemory(mrb_state *mrb);
205
+
204
206
  MRB_API void*
205
207
  mrb_realloc_simple(mrb_state *mrb, void *p, size_t len)
206
208
  {
@@ -224,12 +226,12 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len)
224
226
  if (len == 0) return p2;
225
227
  if (p2 == NULL) {
226
228
  if (mrb->gc.out_of_memory) {
227
- mrb_exc_raise(mrb, mrb_obj_value(mrb->nomem_err));
229
+ mrb_raise_nomemory(mrb);
228
230
  /* mrb_panic(mrb); */
229
231
  }
230
232
  else {
231
233
  mrb->gc.out_of_memory = TRUE;
232
- mrb_exc_raise(mrb, mrb_obj_value(mrb->nomem_err));
234
+ mrb_raise_nomemory(mrb);
233
235
  }
234
236
  }
235
237
  else {
@@ -958,13 +960,12 @@ root_scan_phase(mrb_state *mrb, mrb_gc *gc)
958
960
  }
959
961
  }
960
962
 
963
+ /* rough estimation of number of GC marks (non recursive) */
961
964
  static size_t
962
- gc_gray_mark(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
965
+ gc_gray_counts(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
963
966
  {
964
967
  size_t children = 0;
965
968
 
966
- gc_mark_children(mrb, gc, obj);
967
-
968
969
  switch (obj->tt) {
969
970
  case MRB_TT_ICLASS:
970
971
  children++;
@@ -1062,7 +1063,9 @@ incremental_marking_phase(mrb_state *mrb, mrb_gc *gc, size_t limit)
1062
1063
  size_t tried_marks = 0;
1063
1064
 
1064
1065
  while (gc->gray_list && tried_marks < limit) {
1065
- tried_marks += gc_gray_mark(mrb, gc, gc->gray_list);
1066
+ struct RBasic *obj = gc->gray_list;
1067
+ gc_mark_children(mrb, gc, obj);
1068
+ tried_marks += gc_gray_counts(mrb, gc, obj);
1066
1069
  }
1067
1070
 
1068
1071
  return tried_marks;
@@ -1294,6 +1297,7 @@ mrb_full_gc(mrb_state *mrb)
1294
1297
  {
1295
1298
  mrb_gc *gc = &mrb->gc;
1296
1299
 
1300
+ if (!mrb->c) return;
1297
1301
  if (gc->disabled || gc->iterating) return;
1298
1302
 
1299
1303
  GC_INVOKE_TIME_REPORT("mrb_full_gc()");
@@ -1632,272 +1636,3 @@ mrb_init_gc(mrb_state *mrb)
1632
1636
  #endif
1633
1637
  #endif
1634
1638
  }
1635
-
1636
- #ifdef GC_TEST
1637
- #ifdef GC_DEBUG
1638
- void
1639
- test_mrb_field_write_barrier(void)
1640
- {
1641
- mrb_state *mrb = mrb_open();
1642
- struct RBasic *obj, *value;
1643
- mrb_gc *gc = &mrb->gc;
1644
-
1645
- puts("test_mrb_field_write_barrier");
1646
- gc->generational = FALSE;
1647
- obj = mrb_basic_ptr(mrb_ary_new(mrb));
1648
- value = mrb_basic_ptr(mrb_str_new_lit(mrb, "value"));
1649
- paint_black(obj);
1650
- paint_partial_white(gc, value);
1651
-
1652
-
1653
- puts(" in MRB_GC_STATE_MARK");
1654
- gc->state = MRB_GC_STATE_MARK;
1655
- mrb_field_write_barrier(mrb, obj, value);
1656
-
1657
- mrb_assert(is_gray(value));
1658
-
1659
-
1660
- puts(" in MRB_GC_STATE_SWEEP");
1661
- paint_partial_white(gc, value);
1662
- gc->state = MRB_GC_STATE_SWEEP;
1663
- mrb_field_write_barrier(mrb, obj, value);
1664
-
1665
- mrb_assert(obj->color & gc->current_white_part);
1666
- mrb_assert(value->color & gc->current_white_part);
1667
-
1668
-
1669
- puts(" fail with black");
1670
- gc->state = MRB_GC_STATE_MARK;
1671
- paint_white(obj);
1672
- paint_partial_white(gc, value);
1673
- mrb_field_write_barrier(mrb, obj, value);
1674
-
1675
- mrb_assert(obj->color & gc->current_white_part);
1676
-
1677
-
1678
- puts(" fail with gray");
1679
- gc->state = MRB_GC_STATE_MARK;
1680
- paint_black(obj);
1681
- paint_gray(value);
1682
- mrb_field_write_barrier(mrb, obj, value);
1683
-
1684
- mrb_assert(is_gray(value));
1685
-
1686
-
1687
- {
1688
- puts("test_mrb_field_write_barrier_value");
1689
- obj = mrb_basic_ptr(mrb_ary_new(mrb));
1690
- mrb_value value = mrb_str_new_lit(mrb, "value");
1691
- paint_black(obj);
1692
- paint_partial_white(gc, mrb_basic_ptr(value));
1693
-
1694
- gc->state = MRB_GC_STATE_MARK;
1695
- mrb_field_write_barrier_value(mrb, obj, value);
1696
-
1697
- mrb_assert(is_gray(mrb_basic_ptr(value)));
1698
- }
1699
-
1700
- mrb_close(mrb);
1701
- }
1702
-
1703
- void
1704
- test_mrb_write_barrier(void)
1705
- {
1706
- mrb_state *mrb = mrb_open();
1707
- struct RBasic *obj;
1708
- mrb_gc *gc = &mrb->gc;
1709
-
1710
- puts("test_mrb_write_barrier");
1711
- obj = mrb_basic_ptr(mrb_ary_new(mrb));
1712
- paint_black(obj);
1713
-
1714
- puts(" in MRB_GC_STATE_MARK");
1715
- gc->state = MRB_GC_STATE_MARK;
1716
- mrb_write_barrier(mrb, obj);
1717
-
1718
- mrb_assert(is_gray(obj));
1719
- mrb_assert(gc->atomic_gray_list == obj);
1720
-
1721
-
1722
- puts(" fail with gray");
1723
- paint_gray(obj);
1724
- mrb_write_barrier(mrb, obj);
1725
-
1726
- mrb_assert(is_gray(obj));
1727
-
1728
- mrb_close(mrb);
1729
- }
1730
-
1731
- void
1732
- test_add_gray_list(void)
1733
- {
1734
- mrb_state *mrb = mrb_open();
1735
- struct RBasic *obj1, *obj2;
1736
- mrb_gc *gc = &mrb->gc;
1737
-
1738
- puts("test_add_gray_list");
1739
- change_gen_gc_mode(mrb, gc, FALSE);
1740
- mrb_assert(gc->gray_list == NULL);
1741
- obj1 = mrb_basic_ptr(mrb_str_new_lit(mrb, "test"));
1742
- add_gray_list(mrb, gc, obj1);
1743
- mrb_assert(gc->gray_list == obj1);
1744
- mrb_assert(is_gray(obj1));
1745
-
1746
- obj2 = mrb_basic_ptr(mrb_str_new_lit(mrb, "test"));
1747
- add_gray_list(mrb, gc, obj2);
1748
- mrb_assert(gc->gray_list == obj2);
1749
- mrb_assert(gc->gray_list->gcnext == obj1);
1750
- mrb_assert(is_gray(obj2));
1751
-
1752
- mrb_close(mrb);
1753
- }
1754
-
1755
- void
1756
- test_gc_gray_mark(void)
1757
- {
1758
- mrb_state *mrb = mrb_open();
1759
- mrb_value obj_v, value_v;
1760
- struct RBasic *obj;
1761
- size_t gray_num = 0;
1762
- mrb_gc *gc = &mrb->gc;
1763
-
1764
- puts("test_gc_gray_mark");
1765
-
1766
- puts(" in MRB_TT_CLASS");
1767
- obj = (struct RBasic*)mrb->object_class;
1768
- paint_gray(obj);
1769
- gray_num = gc_gray_mark(mrb, gc, obj);
1770
- mrb_assert(is_black(obj));
1771
- mrb_assert(gray_num > 1);
1772
-
1773
- puts(" in MRB_TT_ARRAY");
1774
- obj_v = mrb_ary_new(mrb);
1775
- value_v = mrb_str_new_lit(mrb, "test");
1776
- paint_gray(mrb_basic_ptr(obj_v));
1777
- paint_partial_white(gc, mrb_basic_ptr(value_v));
1778
- mrb_ary_push(mrb, obj_v, value_v);
1779
- gray_num = gc_gray_mark(mrb, gc, mrb_basic_ptr(obj_v));
1780
- mrb_assert(is_black(mrb_basic_ptr(obj_v)));
1781
- mrb_assert(is_gray(mrb_basic_ptr(value_v)));
1782
- mrb_assert(gray_num == 1);
1783
-
1784
- mrb_close(mrb);
1785
- }
1786
-
1787
- void
1788
- test_incremental_gc(void)
1789
- {
1790
- mrb_state *mrb = mrb_open();
1791
- size_t max = ~0, live = 0, total = 0, freed = 0;
1792
- RVALUE *free;
1793
- mrb_heap_page *page;
1794
- mrb_gc *gc = &mrb->gc;
1795
-
1796
- puts("test_incremental_gc");
1797
- change_gen_gc_mode(mrb, gc, FALSE);
1798
-
1799
- puts(" in mrb_full_gc");
1800
- mrb_full_gc(mrb);
1801
-
1802
- mrb_assert(gc->state == MRB_GC_STATE_ROOT);
1803
- puts(" in MRB_GC_STATE_ROOT");
1804
- incremental_gc(mrb, gc, max);
1805
- mrb_assert(gc->state == MRB_GC_STATE_MARK);
1806
- puts(" in MRB_GC_STATE_MARK");
1807
- incremental_gc_until(mrb, gc, MRB_GC_STATE_SWEEP);
1808
- mrb_assert(gc->state == MRB_GC_STATE_SWEEP);
1809
-
1810
- puts(" in MRB_GC_STATE_SWEEP");
1811
- page = gc->heaps;
1812
- while (page) {
1813
- RVALUE *p = objects(page);
1814
- RVALUE *e = p + MRB_HEAP_PAGE_SIZE;
1815
- while (p<e) {
1816
- if (is_black(&p->as.basic)) {
1817
- live++;
1818
- }
1819
- if (is_gray(&p->as.basic) && !is_dead(gc, &p->as.basic)) {
1820
- printf("%p\n", &p->as.basic);
1821
- }
1822
- p++;
1823
- }
1824
- page = page->next;
1825
- total += MRB_HEAP_PAGE_SIZE;
1826
- }
1827
-
1828
- mrb_assert(gc->gray_list == NULL);
1829
-
1830
- incremental_gc(mrb, gc, max);
1831
- mrb_assert(gc->state == MRB_GC_STATE_SWEEP);
1832
-
1833
- incremental_gc(mrb, gc, max);
1834
- mrb_assert(gc->state == MRB_GC_STATE_ROOT);
1835
-
1836
- free = (RVALUE*)gc->heaps->freelist;
1837
- while (free) {
1838
- freed++;
1839
- free = (RVALUE*)free->as.free.next;
1840
- }
1841
-
1842
- mrb_assert(gc->live == live);
1843
- mrb_assert(gc->live == total-freed);
1844
-
1845
- puts("test_incremental_gc(gen)");
1846
- incremental_gc_until(mrb, gc, MRB_GC_STATE_SWEEP);
1847
- change_gen_gc_mode(mrb, gc, TRUE);
1848
-
1849
- mrb_assert(gc->full == FALSE);
1850
- mrb_assert(gc->state == MRB_GC_STATE_ROOT);
1851
-
1852
- puts(" in minor");
1853
- mrb_assert(is_minor_gc(gc));
1854
- mrb_assert(gc->majorgc_old_threshold > 0);
1855
- gc->majorgc_old_threshold = 0;
1856
- mrb_incremental_gc(mrb);
1857
- mrb_assert(gc->full == TRUE);
1858
- mrb_assert(gc->state == MRB_GC_STATE_ROOT);
1859
-
1860
- puts(" in major");
1861
- mrb_assert(is_major_gc(gc));
1862
- do {
1863
- mrb_incremental_gc(mrb);
1864
- } while (gc->state != MRB_GC_STATE_ROOT);
1865
- mrb_assert(gc->full == FALSE);
1866
-
1867
- mrb_close(mrb);
1868
- }
1869
-
1870
- void
1871
- test_incremental_sweep_phase(void)
1872
- {
1873
- mrb_state *mrb = mrb_open();
1874
- mrb_gc *gc = &mrb->gc;
1875
-
1876
- puts("test_incremental_sweep_phase");
1877
-
1878
- add_heap(mrb, gc);
1879
- gc->sweeps = gc->heaps;
1880
-
1881
- mrb_assert(gc->heaps->next->next == NULL);
1882
- mrb_assert(gc->free_heaps->next->next == NULL);
1883
- incremental_sweep_phase(mrb, gc, MRB_HEAP_PAGE_SIZE * 3);
1884
-
1885
- mrb_assert(gc->heaps->next == NULL);
1886
- mrb_assert(gc->heaps == gc->free_heaps);
1887
-
1888
- mrb_close(mrb);
1889
- }
1890
-
1891
- static mrb_value
1892
- gc_test(mrb_state *mrb, mrb_value self)
1893
- {
1894
- test_mrb_field_write_barrier();
1895
- test_mrb_write_barrier();
1896
- test_add_gray_list();
1897
- test_gc_gray_mark();
1898
- test_incremental_gc();
1899
- test_incremental_sweep_phase();
1900
- return mrb_nil_value();
1901
- }
1902
- #endif /* GC_DEBUG */
1903
- #endif /* GC_TEST */
@@ -222,9 +222,8 @@ static void
222
222
  ht_compact(mrb_state *mrb, htable *t)
223
223
  {
224
224
  segment *seg;
225
- mrb_int i;
225
+ uint16_t i, i2;
226
226
  segment *seg2 = NULL;
227
- mrb_int i2;
228
227
  mrb_int size = 0;
229
228
 
230
229
  if (t == NULL) return;
@@ -366,7 +365,7 @@ ht_put(mrb_state *mrb, htable *t, mrb_value key, mrb_value val)
366
365
  if (!seg->next && i >= t->last_len) {
367
366
  seg->e[i].key = key;
368
367
  seg->e[i].val = val;
369
- t->last_len = i+1;
368
+ t->last_len = (uint16_t)i+1;
370
369
  t->size++;
371
370
  return;
372
371
  }
@@ -374,7 +373,7 @@ ht_put(mrb_state *mrb, htable *t, mrb_value key, mrb_value val)
374
373
  deleted++;
375
374
  continue;
376
375
  }
377
- if (ht_hash_equal(mrb, t, k, key)) {
376
+ if (ht_hash_equal(mrb, t, key, k)) {
378
377
  seg->e[i].val = val;
379
378
  return;
380
379
  }
@@ -408,7 +407,7 @@ ht_put(mrb_state *mrb, htable *t, mrb_value key, mrb_value val)
408
407
  }
409
408
  seg->e[i].key = key;
410
409
  seg->e[i].val = val;
411
- t->last_len = i+1;
410
+ t->last_len = (uint16_t)i+1;
412
411
  if (t->index == NULL && t->size > MRB_HT_INIT_SIZE*4) {
413
412
  ht_index(mrb, t);
414
413
  }
@@ -455,7 +454,7 @@ ht_get(mrb_state *mrb, htable *t, mrb_value key, mrb_value *vp)
455
454
  return FALSE;
456
455
  }
457
456
  if (mrb_undef_p(k)) continue;
458
- if (ht_hash_equal(mrb, t, k, key)) {
457
+ if (ht_hash_equal(mrb, t, key, k)) {
459
458
  if (vp) *vp = seg->e[i].val;
460
459
  return TRUE;
461
460
  }
@@ -325,7 +325,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
325
325
  mrb_value clone;
326
326
 
327
327
  if (mrb_immediate_p(self)) {
328
- mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %v", self);
328
+ return self;
329
329
  }
330
330
  if (mrb_sclass_p(self)) {
331
331
  mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
@@ -366,7 +366,7 @@ mrb_obj_dup(mrb_state *mrb, mrb_value obj)
366
366
  mrb_value dup;
367
367
 
368
368
  if (mrb_immediate_p(obj)) {
369
- mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %v", obj);
369
+ return obj;
370
370
  }
371
371
  if (mrb_sclass_p(obj)) {
372
372
  mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
@@ -14,14 +14,12 @@
14
14
  #include <mruby/string.h>
15
15
  #include <mruby/debug.h>
16
16
  #include <mruby/error.h>
17
+ #include <mruby/data.h>
17
18
 
18
19
  #if SIZE_MAX < UINT32_MAX
19
20
  # error size_t must be at least 32 bits wide
20
21
  #endif
21
22
 
22
- #define FLAG_BYTEORDER_BIG 2
23
- #define FLAG_BYTEORDER_LIL 4
24
- #define FLAG_BYTEORDER_NATIVE 8
25
23
  #define FLAG_SRC_MALLOC 1
26
24
  #define FLAG_SRC_STATIC 0
27
25
 
@@ -58,6 +56,14 @@ str_to_double(mrb_state *mrb, const char *p, size_t len)
58
56
 
59
57
  mrb_value mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, int badcheck);
60
58
 
59
+ static void
60
+ tempirep_free(mrb_state *mrb, void *p)
61
+ {
62
+ if (p) mrb_irep_decref(mrb, (mrb_irep *)p);
63
+ }
64
+
65
+ static const mrb_data_type tempirep_type = { "temporary irep", tempirep_free };
66
+
61
67
  static mrb_irep*
62
68
  read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags)
63
69
  {
@@ -66,8 +72,11 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
66
72
  ptrdiff_t diff;
67
73
  uint16_t tt, pool_data_len, snl;
68
74
  int plen;
69
- int ai = mrb_gc_arena_save(mrb);
75
+ struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
70
76
  mrb_irep *irep = mrb_add_irep(mrb);
77
+ int ai = mrb_gc_arena_save(mrb);
78
+
79
+ irep_obj->data = irep;
71
80
 
72
81
  /* skip record size */
73
82
  src += sizeof(uint32_t);
@@ -94,8 +103,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
94
103
  if (SIZE_ERROR_MUL(irep->ilen, sizeof(mrb_code))) {
95
104
  return NULL;
96
105
  }
97
- if ((flags & FLAG_SRC_MALLOC) == 0 &&
98
- (flags & FLAG_BYTEORDER_NATIVE)) {
106
+ if ((flags & FLAG_SRC_MALLOC) == 0) {
99
107
  irep->iseq = (mrb_code*)src;
100
108
  src += sizeof(mrb_code) * irep->ilen;
101
109
  irep->flags |= MRB_ISEQ_NO_FREE;
@@ -188,36 +196,47 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
188
196
  }
189
197
  }
190
198
 
191
- irep->reps = (mrb_irep**)mrb_malloc(mrb, sizeof(mrb_irep*)*irep->rlen);
199
+ irep->reps = (mrb_irep**)mrb_calloc(mrb, irep->rlen, sizeof(mrb_irep*));
192
200
 
193
201
  diff = src - bin;
194
202
  mrb_assert_int_fit(ptrdiff_t, diff, size_t, SIZE_MAX);
195
203
  *len = (size_t)diff;
196
204
 
205
+ irep_obj->data = NULL;
206
+
197
207
  return irep;
198
208
  }
199
209
 
200
210
  static mrb_irep*
201
211
  read_irep_record(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags)
202
212
  {
213
+ struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
214
+ int ai = mrb_gc_arena_save(mrb);
203
215
  mrb_irep *irep = read_irep_record_1(mrb, bin, len, flags);
204
216
  int i;
205
217
 
218
+ mrb_gc_arena_restore(mrb, ai);
206
219
  if (irep == NULL) {
207
220
  return NULL;
208
221
  }
209
222
 
223
+ irep_obj->data = irep;
224
+
210
225
  bin += *len;
211
226
  for (i=0; i<irep->rlen; i++) {
212
227
  size_t rlen;
213
228
 
214
229
  irep->reps[i] = read_irep_record(mrb, bin, &rlen, flags);
230
+ mrb_gc_arena_restore(mrb, ai);
215
231
  if (irep->reps[i] == NULL) {
216
232
  return NULL;
217
233
  }
218
234
  bin += rlen;
219
235
  *len += rlen;
220
236
  }
237
+
238
+ irep_obj->data = NULL;
239
+
221
240
  return irep;
222
241
  }
223
242
 
@@ -241,21 +260,21 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t *
241
260
 
242
261
  if (irep->debug_info) { return MRB_DUMP_INVALID_IREP; }
243
262
 
244
- irep->debug_info = (mrb_irep_debug_info*)mrb_malloc(mrb, sizeof(mrb_irep_debug_info));
263
+ irep->debug_info = (mrb_irep_debug_info*)mrb_calloc(mrb, 1, sizeof(mrb_irep_debug_info));
245
264
  irep->debug_info->pc_count = (uint32_t)irep->ilen;
246
265
 
247
266
  record_size = (size_t)bin_to_uint32(bin);
248
267
  bin += sizeof(uint32_t);
249
268
 
250
269
  irep->debug_info->flen = bin_to_uint16(bin);
251
- irep->debug_info->files = (mrb_irep_debug_info_file**)mrb_malloc(mrb, sizeof(mrb_irep_debug_info*) * irep->debug_info->flen);
270
+ irep->debug_info->files = (mrb_irep_debug_info_file**)mrb_calloc(mrb, irep->debug_info->flen, sizeof(mrb_irep_debug_info*));
252
271
  bin += sizeof(uint16_t);
253
272
 
254
273
  for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
255
274
  mrb_irep_debug_info_file *file;
256
275
  uint16_t filename_idx;
257
276
 
258
- file = (mrb_irep_debug_info_file *)mrb_malloc(mrb, sizeof(*file));
277
+ file = (mrb_irep_debug_info_file *)mrb_calloc(mrb, 1, sizeof(*file));
259
278
  irep->debug_info->files[f_idx] = file;
260
279
 
261
280
  file->start_pos = bin_to_uint32(bin);
@@ -285,8 +304,8 @@ read_debug_record(mrb_state *mrb, const uint8_t *start, mrb_irep* irep, size_t *
285
304
  case mrb_debug_line_flat_map: {
286
305
  uint32_t l;
287
306
 
288
- file->lines.flat_map = (mrb_irep_debug_info_line*)mrb_malloc(
289
- mrb, sizeof(mrb_irep_debug_info_line) * (size_t)(file->line_entry_count));
307
+ file->lines.flat_map = (mrb_irep_debug_info_line*)mrb_calloc(
308
+ mrb, (size_t)(file->line_entry_count), sizeof(mrb_irep_debug_info_line));
290
309
  for (l = 0; l < file->line_entry_count; ++l) {
291
310
  file->lines.flat_map[l].start_pos = bin_to_uint32(bin);
292
311
  bin += sizeof(uint32_t);
@@ -333,6 +352,7 @@ read_section_debug(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t
333
352
  int result;
334
353
  uint16_t filenames_len;
335
354
  mrb_sym *filenames;
355
+ mrb_value filenames_obj;
336
356
 
337
357
  bin = start;
338
358
  header = (struct rite_section_debug_header *)bin;
@@ -340,7 +360,8 @@ read_section_debug(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t
340
360
 
341
361
  filenames_len = bin_to_uint16(bin);
342
362
  bin += sizeof(uint16_t);
343
- filenames = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym) * (size_t)filenames_len);
363
+ filenames_obj = mrb_str_new(mrb, NULL, sizeof(mrb_sym) * (size_t)filenames_len);
364
+ filenames = (mrb_sym*)RSTRING_PTR(filenames_obj);
344
365
  for (i = 0; i < filenames_len; ++i) {
345
366
  uint16_t f_len = bin_to_uint16(bin);
346
367
  bin += sizeof(uint16_t);
@@ -364,7 +385,7 @@ read_section_debug(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t
364
385
  }
365
386
 
366
387
  debug_exit:
367
- mrb_free(mrb, filenames);
388
+ mrb_str_resize(mrb, filenames_obj, 0);
368
389
  return result;
369
390
  }
370
391
 
@@ -422,6 +443,7 @@ read_section_lv(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t fl
422
443
  int result;
423
444
  uint32_t syms_len;
424
445
  mrb_sym *syms;
446
+ mrb_value syms_obj;
425
447
  mrb_sym (*intern_func)(mrb_state*, const char*, size_t) =
426
448
  (flags & FLAG_SRC_MALLOC)? mrb_intern : mrb_intern_static;
427
449
 
@@ -431,7 +453,8 @@ read_section_lv(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t fl
431
453
 
432
454
  syms_len = bin_to_uint32(bin);
433
455
  bin += sizeof(uint32_t);
434
- syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym) * (size_t)syms_len);
456
+ syms_obj = mrb_str_new(mrb, NULL, sizeof(mrb_sym) * (size_t)syms_len);
457
+ syms = (mrb_sym*)RSTRING_PTR(syms_obj);
435
458
  for (i = 0; i < syms_len; ++i) {
436
459
  uint16_t const str_len = bin_to_uint16(bin);
437
460
  bin += sizeof(uint16_t);
@@ -451,7 +474,7 @@ read_section_lv(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t fl
451
474
  }
452
475
 
453
476
  lv_exit:
454
- mrb_free(mrb, syms);
477
+ mrb_str_resize(mrb, syms_obj, 0);
455
478
  return result;
456
479
  }
457
480
 
@@ -464,19 +487,7 @@ read_binary_header(const uint8_t *bin, size_t bufsize, size_t *bin_size, uint16_
464
487
  return MRB_DUMP_READ_FAULT;
465
488
  }
466
489
 
467
- if (memcmp(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident)) == 0) {
468
- if (bigendian_p())
469
- *flags |= FLAG_BYTEORDER_NATIVE;
470
- else
471
- *flags |= FLAG_BYTEORDER_BIG;
472
- }
473
- else if (memcmp(header->binary_ident, RITE_BINARY_IDENT_LIL, sizeof(header->binary_ident)) == 0) {
474
- if (bigendian_p())
475
- *flags |= FLAG_BYTEORDER_LIL;
476
- else
477
- *flags |= FLAG_BYTEORDER_NATIVE;
478
- }
479
- else {
490
+ if (memcmp(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident)) != 0) {
480
491
  return MRB_DUMP_INVALID_FILE_HEADER;
481
492
  }
482
493
 
@@ -500,6 +511,7 @@ static mrb_irep*
500
511
  read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
501
512
  {
502
513
  int result;
514
+ struct RData *irep_obj = NULL;
503
515
  mrb_irep *irep = NULL;
504
516
  const struct rite_section_header *section_header;
505
517
  uint16_t crc;
@@ -520,12 +532,15 @@ read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
520
532
  return NULL;
521
533
  }
522
534
 
535
+ irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
536
+
523
537
  bin += sizeof(struct rite_binary_header);
524
538
  do {
525
539
  section_header = (const struct rite_section_header *)bin;
526
540
  if (memcmp(section_header->section_ident, RITE_SECTION_IREP_IDENT, sizeof(section_header->section_ident)) == 0) {
527
541
  irep = read_section_irep(mrb, bin, flags);
528
542
  if (!irep) return NULL;
543
+ irep_obj->data = irep;
529
544
  }
530
545
  else if (memcmp(section_header->section_ident, RITE_SECTION_DEBUG_IDENT, sizeof(section_header->section_ident)) == 0) {
531
546
  if (!irep) return NULL; /* corrupted data */
@@ -544,6 +559,8 @@ read_irep(mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
544
559
  bin += bin_to_uint32(section_header->section_size);
545
560
  } while (memcmp(section_header->section_ident, RITE_BINARY_EOF, sizeof(section_header->section_ident)) != 0);
546
561
 
562
+ irep_obj->data = NULL;
563
+
547
564
  return irep;
548
565
  }
549
566
 
@@ -595,7 +612,16 @@ load_irep(mrb_state *mrb, mrb_irep *irep, mrbc_context *c)
595
612
  MRB_API mrb_value
596
613
  mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
597
614
  {
598
- return load_irep(mrb, mrb_read_irep(mrb, bin), c);
615
+ struct RData *irep_obj = mrb_data_object_alloc(mrb, mrb->object_class, NULL, &tempirep_type);
616
+ mrb_irep *irep = mrb_read_irep(mrb, bin);
617
+ mrb_value ret;
618
+
619
+ irep_obj->data = irep;
620
+ mrb_irep_incref(mrb, irep);
621
+ ret = load_irep(mrb, irep, c);
622
+ irep_obj->data = NULL;
623
+ mrb_irep_decref(mrb, irep);
624
+ return ret;
599
625
  }
600
626
 
601
627
  MRB_API mrb_value