script_core 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -57
- data/.ruby-version +1 -1
- data/Gemfile +2 -2
- data/README.md +7 -1
- data/ext/enterprise_script_service/Rakefile +1 -1
- data/ext/enterprise_script_service/libseccomp/.travis.yml +24 -12
- data/ext/enterprise_script_service/libseccomp/CHANGELOG +32 -0
- data/ext/enterprise_script_service/libseccomp/CONTRIBUTING.md +37 -26
- data/ext/enterprise_script_service/libseccomp/CREDITS +11 -0
- data/ext/enterprise_script_service/libseccomp/README.md +21 -1
- data/ext/enterprise_script_service/libseccomp/configure.ac +13 -8
- data/ext/enterprise_script_service/libseccomp/doc/Makefile.am +6 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_api_get.3 +12 -2
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_arch_add.3 +38 -6
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_attr_set.3 +53 -2
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_export_bpf.3 +20 -2
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_init.3 +9 -2
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_load.3 +32 -2
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_merge.3 +16 -2
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_alloc.3 +113 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_fd.3 +1 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_free.3 +1 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_id_valid.3 +1 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_receive.3 +1 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_notify_respond.3 +1 -0
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_rule_add.3 +64 -3
- data/ext/enterprise_script_service/libseccomp/doc/man/man3/seccomp_syscall_priority.3 +18 -3
- data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +19 -0
- data/ext/enterprise_script_service/libseccomp/include/seccomp.h.in +116 -0
- data/ext/enterprise_script_service/libseccomp/src/.gitignore +2 -0
- data/ext/enterprise_script_service/libseccomp/src/Makefile.am +31 -17
- data/ext/enterprise_script_service/libseccomp/src/api.c +254 -58
- data/ext/enterprise_script_service/libseccomp/src/arch-aarch64.h +1 -9
- data/ext/enterprise_script_service/libseccomp/src/arch-arm.c +47 -2
- data/ext/enterprise_script_service/libseccomp/src/arch-arm.h +1 -9
- data/ext/enterprise_script_service/libseccomp/src/arch-gperf-generate +40 -0
- data/ext/enterprise_script_service/libseccomp/src/arch-mips.c +41 -4
- data/ext/enterprise_script_service/libseccomp/src/arch-mips.h +2 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64.c +41 -4
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64.h +3 -11
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32.c +41 -4
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32.h +2 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-parisc.h +1 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-parisc64.c +3 -3
- data/ext/enterprise_script_service/libseccomp/src/arch-parisc64.h +29 -0
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc.h +1 -9
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc64.c +606 -8
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc64.h +2 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-riscv64.c +31 -0
- data/ext/enterprise_script_service/libseccomp/src/arch-riscv64.h +22 -0
- data/ext/enterprise_script_service/libseccomp/src/arch-s390.c +171 -12
- data/ext/enterprise_script_service/libseccomp/src/arch-s390.h +1 -17
- data/ext/enterprise_script_service/libseccomp/src/arch-s390x.c +166 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-s390x.h +1 -20
- data/ext/enterprise_script_service/libseccomp/src/arch-syscall-dump.c +8 -1
- data/ext/enterprise_script_service/libseccomp/src/arch-syscall-validate +359 -143
- data/ext/enterprise_script_service/libseccomp/src/arch-x32.c +36 -2
- data/ext/enterprise_script_service/libseccomp/src/arch-x32.h +2 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-x86.c +172 -10
- data/ext/enterprise_script_service/libseccomp/src/arch-x86.h +1 -14
- data/ext/enterprise_script_service/libseccomp/src/arch-x86_64.h +1 -9
- data/ext/enterprise_script_service/libseccomp/src/arch.c +11 -3
- data/ext/enterprise_script_service/libseccomp/src/arch.h +7 -0
- data/ext/enterprise_script_service/libseccomp/src/db.c +268 -57
- data/ext/enterprise_script_service/libseccomp/src/db.h +16 -2
- data/ext/enterprise_script_service/libseccomp/src/gen_bpf.c +503 -148
- data/ext/enterprise_script_service/libseccomp/src/gen_bpf.h +2 -1
- data/ext/enterprise_script_service/libseccomp/src/gen_pfc.c +165 -37
- data/ext/enterprise_script_service/libseccomp/src/python/libseccomp.pxd +37 -1
- data/ext/enterprise_script_service/libseccomp/src/python/seccomp.pyx +295 -5
- data/ext/enterprise_script_service/libseccomp/src/syscalls.c +56 -0
- data/ext/enterprise_script_service/libseccomp/src/syscalls.csv +470 -0
- data/ext/enterprise_script_service/libseccomp/src/syscalls.h +62 -0
- data/ext/enterprise_script_service/libseccomp/src/syscalls.perf.template +82 -0
- data/ext/enterprise_script_service/libseccomp/src/system.c +196 -16
- data/ext/enterprise_script_service/libseccomp/src/system.h +68 -13
- data/ext/enterprise_script_service/libseccomp/tests/.gitignore +10 -2
- data/ext/enterprise_script_service/libseccomp/tests/06-sim-actions.tests +1 -1
- data/ext/enterprise_script_service/libseccomp/tests/11-basic-basic_errors.c +5 -5
- data/ext/enterprise_script_service/libseccomp/tests/13-basic-attrs.c +35 -1
- data/ext/enterprise_script_service/libseccomp/tests/13-basic-attrs.py +10 -1
- data/ext/enterprise_script_service/libseccomp/tests/15-basic-resolver.c +4 -3
- data/ext/enterprise_script_service/libseccomp/tests/16-sim-arch_basic.c +12 -0
- data/ext/enterprise_script_service/libseccomp/tests/16-sim-arch_basic.py +1 -0
- data/ext/enterprise_script_service/libseccomp/tests/{18-sim-basic_whitelist.c → 18-sim-basic_allowlist.c} +0 -0
- data/ext/enterprise_script_service/libseccomp/tests/{18-sim-basic_whitelist.py → 18-sim-basic_allowlist.py} +0 -0
- data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_allowlist.tests +32 -0
- data/ext/enterprise_script_service/libseccomp/tests/23-sim-arch_all_le_basic.c +3 -0
- data/ext/enterprise_script_service/libseccomp/tests/23-sim-arch_all_le_basic.py +1 -0
- data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.c +3 -0
- data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.py +1 -0
- data/ext/enterprise_script_service/libseccomp/tests/30-sim-socket_syscalls.tests +33 -17
- data/ext/enterprise_script_service/libseccomp/tests/{34-sim-basic_blacklist.c → 34-sim-basic_denylist.c} +0 -0
- data/ext/enterprise_script_service/libseccomp/tests/{34-sim-basic_blacklist.py → 34-sim-basic_denylist.py} +0 -0
- data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_denylist.tests +32 -0
- data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.c +3 -0
- data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.py +1 -0
- data/ext/enterprise_script_service/libseccomp/tests/36-sim-ipc_syscalls.tests +25 -25
- data/ext/enterprise_script_service/libseccomp/tests/39-basic-api_level.c +24 -3
- data/ext/enterprise_script_service/libseccomp/tests/39-basic-api_level.py +16 -1
- data/ext/enterprise_script_service/libseccomp/tests/47-live-kill_process.c +3 -3
- data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.c +112 -0
- data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.py +60 -0
- data/ext/enterprise_script_service/libseccomp/tests/51-live-user_notification.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.c +48 -0
- data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.py +38 -0
- data/ext/enterprise_script_service/libseccomp/tests/52-basic-load.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.c +156 -0
- data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.py +95 -0
- data/ext/enterprise_script_service/libseccomp/tests/53-sim-binary_tree.tests +65 -0
- data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.c +128 -0
- data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.py +95 -0
- data/ext/enterprise_script_service/libseccomp/tests/54-live-binary_tree.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.c +134 -0
- data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.sh +46 -0
- data/ext/enterprise_script_service/libseccomp/tests/55-basic-pfc_binary_tree.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.c +90 -0
- data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.py +65 -0
- data/ext/enterprise_script_service/libseccomp/tests/56-basic-iterate_syscalls.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.c +64 -0
- data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.py +46 -0
- data/ext/enterprise_script_service/libseccomp/tests/57-basic-rawsysrc.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.c +116 -0
- data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.py +61 -0
- data/ext/enterprise_script_service/libseccomp/tests/58-live-tsync_notify.tests +11 -0
- data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +34 -10
- data/ext/enterprise_script_service/libseccomp/tests/regression +10 -3
- data/ext/enterprise_script_service/libseccomp/tests/util.c +3 -3
- data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -3
- data/ext/enterprise_script_service/libseccomp/tools/check-syntax +1 -1
- data/ext/enterprise_script_service/libseccomp/tools/scmp_arch_detect.c +3 -0
- data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_disasm.c +4 -2
- data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +4 -0
- data/ext/enterprise_script_service/libseccomp/tools/util.c +14 -12
- data/ext/enterprise_script_service/libseccomp/tools/util.h +7 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +149 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +55 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
- data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
- data/ext/enterprise_script_service/mruby/.gitignore +3 -0
- data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
- data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
- data/ext/enterprise_script_service/mruby/.travis.yml +7 -10
- data/ext/enterprise_script_service/mruby/.yamllint +8 -0
- data/ext/enterprise_script_service/mruby/AUTHORS +4 -0
- data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
- data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
- data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
- data/ext/enterprise_script_service/mruby/LICENSE +1 -1
- data/ext/enterprise_script_service/mruby/Makefile +1 -1
- data/ext/enterprise_script_service/mruby/README.md +5 -11
- data/ext/enterprise_script_service/mruby/Rakefile +18 -108
- data/ext/enterprise_script_service/mruby/TODO.md +17 -0
- data/ext/enterprise_script_service/mruby/appveyor.yml +29 -26
- data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
- data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +4 -21
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +4 -4
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +3 -20
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +4 -21
- data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_android_armeabi_v7a_neon_hard.rb → build_config/android_armeabi_v7a_neon_hard.rb} +0 -15
- data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
- data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +4 -21
- data/ext/enterprise_script_service/mruby/{appveyor_config.rb → build_config/ci/gcc-clang.rb} +11 -8
- data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
- data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
- data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
- data/ext/enterprise_script_service/mruby/build_config/dreamcast_shelf.rb +94 -0
- data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
- data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
- data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
- data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
- data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
- data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
- data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
- data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
- data/ext/enterprise_script_service/mruby/doc/guides/compile.md +142 -49
- data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
- data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
- data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +53 -30
- data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
- data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
- data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
- data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
- data/ext/enterprise_script_service/mruby/doc/opcode.md +102 -103
- data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
- data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
- data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
- data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
- data/ext/enterprise_script_service/mruby/include/mrbconf.h +88 -66
- data/ext/enterprise_script_service/mruby/include/mruby.h +160 -104
- data/ext/enterprise_script_service/mruby/include/mruby/array.h +27 -6
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +80 -46
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
- data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +76 -55
- data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
- data/ext/enterprise_script_service/mruby/include/mruby/common.h +14 -1
- data/ext/enterprise_script_service/mruby/include/mruby/compile.h +20 -6
- data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
- data/ext/enterprise_script_service/mruby/include/mruby/dump.h +18 -52
- data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
- data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
- data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
- data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
- data/ext/enterprise_script_service/mruby/include/mruby/irep.h +74 -14
- data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -1
- data/ext/enterprise_script_service/mruby/include/mruby/khash.h +19 -9
- data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +37 -63
- data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
- data/ext/enterprise_script_service/mruby/include/mruby/ops.h +29 -24
- data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
- data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
- data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
- data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
- data/ext/enterprise_script_service/mruby/include/mruby/proc.h +93 -21
- data/ext/enterprise_script_service/mruby/include/mruby/string.h +12 -16
- data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
- data/ext/enterprise_script_service/mruby/include/mruby/value.h +60 -59
- data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
- data/ext/enterprise_script_service/mruby/include/mruby/version.h +25 -6
- data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -72
- data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +71 -78
- data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
- data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
- data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +84 -32
- data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
- data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
- data/ext/enterprise_script_service/mruby/lib/mruby/source.rb +3 -1
- data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
- data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
- data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -81
- data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
- data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
- data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -32
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +10 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +0 -13
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +30 -18
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +6 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +46 -35
- data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +41 -28
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +26 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +6 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +7 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +495 -436
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +637 -220
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +13734 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +20 -23
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +9 -9
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +3 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +19 -238
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +21 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +19 -15
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +31 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +5 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +39 -7
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +2 -8
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file_constants.rb +0 -16
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +9 -14
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +107 -59
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +22 -38
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +417 -203
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +20 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +33 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +58 -50
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +13 -14
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +56 -73
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +13 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +80 -78
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +8 -16
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -13
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +120 -67
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +65 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +34 -21
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +21 -43
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +12 -20
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +5 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/mrbgem.rake +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/test/sockettest.c +3 -2
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +161 -93
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +9 -25
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +17 -14
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +23 -36
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +7 -6
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +17 -44
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +37 -41
- data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
- data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
- data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
- data/ext/enterprise_script_service/mruby/mrblib/00class.rb +10 -0
- data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
- data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
- data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
- data/ext/enterprise_script_service/mruby/mrblib/hash.rb +3 -23
- data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
- data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
- data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
- data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
- data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
- data/ext/enterprise_script_service/mruby/src/array.c +67 -90
- data/ext/enterprise_script_service/mruby/src/backtrace.c +18 -19
- data/ext/enterprise_script_service/mruby/src/class.c +819 -211
- data/ext/enterprise_script_service/mruby/src/codedump.c +226 -197
- data/ext/enterprise_script_service/mruby/src/debug.c +14 -11
- data/ext/enterprise_script_service/mruby/src/dump.c +470 -207
- data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
- data/ext/enterprise_script_service/mruby/src/error.c +94 -20
- data/ext/enterprise_script_service/mruby/src/etc.c +56 -39
- data/ext/enterprise_script_service/mruby/src/fmt_fp.c +103 -27
- data/ext/enterprise_script_service/mruby/src/gc.c +86 -349
- data/ext/enterprise_script_service/mruby/src/hash.c +1058 -723
- data/ext/enterprise_script_service/mruby/src/kernel.c +78 -226
- data/ext/enterprise_script_service/mruby/src/load.c +215 -159
- data/ext/enterprise_script_service/mruby/src/numeric.c +400 -382
- data/ext/enterprise_script_service/mruby/src/object.c +115 -90
- data/ext/enterprise_script_service/mruby/src/print.c +31 -6
- data/ext/enterprise_script_service/mruby/src/proc.c +56 -45
- data/ext/enterprise_script_service/mruby/src/range.c +49 -33
- data/ext/enterprise_script_service/mruby/src/state.c +58 -42
- data/ext/enterprise_script_service/mruby/src/string.c +151 -156
- data/ext/enterprise_script_service/mruby/src/symbol.c +132 -66
- data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
- data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
- data/ext/enterprise_script_service/mruby/src/vm.c +655 -645
- data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
- data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
- data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
- data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
- data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +64 -61
- data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
- data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
- data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
- data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
- data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
- data/ext/enterprise_script_service/mruby/tasks/toolchains/android.rake +46 -1
- data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +8 -7
- data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +13 -17
- data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +21 -25
- data/ext/enterprise_script_service/mruby/test/assert.rb +5 -4
- data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
- data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
- data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
- data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
- data/ext/enterprise_script_service/mruby/test/t/ensure.rb +8 -26
- data/ext/enterprise_script_service/mruby/test/t/exception.rb +2 -2
- data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
- data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
- data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
- data/ext/enterprise_script_service/mruby/test/t/kernel.rb +16 -25
- data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
- data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
- data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
- data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
- data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
- data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
- data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
- data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
- data/ext/enterprise_script_service/mruby_config.rb +2 -5
- data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
- data/ext/enterprise_script_service/msgpack/.github/depends/boost.sh +56 -0
- data/ext/enterprise_script_service/msgpack/.github/workflows/coverage.yml +62 -0
- data/ext/enterprise_script_service/msgpack/.github/workflows/gha.yml +304 -0
- data/ext/enterprise_script_service/msgpack/CHANGELOG.md +11 -0
- data/ext/enterprise_script_service/msgpack/CMakeLists.txt +82 -39
- data/ext/enterprise_script_service/msgpack/Files.cmake +22 -12
- data/ext/enterprise_script_service/msgpack/QUICKSTART-C.md +26 -29
- data/ext/enterprise_script_service/msgpack/README.md +3 -2
- data/ext/enterprise_script_service/msgpack/appveyor.yml +6 -2
- data/ext/enterprise_script_service/msgpack/ci/build_cmake.sh +3 -1
- data/ext/enterprise_script_service/msgpack/cmake/CodeCoverage.cmake +55 -0
- data/ext/enterprise_script_service/msgpack/codecov.yml +36 -0
- data/ext/enterprise_script_service/msgpack/example/CMakeLists.txt +9 -5
- data/ext/enterprise_script_service/msgpack/example/boost/CMakeLists.txt +1 -1
- data/ext/enterprise_script_service/msgpack/example/c/CMakeLists.txt +17 -6
- data/ext/enterprise_script_service/msgpack/example/c/boundary.c +296 -0
- data/ext/enterprise_script_service/msgpack/example/c/jsonconv.c +419 -0
- data/ext/enterprise_script_service/msgpack/example/c/simple_c.c +1 -1
- data/ext/enterprise_script_service/msgpack/example/cpp03/CMakeLists.txt +3 -3
- data/ext/enterprise_script_service/msgpack/example/cpp11/CMakeLists.txt +2 -2
- data/ext/enterprise_script_service/msgpack/example/x3/CMakeLists.txt +2 -2
- data/ext/enterprise_script_service/msgpack/include/msgpack/pack.h +24 -1
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +5 -4
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/boost/optional.hpp +4 -4
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp +8 -8
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/map.hpp +4 -4
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector.hpp +4 -4
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_char.hpp +8 -8
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/vector_unsigned_char.hpp +8 -8
- data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +4 -4
- data/ext/enterprise_script_service/msgpack/include/msgpack/v3/unpack.hpp +6 -6
- data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
- data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +4 -4
- data/ext/enterprise_script_service/msgpack/make_file_list.sh +38 -11
- data/ext/enterprise_script_service/msgpack/src/vrefbuffer.c +6 -0
- data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +86 -64
- data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +4 -1
- data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/buffer.cpp +4 -47
- data/ext/enterprise_script_service/msgpack/test/buffer_c.cpp +148 -0
- data/ext/enterprise_script_service/msgpack/test/carray.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/cases.cpp +8 -4
- data/ext/enterprise_script_service/msgpack/test/convert.cpp +8 -4
- data/ext/enterprise_script_service/msgpack/test/fixint.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/json.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/limit.cpp +8 -4
- data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +159 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +32 -27
- data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +4 -1
- data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/object.cpp +4 -1
- data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +12 -8
- data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +30 -26
- data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/raw.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/reference.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/streaming.cpp +8 -4
- data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/user_class.cpp +16 -12
- data/ext/enterprise_script_service/msgpack/test/version.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/visitor.cpp +4 -0
- data/ext/enterprise_script_service/msgpack/test/zone.cpp +4 -0
- data/lib/script_core/engine.rb +24 -5
- data/lib/script_core/executable.rb +4 -3
- data/lib/script_core/version.rb +1 -1
- data/lib/tasks/script_core.rake +3 -1
- data/script_core.gemspec +1 -2
- data/spec/dummy/app/lib/script_engine.rb +64 -5
- data/spec/script_core_spec.rb +13 -0
- metadata +123 -61
- data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +0 -559
- data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +0 -570
- data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +0 -562
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +0 -562
- data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +0 -562
- data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +0 -542
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +0 -559
- data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +0 -559
- data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +0 -626
- data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +0 -626
- data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +0 -558
- data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +0 -692
- data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +0 -559
- data/ext/enterprise_script_service/libseccomp/tests/18-sim-basic_whitelist.tests +0 -32
- data/ext/enterprise_script_service/libseccomp/tests/34-sim-basic_blacklist.tests +0 -32
- data/ext/enterprise_script_service/mruby/TODO +0 -8
- data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
- data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
- data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
- data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
- data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
- data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
- data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
- data/ext/enterprise_script_service/mruby/travis_config.rb +0 -54
- data/ext/enterprise_script_service/msgpack/.travis.yml +0 -258
@@ -4,88 +4,320 @@
|
|
4
4
|
** See Copyright Notice in mruby.h
|
5
5
|
*/
|
6
6
|
|
7
|
+
#include <string.h>
|
7
8
|
#include <mruby.h>
|
8
9
|
#include <mruby/array.h>
|
9
10
|
#include <mruby/class.h>
|
10
11
|
#include <mruby/hash.h>
|
11
12
|
#include <mruby/string.h>
|
12
13
|
#include <mruby/variable.h>
|
14
|
+
#include <mruby/presym.h>
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
/*
|
17
|
+
* === Glossary
|
18
|
+
*
|
19
|
+
* [EA]
|
20
|
+
* Entry Array. Store `Hash' entries in insertion order.
|
21
|
+
*
|
22
|
+
* [AR]
|
23
|
+
* Array Table Implementation. The structure of `Hash` that doesn't have a
|
24
|
+
* hash table and linearly searches EA. It is used when `Hash` size <= 16.
|
25
|
+
*
|
26
|
+
* [IB]
|
27
|
+
* Index Buckets. The buckets of hash table, where the bucket value is EA
|
28
|
+
* index. The index is represented by variable length bits according to
|
29
|
+
* the capacity.
|
30
|
+
*
|
31
|
+
* [HT]
|
32
|
+
* Hash Table Implementation. The structure of `Hash` that has IB and is
|
33
|
+
* searched by hash table algorithm. It is used when `Hash` size > 16.
|
34
|
+
* Collision resolution strategy is open addressing method.
|
35
|
+
*
|
36
|
+
* [size]
|
37
|
+
* The number of `Hash` entries (value of `Hash#size`).
|
38
|
+
*
|
39
|
+
* [slot]
|
40
|
+
* The generic term for EA or IB elements.
|
41
|
+
*
|
42
|
+
* [active]
|
43
|
+
* The state in which a slot is recognized as a `Hash` entry.
|
44
|
+
*
|
45
|
+
* [deleted]
|
46
|
+
* The state in which a slot is marked as deleted.
|
47
|
+
*
|
48
|
+
* [used]
|
49
|
+
* The state in which a slot is active or deleted.
|
50
|
+
*
|
51
|
+
* [empty]
|
52
|
+
* The state in which a slot is not used. Capacity is equal to the sum of
|
53
|
+
* the number of used slots and the number of empty slots.
|
54
|
+
*/
|
55
|
+
|
56
|
+
#define EA_N_RESERVED_INDICES 2 /* empty and deleted */
|
57
|
+
#define EA_INCREASE_RATIO 6 / 5 + 6
|
58
|
+
#define EA_MAX_INCREASE UINT16_MAX
|
59
|
+
#define EA_MAX_CAPA U32(lesser(IB_MAX_CAPA - EA_N_RESERVED_INDICES, MRB_INT_MAX))
|
60
|
+
#define IB_MAX_CAPA (U32(1) << IB_MAX_BIT)
|
61
|
+
#define IB_TYPE_BIT 32
|
62
|
+
#define IB_INIT_BIT ( \
|
63
|
+
ib_upper_bound_for(32) <= AR_MAX_SIZE ? 6 : \
|
64
|
+
ib_upper_bound_for(16) <= AR_MAX_SIZE ? 5 : \
|
65
|
+
4 \
|
66
|
+
)
|
67
|
+
#define IB_MAX_BIT (IB_TYPE_BIT - 1)
|
68
|
+
#define AR_DEFAULT_CAPA 4
|
69
|
+
#define AR_MAX_SIZE 16
|
70
|
+
#define H_MAX_SIZE EA_MAX_CAPA
|
71
|
+
|
72
|
+
mrb_static_assert1(offsetof(struct RHash, iv) == offsetof(struct RObject, iv));
|
73
|
+
mrb_static_assert1(AR_MAX_SIZE < (1 << MRB_HASH_AR_EA_CAPA_BIT));
|
74
|
+
|
75
|
+
typedef struct hash_entry {
|
76
|
+
mrb_value key;
|
77
|
+
mrb_value val;
|
78
|
+
} hash_entry;
|
79
|
+
|
80
|
+
typedef struct hash_table {
|
81
|
+
hash_entry *ea;
|
82
|
+
#ifdef MRB_32BIT
|
83
|
+
uint32_t ea_capa;
|
84
|
+
uint32_t ea_n_used;
|
85
|
+
#endif
|
86
|
+
uint32_t ib[];
|
87
|
+
} hash_table;
|
88
|
+
|
89
|
+
typedef struct index_buckets_iter {
|
90
|
+
struct RHash *h;
|
91
|
+
uint32_t bit;
|
92
|
+
uint32_t mask;
|
93
|
+
uint32_t pos;
|
94
|
+
uint32_t ary_index;
|
95
|
+
uint32_t ea_index;
|
96
|
+
uint32_t shift1;
|
97
|
+
uint32_t shift2;
|
98
|
+
uint32_t step;
|
99
|
+
} index_buckets_iter;
|
100
|
+
|
101
|
+
/*
|
102
|
+
* `c_` :: receiver class (category)
|
103
|
+
* `n_` :: attribute name
|
104
|
+
* `t_` :: attribute type
|
105
|
+
* `p_` :: struct member path
|
106
|
+
* `k_` :: macro key
|
107
|
+
*/
|
108
|
+
#define DEFINE_GETTER(c_, n_, t_, p_) \
|
109
|
+
MRB_INLINE t_ c_##_##n_(const struct RHash *h) {return h->p_;}
|
110
|
+
#define DEFINE_SETTER(c_, n_, t_, p_) \
|
111
|
+
MRB_INLINE void c_##_set_##n_(struct RHash *h, t_ v) {h->p_ = v;}
|
112
|
+
#define DEFINE_ACCESSOR(c_, n_, t_, p_) \
|
113
|
+
DEFINE_GETTER(c_, n_, t_, p_) \
|
114
|
+
DEFINE_SETTER(c_, n_, t_, p_)
|
115
|
+
#define DEFINE_FLAG_GETTER(c_, n_, t_, k_) \
|
116
|
+
MRB_INLINE t_ c_##_##n_(const struct RHash *h) { \
|
117
|
+
return (t_)((h->flags & MRB_HASH_##k_##_MASK) >> MRB_HASH_##k_##_SHIFT); \
|
118
|
+
}
|
119
|
+
#define DEFINE_FLAG_SETTER(c_, n_, t_, k_) \
|
120
|
+
MRB_INLINE void c_##_set_##n_(struct RHash *h, t_ v) { \
|
121
|
+
h->flags &= ~MRB_HASH_##k_##_MASK; \
|
122
|
+
h->flags |= v << MRB_HASH_##k_##_SHIFT; \
|
123
|
+
}
|
124
|
+
#define DEFINE_FLAG_ACCESSOR(c_, n_, t_, k_) \
|
125
|
+
DEFINE_FLAG_GETTER(c_, n_, t_, k_) \
|
126
|
+
DEFINE_FLAG_SETTER(c_, n_, t_, k_)
|
127
|
+
#define DEFINE_INCREMENTER(c_, n_) \
|
128
|
+
MRB_INLINE void c_##_inc_##n_(struct RHash *h) { \
|
129
|
+
c_##_set_##n_(h, c_##_##n_(h) + 1); \
|
130
|
+
}
|
131
|
+
#define DEFINE_DECREMENTER(c_, n_) \
|
132
|
+
MRB_INLINE void c_##_dec_##n_(struct RHash *h) { \
|
133
|
+
c_##_set_##n_(h, c_##_##n_(h) - 1); \
|
134
|
+
}
|
135
|
+
#define DEFINE_SWITCHER(n_, k_) \
|
136
|
+
MRB_INLINE void h_##n_##_on(struct RHash *h) { \
|
137
|
+
h->flags |= MRB_HASH_##k_; \
|
138
|
+
} \
|
139
|
+
MRB_INLINE void h_##n_##_off(struct RHash *h) { \
|
140
|
+
h->flags &= ~MRB_HASH_##k_; \
|
141
|
+
} \
|
142
|
+
MRB_INLINE mrb_bool h_##n_##_p(const struct RHash *h) { \
|
143
|
+
return (h->flags & MRB_HASH_##k_) == MRB_HASH_##k_; \
|
144
|
+
}
|
145
|
+
|
146
|
+
#ifdef MRB_64BIT
|
147
|
+
DEFINE_ACCESSOR(ar, ea_capa, uint32_t, ea_capa)
|
148
|
+
DEFINE_ACCESSOR(ar, ea_n_used, uint32_t, ea_n_used)
|
149
|
+
DEFINE_ACCESSOR(ht, ea_capa, uint32_t, ea_capa)
|
150
|
+
DEFINE_ACCESSOR(ht, ea_n_used, uint32_t, ea_n_used)
|
151
|
+
#else
|
152
|
+
DEFINE_FLAG_ACCESSOR(ar, ea_capa, uint32_t, AR_EA_CAPA)
|
153
|
+
DEFINE_FLAG_ACCESSOR(ar, ea_n_used, uint32_t, AR_EA_N_USED)
|
154
|
+
DEFINE_ACCESSOR(ht, ea_capa, uint32_t, ht->ea_capa)
|
155
|
+
DEFINE_ACCESSOR(ht, ea_n_used, uint32_t, ht->ea_n_used)
|
17
156
|
#endif
|
157
|
+
DEFINE_FLAG_ACCESSOR(ib, bit, uint32_t, IB_BIT)
|
158
|
+
DEFINE_ACCESSOR(ar, size, uint32_t, size)
|
159
|
+
DEFINE_ACCESSOR(ar, ea, hash_entry*, ea)
|
160
|
+
DEFINE_DECREMENTER(ar, size)
|
161
|
+
DEFINE_ACCESSOR(ht, size, uint32_t, size)
|
162
|
+
DEFINE_ACCESSOR(ht, ea, hash_entry*, ht->ea)
|
163
|
+
DEFINE_GETTER(ht, ib, uint32_t*, ht->ib)
|
164
|
+
DEFINE_INCREMENTER(ht, size)
|
165
|
+
DEFINE_DECREMENTER(ht, size)
|
166
|
+
DEFINE_GETTER(h, size, uint32_t, size)
|
167
|
+
DEFINE_ACCESSOR(h, ht, hash_table*, ht)
|
168
|
+
DEFINE_SWITCHER(ht, HT)
|
169
|
+
|
170
|
+
#define ea_each_used(ea, n_used, entry_var, code) do { \
|
171
|
+
hash_entry *entry_var = ea, *ea_end__ = entry_var + (n_used); \
|
172
|
+
for (; entry_var < ea_end__; ++entry_var) { \
|
173
|
+
code; \
|
174
|
+
} \
|
175
|
+
} while (0)
|
176
|
+
|
177
|
+
#define ea_each(ea, size, entry_var, code) do { \
|
178
|
+
hash_entry *entry_var = ea; \
|
179
|
+
uint32_t size__ = size; \
|
180
|
+
for (; 0 < size__; ++entry_var) { \
|
181
|
+
if (entry_deleted_p(entry_var)) continue; \
|
182
|
+
--size__; \
|
183
|
+
code; \
|
184
|
+
} \
|
185
|
+
} while (0)
|
186
|
+
|
187
|
+
#define ib_cycle_by_key(mrb, h, key, it_var, code) do { \
|
188
|
+
index_buckets_iter it_var[1]; \
|
189
|
+
ib_it_init(mrb, it_var, h, key); \
|
190
|
+
for (;;) { \
|
191
|
+
ib_it_next(it_var); \
|
192
|
+
code; \
|
193
|
+
} \
|
194
|
+
} while (0)
|
195
|
+
|
196
|
+
#define ib_find_by_key(mrb, h_, key_, it_var, code) do { \
|
197
|
+
mrb_value ib_fbk_key__ = key_; \
|
198
|
+
ib_cycle_by_key(mrb, h_, ib_fbk_key__, it_var, { \
|
199
|
+
if (ib_it_empty_p(it_var)) break; \
|
200
|
+
if (ib_it_deleted_p(it_var)) continue; \
|
201
|
+
if (obj_eql(mrb, ib_fbk_key__, ib_it_entry(it_var)->key, it_var->h)) { \
|
202
|
+
code; \
|
203
|
+
break; \
|
204
|
+
} \
|
205
|
+
}); \
|
206
|
+
} while (0)
|
207
|
+
|
208
|
+
#define h_each(h, entry_var, code) do { \
|
209
|
+
struct RHash *h__ = h; \
|
210
|
+
hash_entry *h_e_ea__; \
|
211
|
+
uint32_t h_e_size__; \
|
212
|
+
h_ar_p(h) ? (h_e_ea__ = ar_ea(h__), h_e_size__ = ar_size(h__)) : \
|
213
|
+
(h_e_ea__ = ht_ea(h__), h_e_size__ = ht_size(h__)); \
|
214
|
+
ea_each(h_e_ea__, h_e_size__, entry_var, code); \
|
215
|
+
} while (0)
|
18
216
|
|
19
|
-
|
20
|
-
|
217
|
+
/*
|
218
|
+
* `h_check_modified` raises an exception when a dangerous modification is
|
219
|
+
* made to `h` by executing `code`.
|
220
|
+
*
|
221
|
+
* This macro is not called if `h->ht` (`h->ea`) is `NULL` (`Hash` size is
|
222
|
+
* zero). And because the `hash_entry` is rather large, `h->ht->ea` and
|
223
|
+
* `h->ht->ea_capa` are able to be safely accessed even in AR. This nature
|
224
|
+
* is used to eliminate branch of AR or HT.
|
225
|
+
*
|
226
|
+
* `HT_ASSERT_SAFE_READ` checks if members can be accessed according to its
|
227
|
+
* assumptions.
|
228
|
+
*/
|
229
|
+
#define HT_ASSERT_SAFE_READ(attr_name) \
|
230
|
+
mrb_static_assert1( \
|
231
|
+
offsetof(hash_table, attr_name) + sizeof(((hash_table*)0)->attr_name) <= \
|
232
|
+
sizeof(hash_entry))
|
233
|
+
HT_ASSERT_SAFE_READ(ea);
|
234
|
+
#ifdef MRB_32BIT
|
235
|
+
HT_ASSERT_SAFE_READ(ea_capa);
|
21
236
|
#endif
|
22
|
-
#
|
237
|
+
#undef HT_ASSERT_SAFE_READ
|
238
|
+
#define h_check_modified(mrb, h, code) do { \
|
239
|
+
struct RHash *h__ = h; \
|
240
|
+
uint32_t mask = MRB_HASH_HT|MRB_HASH_IB_BIT_MASK|MRB_HASH_AR_EA_CAPA_MASK; \
|
241
|
+
uint32_t flags = h__->flags & mask; \
|
242
|
+
void* tbl__ = (mrb_assert(h__->ht), h__->ht); \
|
243
|
+
uint32_t ht_ea_capa__ = ht_ea_capa(h__); \
|
244
|
+
hash_entry *ht_ea__ = ht_ea(h__); \
|
245
|
+
code; \
|
246
|
+
if (flags != (h__->flags & mask) || \
|
247
|
+
tbl__ != h__->ht || \
|
248
|
+
ht_ea_capa__ != ht_ea_capa(h__) || \
|
249
|
+
ht_ea__ != ht_ea(h__)) { \
|
250
|
+
mrb_raise(mrb, E_RUNTIME_ERROR, "hash modified"); \
|
251
|
+
} \
|
252
|
+
} while (0)
|
23
253
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
/* hash table structure */
|
42
|
-
typedef struct htable {
|
43
|
-
segment *rootseg;
|
44
|
-
segment *lastseg;
|
45
|
-
mrb_int size;
|
46
|
-
uint16_t last_len;
|
47
|
-
segindex *index;
|
48
|
-
} htable;
|
49
|
-
|
50
|
-
static /* inline */ size_t
|
51
|
-
ht_hash_func(mrb_state *mrb, htable *t, mrb_value key)
|
254
|
+
#define U32(v) ((uint32_t)(v))
|
255
|
+
#define h_ar_p(h) (!h_ht_p(h))
|
256
|
+
#define h_ar_on(h) h_ht_off(h)
|
257
|
+
#define lesser(a, b) ((a) < (b) ? (a) : (b))
|
258
|
+
#define RHASH_IFNONE(hash) mrb_iv_get(mrb, (hash), MRB_SYM(ifnone))
|
259
|
+
#define RHASH_PROCDEFAULT(hash) RHASH_IFNONE(hash)
|
260
|
+
|
261
|
+
static uint32_t ib_upper_bound_for(uint32_t capa);
|
262
|
+
static uint32_t ib_bit_to_capa(uint32_t bit);
|
263
|
+
static void ht_init(
|
264
|
+
mrb_state *mrb, struct RHash *h, uint32_t size,
|
265
|
+
hash_entry *ea, uint32_t ea_capa, hash_table *ht, uint32_t ib_bit);
|
266
|
+
static void ht_set_without_ib_adjustment(
|
267
|
+
mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val);
|
268
|
+
|
269
|
+
static uint32_t
|
270
|
+
next_power2(uint32_t v)
|
52
271
|
{
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
272
|
+
mrb_assert(v != 0);
|
273
|
+
#ifdef __GNUC__
|
274
|
+
return U32(1) << ((sizeof(unsigned) * CHAR_BIT) - __builtin_clz(v));
|
275
|
+
#else
|
276
|
+
v |= v >> 1;
|
277
|
+
v |= v >> 2;
|
278
|
+
v |= v >> 4;
|
279
|
+
v |= v >> 8;
|
280
|
+
v |= v >> 16;
|
281
|
+
++v;
|
282
|
+
return v;
|
283
|
+
#endif
|
284
|
+
}
|
58
285
|
|
286
|
+
static uint32_t
|
287
|
+
obj_hash_code(mrb_state *mrb, mrb_value key, struct RHash *h)
|
288
|
+
{
|
289
|
+
enum mrb_vtype tt = mrb_type(key);
|
290
|
+
uint32_t hash_code;
|
291
|
+
mrb_value hash_code_obj;
|
59
292
|
switch (tt) {
|
60
293
|
case MRB_TT_STRING:
|
61
|
-
|
294
|
+
hash_code = mrb_str_hash(mrb, key);
|
62
295
|
break;
|
63
|
-
|
64
296
|
case MRB_TT_TRUE:
|
65
297
|
case MRB_TT_FALSE:
|
66
298
|
case MRB_TT_SYMBOL:
|
67
|
-
case
|
68
|
-
#ifndef
|
299
|
+
case MRB_TT_INTEGER:
|
300
|
+
#ifndef MRB_NO_FLOAT
|
69
301
|
case MRB_TT_FLOAT:
|
70
302
|
#endif
|
71
|
-
|
303
|
+
hash_code = U32(mrb_obj_id(key));
|
72
304
|
break;
|
73
|
-
|
74
305
|
default:
|
75
|
-
|
76
|
-
|
306
|
+
h_check_modified(mrb, h, {
|
307
|
+
hash_code_obj = mrb_funcall_argv(mrb, key, MRB_SYM(hash), 0, NULL);
|
308
|
+
});
|
309
|
+
|
310
|
+
hash_code = U32(tt) ^ U32(mrb_integer(hash_code_obj));
|
77
311
|
break;
|
78
312
|
}
|
79
|
-
|
80
|
-
mrb_raise(mrb, E_RUNTIME_ERROR, "hash modified");
|
81
|
-
}
|
82
|
-
return ((h)^((h)<<2)^((h)>>2));
|
313
|
+
return hash_code ^ (hash_code << 2) ^ (hash_code >> 2);
|
83
314
|
}
|
84
315
|
|
85
|
-
static
|
86
|
-
|
316
|
+
static mrb_bool
|
317
|
+
obj_eql(mrb_state *mrb, mrb_value a, mrb_value b, struct RHash *h)
|
87
318
|
{
|
88
319
|
enum mrb_vtype tt = mrb_type(a);
|
320
|
+
mrb_bool eql;
|
89
321
|
|
90
322
|
switch (tt) {
|
91
323
|
case MRB_TT_STRING:
|
@@ -95,611 +327,848 @@ ht_hash_equal(mrb_state *mrb, htable *t, mrb_value a, mrb_value b)
|
|
95
327
|
if (!mrb_symbol_p(b)) return FALSE;
|
96
328
|
return mrb_symbol(a) == mrb_symbol(b);
|
97
329
|
|
98
|
-
case
|
99
|
-
|
100
|
-
|
101
|
-
return mrb_fixnum(a) == mrb_fixnum(b);
|
102
|
-
#ifndef MRB_WITHOUT_FLOAT
|
103
|
-
case MRB_TT_FLOAT:
|
104
|
-
return (mrb_float)mrb_fixnum(a) == mrb_float(b);
|
105
|
-
#endif
|
106
|
-
default:
|
107
|
-
return FALSE;
|
108
|
-
}
|
330
|
+
case MRB_TT_INTEGER:
|
331
|
+
if (!mrb_integer_p(b)) return FALSE;
|
332
|
+
return mrb_integer(a) == mrb_integer(b);
|
109
333
|
|
110
|
-
#ifndef
|
334
|
+
#ifndef MRB_NO_FLOAT
|
111
335
|
case MRB_TT_FLOAT:
|
112
|
-
|
113
|
-
|
114
|
-
return mrb_float(a) == (mrb_float)mrb_fixnum(b);
|
115
|
-
case MRB_TT_FLOAT:
|
116
|
-
return mrb_float(a) == mrb_float(b);
|
117
|
-
default:
|
118
|
-
return FALSE;
|
119
|
-
}
|
336
|
+
if (!mrb_float_p(b)) return FALSE;
|
337
|
+
return mrb_float(a) == mrb_float(b);
|
120
338
|
#endif
|
121
339
|
|
122
340
|
default:
|
123
|
-
{
|
124
|
-
|
125
|
-
|
126
|
-
mrb_bool eql = mrb_eql(mrb, a, b);
|
127
|
-
if (index && (index != t->index || capa != index->capa)) {
|
128
|
-
mrb_raise(mrb, E_RUNTIME_ERROR, "hash modified");
|
129
|
-
}
|
130
|
-
return eql;
|
131
|
-
}
|
132
|
-
}
|
341
|
+
h_check_modified(mrb, h, {eql = mrb_eql(mrb, a, b);});
|
342
|
+
return eql;
|
343
|
+
}
|
133
344
|
}
|
134
345
|
|
135
|
-
|
136
|
-
|
137
|
-
ht_new(mrb_state *mrb)
|
346
|
+
static mrb_bool
|
347
|
+
entry_deleted_p(const hash_entry* entry)
|
138
348
|
{
|
139
|
-
|
349
|
+
return mrb_undef_p(entry->key);
|
350
|
+
}
|
140
351
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
t->index = NULL;
|
352
|
+
static void
|
353
|
+
entry_delete(hash_entry* entry)
|
354
|
+
{
|
355
|
+
entry->key = mrb_undef_value();
|
356
|
+
}
|
147
357
|
|
148
|
-
|
358
|
+
static uint32_t
|
359
|
+
ea_next_capa_for(uint32_t size, uint32_t max_capa)
|
360
|
+
{
|
361
|
+
if (size < AR_DEFAULT_CAPA) {
|
362
|
+
return AR_DEFAULT_CAPA;
|
363
|
+
}
|
364
|
+
else {
|
365
|
+
/*
|
366
|
+
* For 32-bit CPU, the theoretical value of maximum EA capacity is
|
367
|
+
* `UINT32_MAX / sizeof (hash_entry)`. At this time, if
|
368
|
+
* `EA_INCREASE_RATIO` is the current value, 32-bit range will not be
|
369
|
+
* exceeded during the calculation of `capa`, so `size_t` is used.
|
370
|
+
*/
|
371
|
+
size_t capa = (size_t)size * EA_INCREASE_RATIO, inc = capa - size;
|
372
|
+
if (EA_MAX_INCREASE < inc) capa = size + EA_MAX_INCREASE;
|
373
|
+
return capa <= max_capa ? U32(capa) : max_capa;
|
374
|
+
}
|
149
375
|
}
|
150
376
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
v |= v >> 8;\
|
157
|
-
v |= v >> 16;\
|
158
|
-
v++;\
|
159
|
-
} while (0)
|
377
|
+
static hash_entry*
|
378
|
+
ea_resize(mrb_state *mrb, hash_entry *ea, uint32_t capa)
|
379
|
+
{
|
380
|
+
return (hash_entry*)mrb_realloc(mrb, ea, sizeof(hash_entry) * capa);
|
381
|
+
}
|
160
382
|
|
161
|
-
|
162
|
-
|
163
|
-
|
383
|
+
static void
|
384
|
+
ea_compress(hash_entry *ea, uint32_t n_used)
|
385
|
+
{
|
386
|
+
hash_entry *w_entry = ea;
|
387
|
+
ea_each_used(ea, n_used, r_entry, {
|
388
|
+
if (entry_deleted_p(r_entry)) continue;
|
389
|
+
if (r_entry != w_entry) *w_entry = *r_entry;
|
390
|
+
++w_entry;
|
391
|
+
});
|
392
|
+
}
|
393
|
+
|
394
|
+
/*
|
395
|
+
* Increase or decrease capacity of `ea` to a standard size that can
|
396
|
+
* accommodate `*capap + 1` entries (but, not exceed `max_capa`). Set the
|
397
|
+
* changed capacity to `*capap` and return a pointer to `mrb_realloc`ed EA.
|
398
|
+
*/
|
399
|
+
static hash_entry*
|
400
|
+
ea_adjust(mrb_state *mrb, hash_entry *ea, uint32_t *capap, uint32_t max_capa)
|
401
|
+
{
|
402
|
+
*capap = ea_next_capa_for(*capap, max_capa);
|
403
|
+
return ea_resize(mrb, ea, *capap);
|
404
|
+
}
|
164
405
|
|
165
|
-
|
406
|
+
static hash_entry*
|
407
|
+
ea_dup(mrb_state *mrb, const hash_entry *ea, uint32_t capa)
|
408
|
+
{
|
409
|
+
size_t byte_size = sizeof(hash_entry) * capa;
|
410
|
+
hash_entry *new_ea = (hash_entry*)mrb_malloc(mrb, byte_size);
|
411
|
+
return (hash_entry*)memcpy(new_ea, ea, byte_size);
|
412
|
+
}
|
413
|
+
|
414
|
+
static hash_entry*
|
415
|
+
ea_get_by_key(mrb_state *mrb, hash_entry *ea, uint32_t size, mrb_value key,
|
416
|
+
struct RHash *h)
|
417
|
+
{
|
418
|
+
ea_each(ea, size, entry, {
|
419
|
+
if (obj_eql(mrb, key, entry->key, h)) return entry;
|
420
|
+
});
|
421
|
+
return NULL;
|
422
|
+
}
|
423
|
+
|
424
|
+
static hash_entry*
|
425
|
+
ea_get(hash_entry *ea, uint32_t index)
|
426
|
+
{
|
427
|
+
return &ea[index];
|
428
|
+
}
|
166
429
|
|
167
|
-
/* Build index for the hash table */
|
168
430
|
static void
|
169
|
-
|
431
|
+
ea_set(hash_entry *ea, uint32_t index, mrb_value key, mrb_value val)
|
170
432
|
{
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
segment *seg;
|
175
|
-
size_t i;
|
433
|
+
ea[index].key = key;
|
434
|
+
ea[index].val = val;
|
435
|
+
}
|
176
436
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
return;
|
188
|
-
}
|
189
|
-
t->index = index;
|
190
|
-
}
|
191
|
-
index->size = t->size;
|
192
|
-
index->capa = size;
|
193
|
-
for (i=0; i<size; i++) {
|
194
|
-
index->table[i] = NULL;
|
195
|
-
}
|
437
|
+
static void
|
438
|
+
ar_init(struct RHash *h, uint32_t size,
|
439
|
+
hash_entry *ea, uint32_t ea_capa, uint32_t ea_n_used)
|
440
|
+
{
|
441
|
+
h_ar_on(h);
|
442
|
+
ar_set_size(h, size);
|
443
|
+
ar_set_ea(h, ea);
|
444
|
+
ar_set_ea_capa(h, ea_capa);
|
445
|
+
ar_set_ea_n_used(h, ea_n_used);
|
446
|
+
}
|
196
447
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
mrb_value key;
|
203
|
-
size_t k, step = 0;
|
448
|
+
static void
|
449
|
+
ar_free(mrb_state *mrb, struct RHash *h)
|
450
|
+
{
|
451
|
+
mrb_free(mrb, ar_ea(h));
|
452
|
+
}
|
204
453
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
k = (k+(++step)) & mask;
|
213
|
-
}
|
214
|
-
index->table[k] = &seg->e[i];
|
215
|
-
}
|
216
|
-
seg = seg->next;
|
217
|
-
}
|
454
|
+
static void
|
455
|
+
ar_adjust_ea(mrb_state *mrb, struct RHash *h, uint32_t size, uint32_t max_ea_capa)
|
456
|
+
{
|
457
|
+
uint32_t ea_capa = size;
|
458
|
+
hash_entry *ea = ea_adjust(mrb, ar_ea(h), &ea_capa, max_ea_capa);
|
459
|
+
ar_set_ea(h, ea);
|
460
|
+
ar_set_ea_capa(h, ea_capa);
|
218
461
|
}
|
219
462
|
|
220
|
-
/* Compacts the hash table removing deleted entries. */
|
221
463
|
static void
|
222
|
-
|
223
|
-
{
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
if (t == NULL) return;
|
231
|
-
seg = t->rootseg;
|
232
|
-
if (t->index && (size_t)t->size == t->index->size) {
|
233
|
-
ht_index(mrb, t);
|
234
|
-
return;
|
235
|
-
}
|
236
|
-
while (seg) {
|
237
|
-
for (i=0; i<seg->size; i++) {
|
238
|
-
mrb_value k = seg->e[i].key;
|
464
|
+
ar_compress(mrb_state *mrb, struct RHash *h)
|
465
|
+
{
|
466
|
+
uint32_t size = ar_size(h);
|
467
|
+
ea_compress(ar_ea(h), ar_ea_n_used(h));
|
468
|
+
ar_set_ea_n_used(h, size);
|
469
|
+
ar_adjust_ea(mrb, h, size, lesser(ar_ea_capa(h), AR_MAX_SIZE));
|
470
|
+
}
|
239
471
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
472
|
+
static mrb_bool
|
473
|
+
ar_get(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value *valp)
|
474
|
+
{
|
475
|
+
ea_each(ar_ea(h), ar_size(h), entry, {
|
476
|
+
if (!obj_eql(mrb, key, entry->key, h)) continue;
|
477
|
+
*valp = entry->val;
|
478
|
+
return TRUE;
|
479
|
+
});
|
480
|
+
return FALSE;
|
481
|
+
}
|
482
|
+
|
483
|
+
static void
|
484
|
+
ar_set(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val)
|
485
|
+
{
|
486
|
+
uint32_t size = ar_size(h);
|
487
|
+
hash_entry *entry;
|
488
|
+
if ((entry = ea_get_by_key(mrb, ar_ea(h), size, key, h))) {
|
489
|
+
entry->val = val;
|
490
|
+
}
|
491
|
+
else {
|
492
|
+
uint32_t ea_capa = ar_ea_capa(h), ea_n_used = ar_ea_n_used(h);
|
493
|
+
if (ea_capa == ea_n_used) {
|
494
|
+
if (size == ea_n_used) {
|
495
|
+
if (size == AR_MAX_SIZE) {
|
496
|
+
hash_entry *ea = ea_adjust(mrb, ar_ea(h), &ea_capa, EA_MAX_CAPA);
|
497
|
+
ea_set(ea, ea_n_used, key, val);
|
498
|
+
ht_init(mrb, h, ++size, ea, ea_capa, NULL, IB_INIT_BIT);
|
499
|
+
return;
|
500
|
+
}
|
501
|
+
else {
|
502
|
+
ar_adjust_ea(mrb, h, size, AR_MAX_SIZE);
|
247
503
|
}
|
248
504
|
}
|
249
505
|
else {
|
250
|
-
|
251
|
-
|
252
|
-
seg2->e[i2++] = seg->e[i];
|
253
|
-
if (i2 >= seg2->size) {
|
254
|
-
seg2 = seg2->next;
|
255
|
-
i2 = 0;
|
256
|
-
}
|
257
|
-
}
|
506
|
+
ar_compress(mrb, h);
|
507
|
+
ea_n_used = size;
|
258
508
|
}
|
259
509
|
}
|
260
|
-
|
510
|
+
ea_set(ar_ea(h), ea_n_used, key, val);
|
511
|
+
ar_set_size(h, ++size);
|
512
|
+
ar_set_ea_n_used(h, ++ea_n_used);
|
261
513
|
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
514
|
+
}
|
515
|
+
|
516
|
+
static mrb_bool
|
517
|
+
ar_delete(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value *valp)
|
518
|
+
{
|
519
|
+
hash_entry *entry = ea_get_by_key(mrb, ar_ea(h), ar_size(h), key, h);
|
520
|
+
if (!entry) return FALSE;
|
521
|
+
*valp = entry->val;
|
522
|
+
entry_delete(entry);
|
523
|
+
ar_dec_size(h);
|
524
|
+
return TRUE;
|
525
|
+
}
|
526
|
+
|
527
|
+
static void
|
528
|
+
ar_shift(mrb_state *mrb, struct RHash *h, mrb_value *keyp, mrb_value *valp)
|
529
|
+
{
|
530
|
+
uint32_t size = ar_size(h);
|
531
|
+
ea_each(ar_ea(h), size, entry, {
|
532
|
+
*keyp = entry->key;
|
533
|
+
*valp = entry->val;
|
534
|
+
entry_delete(entry);
|
535
|
+
ar_set_size(h, --size);
|
536
|
+
return;
|
537
|
+
});
|
538
|
+
}
|
539
|
+
|
540
|
+
static void
|
541
|
+
ar_rehash(mrb_state *mrb, struct RHash *h)
|
542
|
+
{
|
543
|
+
/* see comments in `h_rehash` */
|
544
|
+
uint32_t size = ar_size(h), w_size = 0, ea_capa = ar_ea_capa(h);
|
545
|
+
hash_entry *ea = ar_ea(h), *w_entry;
|
546
|
+
ea_each(ea, size, r_entry, {
|
547
|
+
if ((w_entry = ea_get_by_key(mrb, ea, w_size, r_entry->key, h))) {
|
548
|
+
w_entry->val = r_entry->val;
|
549
|
+
ar_set_size(h, --size);
|
550
|
+
entry_delete(r_entry);
|
274
551
|
}
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
552
|
+
else {
|
553
|
+
if (w_size != U32(r_entry - ea)) {
|
554
|
+
ea_set(ea, w_size, r_entry->key, r_entry->val);
|
555
|
+
entry_delete(r_entry);
|
556
|
+
}
|
557
|
+
++w_size;
|
558
|
+
}
|
559
|
+
});
|
560
|
+
mrb_assert(size == w_size);
|
561
|
+
ar_set_ea_n_used(h, size);
|
562
|
+
ar_adjust_ea(mrb, h, size, ea_capa);
|
279
563
|
}
|
280
564
|
|
281
|
-
static
|
282
|
-
|
565
|
+
static uint32_t
|
566
|
+
ib_it_pos_for(index_buckets_iter *it, uint32_t v)
|
283
567
|
{
|
284
|
-
|
568
|
+
return v & it->mask;
|
569
|
+
}
|
285
570
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
571
|
+
static uint32_t
|
572
|
+
ib_it_empty_value(const index_buckets_iter *it)
|
573
|
+
{
|
574
|
+
return it->mask;
|
575
|
+
}
|
291
576
|
|
292
|
-
|
293
|
-
|
294
|
-
|
577
|
+
static uint32_t
|
578
|
+
ib_it_deleted_value(const index_buckets_iter *it)
|
579
|
+
{
|
580
|
+
return it->mask - 1;
|
581
|
+
}
|
295
582
|
|
296
|
-
|
583
|
+
static mrb_bool
|
584
|
+
ib_it_empty_p(const index_buckets_iter *it)
|
585
|
+
{
|
586
|
+
return it->ea_index == ib_it_empty_value(it);
|
587
|
+
}
|
588
|
+
|
589
|
+
static mrb_bool
|
590
|
+
ib_it_deleted_p(const index_buckets_iter *it)
|
591
|
+
{
|
592
|
+
return it->ea_index == ib_it_deleted_value(it);
|
593
|
+
}
|
594
|
+
|
595
|
+
static mrb_bool
|
596
|
+
ib_it_active_p(const index_buckets_iter *it)
|
597
|
+
{
|
598
|
+
return it->ea_index < ib_it_deleted_value(it);
|
297
599
|
}
|
298
600
|
|
299
|
-
/* Set the value for the key in the indexed table. */
|
300
601
|
static void
|
301
|
-
|
602
|
+
ib_it_init(mrb_state *mrb, index_buckets_iter *it, struct RHash *h, mrb_value key)
|
302
603
|
{
|
303
|
-
|
304
|
-
|
305
|
-
|
604
|
+
it->h = h;
|
605
|
+
it->bit = ib_bit(h);
|
606
|
+
it->mask = ib_bit_to_capa(it->bit) - 1;
|
607
|
+
it->pos = ib_it_pos_for(it, obj_hash_code(mrb, key, h));
|
608
|
+
it->step = 0;
|
609
|
+
}
|
306
610
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
611
|
+
static void
|
612
|
+
ib_it_next(index_buckets_iter *it)
|
613
|
+
{
|
614
|
+
/*
|
615
|
+
* [IB image]
|
616
|
+
*
|
617
|
+
* ary_index(1) --.
|
618
|
+
* \ .-- shift1(3) .-- shift2(29)
|
619
|
+
* pos(6) --. \ / /
|
620
|
+
* View | \ \ <-o-> <----------o---------->
|
621
|
+
* -------- +---------------------\----\--+-----------------------------+-----
|
622
|
+
* array | 0 `--. `-|--- o 1 | ...
|
623
|
+
* +---------+---------+-----+\--+-----+---------+---------+---+-----
|
624
|
+
* buckets | 0 | 1 | ... | o 6 | 7 | 8 | ...
|
625
|
+
* +---------+---------+-----+=========+---------+---------+---------
|
626
|
+
* bit set |1 1 1 0 0|0 0 0 1 1| ... |0 1 0 1 1|0 1 1 1 0|0 1 0 1 0| ...
|
627
|
+
* +---------+---------+-----+========*+---------+---------+---------
|
628
|
+
* <---o---> \
|
629
|
+
* \ `-- bit_pos(34)
|
630
|
+
* `-- bit(5)
|
631
|
+
*/
|
632
|
+
|
633
|
+
/* Slide to handle as `capa == 32` to avoid 64-bit operations */
|
634
|
+
uint32_t slid_pos = it->pos & (IB_TYPE_BIT - 1);
|
635
|
+
uint32_t slid_bit_pos = it->bit * (slid_pos + 1) - 1;
|
636
|
+
uint32_t slid_ary_index = slid_bit_pos / IB_TYPE_BIT;
|
637
|
+
it->ary_index = slid_ary_index + it->pos / IB_TYPE_BIT * it->bit;
|
638
|
+
it->shift2 = (slid_ary_index + 1) * IB_TYPE_BIT - slid_bit_pos - 1;
|
639
|
+
it->ea_index = (ht_ib(it->h)[it->ary_index] >> it->shift2) & it->mask;
|
640
|
+
if (IB_TYPE_BIT - it->bit < it->shift2) {
|
641
|
+
it->shift1 = IB_TYPE_BIT - it->shift2;
|
642
|
+
it->ea_index |= (ht_ib(it->h)[it->ary_index - 1] << it->shift1) & it->mask;
|
325
643
|
}
|
326
|
-
|
327
|
-
|
644
|
+
else {
|
645
|
+
it->shift1 = 0;
|
328
646
|
}
|
647
|
+
it->pos = ib_it_pos_for(it, it->pos + (++it->step));
|
648
|
+
}
|
329
649
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
650
|
+
static uint32_t
|
651
|
+
ib_it_get(const index_buckets_iter *it)
|
652
|
+
{
|
653
|
+
return it->ea_index;
|
654
|
+
}
|
655
|
+
|
656
|
+
static void
|
657
|
+
ib_it_set(index_buckets_iter *it, uint32_t ea_index)
|
658
|
+
{
|
659
|
+
uint32_t mask, i;
|
660
|
+
it->ea_index = ea_index;
|
661
|
+
if (it->shift1) {
|
662
|
+
i = it->ary_index - 1;
|
663
|
+
mask = it->mask >> it->shift1;
|
664
|
+
ht_ib(it->h)[i] = (ht_ib(it->h)[i] & ~mask) | (ea_index >> it->shift1);
|
342
665
|
}
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
t->size++;
|
666
|
+
i = it->ary_index;
|
667
|
+
mask = it->mask << it->shift2;
|
668
|
+
ht_ib(it->h)[i] = (ht_ib(it->h)[i] & ~mask) | (ea_index << it->shift2);
|
347
669
|
}
|
348
670
|
|
349
|
-
/* Set the value for the key in the hash table. */
|
350
671
|
static void
|
351
|
-
|
672
|
+
ib_it_delete(index_buckets_iter *it)
|
352
673
|
{
|
353
|
-
|
354
|
-
|
674
|
+
ib_it_set(it, ib_it_deleted_value(it));
|
675
|
+
}
|
355
676
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
seg = t->rootseg;
|
362
|
-
while (seg) {
|
363
|
-
for (i=0; i<seg->size; i++) {
|
364
|
-
mrb_value k = seg->e[i].key;
|
365
|
-
/* Found room in last segment after last_len */
|
366
|
-
if (!seg->next && i >= t->last_len) {
|
367
|
-
seg->e[i].key = key;
|
368
|
-
seg->e[i].val = val;
|
369
|
-
t->last_len = i+1;
|
370
|
-
t->size++;
|
371
|
-
return;
|
372
|
-
}
|
373
|
-
if (mrb_undef_p(k)) {
|
374
|
-
deleted++;
|
375
|
-
continue;
|
376
|
-
}
|
377
|
-
if (ht_hash_equal(mrb, t, k, key)) {
|
378
|
-
seg->e[i].val = val;
|
379
|
-
return;
|
380
|
-
}
|
381
|
-
}
|
382
|
-
seg = seg->next;
|
383
|
-
}
|
384
|
-
/* Not found */
|
677
|
+
static hash_entry*
|
678
|
+
ib_it_entry(index_buckets_iter *it)
|
679
|
+
{
|
680
|
+
return ea_get(ht_ea(it->h), it->ea_index);
|
681
|
+
}
|
385
682
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
683
|
+
static uint32_t
|
684
|
+
ib_capa_to_bit(uint32_t capa)
|
685
|
+
{
|
686
|
+
#ifdef __GNUC__
|
687
|
+
return U32(__builtin_ctz(capa));
|
688
|
+
#else
|
689
|
+
/* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn */
|
690
|
+
static const uint32_t MultiplyDeBruijnBitPosition2[] = {
|
691
|
+
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
|
692
|
+
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
|
693
|
+
};
|
694
|
+
return MultiplyDeBruijnBitPosition2[U32(capa * 0x077CB531U) >> 27];
|
695
|
+
#endif
|
696
|
+
}
|
391
697
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
}
|
397
|
-
else {
|
398
|
-
/* append new segment */
|
399
|
-
seg = segment_alloc(mrb, t->lastseg);
|
400
|
-
i = 0;
|
401
|
-
if (t->rootseg == NULL) {
|
402
|
-
t->rootseg = seg;
|
403
|
-
}
|
404
|
-
else {
|
405
|
-
t->lastseg->next = seg;
|
406
|
-
}
|
407
|
-
t->lastseg = seg;
|
408
|
-
}
|
409
|
-
seg->e[i].key = key;
|
410
|
-
seg->e[i].val = val;
|
411
|
-
t->last_len = i+1;
|
412
|
-
if (t->index == NULL && t->size > MRB_HT_INIT_SIZE*4) {
|
413
|
-
ht_index(mrb, t);
|
414
|
-
}
|
698
|
+
static uint32_t
|
699
|
+
ib_bit_to_capa(uint32_t bit)
|
700
|
+
{
|
701
|
+
return U32(1) << bit;
|
415
702
|
}
|
416
703
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
segindex *index = t->index;
|
422
|
-
size_t mask = HT_MASK(index);
|
423
|
-
size_t k = ht_hash_func(mrb, t, key) & mask;
|
424
|
-
size_t step = 0;
|
425
|
-
|
426
|
-
while (index->table[k]) {
|
427
|
-
mrb_value key2 = index->table[k]->key;
|
428
|
-
if (!mrb_undef_p(key2) && ht_hash_equal(mrb, t, key, key2)) {
|
429
|
-
if (vp) *vp = index->table[k]->val;
|
430
|
-
return TRUE;
|
431
|
-
}
|
432
|
-
k = (k+(++step)) & mask;
|
433
|
-
}
|
434
|
-
return FALSE;
|
704
|
+
static uint32_t
|
705
|
+
ib_upper_bound_for(uint32_t capa)
|
706
|
+
{
|
707
|
+
return (capa >> 2) | (capa >> 1); /* 3/4 */
|
435
708
|
}
|
436
709
|
|
437
|
-
|
438
|
-
|
439
|
-
ht_get(mrb_state *mrb, htable *t, mrb_value key, mrb_value *vp)
|
710
|
+
static uint32_t
|
711
|
+
ib_bit_for(uint32_t size)
|
440
712
|
{
|
441
|
-
|
442
|
-
|
713
|
+
uint32_t capa = next_power2(size);
|
714
|
+
if (capa != IB_MAX_CAPA && ib_upper_bound_for(capa) < size) capa *= 2;
|
715
|
+
return ib_capa_to_bit(capa);
|
716
|
+
}
|
443
717
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
718
|
+
static uint32_t
|
719
|
+
ib_byte_size_for(uint32_t ib_bit)
|
720
|
+
{
|
721
|
+
uint32_t ary_size = IB_INIT_BIT == 4 ?
|
722
|
+
ib_bit_to_capa(ib_bit) * 2 / IB_TYPE_BIT * ib_bit / 2 :
|
723
|
+
ib_bit_to_capa(ib_bit) / IB_TYPE_BIT * ib_bit;
|
724
|
+
return U32(sizeof(uint32_t) * ary_size);
|
725
|
+
}
|
448
726
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
727
|
+
static void
|
728
|
+
ib_init(mrb_state *mrb, struct RHash *h, uint32_t ib_bit, size_t ib_byte_size)
|
729
|
+
{
|
730
|
+
hash_entry *ea = ht_ea(h);
|
731
|
+
memset(ht_ib(h), 0xff, ib_byte_size);
|
732
|
+
ib_set_bit(h, ib_bit);
|
733
|
+
ea_each_used(ea, ht_ea_n_used(h), entry, {
|
734
|
+
ib_cycle_by_key(mrb, h, entry->key, it, {
|
735
|
+
if (!ib_it_empty_p(it)) continue;
|
736
|
+
ib_it_set(it, U32(entry - ea));
|
737
|
+
break;
|
738
|
+
});
|
739
|
+
});
|
740
|
+
}
|
453
741
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
742
|
+
static void
|
743
|
+
ht_init(mrb_state *mrb, struct RHash *h, uint32_t size,
|
744
|
+
hash_entry *ea, uint32_t ea_capa, hash_table *ht, uint32_t ib_bit)
|
745
|
+
{
|
746
|
+
size_t ib_byte_size = ib_byte_size_for(ib_bit);
|
747
|
+
size_t ht_byte_size = sizeof(hash_table) + ib_byte_size;
|
748
|
+
h_ht_on(h);
|
749
|
+
h_set_ht(h, (hash_table*)mrb_realloc(mrb, ht, ht_byte_size));
|
750
|
+
ht_set_size(h, size);
|
751
|
+
ht_set_ea(h, ea);
|
752
|
+
ht_set_ea_capa(h, ea_capa);
|
753
|
+
ht_set_ea_n_used(h, size);
|
754
|
+
ib_init(mrb, h, ib_bit, ib_byte_size);
|
755
|
+
}
|
756
|
+
|
757
|
+
static void
|
758
|
+
ht_free(mrb_state *mrb, struct RHash *h)
|
759
|
+
{
|
760
|
+
mrb_free(mrb, ht_ea(h));
|
761
|
+
mrb_free(mrb, h_ht(h));
|
762
|
+
}
|
763
|
+
|
764
|
+
static hash_table*
|
765
|
+
ht_dup(mrb_state *mrb, const struct RHash *h)
|
766
|
+
{
|
767
|
+
size_t ib_byte_size = ib_byte_size_for(ib_bit(h));
|
768
|
+
size_t ht_byte_size = sizeof(hash_table) + ib_byte_size;
|
769
|
+
hash_table *new_ht = (hash_table*)mrb_malloc(mrb, ht_byte_size);
|
770
|
+
return (hash_table*)memcpy(new_ht, h_ht(h), ht_byte_size);
|
771
|
+
}
|
772
|
+
|
773
|
+
static void
|
774
|
+
ht_adjust_ea(mrb_state *mrb, struct RHash *h, uint32_t size, uint32_t max_ea_capa)
|
775
|
+
{
|
776
|
+
uint32_t ea_capa = size;
|
777
|
+
hash_entry *ea = ea_adjust(mrb, ht_ea(h), &ea_capa, max_ea_capa);
|
778
|
+
ht_set_ea(h, ea);
|
779
|
+
ht_set_ea_capa(h, ea_capa);
|
780
|
+
}
|
781
|
+
|
782
|
+
static void
|
783
|
+
ht_to_ar(mrb_state *mrb, struct RHash *h)
|
784
|
+
{
|
785
|
+
uint32_t size = ht_size(h), ea_capa = size;
|
786
|
+
hash_entry *ea = ht_ea(h);
|
787
|
+
ea_compress(ea, ht_ea_n_used(h));
|
788
|
+
ea = ea_adjust(mrb, ea, &ea_capa, AR_MAX_SIZE);
|
789
|
+
mrb_free(mrb, h_ht(h));
|
790
|
+
ar_init(h, size, ea, ea_capa, size);
|
466
791
|
}
|
467
792
|
|
468
|
-
/* Deletes the value for the symbol from the hash table. */
|
469
|
-
/* Deletion is done by overwriting keys by `undef`. */
|
470
793
|
static mrb_bool
|
471
|
-
|
794
|
+
ht_get(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value *valp)
|
472
795
|
{
|
473
|
-
|
474
|
-
|
796
|
+
ib_find_by_key(mrb, h, key, it, {
|
797
|
+
*valp = ib_it_entry(it)->val;
|
798
|
+
return TRUE;
|
799
|
+
});
|
800
|
+
return FALSE;
|
801
|
+
}
|
475
802
|
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
803
|
+
static void
|
804
|
+
ht_set_as_ar(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val)
|
805
|
+
{
|
806
|
+
ht_to_ar(mrb, h);
|
807
|
+
ar_set(mrb, h, key, val);
|
808
|
+
}
|
481
809
|
|
482
|
-
|
483
|
-
|
484
|
-
|
810
|
+
static void
|
811
|
+
ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h,
|
812
|
+
mrb_value key, mrb_value val)
|
813
|
+
{
|
814
|
+
mrb_assert(ht_size(h) < ib_bit_to_capa(ib_bit(h)));
|
815
|
+
ib_cycle_by_key(mrb, h, key, it, {
|
816
|
+
if (ib_it_active_p(it)) {
|
817
|
+
if (!obj_eql(mrb, key, ib_it_entry(it)->key, h)) continue;
|
818
|
+
ib_it_entry(it)->val = val;
|
819
|
+
}
|
820
|
+
else {
|
821
|
+
uint32_t ea_n_used = ht_ea_n_used(h);
|
822
|
+
if (ea_n_used == H_MAX_SIZE) {
|
823
|
+
mrb_assert(ht_size(h) == ea_n_used);
|
824
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "hash too big");
|
485
825
|
}
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
826
|
+
if (ea_n_used == ht_ea_capa(h)) ht_adjust_ea(mrb, h, ea_n_used, EA_MAX_CAPA);
|
827
|
+
ib_it_set(it, ea_n_used);
|
828
|
+
ea_set(ht_ea(h), ea_n_used, key, val);
|
829
|
+
ht_inc_size(h);
|
830
|
+
ht_set_ea_n_used(h, ++ea_n_used);
|
831
|
+
}
|
832
|
+
return;
|
833
|
+
});
|
834
|
+
}
|
835
|
+
|
836
|
+
static void
|
837
|
+
ht_set(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val)
|
838
|
+
{
|
839
|
+
uint32_t size = ht_size(h);
|
840
|
+
uint32_t ib_bit_width = ib_bit(h), ib_capa = ib_bit_to_capa(ib_bit_width);
|
841
|
+
if (ib_upper_bound_for(ib_capa) <= size) {
|
842
|
+
if (size != ht_ea_n_used(h)) ea_compress(ht_ea(h), ht_ea_n_used(h));
|
843
|
+
ht_init(mrb, h, size, ht_ea(h), ht_ea_capa(h), h_ht(h), ++ib_bit_width);
|
844
|
+
}
|
845
|
+
else if (size != ht_ea_n_used(h)) {
|
846
|
+
if (ib_capa - EA_N_RESERVED_INDICES <= ht_ea_n_used(h)) goto compress;
|
847
|
+
if (ht_ea_capa(h) == ht_ea_n_used(h)) {
|
848
|
+
if (size <= AR_MAX_SIZE) {ht_set_as_ar(mrb, h, key, val); return;}
|
849
|
+
if (ea_next_capa_for(size, EA_MAX_CAPA) <= ht_ea_capa(h)) {
|
850
|
+
compress:
|
851
|
+
ea_compress(ht_ea(h), ht_ea_n_used(h));
|
852
|
+
ht_adjust_ea(mrb, h, size, ht_ea_capa(h));
|
853
|
+
ht_init(mrb, h, size, ht_ea(h), ht_ea_capa(h), h_ht(h), ib_bit_width);
|
492
854
|
}
|
493
855
|
}
|
494
|
-
seg = seg->next;
|
495
856
|
}
|
857
|
+
ht_set_without_ib_adjustment(mrb, h, key, val);
|
858
|
+
}
|
859
|
+
|
860
|
+
static mrb_bool
|
861
|
+
ht_delete(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value *valp)
|
862
|
+
{
|
863
|
+
ib_find_by_key(mrb, h, key, it, {
|
864
|
+
hash_entry *entry = ib_it_entry(it);
|
865
|
+
*valp = entry->val;
|
866
|
+
ib_it_delete(it);
|
867
|
+
entry_delete(entry);
|
868
|
+
ht_dec_size(h);
|
869
|
+
return TRUE;
|
870
|
+
});
|
496
871
|
return FALSE;
|
497
872
|
}
|
498
873
|
|
499
|
-
/* Iterates over the hash table. */
|
500
874
|
static void
|
501
|
-
|
502
|
-
{
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
875
|
+
ht_shift(mrb_state *mrb, struct RHash *h, mrb_value *keyp, mrb_value *valp)
|
876
|
+
{
|
877
|
+
hash_entry *ea = ht_ea(h);
|
878
|
+
ea_each(ea, ht_size(h), entry, {
|
879
|
+
ib_cycle_by_key(mrb, h, entry->key, it, {
|
880
|
+
if (ib_it_get(it) != U32(entry - ea)) continue;
|
881
|
+
*keyp = entry->key;
|
882
|
+
*valp = entry->val;
|
883
|
+
ib_it_delete(it);
|
884
|
+
entry_delete(entry);
|
885
|
+
ht_dec_size(h);
|
886
|
+
return;
|
887
|
+
});
|
888
|
+
});
|
889
|
+
}
|
890
|
+
|
891
|
+
static void
|
892
|
+
ht_rehash(mrb_state *mrb, struct RHash *h)
|
893
|
+
{
|
894
|
+
/* see comments in `h_rehash` */
|
895
|
+
uint32_t size = ht_size(h), w_size = 0, ea_capa = ht_ea_capa(h);
|
896
|
+
hash_entry *ea = ht_ea(h);
|
897
|
+
ht_init(mrb, h, 0, ea, ea_capa, h_ht(h), ib_bit_for(size));
|
898
|
+
ht_set_size(h, size);
|
899
|
+
ht_set_ea_n_used(h, ht_ea_n_used(h));
|
900
|
+
ea_each(ea, size, r_entry, {
|
901
|
+
ib_cycle_by_key(mrb, h, r_entry->key, it, {
|
902
|
+
if (ib_it_active_p(it)) {
|
903
|
+
if (!obj_eql(mrb, r_entry->key, ib_it_entry(it)->key, h)) continue;
|
904
|
+
ib_it_entry(it)->val = r_entry->val;
|
905
|
+
ht_set_size(h, --size);
|
906
|
+
entry_delete(r_entry);
|
513
907
|
}
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
908
|
+
else {
|
909
|
+
if (w_size != U32(r_entry - ea)) {
|
910
|
+
ea_set(ea, w_size, r_entry->key, r_entry->val);
|
911
|
+
entry_delete(r_entry);
|
912
|
+
}
|
913
|
+
ib_it_set(it, w_size++);
|
914
|
+
}
|
915
|
+
break;
|
916
|
+
});
|
917
|
+
});
|
918
|
+
mrb_assert(size == w_size);
|
919
|
+
ht_set_ea_n_used(h, size);
|
920
|
+
size <= AR_MAX_SIZE ? ht_to_ar(mrb, h) : ht_adjust_ea(mrb, h, size, ea_capa);
|
921
|
+
}
|
922
|
+
|
923
|
+
static mrb_value
|
924
|
+
h_key_for(mrb_state *mrb, mrb_value key)
|
925
|
+
{
|
926
|
+
if (mrb_string_p(key) && !MRB_FROZEN_P(mrb_str_ptr(key))) {
|
927
|
+
key = mrb_str_dup(mrb, key);
|
928
|
+
MRB_SET_FROZEN_FLAG(mrb_str_ptr(key));
|
519
929
|
}
|
930
|
+
return key;
|
520
931
|
}
|
521
932
|
|
522
|
-
|
523
|
-
|
524
|
-
mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, mrb_hash_foreach_func *func, void *p)
|
933
|
+
static struct RHash*
|
934
|
+
h_alloc(mrb_state *mrb)
|
525
935
|
{
|
526
|
-
|
936
|
+
return (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class);
|
527
937
|
}
|
528
938
|
|
529
|
-
|
530
|
-
|
531
|
-
ht_copy(mrb_state *mrb, htable *t)
|
939
|
+
static void
|
940
|
+
h_init(struct RHash *h)
|
532
941
|
{
|
533
|
-
|
534
|
-
|
535
|
-
mrb_int i;
|
942
|
+
ar_init(h, 0, NULL, 0, 0);
|
943
|
+
}
|
536
944
|
|
537
|
-
|
538
|
-
|
539
|
-
|
945
|
+
static void
|
946
|
+
h_free_table(mrb_state *mrb, struct RHash *h)
|
947
|
+
{
|
948
|
+
(h_ar_p(h) ? ar_free : ht_free)(mrb, h);
|
949
|
+
}
|
540
950
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
951
|
+
static void
|
952
|
+
h_clear(mrb_state *mrb, struct RHash *h)
|
953
|
+
{
|
954
|
+
h_free_table(mrb, h);
|
955
|
+
h_init(h);
|
956
|
+
}
|
545
957
|
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
ht_put(mrb, t2, key, val);
|
551
|
-
}
|
552
|
-
seg = seg->next;
|
553
|
-
}
|
554
|
-
return t2;
|
958
|
+
static mrb_bool
|
959
|
+
h_get(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value *valp)
|
960
|
+
{
|
961
|
+
return (h_ar_p(h) ? ar_get : ht_get)(mrb, h, key, valp);
|
555
962
|
}
|
556
963
|
|
557
|
-
/* Free memory of the hash table. */
|
558
964
|
static void
|
559
|
-
|
965
|
+
h_set(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val)
|
560
966
|
{
|
561
|
-
|
967
|
+
(h_ar_p(h) ? ar_set : ht_set)(mrb, h, key, val);
|
968
|
+
}
|
562
969
|
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
seg = seg->next;
|
568
|
-
mrb_free(mrb, p);
|
569
|
-
}
|
570
|
-
if (t->index) mrb_free(mrb, t->index);
|
571
|
-
mrb_free(mrb, t);
|
970
|
+
static mrb_bool
|
971
|
+
h_delete(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value *valp)
|
972
|
+
{
|
973
|
+
return (h_ar_p(h) ? ar_delete : ht_delete)(mrb, h, key, valp);
|
572
974
|
}
|
573
975
|
|
574
|
-
|
976
|
+
/* find first element in the table, and remove it. */
|
977
|
+
static void
|
978
|
+
h_shift(mrb_state *mrb, struct RHash *h, mrb_value *keyp, mrb_value *valp)
|
979
|
+
{
|
980
|
+
(h_ar_p(h) ? ar_shift : ht_shift)(mrb, h, keyp, valp);
|
981
|
+
}
|
575
982
|
|
576
|
-
static
|
577
|
-
|
983
|
+
static void
|
984
|
+
h_rehash(mrb_state *mrb, struct RHash *h)
|
578
985
|
{
|
579
|
-
|
580
|
-
|
581
|
-
|
986
|
+
/*
|
987
|
+
* ==== Comments common to `ar_rehash` and `ht_rehash`
|
988
|
+
*
|
989
|
+
* - Because reindex (such as elimination of duplicate keys) must be
|
990
|
+
* guaranteed, it is necessary to set one by one.
|
991
|
+
*
|
992
|
+
* - To prevent EA from breaking if an exception occurs in the middle,
|
993
|
+
* delete the slot before moving when moving the entry, and update size
|
994
|
+
* at any time when overwriting.
|
995
|
+
*/
|
996
|
+
(h_size(h) == 0 ? h_clear : h_ar_p(h) ? ar_rehash : ht_rehash)(mrb, h);
|
997
|
+
}
|
998
|
+
|
999
|
+
static void
|
1000
|
+
h_replace(mrb_state *mrb, struct RHash *h, struct RHash *orig_h)
|
1001
|
+
{
|
1002
|
+
uint32_t size = h_size(orig_h);
|
1003
|
+
if (size == 0) {
|
1004
|
+
h_clear(mrb, h);
|
1005
|
+
}
|
1006
|
+
else if (h_ar_p(orig_h)) {
|
1007
|
+
uint32_t ea_capa = ar_ea_capa(orig_h);
|
1008
|
+
hash_entry *ea = ea_dup(mrb, ar_ea(orig_h), ea_capa);
|
1009
|
+
h_free_table(mrb, h);
|
1010
|
+
ar_init(h, size, ea, ea_capa, ar_ea_n_used(orig_h));
|
1011
|
+
}
|
1012
|
+
else { /* HT */
|
1013
|
+
uint32_t ea_capa = ht_ea_capa(orig_h);
|
1014
|
+
hash_entry *ea = ea_dup(mrb, ht_ea(orig_h), ea_capa);
|
1015
|
+
hash_table *ht = ht_dup(mrb, orig_h);
|
1016
|
+
h_free_table(mrb, h);
|
1017
|
+
h_ht_on(h);
|
1018
|
+
h_set_ht(h, ht);
|
1019
|
+
ht_set_size(h, size);
|
1020
|
+
ht_set_ea(h, ea);
|
1021
|
+
#ifdef MRB_64BIT
|
1022
|
+
ht_set_ea_capa(h, ea_capa);
|
1023
|
+
ht_set_ea_n_used(h, ht_ea_n_used(orig_h));
|
1024
|
+
#endif
|
1025
|
+
ib_set_bit(h, ib_bit(orig_h));
|
582
1026
|
}
|
583
|
-
return key;
|
584
1027
|
}
|
585
1028
|
|
586
|
-
|
1029
|
+
void
|
1030
|
+
mrb_gc_mark_hash(mrb_state *mrb, struct RHash *h)
|
1031
|
+
{
|
1032
|
+
h_each(h, entry, {
|
1033
|
+
mrb_gc_mark_value(mrb, entry->key);
|
1034
|
+
mrb_gc_mark_value(mrb, entry->val);
|
1035
|
+
});
|
1036
|
+
}
|
587
1037
|
|
588
|
-
|
589
|
-
|
1038
|
+
size_t
|
1039
|
+
mrb_gc_mark_hash_size(mrb_state *mrb, struct RHash *h)
|
590
1040
|
{
|
591
|
-
|
592
|
-
mrb_gc_mark_value(mrb, val);
|
593
|
-
return 0;
|
1041
|
+
return h_size(h) * 2;
|
594
1042
|
}
|
595
1043
|
|
596
1044
|
void
|
597
|
-
|
1045
|
+
mrb_gc_free_hash(mrb_state *mrb, struct RHash *h)
|
598
1046
|
{
|
599
|
-
|
1047
|
+
h_free_table(mrb, h);
|
600
1048
|
}
|
601
1049
|
|
602
1050
|
size_t
|
603
|
-
|
1051
|
+
mrb_hash_memsize(mrb_value self)
|
604
1052
|
{
|
605
|
-
|
606
|
-
return
|
1053
|
+
struct RHash *h = mrb_hash_ptr(self);
|
1054
|
+
return mrb_obj_iv_tbl_memsize(self) +
|
1055
|
+
(h_ar_p(h) ? (ar_ea_capa(h) * sizeof(hash_entry)) :
|
1056
|
+
(ht_ea_capa(h) * sizeof(hash_entry) +
|
1057
|
+
sizeof(hash_table) +
|
1058
|
+
ib_byte_size_for(ib_bit(h))));
|
607
1059
|
}
|
608
1060
|
|
609
|
-
|
610
|
-
|
1061
|
+
/* Iterates over the key/value pairs. */
|
1062
|
+
MRB_API void
|
1063
|
+
mrb_hash_foreach(mrb_state *mrb, struct RHash *h, mrb_hash_foreach_func *func, void *data)
|
611
1064
|
{
|
612
|
-
|
1065
|
+
h_each(h, entry, {
|
1066
|
+
if (func(mrb, entry->key, entry->val, data) != 0) return;
|
1067
|
+
});
|
613
1068
|
}
|
614
1069
|
|
615
1070
|
MRB_API mrb_value
|
616
1071
|
mrb_hash_new(mrb_state *mrb)
|
617
1072
|
{
|
618
|
-
struct RHash *h;
|
619
|
-
|
620
|
-
h = (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class);
|
621
|
-
h->ht = 0;
|
622
|
-
h->iv = 0;
|
1073
|
+
struct RHash *h = h_alloc(mrb);
|
623
1074
|
return mrb_obj_value(h);
|
624
1075
|
}
|
625
1076
|
|
1077
|
+
/*
|
1078
|
+
* Set the capacity of EA and IB to minimum capacity (and appropriate load
|
1079
|
+
* factor) that does not cause expansion when inserting `capa` elements.
|
1080
|
+
*/
|
626
1081
|
MRB_API mrb_value
|
627
1082
|
mrb_hash_new_capa(mrb_state *mrb, mrb_int capa)
|
628
1083
|
{
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
1084
|
+
if (capa < 0 || EA_MAX_CAPA < capa) {
|
1085
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "hash too big");
|
1086
|
+
return mrb_nil_value(); /* not reached */
|
1087
|
+
}
|
1088
|
+
else if (capa == 0) {
|
1089
|
+
return mrb_hash_new(mrb);
|
1090
|
+
}
|
1091
|
+
else {
|
1092
|
+
uint32_t size = U32(capa);
|
1093
|
+
struct RHash *h = h_alloc(mrb);
|
1094
|
+
hash_entry *ea = ea_resize(mrb, NULL, size);
|
1095
|
+
if (size <= AR_MAX_SIZE) {
|
1096
|
+
ar_init(h, 0, ea, size, 0);
|
1097
|
+
}
|
1098
|
+
else {
|
1099
|
+
ht_init(mrb, h, 0, ea, size, NULL, ib_bit_for(size));
|
1100
|
+
}
|
1101
|
+
return mrb_obj_value(h);
|
1102
|
+
}
|
637
1103
|
}
|
638
1104
|
|
639
1105
|
static mrb_value mrb_hash_default(mrb_state *mrb, mrb_value hash);
|
640
|
-
|
1106
|
+
|
1107
|
+
static void
|
1108
|
+
hash_modify(mrb_state *mrb, mrb_value hash)
|
1109
|
+
{
|
1110
|
+
mrb_check_frozen(mrb, mrb_hash_ptr(hash));
|
1111
|
+
}
|
641
1112
|
|
642
1113
|
static mrb_value
|
643
|
-
|
1114
|
+
hash_default(mrb_state *mrb, mrb_value hash, mrb_value key)
|
644
1115
|
{
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
if ((mrb_type(self) != mrb_type(orig)) || (mrb_obj_class(mrb, self) != mrb_obj_class(mrb, orig))) {
|
653
|
-
mrb_raise(mrb, E_TYPE_ERROR, "initialize_copy should take same class object");
|
1116
|
+
if (MRB_RHASH_DEFAULT_P(hash)) {
|
1117
|
+
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
|
1118
|
+
return mrb_funcall_id(mrb, RHASH_PROCDEFAULT(hash), MRB_SYM(call), 2, hash, key);
|
1119
|
+
}
|
1120
|
+
else {
|
1121
|
+
return RHASH_IFNONE(hash);
|
1122
|
+
}
|
654
1123
|
}
|
1124
|
+
return mrb_nil_value();
|
1125
|
+
}
|
655
1126
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
1127
|
+
static void
|
1128
|
+
hash_replace(mrb_state *mrb, mrb_value self, mrb_value orig)
|
1129
|
+
{
|
1130
|
+
struct RHash *h = mrb_hash_ptr(self), *orig_h = mrb_hash_ptr(orig);
|
1131
|
+
uint32_t mask = MRB_HASH_DEFAULT | MRB_HASH_PROC_DEFAULT;
|
1132
|
+
mrb_sym name;
|
1133
|
+
h_replace(mrb, h, orig_h);
|
1134
|
+
name = MRB_SYM(ifnone);
|
1135
|
+
if (orig_h->flags & MRB_HASH_DEFAULT) {
|
1136
|
+
mrb_iv_set(mrb, self, name, mrb_iv_get(mrb, orig, name));
|
665
1137
|
}
|
666
|
-
|
667
|
-
|
668
|
-
if (!mrb_nil_p(ifnone)) {
|
669
|
-
mrb_iv_set(mrb, vret, mrb_intern_lit(mrb, "ifnone"), ifnone);
|
1138
|
+
else {
|
1139
|
+
mrb_iv_remove(mrb, self, name);
|
670
1140
|
}
|
671
|
-
|
1141
|
+
h->flags &= ~mask;
|
1142
|
+
h->flags |= orig_h->flags & mask;
|
672
1143
|
}
|
673
1144
|
|
674
|
-
static
|
675
|
-
|
1145
|
+
static mrb_value
|
1146
|
+
mrb_hash_init_copy(mrb_state *mrb, mrb_value self)
|
676
1147
|
{
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
1148
|
+
mrb_value orig;
|
1149
|
+
mrb_get_args(mrb, "H", &orig);
|
1150
|
+
hash_modify(mrb, self);
|
1151
|
+
if (mrb_hash_ptr(self) != mrb_hash_ptr(orig)) hash_replace(mrb, self, orig);
|
1152
|
+
return self;
|
681
1153
|
}
|
682
1154
|
|
683
1155
|
void
|
684
1156
|
mrb_hash_check_kdict(mrb_state *mrb, mrb_value self)
|
685
1157
|
{
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
ht_foreach(mrb, t, check_kdict_i, NULL);
|
1158
|
+
h_each(mrb_hash_ptr(self), entry, {
|
1159
|
+
if (mrb_symbol_p(entry->key)) continue;
|
1160
|
+
mrb_raise(mrb, E_ARGUMENT_ERROR, "keyword argument hash with non symbol keys");
|
1161
|
+
});
|
691
1162
|
}
|
692
1163
|
|
693
1164
|
MRB_API mrb_value
|
694
1165
|
mrb_hash_dup(mrb_state *mrb, mrb_value self)
|
695
1166
|
{
|
696
|
-
struct RHash*
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
copy
|
701
|
-
copy->ht = orig_h ? ht_copy(mrb, orig_h) : NULL;
|
702
|
-
return mrb_obj_value(copy);
|
1167
|
+
struct RHash* copy_h = h_alloc(mrb);
|
1168
|
+
mrb_value copy = mrb_obj_value(copy_h);
|
1169
|
+
copy_h->c = mrb_hash_ptr(self)->c;
|
1170
|
+
hash_replace(mrb, copy, self);
|
1171
|
+
return copy;
|
703
1172
|
}
|
704
1173
|
|
705
1174
|
MRB_API mrb_value
|
@@ -708,11 +1177,11 @@ mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key)
|
|
708
1177
|
mrb_value val;
|
709
1178
|
mrb_sym mid;
|
710
1179
|
|
711
|
-
if (
|
1180
|
+
if (h_get(mrb, mrb_hash_ptr(hash), key, &val)) {
|
712
1181
|
return val;
|
713
1182
|
}
|
714
1183
|
|
715
|
-
mid =
|
1184
|
+
mid = MRB_SYM(default);
|
716
1185
|
if (mrb_func_basic_p(mrb, hash, mid, mrb_hash_default)) {
|
717
1186
|
return hash_default(mrb, hash, key);
|
718
1187
|
}
|
@@ -725,7 +1194,7 @@ mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def)
|
|
725
1194
|
{
|
726
1195
|
mrb_value val;
|
727
1196
|
|
728
|
-
if (
|
1197
|
+
if (h_get(mrb, mrb_hash_ptr(hash), key, &val)) {
|
729
1198
|
return val;
|
730
1199
|
}
|
731
1200
|
/* not found */
|
@@ -735,22 +1204,11 @@ mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def)
|
|
735
1204
|
MRB_API void
|
736
1205
|
mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val)
|
737
1206
|
{
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
mrb_field_write_barrier_value(mrb, (
|
743
|
-
mrb_field_write_barrier_value(mrb, (struct RBasic*)RHASH(hash), val);
|
744
|
-
return;
|
745
|
-
}
|
746
|
-
|
747
|
-
static void
|
748
|
-
mrb_hash_modify(mrb_state *mrb, mrb_value hash)
|
749
|
-
{
|
750
|
-
mrb_check_frozen(mrb, mrb_hash_ptr(hash));
|
751
|
-
if (!RHASH_TBL(hash)) {
|
752
|
-
RHASH_TBL(hash) = ht_new(mrb);
|
753
|
-
}
|
1207
|
+
hash_modify(mrb, hash);
|
1208
|
+
key = h_key_for(mrb, key);
|
1209
|
+
h_set(mrb, mrb_hash_ptr(hash), key, val);
|
1210
|
+
mrb_field_write_barrier_value(mrb, mrb_basic_ptr(hash), key);
|
1211
|
+
mrb_field_write_barrier_value(mrb, mrb_basic_ptr(hash), val);
|
754
1212
|
}
|
755
1213
|
|
756
1214
|
/* 15.2.13.4.16 */
|
@@ -797,7 +1255,7 @@ mrb_hash_init(mrb_state *mrb, mrb_value hash)
|
|
797
1255
|
|
798
1256
|
ifnone = mrb_nil_value();
|
799
1257
|
mrb_get_args(mrb, "&|o?", &block, &ifnone, &ifnone_p);
|
800
|
-
|
1258
|
+
hash_modify(mrb, hash);
|
801
1259
|
if (!mrb_nil_p(block)) {
|
802
1260
|
if (ifnone_p) {
|
803
1261
|
mrb_argnum_error(mrb, 1, 0, 0);
|
@@ -807,7 +1265,7 @@ mrb_hash_init(mrb_state *mrb, mrb_value hash)
|
|
807
1265
|
}
|
808
1266
|
if (!mrb_nil_p(ifnone)) {
|
809
1267
|
RHASH(hash)->flags |= MRB_HASH_DEFAULT;
|
810
|
-
mrb_iv_set(mrb, hash,
|
1268
|
+
mrb_iv_set(mrb, hash, MRB_SYM(ifnone), ifnone);
|
811
1269
|
}
|
812
1270
|
return hash;
|
813
1271
|
}
|
@@ -829,26 +1287,11 @@ mrb_hash_init(mrb_state *mrb, mrb_value hash)
|
|
829
1287
|
static mrb_value
|
830
1288
|
mrb_hash_aget(mrb_state *mrb, mrb_value self)
|
831
1289
|
{
|
832
|
-
mrb_value key;
|
1290
|
+
mrb_value key = mrb_get_arg1(mrb);
|
833
1291
|
|
834
|
-
mrb_get_args(mrb, "o", &key);
|
835
1292
|
return mrb_hash_get(mrb, self, key);
|
836
1293
|
}
|
837
1294
|
|
838
|
-
static mrb_value
|
839
|
-
hash_default(mrb_state *mrb, mrb_value hash, mrb_value key)
|
840
|
-
{
|
841
|
-
if (MRB_RHASH_DEFAULT_P(hash)) {
|
842
|
-
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
|
843
|
-
return mrb_funcall(mrb, RHASH_PROCDEFAULT(hash), "call", 2, hash, key);
|
844
|
-
}
|
845
|
-
else {
|
846
|
-
return RHASH_IFNONE(hash);
|
847
|
-
}
|
848
|
-
}
|
849
|
-
return mrb_nil_value();
|
850
|
-
}
|
851
|
-
|
852
1295
|
/* 15.2.13.4.5 */
|
853
1296
|
/*
|
854
1297
|
* call-seq:
|
@@ -881,7 +1324,7 @@ mrb_hash_default(mrb_state *mrb, mrb_value hash)
|
|
881
1324
|
if (MRB_RHASH_DEFAULT_P(hash)) {
|
882
1325
|
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
|
883
1326
|
if (!given) return mrb_nil_value();
|
884
|
-
return
|
1327
|
+
return mrb_funcall_id(mrb, RHASH_PROCDEFAULT(hash), MRB_SYM(call), 2, hash, key);
|
885
1328
|
}
|
886
1329
|
else {
|
887
1330
|
return RHASH_IFNONE(hash);
|
@@ -914,11 +1357,10 @@ mrb_hash_default(mrb_state *mrb, mrb_value hash)
|
|
914
1357
|
static mrb_value
|
915
1358
|
mrb_hash_set_default(mrb_state *mrb, mrb_value hash)
|
916
1359
|
{
|
917
|
-
mrb_value ifnone;
|
1360
|
+
mrb_value ifnone = mrb_get_arg1(mrb);
|
918
1361
|
|
919
|
-
|
920
|
-
|
921
|
-
mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
|
1362
|
+
hash_modify(mrb, hash);
|
1363
|
+
mrb_iv_set(mrb, hash, MRB_SYM(ifnone), ifnone);
|
922
1364
|
RHASH(hash)->flags &= ~MRB_HASH_PROC_DEFAULT;
|
923
1365
|
if (!mrb_nil_p(ifnone)) {
|
924
1366
|
RHASH(hash)->flags |= MRB_HASH_DEFAULT;
|
@@ -944,7 +1386,6 @@ mrb_hash_set_default(mrb_state *mrb, mrb_value hash)
|
|
944
1386
|
* a #=> [nil, nil, 4]
|
945
1387
|
*/
|
946
1388
|
|
947
|
-
|
948
1389
|
static mrb_value
|
949
1390
|
mrb_hash_default_proc(mrb_state *mrb, mrb_value hash)
|
950
1391
|
{
|
@@ -970,11 +1411,10 @@ mrb_hash_default_proc(mrb_state *mrb, mrb_value hash)
|
|
970
1411
|
static mrb_value
|
971
1412
|
mrb_hash_set_default_proc(mrb_state *mrb, mrb_value hash)
|
972
1413
|
{
|
973
|
-
mrb_value ifnone;
|
1414
|
+
mrb_value ifnone = mrb_get_arg1(mrb);
|
974
1415
|
|
975
|
-
|
976
|
-
|
977
|
-
mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
|
1416
|
+
hash_modify(mrb, hash);
|
1417
|
+
mrb_iv_set(mrb, hash, MRB_SYM(ifnone), ifnone);
|
978
1418
|
if (!mrb_nil_p(ifnone)) {
|
979
1419
|
RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT;
|
980
1420
|
RHASH(hash)->flags |= MRB_HASH_DEFAULT;
|
@@ -990,10 +1430,10 @@ mrb_hash_set_default_proc(mrb_state *mrb, mrb_value hash)
|
|
990
1430
|
MRB_API mrb_value
|
991
1431
|
mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key)
|
992
1432
|
{
|
993
|
-
htable *t = RHASH_TBL(hash);
|
994
1433
|
mrb_value del_val;
|
995
1434
|
|
996
|
-
|
1435
|
+
hash_modify(mrb, hash);
|
1436
|
+
if (h_delete(mrb, mrb_hash_ptr(hash), key, &del_val)) {
|
997
1437
|
return del_val;
|
998
1438
|
}
|
999
1439
|
|
@@ -1004,40 +1444,10 @@ mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key)
|
|
1004
1444
|
static mrb_value
|
1005
1445
|
mrb_hash_delete(mrb_state *mrb, mrb_value self)
|
1006
1446
|
{
|
1007
|
-
mrb_value key;
|
1008
|
-
|
1009
|
-
mrb_get_args(mrb, "o", &key);
|
1010
|
-
mrb_hash_modify(mrb, self);
|
1447
|
+
mrb_value key = mrb_get_arg1(mrb);
|
1011
1448
|
return mrb_hash_delete_key(mrb, self, key);
|
1012
1449
|
}
|
1013
1450
|
|
1014
|
-
/* find first element in the hash table, and remove it. */
|
1015
|
-
static void
|
1016
|
-
ht_shift(mrb_state *mrb, htable *t, mrb_value *kp, mrb_value *vp)
|
1017
|
-
{
|
1018
|
-
segment *seg = t->rootseg;
|
1019
|
-
mrb_int i;
|
1020
|
-
|
1021
|
-
while (seg) {
|
1022
|
-
for (i=0; i<seg->size; i++) {
|
1023
|
-
mrb_value key;
|
1024
|
-
|
1025
|
-
if (!seg->next && i >= t->last_len) {
|
1026
|
-
return;
|
1027
|
-
}
|
1028
|
-
key = seg->e[i].key;
|
1029
|
-
if (mrb_undef_p(key)) continue;
|
1030
|
-
*kp = key;
|
1031
|
-
*vp = seg->e[i].val;
|
1032
|
-
/* delete element */
|
1033
|
-
seg->e[i].key = mrb_undef_value();
|
1034
|
-
t->size--;
|
1035
|
-
return;
|
1036
|
-
}
|
1037
|
-
seg = seg->next;
|
1038
|
-
}
|
1039
|
-
}
|
1040
|
-
|
1041
1451
|
/* 15.2.13.4.24 */
|
1042
1452
|
/*
|
1043
1453
|
* call-seq:
|
@@ -1055,27 +1465,19 @@ ht_shift(mrb_state *mrb, htable *t, mrb_value *kp, mrb_value *vp)
|
|
1055
1465
|
static mrb_value
|
1056
1466
|
mrb_hash_shift(mrb_state *mrb, mrb_value hash)
|
1057
1467
|
{
|
1058
|
-
|
1468
|
+
struct RHash *h = mrb_hash_ptr(hash);
|
1059
1469
|
|
1060
|
-
|
1061
|
-
if (
|
1470
|
+
hash_modify(mrb, hash);
|
1471
|
+
if (h_size(h) == 0) {
|
1472
|
+
return hash_default(mrb, hash, mrb_nil_value());
|
1473
|
+
}
|
1474
|
+
else {
|
1062
1475
|
mrb_value del_key, del_val;
|
1063
|
-
|
1064
|
-
ht_shift(mrb, t, &del_key, &del_val);
|
1476
|
+
h_shift(mrb, h, &del_key, &del_val);
|
1065
1477
|
mrb_gc_protect(mrb, del_key);
|
1066
1478
|
mrb_gc_protect(mrb, del_val);
|
1067
1479
|
return mrb_assoc_new(mrb, del_key, del_val);
|
1068
1480
|
}
|
1069
|
-
|
1070
|
-
if (MRB_RHASH_DEFAULT_P(hash)) {
|
1071
|
-
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
|
1072
|
-
return mrb_funcall(mrb, RHASH_PROCDEFAULT(hash), "call", 2, hash, mrb_nil_value());
|
1073
|
-
}
|
1074
|
-
else {
|
1075
|
-
return RHASH_IFNONE(hash);
|
1076
|
-
}
|
1077
|
-
}
|
1078
|
-
return mrb_nil_value();
|
1079
1481
|
}
|
1080
1482
|
|
1081
1483
|
/* 15.2.13.4.4 */
|
@@ -1093,13 +1495,8 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
|
|
1093
1495
|
MRB_API mrb_value
|
1094
1496
|
mrb_hash_clear(mrb_state *mrb, mrb_value hash)
|
1095
1497
|
{
|
1096
|
-
|
1097
|
-
|
1098
|
-
mrb_hash_modify(mrb, hash);
|
1099
|
-
if (t) {
|
1100
|
-
ht_free(mrb, t);
|
1101
|
-
RHASH_TBL(hash) = NULL;
|
1102
|
-
}
|
1498
|
+
hash_modify(mrb, hash);
|
1499
|
+
h_clear(mrb, mrb_hash_ptr(hash));
|
1103
1500
|
return hash;
|
1104
1501
|
}
|
1105
1502
|
|
@@ -1135,18 +1532,15 @@ mrb_hash_aset(mrb_state *mrb, mrb_value self)
|
|
1135
1532
|
MRB_API mrb_int
|
1136
1533
|
mrb_hash_size(mrb_state *mrb, mrb_value hash)
|
1137
1534
|
{
|
1138
|
-
|
1139
|
-
|
1140
|
-
if (!t) return 0;
|
1141
|
-
return t->size;
|
1535
|
+
return (mrb_int)h_size(mrb_hash_ptr(hash));
|
1142
1536
|
}
|
1143
1537
|
|
1144
1538
|
/* 15.2.13.4.20 */
|
1145
1539
|
/* 15.2.13.4.25 */
|
1146
1540
|
/*
|
1147
1541
|
* call-seq:
|
1148
|
-
* hsh.length ->
|
1149
|
-
* hsh.size ->
|
1542
|
+
* hsh.length -> integer
|
1543
|
+
* hsh.size -> integer
|
1150
1544
|
*
|
1151
1545
|
* Returns the number of key-value pairs in the hash.
|
1152
1546
|
*
|
@@ -1159,16 +1553,13 @@ static mrb_value
|
|
1159
1553
|
mrb_hash_size_m(mrb_state *mrb, mrb_value self)
|
1160
1554
|
{
|
1161
1555
|
mrb_int size = mrb_hash_size(mrb, self);
|
1162
|
-
return
|
1556
|
+
return mrb_int_value(mrb, size);
|
1163
1557
|
}
|
1164
1558
|
|
1165
1559
|
MRB_API mrb_bool
|
1166
1560
|
mrb_hash_empty_p(mrb_state *mrb, mrb_value self)
|
1167
1561
|
{
|
1168
|
-
|
1169
|
-
|
1170
|
-
if (!t) return TRUE;
|
1171
|
-
return t->size == 0;
|
1562
|
+
return h_size(mrb_hash_ptr(self)) == 0;
|
1172
1563
|
}
|
1173
1564
|
|
1174
1565
|
/* 15.2.13.4.12 */
|
@@ -1187,13 +1578,6 @@ mrb_hash_empty_m(mrb_state *mrb, mrb_value self)
|
|
1187
1578
|
return mrb_bool_value(mrb_hash_empty_p(mrb, self));
|
1188
1579
|
}
|
1189
1580
|
|
1190
|
-
static int
|
1191
|
-
hash_keys_i(mrb_state *mrb, mrb_value key, mrb_value val, void *p)
|
1192
|
-
{
|
1193
|
-
mrb_ary_push(mrb, *(mrb_value*)p, key);
|
1194
|
-
return 0;
|
1195
|
-
}
|
1196
|
-
|
1197
1581
|
/* 15.2.13.4.19 */
|
1198
1582
|
/*
|
1199
1583
|
* call-seq:
|
@@ -1210,24 +1594,14 @@ hash_keys_i(mrb_state *mrb, mrb_value key, mrb_value val, void *p)
|
|
1210
1594
|
MRB_API mrb_value
|
1211
1595
|
mrb_hash_keys(mrb_state *mrb, mrb_value hash)
|
1212
1596
|
{
|
1213
|
-
|
1214
|
-
mrb_int
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
return mrb_ary_new(mrb);
|
1219
|
-
ary = mrb_ary_new_capa(mrb, size);
|
1220
|
-
ht_foreach(mrb, t, hash_keys_i, (void*)&ary);
|
1597
|
+
struct RHash *h = mrb_hash_ptr(hash);
|
1598
|
+
mrb_value ary = mrb_ary_new_capa(mrb, (mrb_int)h_size(h));
|
1599
|
+
h_each(h, entry, {
|
1600
|
+
mrb_ary_push(mrb, ary, entry->key);
|
1601
|
+
});
|
1221
1602
|
return ary;
|
1222
1603
|
}
|
1223
1604
|
|
1224
|
-
static int
|
1225
|
-
hash_vals_i(mrb_state *mrb, mrb_value key, mrb_value val, void *p)
|
1226
|
-
{
|
1227
|
-
mrb_ary_push(mrb, *(mrb_value*)p, val);
|
1228
|
-
return 0;
|
1229
|
-
}
|
1230
|
-
|
1231
1605
|
/* 15.2.13.4.28 */
|
1232
1606
|
/*
|
1233
1607
|
* call-seq:
|
@@ -1244,14 +1618,11 @@ hash_vals_i(mrb_state *mrb, mrb_value key, mrb_value val, void *p)
|
|
1244
1618
|
MRB_API mrb_value
|
1245
1619
|
mrb_hash_values(mrb_state *mrb, mrb_value hash)
|
1246
1620
|
{
|
1247
|
-
|
1248
|
-
mrb_int
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
return mrb_ary_new(mrb);
|
1253
|
-
ary = mrb_ary_new_capa(mrb, size);
|
1254
|
-
ht_foreach(mrb, t, hash_vals_i, (void*)&ary);
|
1621
|
+
struct RHash *h = mrb_hash_ptr(hash);
|
1622
|
+
mrb_value ary = mrb_ary_new_capa(mrb, (mrb_int)h_size(h));
|
1623
|
+
h_each(h, entry, {
|
1624
|
+
mrb_ary_push(mrb, ary, entry->val);
|
1625
|
+
});
|
1255
1626
|
return ary;
|
1256
1627
|
}
|
1257
1628
|
|
@@ -1277,43 +1648,20 @@ mrb_hash_values(mrb_state *mrb, mrb_value hash)
|
|
1277
1648
|
MRB_API mrb_bool
|
1278
1649
|
mrb_hash_key_p(mrb_state *mrb, mrb_value hash, mrb_value key)
|
1279
1650
|
{
|
1280
|
-
|
1281
|
-
|
1282
|
-
t = RHASH_TBL(hash);
|
1283
|
-
if (ht_get(mrb, t, key, NULL)) {
|
1284
|
-
return TRUE;
|
1285
|
-
}
|
1286
|
-
return FALSE;
|
1651
|
+
mrb_value val;
|
1652
|
+
return h_get(mrb, mrb_hash_ptr(hash), key, &val);
|
1287
1653
|
}
|
1288
1654
|
|
1289
1655
|
static mrb_value
|
1290
1656
|
mrb_hash_has_key(mrb_state *mrb, mrb_value hash)
|
1291
1657
|
{
|
1292
|
-
mrb_value key;
|
1658
|
+
mrb_value key = mrb_get_arg1(mrb);
|
1293
1659
|
mrb_bool key_p;
|
1294
1660
|
|
1295
|
-
mrb_get_args(mrb, "o", &key);
|
1296
1661
|
key_p = mrb_hash_key_p(mrb, hash, key);
|
1297
1662
|
return mrb_bool_value(key_p);
|
1298
1663
|
}
|
1299
1664
|
|
1300
|
-
struct has_v_arg {
|
1301
|
-
mrb_bool found;
|
1302
|
-
mrb_value val;
|
1303
|
-
};
|
1304
|
-
|
1305
|
-
static int
|
1306
|
-
hash_has_value_i(mrb_state *mrb, mrb_value key, mrb_value val, void *p)
|
1307
|
-
{
|
1308
|
-
struct has_v_arg *arg = (struct has_v_arg*)p;
|
1309
|
-
|
1310
|
-
if (mrb_equal(mrb, arg->val, val)) {
|
1311
|
-
arg->found = TRUE;
|
1312
|
-
return 1;
|
1313
|
-
}
|
1314
|
-
return 0;
|
1315
|
-
}
|
1316
|
-
|
1317
1665
|
/* 15.2.13.4.14 */
|
1318
1666
|
/* 15.2.13.4.27 */
|
1319
1667
|
/*
|
@@ -1332,43 +1680,33 @@ hash_has_value_i(mrb_state *mrb, mrb_value key, mrb_value val, void *p)
|
|
1332
1680
|
static mrb_value
|
1333
1681
|
mrb_hash_has_value(mrb_state *mrb, mrb_value hash)
|
1334
1682
|
{
|
1335
|
-
mrb_value val;
|
1336
|
-
struct
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
return
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
static int
|
1346
|
-
merge_i(mrb_state *mrb, mrb_value key, mrb_value val, void *data)
|
1347
|
-
{
|
1348
|
-
htable *h1 = (htable*)data;
|
1349
|
-
|
1350
|
-
ht_put(mrb, h1, key, val);
|
1351
|
-
return 0;
|
1683
|
+
mrb_value val = mrb_get_arg1(mrb);
|
1684
|
+
struct RHash *h = mrb_hash_ptr(hash);
|
1685
|
+
h_each(h, entry, {
|
1686
|
+
h_check_modified(mrb, h, {
|
1687
|
+
if (mrb_equal(mrb, val, entry->val)) return mrb_true_value();
|
1688
|
+
});
|
1689
|
+
});
|
1690
|
+
return mrb_false_value();
|
1352
1691
|
}
|
1353
1692
|
|
1354
1693
|
MRB_API void
|
1355
1694
|
mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2)
|
1356
1695
|
{
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
h1 =
|
1362
|
-
h2 =
|
1363
|
-
|
1364
|
-
if (
|
1365
|
-
if (
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
return;
|
1696
|
+
struct RHash *h1, *h2;
|
1697
|
+
|
1698
|
+
hash_modify(mrb, hash1);
|
1699
|
+
mrb_ensure_hash_type(mrb, hash2);
|
1700
|
+
h1 = mrb_hash_ptr(hash1);
|
1701
|
+
h2 = mrb_hash_ptr(hash2);
|
1702
|
+
|
1703
|
+
if (h1 == h2) return;
|
1704
|
+
if (h_size(h2) == 0) return;
|
1705
|
+
h_each(h2, entry, {
|
1706
|
+
h_check_modified(mrb, h2, {h_set(mrb, h1, entry->key, entry->val);});
|
1707
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic *)h1, entry->key);
|
1708
|
+
mrb_field_write_barrier_value(mrb, (struct RBasic *)h1, entry->val);
|
1709
|
+
});
|
1372
1710
|
}
|
1373
1711
|
|
1374
1712
|
/*
|
@@ -1383,14 +1721,10 @@ mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2)
|
|
1383
1721
|
* k = keys[0]
|
1384
1722
|
* h = {}
|
1385
1723
|
* keys.each{|key| h[key] = key[0]}
|
1386
|
-
* h #=> { [1]=>
|
1387
|
-
* [8]=> 8, [9]=> 9,[10]=>10,[11]=>11,[12]=>12,[13]=>13,[14]=>14,
|
1388
|
-
* [15]=>15,[16]=>16,[17]=>17}
|
1724
|
+
* h #=> { [1]=>1, [2]=>2, ... [16]=>16, [17]=>17}
|
1389
1725
|
* h[k] #=> 1
|
1390
1726
|
* k[0] = keys.size + 1
|
1391
|
-
* h #=> {[18]=>
|
1392
|
-
* [8]=> 8, [9]=> 9,[10]=>10,[11]=>11,[12]=>12,[13]=>13,[14]=>14,
|
1393
|
-
* [15]=>15,[16]=>16,[17]=>17}
|
1727
|
+
* h #=> {[18]=>1, [2]=>2, ... [16]=>16, [17]=>17}
|
1394
1728
|
* h[k] #=> nil
|
1395
1729
|
* h.rehash
|
1396
1730
|
* h[k] #=> 1
|
@@ -1398,7 +1732,7 @@ mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2)
|
|
1398
1732
|
static mrb_value
|
1399
1733
|
mrb_hash_rehash(mrb_state *mrb, mrb_value self)
|
1400
1734
|
{
|
1401
|
-
|
1735
|
+
h_rehash(mrb, mrb_hash_ptr(self));
|
1402
1736
|
return self;
|
1403
1737
|
}
|
1404
1738
|
|
@@ -1410,11 +1744,10 @@ mrb_init_hash(mrb_state *mrb)
|
|
1410
1744
|
mrb->hash_class = h = mrb_define_class(mrb, "Hash", mrb->object_class); /* 15.2.13 */
|
1411
1745
|
MRB_SET_INSTANCE_TT(h, MRB_TT_HASH);
|
1412
1746
|
|
1413
|
-
mrb_define_method(mrb, h, "initialize_copy", mrb_hash_init_copy, MRB_ARGS_REQ(1));
|
1414
1747
|
mrb_define_method(mrb, h, "[]", mrb_hash_aget, MRB_ARGS_REQ(1)); /* 15.2.13.4.2 */
|
1415
1748
|
mrb_define_method(mrb, h, "[]=", mrb_hash_aset, MRB_ARGS_REQ(2)); /* 15.2.13.4.3 */
|
1416
1749
|
mrb_define_method(mrb, h, "clear", mrb_hash_clear, MRB_ARGS_NONE()); /* 15.2.13.4.4 */
|
1417
|
-
mrb_define_method(mrb, h, "default", mrb_hash_default, MRB_ARGS_OPT(1));
|
1750
|
+
mrb_define_method(mrb, h, "default", mrb_hash_default, MRB_ARGS_OPT(1)); /* 15.2.13.4.5 */
|
1418
1751
|
mrb_define_method(mrb, h, "default=", mrb_hash_set_default, MRB_ARGS_REQ(1)); /* 15.2.13.4.6 */
|
1419
1752
|
mrb_define_method(mrb, h, "default_proc", mrb_hash_default_proc,MRB_ARGS_NONE()); /* 15.2.13.4.7 */
|
1420
1753
|
mrb_define_method(mrb, h, "default_proc=", mrb_hash_set_default_proc,MRB_ARGS_REQ(1)); /* 15.2.13.4.7 */
|
@@ -1424,10 +1757,12 @@ mrb_init_hash(mrb_state *mrb)
|
|
1424
1757
|
mrb_define_method(mrb, h, "has_value?", mrb_hash_has_value, MRB_ARGS_REQ(1)); /* 15.2.13.4.14 */
|
1425
1758
|
mrb_define_method(mrb, h, "include?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.15 */
|
1426
1759
|
mrb_define_method(mrb, h, "initialize", mrb_hash_init, MRB_ARGS_OPT(1)|MRB_ARGS_BLOCK()); /* 15.2.13.4.16 */
|
1760
|
+
mrb_define_method(mrb, h, "initialize_copy", mrb_hash_init_copy, MRB_ARGS_REQ(1)); /* 15.2.13.4.17 */
|
1427
1761
|
mrb_define_method(mrb, h, "key?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.18 */
|
1428
1762
|
mrb_define_method(mrb, h, "keys", mrb_hash_keys, MRB_ARGS_NONE()); /* 15.2.13.4.19 */
|
1429
1763
|
mrb_define_method(mrb, h, "length", mrb_hash_size_m, MRB_ARGS_NONE()); /* 15.2.13.4.20 */
|
1430
1764
|
mrb_define_method(mrb, h, "member?", mrb_hash_has_key, MRB_ARGS_REQ(1)); /* 15.2.13.4.21 */
|
1765
|
+
mrb_define_method(mrb, h, "replace", mrb_hash_init_copy, MRB_ARGS_REQ(1)); /* 15.2.13.4.23 */
|
1431
1766
|
mrb_define_method(mrb, h, "shift", mrb_hash_shift, MRB_ARGS_NONE()); /* 15.2.13.4.24 */
|
1432
1767
|
mrb_define_method(mrb, h, "size", mrb_hash_size_m, MRB_ARGS_NONE()); /* 15.2.13.4.25 */
|
1433
1768
|
mrb_define_method(mrb, h, "store", mrb_hash_aset, MRB_ARGS_REQ(2)); /* 15.2.13.4.26 */
|