yeptris 0.6.64.0-riscv64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +150 -0
  3. data/ext/build_windows_native.rb +60 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +198 -0
  6. data/ext/yeptris_native/extconf.rb +99 -0
  7. data/ext/yeptris_native/json_ruby.c +414 -0
  8. data/ext/yeptris_native/version.h +29 -0
  9. data/ext/yeptris_native/yeptris_native.c +507 -0
  10. data/lib/yeptris/3.3/native.so +0 -0
  11. data/lib/yeptris/cbor.rb +169 -0
  12. data/lib/yeptris/document.rb +319 -0
  13. data/lib/yeptris/ffi.rb +572 -0
  14. data/lib/yeptris/json/descriptor.rb +266 -0
  15. data/lib/yeptris/json.rb +502 -0
  16. data/lib/yeptris/materializer.rb +389 -0
  17. data/lib/yeptris/node.rb +482 -0
  18. data/lib/yeptris/psych/class_loader.rb +24 -0
  19. data/lib/yeptris/psych/coder_shim.rb +55 -0
  20. data/lib/yeptris/psych/drop_in.rb +63 -0
  21. data/lib/yeptris/psych/encodable.rb +14 -0
  22. data/lib/yeptris/psych/handler.rb +95 -0
  23. data/lib/yeptris/psych/parser.rb +114 -0
  24. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  25. data/lib/yeptris/psych/tree_builder.rb +119 -0
  26. data/lib/yeptris/psych/visitors.rb +670 -0
  27. data/lib/yeptris/psych.rb +796 -0
  28. data/lib/yeptris/schema.rb +253 -0
  29. data/lib/yeptris/validation.rb +320 -0
  30. data/lib/yeptris/valueml.rb +477 -0
  31. data/lib/yeptris/yaml/descriptor.rb +56 -0
  32. data/lib/yeptris/yaml.rb +668 -0
  33. data/lib/yeptris.rb +130 -0
  34. data/libyeptris.so +0 -0
  35. data/vendor/libyeptris/CMakeLists.txt +280 -0
  36. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  37. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  38. data/vendor/libyeptris/src/CMakeLists.txt +183 -0
  39. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  40. data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
  41. data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
  42. data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
  43. data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
  44. data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
  45. data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
  46. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  47. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  48. data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
  49. data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  51. data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
  52. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  53. data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
  54. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  55. data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
  56. data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
  57. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  58. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  59. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  60. data/vendor/libyeptris/src/include/yeptris.h +24 -0
  61. data/vendor/libyeptris/src/yeptris/build.c +393 -0
  62. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
  63. data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
  64. data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
  65. data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
  66. data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
  67. data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
  68. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  69. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  70. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  71. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  72. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  73. data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
  74. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  75. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  76. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  77. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  78. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  79. data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
  80. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
  81. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
  82. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
  83. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  84. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  85. data/vendor/libyeptris/src/yeptris/doc.h +86 -0
  86. data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
  87. data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
  88. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  89. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  90. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  91. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  92. data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
  93. data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
  94. data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
  95. data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
  96. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  97. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  98. data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
  99. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  100. data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
  101. data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
  102. data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
  103. data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
  104. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  105. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  106. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
  107. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  108. data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
  109. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  110. data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
  111. data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
  112. data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
  113. data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
  114. data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
  115. data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
  116. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  117. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  118. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  119. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  120. data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
  121. data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
  122. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  123. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  124. data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
  125. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  126. data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
  127. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  128. data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
  129. data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
  130. data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
  131. data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
  132. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  133. data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
  134. data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
  135. data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
  136. data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
  137. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  138. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
  139. data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
  140. data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
  141. data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
  142. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
  143. data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
  144. data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
  145. data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
  146. data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
  147. data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
  148. data/vendor/libyeptris/src/yeptris/schema.c +309 -0
  149. data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
  150. data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
  151. data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
  152. data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
  153. data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
  154. data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
  155. data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
  156. data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
  157. data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
  158. data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
  159. data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
  160. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  161. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  162. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  163. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  164. metadata +221 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f3c5c087e4500f9a0480435ee0463df0f6776f83885b797d49984353c3fac7fd
4
+ data.tar.gz: 9dbb7021089892b3696024be841dd7f56a3abbe17208d46bb63ef633c1785c89
5
+ SHA512:
6
+ metadata.gz: a64df1e913588797b1f6da5b31423b2f2a492869703c63ee13dcb26a3d1c887850354c9c36e5a68ac45282497a5a952b55fc002afe347d05ce8b029b6a19091e
7
+ data.tar.gz: 3cc845033b31ffa96123dd8e13b375ab530424eca1ba7d22d2e1504c8e4a7f0cf2b7a650eb929fbf6571969c6adf9a5665910780274ebe48246fbf8a5882078c
data/README.adoc ADDED
@@ -0,0 +1,150 @@
1
+ = yeptris — YAML for Ruby at libleptris speed
2
+
3
+ An FFI-based (no C extension) Ruby YAML library over
4
+ https://github.com/leptris/yeptris[libyeptris] — the YAML counterpart
5
+ of libleptris. Psych-compatible semantics, one shared library, zero
6
+ compilation at install.
7
+
8
+ Part of the yeptris program: *the best (multiple dimensions)
9
+ YAML/JSON parser/builder ever* — conformance, performance,
10
+ safety/hardening, API surfaces, transport correctness, and trust,
11
+ held simultaneously, in C, Ruby, Rust, and JS. This binding is the
12
+ most complete surface: the Psych drop-in namespace, JSON.parse
13
+ parity with the strict duplicate-key contract, CBOR, and ValueML,
14
+ tracking every libyeptris release in lockstep. The achievement
15
+ program lives in the engine's PLAN.md ("The best-ever program").
16
+
17
+ == Install (development)
18
+
19
+ The gem loads a shared `libyeptris` — from `YEPTRIS_LIB_PATH`, a
20
+ vendored `lib/platform/<tag>/` copy, or the system paths. For
21
+ development against a local build:
22
+
23
+ ....
24
+ # the sibling C checkout: ~/src/leptris/yeptris
25
+ cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DYEPTRIS_BUILD_SHARED=ON
26
+ cmake --build build
27
+
28
+ cd ~/src/leptris/yeptris-ruby
29
+ YEPTRIS_LIB_PATH=../yeptris/build/src/libyeptris.dylib bundle exec rspec
30
+ ....
31
+
32
+ Without `YEPTRIS_LIB_PATH` the spec helper falls back to a vendored
33
+ `lib/platform/<tag>/` copy, then to the sibling checkout's
34
+ `build-validate` — any `libyeptris.{so,dylib,dll}` path works.
35
+
36
+ == Usage
37
+
38
+ [source,ruby]
39
+ ----
40
+ require "yeptris"
41
+
42
+ Yeptris::YAML.load("name: yeptris\nrating: 10\n")
43
+ # => {"name" => "yeptris", "rating" => 10}
44
+
45
+ # brace mixed hashes on Ruby 3.x: a trailing symbol key otherwise
46
+ # splits the literal into keywords
47
+ Yeptris::YAML.dump({"name" => "yeptris", "tags" => [:yaml, :fast]})
48
+
49
+ doc = Yeptris::Document.parse(config_yaml)
50
+ doc.root["server"]["port"].to_i
51
+ doc.serialize
52
+ ----
53
+
54
+ `Yeptris::YAML.load` defaults to Psych's YAML 1.1 implicit typing
55
+ (`yes` is `true`, `017` is octal); pass `schema: :core_12` for YAML
56
+ 1.2 core semantics. Dump builds through the library's DOM mutation
57
+ API, so the writer's sizing/escape machinery applies to synthesized
58
+ trees unchanged.
59
+
60
+ Handles are document-scoped: `Document#free` releases everything
61
+ (one C call), a GC finalizer backs it up, and any use after free
62
+ raises `Yeptris::FreedError` — never a segfault.
63
+
64
+ == Two load surfaces: YAML and strict JSON
65
+
66
+ `Yeptris::YAML.load` keeps the Psych contract for EVERY input —
67
+ including JSON-shaped ones. `{"a": [1,]}` is legal flow YAML (spec
68
+ production [141] allows the trailing comma); `"1e3"` is a Psych
69
+ String. These semantics never flip because input happens to look
70
+ like JSON.
71
+
72
+ `Yeptris::JSON.load` is the STRICT RFC 8259 surface — exact
73
+ `JSON.parse` semantics by construction (spec-pinned in
74
+ `spec/json_parity_spec.rb`: every value and every error case,
75
+ Bignum integers, exponent-only floats, duplicate keys). Engines,
76
+ fastest first:
77
+
78
+ 1. **Native materializer** (opt-in build; see below): a fused C scan
79
+ → `VALUE` parser. Order-alternating interleaved profile, 152 KB /
80
+ ~29k-value corpus, Ruby 3.4:
81
+ +
82
+ ....
83
+ CI referee (gated at 1.05 on both platforms, order-alternating
84
+ interleave, N=200; prefix-hashed token cache):
85
+ ubuntu (x86_64) mean 0.745x vs JSON.parse, 200/200 head-to-head
86
+ macos (arm64) mean 0.759x vs JSON.parse, 169/200 head-to-head
87
+ ....
88
+
89
+ The parse-window GC strategy is per-arch and runtime-switchable:
90
+ `Yeptris::Native.gc_mode` / `YEPTRIS_NATIVE_GC` = `:none`
91
+ (steady-state: +0 heap pages, the stdlib's own GC cadence — the
92
+ default on arm64) or `:disable` (no GC during the parse — the
93
+ default on x86_64, faster where pages are free). On a LOADED x86_64
94
+ box prefer `:none`: `:disable` grows ~478 heap pages per 50 parses,
95
+ and page growth under contention is exactly the loaded-box
96
+ regression. `:start` (in-window collection) measured 8x — dead.
97
+ 2. **Record-drain fallback** (always available): the strict-JSON
98
+ validator gates, then the value records convert without the Psych
99
+ quirk table — exact parity with engine 1, spec-pinned.
100
+
101
+ The committed profile (`benchmark/json_profile.rb`) is the fair
102
+ benchmark of record — any performance claim runs through it.
103
+
104
+ === Building the native materializer (opt-in)
105
+
106
+ ....
107
+ cd ext/yeptris_native
108
+ YEPTRIS_LIB_PATH=/path/to/libyeptris.dylib ruby extconf.rb && make
109
+ cp native.bundle ../../lib/yeptris/ # or .so on Linux
110
+ ....
111
+
112
+ `require "yeptris"` picks it up automatically (`Yeptris::JSON` then
113
+ uses it; missing builds silently use the fallback — the gem installs
114
+ without compiling).
115
+
116
+ == Shipped beyond the original plan
117
+
118
+ * The columnar value drain (bulk, pre-converted typed columns — the
119
+ load fast path) and the bulk DOM builder (one `document_build`
120
+ call per dump).
121
+ * **Ruby Marshal 4.8 emission** (libyeptris >= 0.1.11): the C side
122
+ converts value records into Marshal bytes; one `Marshal.load`
123
+ materializes the whole graph. ~10× faster than the columnar walk
124
+ on JSON-shaped input, ~5× on YAML, ~50× on the per-node DOM walk
125
+ (`Node#to_ruby` becomes bulk). Alias identity preserved through
126
+ object links; merge keys and timestamps return UNSUPPORTED for the
127
+ record-walk fallback.
128
+ * `Yeptris::Psych` — the Psych-compatible namespace with the ported
129
+ Psych suite (143 specs), `.tml` corpora conformance, and the
130
+ Encodable object protocol (`include Yeptris::Psych::Encodable` +
131
+ `encode_with`/`init_with` — no `respond_to?`, no ivar reflection;
132
+ the library never reaches into an object's internals).
133
+ ** CO-EXISTENCE (issue #69): `require "yeptris/psych"` loads the
134
+ namespace WITHOUT touching the top-level `Psych` constant — it
135
+ coexists with stdlib psych in ANY load order. The process-
136
+ exclusive drop-in rebind (`::Psych = Yeptris::Psych`) is now
137
+ OPT-IN: `require "yeptris/psych/drop_in"`. Once the drop-in runs,
138
+ stdlib psych must NOT be loaded afterwards (its require re-opens
139
+ the rebound module and clobbers constants). Bundles that cannot
140
+ control the load order (activesupport et al.) should use
141
+ `Yeptris::Psych` / `Yeptris::YAML` directly.
142
+ ** `Yeptris::YAML.safe_load(yaml, permitted_classes: [], aliases:
143
+ false)` — Psych's safe_load semantics on the native surface:
144
+ plain data by default; a leaf that would materialize to a
145
+ non-permitted class (a compat_11 date) raises
146
+ `Yeptris::Psych::DisallowedClass`; alias use without `aliases:
147
+ true` raises `Yeptris::Psych::AliasesError`.
148
+ * Lockstep versioning with the C library
149
+ (`{c-semver}.{gem-patch}`); releases published from the C repo's
150
+ workflow through the RubyGems trusted publisher.
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Builds the native materializer for the CURRENT Ruby and installs it
4
+ # under the per-minor DIRECTORY layout
5
+ # (lib/yeptris/<major.minor>/native.<so|bundle|dll>).
6
+ #
7
+ # The leptris-ruby Windows lesson (#207/#227): a PE DLL cannot
8
+ # resolve Ruby imports lazily — it must bind the build Ruby's
9
+ # x64-ucrt-rubyNNN.dll. One bundle per supported minor therefore ships
10
+ # in the platform gems, and the loader in lib/yeptris.rb picks by
11
+ # RUBY_VERSION at require. Ruby 3.3 has no arm64 build: that cell
12
+ # ships no artifact and falls back loudly to the FFI ladder.
13
+ #
14
+ # The MINOR goes in the directory and the file name stays "native":
15
+ # ruby derives the init symbol from the feature basename, so the old
16
+ # native-<minor>.so name made require ask for the untypeable
17
+ # "Init_native-3" and no shipped bundle could ever load (#157).
18
+ #
19
+ # Unix bundles link the same shape build-platform-gem.sh uses — no
20
+ # libruby DT_NEEDED (its absolute build-runner path dangles on user
21
+ # machines; Ruby API symbols resolve from the host process), and
22
+ # darwin links with -undefined dynamic_lookup.
23
+ #
24
+ # Standalone by design: the release workflow runs this under each
25
+ # Ruby minor (3.3/3.4/4.0) with no bundler context.
26
+
27
+ require "rbconfig"
28
+ require "fileutils"
29
+
30
+ root = File.expand_path("..", __dir__)
31
+ ext_dir = File.join(root, "ext", "yeptris_native")
32
+ minor = RUBY_VERSION[/\A\d+\.\d+/]
33
+ windows = RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
34
+
35
+ Dir.chdir(ext_dir) do
36
+ system(RbConfig.ruby, "extconf.rb") or abort "extconf failed under #{RUBY_VERSION}"
37
+ # mkmf's link binds the CURRENT Ruby's runtime DLL — exactly
38
+ # what the per-minor scheme is for.
39
+ if windows
40
+ success = system("make")
41
+ else
42
+ darwin = RbConfig::CONFIG["host_os"] =~ /darwin/
43
+ dld = darwin ? "-dynamic -bundle -undefined dynamic_lookup" : ""
44
+ success = system("make", "LIBRUBYARG_SHARED=", "LIBRUBYARG_STATIC=",
45
+ "DLDFLAGS=#{dld}")
46
+ end
47
+ abort "make failed under #{RUBY_VERSION}" unless success
48
+ so = Dir.glob("native.{so,bundle,dll}").first
49
+ abort "native bundle not produced under #{RUBY_VERSION}" unless so
50
+ dest_dir = File.join(root, "lib", "yeptris", minor)
51
+ dest = File.join(dest_dir, File.basename(so))
52
+ # The artifact must reference only this minor's Ruby DLL.
53
+ imported = `strings #{so} 2>/dev/null`[/[a-z0-9-]*ruby\d{3,}\.dll/i]
54
+ if imported && !imported.include?("ruby#{minor.delete('.')}")
55
+ abort "#{so} imports #{imported} but was built under #{RUBY_VERSION} — refuse to mis-name it"
56
+ end
57
+ FileUtils.mkdir_p(dest_dir)
58
+ FileUtils.cp(so, dest)
59
+ puts "Installed native materializer for Ruby #{minor} -> #{dest} (#{imported || 'no ruby dll string found'})"
60
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Builds the vendored libyeptris at gem-install time so EVERY install
4
+ # carries the engine (the pure `ruby`-platform gem has no prebuilt
5
+ # binary). Platform gems vendor the prebuilt lib at the gem root —
6
+ # when one is present this extension no-ops.
7
+
8
+ require "mkmf"
9
+ require "fileutils"
10
+
11
+ gem_root = File.expand_path("../..", __dir__)
12
+ vendored = File.join(gem_root, "vendor", "libyeptris")
13
+
14
+ prebuilt = ["libyeptris.so", "libyeptris.dylib", "libyeptris.dll",
15
+ "yeptris.dll"].any? { |n| File.exist?(File.join(gem_root, n)) }
16
+
17
+ def write_dummy_makefile(reason)
18
+ File.write("Makefile", <<~MAKE)
19
+ all:
20
+ \t@echo "#{reason}"
21
+ install:
22
+ clean:
23
+ MAKE
24
+ end
25
+
26
+ if prebuilt
27
+ write_dummy_makefile("yeptris: prebuilt libyeptris ships in this gem; source build skipped")
28
+ elsif !File.directory?(vendored)
29
+ write_dummy_makefile("yeptris: no vendored libyeptris sources; set YEPTRIS_LIB_PATH at require time")
30
+ elsif find_executable("cmake").nil?
31
+ write_dummy_makefile("yeptris: cmake not found; set YEPTRIS_LIB_PATH at require time")
32
+ else
33
+ # Out-of-source into the ext workdir; the shared lib then moves to
34
+ # the GEM ROOT, where ffi.rb's ladder probes it.
35
+ build = File.join(Dir.pwd, "libyeptris-build")
36
+ # BUILD_TESTING (the CMake standard) gates test/ — the vendored
37
+ # tree ships no test dir; the static target must build because the
38
+ # unconditional install(TARGETS yeptris_static) expects it
39
+ args = [
40
+ "-DCMAKE_BUILD_TYPE=Release",
41
+ "-DBUILD_TESTING=OFF",
42
+ "-DYEPTRIS_BUILD_CLI=OFF",
43
+ "-DYEPTRIS_BUILD_BENCHMARKS=OFF",
44
+ "-DYEPTRIS_BUILD_SHARED=ON",
45
+ ]
46
+ ok = system("cmake", "-S", vendored, "-B", build, *args) &&
47
+ system("cmake", "--build", build, "--config", "Release")
48
+ lib = Dir.glob(File.join(build, "**", "libyeptris.{so,dylib}")).first
49
+ if ok && lib
50
+ FileUtils.cp(lib, File.join(gem_root, File.basename(lib)))
51
+ write_dummy_makefile("yeptris: built vendored libyeptris at gem install")
52
+ else
53
+ # a failed build must not abort the install — require-time raises
54
+ # the informative ladder error instead
55
+ write_dummy_makefile("yeptris: libyeptris source build failed; set YEPTRIS_LIB_PATH at require time")
56
+ end
57
+ end
@@ -0,0 +1,198 @@
1
+ /* cbor_ruby.c — CBOR decode → Ruby VALUE in one C pass (#157).
2
+ *
3
+ * The FFI ladder's CBOR.load pays decode + a Marshal emit/load round
4
+ * trip; this walks the decoded DOM directly, building the same VALUEs
5
+ * the materializer builds (tag-driven scalar semantics, insertion-
6
+ * order mappings), with no intermediate representation.
7
+ */
8
+ #include <ruby.h>
9
+ /* rb_hash_new_capa is Ruby 3.2+; older Rubies grow dynamically (the
10
+ * json_ruby.c guard, verbatim). */
11
+ #if RUBY_API_VERSION_MAJOR > 3 || (RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 2)
12
+ #define HASH_NEW_CAPA(n) rb_hash_new_capa(n)
13
+ #else
14
+ #define HASH_NEW_CAPA(n) rb_hash_new()
15
+ #endif
16
+ #include <ruby/encoding.h>
17
+ #include <stdlib.h>
18
+ #include <string.h>
19
+
20
+ static rb_encoding* cr_utf8_enc;
21
+
22
+ /* Map keys repeat across records in CBOR corpora; interning shares one
23
+ * VALUE per distinct key (the json_ruby.c on_key pattern, #157). */
24
+ static VALUE cr_key_str(const char* p, size_t len) {
25
+ return rb_enc_interned_str(p, (long)len, cr_utf8_enc);
26
+ }
27
+
28
+ #include "cbor/sink.h"
29
+ #include "dom/dom.h"
30
+ #include "doc.h" /* the public YeptrisDocument wrapper: ->dom */
31
+ #include <yeptris/cbor.h>
32
+ #include <yeptris/dom.h>
33
+ #include <yeptris/resolve.h>
34
+
35
+ /* ---- the VALUE sink (#157): bytes -> VALUE in ONE pass ----
36
+ *
37
+ * The decode grammar drives; these callbacks build the same VALUEs
38
+ * the old DOM + cr_walk pair produced (verified by the binding's
39
+ * differential suite): nil/true/false by tag, ints via LL2NUM (the
40
+ * INT64_MIN text parity wart kept), floats via DBL2NUM (no
41
+ * text round trip), strings copied utf8 (byte strings today ride the
42
+ * same utf8 String), map keys interned (values never are).
43
+ *
44
+ * GC: the container stack is a Ruby array (every VALUE reachable);
45
+ * the input buffer is read directly, so decode runs with GC disabled
46
+ * (the caller's String may move otherwise — the #160 bus error). */
47
+
48
+ struct rv_ctx {
49
+ VALUE stack; /* [.., container, (pending-key)?] */
50
+ VALUE root; /* Qnil until the top item closes */
51
+ };
52
+
53
+ static VALUE rv_top(const struct rv_ctx* c) {
54
+ long n = RARRAY_LEN(c->stack);
55
+ return n > 0 ? rb_ary_entry(c->stack, n - 1) : Qnil;
56
+ }
57
+
58
+ static VALUE rv_attach(struct rv_ctx* c, VALUE v) {
59
+ VALUE top = rv_top(c);
60
+ if (RB_TYPE_P(top, T_ARRAY)) {
61
+ rb_ary_push(top, v);
62
+ return v;
63
+ }
64
+ if (RB_TYPE_P(top, T_HASH)) {
65
+ rb_ary_push(c->stack, v); /* becomes the pending key */
66
+ return v;
67
+ }
68
+ /* a pending key: pop it, land v in the map */
69
+ VALUE k = rb_ary_pop(c->stack);
70
+ VALUE map = rv_top(c);
71
+ if (RB_TYPE_P(map, T_HASH)) {
72
+ rb_hash_aset(map, k, v);
73
+ return v;
74
+ }
75
+ /* the stack emptied: v is the root */
76
+ c->root = v;
77
+ return v;
78
+ }
79
+
80
+ static int rv_text(void* ctx, const char* s, uint32_t n, uint8_t tag_id, int is_key,
81
+ const char* tag, uint32_t tag_len) {
82
+ (void)tag;
83
+ (void)tag_len;
84
+ struct rv_ctx* c = ctx;
85
+ VALUE v;
86
+ switch (tag_id) {
87
+ case YEPTRIS_TAG_NULL:
88
+ v = Qnil;
89
+ break;
90
+ case YEPTRIS_TAG_BOOL:
91
+ v = (n == 4 && memcmp(s, "true", 4) == 0) ? Qtrue : Qfalse;
92
+ break;
93
+ default: /* rendered text (diagnostics, simple(N), key ints) */
94
+ v = rb_utf8_str_new(s, (long)n);
95
+ break;
96
+ }
97
+ (void)is_key;
98
+ rv_attach(c, v);
99
+ return 1;
100
+ }
101
+
102
+ static int rv_int(void* ctx, int negative, uint64_t mag, int is_key, const char* tag,
103
+ uint32_t tag_len) {
104
+ (void)tag;
105
+ (void)tag_len;
106
+ struct rv_ctx* c = ctx;
107
+ VALUE v;
108
+ if (negative && mag == (uint64_t)1 << 63) {
109
+ /* parity: the DOM path's strtoll guard renders INT64_MIN a
110
+ * String today; the differential suite pins it */
111
+ v = rb_utf8_str_new("-9223372036854775808", 20);
112
+ } else {
113
+ v = LL2NUM(negative ? -(int64_t)mag : (int64_t)mag);
114
+ }
115
+ rv_attach(c, v);
116
+ return 1;
117
+ }
118
+
119
+ static int rv_float(void* ctx, double dv, int is_key, const char* tag, uint32_t tag_len) {
120
+ (void)is_key;
121
+ (void)tag;
122
+ (void)tag_len;
123
+ rv_attach(ctx, DBL2NUM(dv));
124
+ return 1;
125
+ }
126
+
127
+ static int rv_str(void* ctx, const unsigned char* p, uint32_t n, int borrowed, int is_key,
128
+ const char* tag, uint32_t tag_len) {
129
+ (void)borrowed;
130
+ (void)tag;
131
+ (void)tag_len;
132
+ struct rv_ctx* c = ctx;
133
+ VALUE v = is_key ? rb_enc_interned_str((const char*)p, (long)n, cr_utf8_enc)
134
+ : rb_utf8_str_new((const char*)p, (long)n);
135
+ rv_attach(c, v);
136
+ return 1;
137
+ }
138
+
139
+ static int rv_bytes(void* ctx, const unsigned char* p, uint32_t n, int borrowed, int is_key,
140
+ const char* tag, uint32_t tag_len) {
141
+ /* parity: byte strings ride the same utf8 String today */
142
+ return rv_str(ctx, p, n, borrowed, is_key, tag, tag_len);
143
+ }
144
+
145
+ static int rv_open(void* ctx, int is_map, uint64_t cap, const char* tag, uint32_t tag_len) {
146
+ (void)tag;
147
+ (void)tag_len;
148
+ struct rv_ctx* c = ctx;
149
+ VALUE v;
150
+ if (is_map) {
151
+ v = (cap != UINT64_MAX && cap / 2 <= 4096) ? HASH_NEW_CAPA((long)(cap / 2))
152
+ : rb_hash_new();
153
+ } else {
154
+ v = (cap != UINT64_MAX && cap <= 8192) ? rb_ary_new_capa((long)cap) : rb_ary_new();
155
+ }
156
+ rb_ary_push(c->stack, v);
157
+ return 1;
158
+ }
159
+
160
+ static int rv_close(void* ctx, int is_map) {
161
+ (void)is_map;
162
+ struct rv_ctx* c = ctx;
163
+ VALUE v = rb_ary_pop(c->stack);
164
+ rv_attach(c, v);
165
+ return 1;
166
+ }
167
+
168
+ VALUE yep_rb_cbor_load(const char* p, size_t len, int strict) {
169
+ if (cr_utf8_enc == NULL) {
170
+ cr_utf8_enc = rb_utf8_encoding();
171
+ }
172
+ YeptrisStatus st = YEPTRIS_OK;
173
+ /* the decoder reads the caller's buffer directly; GC off across
174
+ * the pass (a compaction would move the String under p — the
175
+ * #160 bus error) */
176
+ VALUE gc_on = rb_gc_disable();
177
+ struct rv_ctx ctx;
178
+ ctx.stack = rb_ary_new();
179
+ ctx.root = Qnil;
180
+ static const yep_cbor_sink RV_SINK = {
181
+ NULL, rv_text, rv_int, rv_float, rv_str, rv_bytes, rv_open, rv_close,
182
+ };
183
+ yep_cbor_sink sink = RV_SINK;
184
+ sink.ctx = &ctx;
185
+ st = yep_cbor_decode_gen((const unsigned char*)p, len, strict, NULL, &sink);
186
+ /* rb_gc_disable returns Qfalse when GC was ON — enable exactly
187
+ * then (the old RTEST(gc_on) tested the inverted sense, so every
188
+ * CBOR load left GC permanently off; the Init self-check rides
189
+ * this path too, so one require disabled GC for the process —
190
+ * #259's linear RSS growth and never-running finalizers) */
191
+ if (gc_on == Qfalse) {
192
+ rb_gc_enable();
193
+ }
194
+ if (st != YEPTRIS_OK) {
195
+ return Qundef;
196
+ }
197
+ return ctx.root;
198
+ }
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Builds the native JSON/CBOR materializer (yeptris-ruby#311): the
4
+ # per-minor prebuilt bundle loads FIRST ("lib/yeptris/<minor>/native")
5
+ # and THIS build is the fallback slot ("require 'yeptris/native'") —
6
+ # compiled by the installing Ruby, so it is ABI-correct on every
7
+ # minor, present and future. Installs must NEVER fail: any miss (no
8
+ # engine binary, no headers, no usable toolchain) degrades to a no-op
9
+ # Makefile and the FFI ladder carries the load, exactly as today.
10
+
11
+ require "mkmf"
12
+ require "fileutils"
13
+
14
+ gem_root = File.expand_path("../..", __dir__)
15
+ vendored = File.join(gem_root, "vendor", "libyeptris")
16
+
17
+ def write_dummy_makefile(reason)
18
+ File.write("Makefile", <<~MAKE)
19
+ all:
20
+ \t@echo "#{reason}"
21
+ install:
22
+ clean:
23
+ MAKE
24
+ end
25
+
26
+ # 1. The engine binary to LINK. Order: CI/dev explicit, then the gem
27
+ # root — platform gems vendor the prebuilt lib there, and the pure
28
+ # gem's ext/libyeptris extconf builds it there BEFORE this extension
29
+ # runs (rubygems builds extensions in gemspec order).
30
+ lib = ENV["YEPTRIS_LIB_PATH"]
31
+ lib = nil unless lib && File.file?(lib)
32
+ lib ||= ["libyeptris.so", "libyeptris.dylib", "yeptris.dll"]
33
+ .map { |n| File.join(gem_root, n) }
34
+ .find { |f| File.exist?(f) }
35
+
36
+ # 2. The engine headers: CI/dev checkout, then the vendored tree that
37
+ # rides every gem artifact (the packaging doctrine's recompile half).
38
+ src_roots = [ENV["YEPTRIS_SRC"]].compact
39
+ src_roots << File.join(vendored, "src")
40
+ src_root = src_roots.find { |d| d && File.directory?(File.join(d, "include")) }
41
+
42
+ # 0. The toolchain probe — the docstring's third miss (yeptris-ruby#317):
43
+ # a toolchain-free image (the alpine musl smoke has no compiler) must
44
+ # degrade to the no-op Makefile, not abort inside mkmf's sanity link.
45
+ if !have_devel?
46
+ write_dummy_makefile("yeptris: no usable toolchain for the materializer; the FFI ladder carries the load")
47
+ elsif lib.nil?
48
+ write_dummy_makefile("yeptris: no libyeptris binary for the materializer; the FFI ladder carries the load")
49
+ elsif src_root.nil?
50
+ write_dummy_makefile("yeptris: no engine headers for the materializer; the FFI ladder carries the load")
51
+ else
52
+ $INCFLAGS << " -I#{src_root}/include -I#{src_root}/yeptris"
53
+ %w[build-validate/generated build/generated].each do |g|
54
+ d = File.join(File.dirname(src_root), g)
55
+ $INCFLAGS << " -I#{d}" if File.directory?(d)
56
+ end
57
+ # the generated version.h: nothing in the materializer's include
58
+ # chain needs it today; generate it into the workdir so a future
59
+ # include cannot break installs (the vendored tree ships only .in)
60
+ vhin = File.join(src_root, "include", "yeptris", "version.h.in")
61
+ unless File.exist?(File.join(src_root, "include", "yeptris", "version.h"))
62
+ if File.exist?(vhin)
63
+ # CMakeLists sits at the engine tree's root: the vendored gem
64
+ # tree (vendor/libyeptris) or the CI checkout (libyeptris-src).
65
+ # encoding: pinned UTF-8 — the engine sources carry UTF-8 prose
66
+ # (em-dashes in comments), and a POSIX/C-locale environment
67
+ # (debian distro ruby, LC_ALL=C users building the source gem)
68
+ # defaults Ruby's external encoding to US-ASCII, where any byte
69
+ # >= 0x80 makes this regex raise "invalid byte sequence"
70
+ # (surfaced by the riscv64-linux platform-gem leg).
71
+ ver = File.read(File.join(File.dirname(src_root), "CMakeLists.txt"), encoding: "UTF-8")[/project\s*\([^)]*?VERSION\s+([0-9.]+)/m, 1] || "0.0.0"
72
+ maj, min, pat = ver.split(".")
73
+ File.write("version.h", File.read(vhin, encoding: "UTF-8")
74
+ .gsub("@PROJECT_VERSION_MAJOR@", maj || "0")
75
+ .gsub("@PROJECT_VERSION_MINOR@", min || "0")
76
+ .gsub("@PROJECT_VERSION_PATCH@", pat || "0")
77
+ .gsub("@PROJECT_VERSION@", ver))
78
+ $INCFLAGS << " -I."
79
+ end
80
+ end
81
+
82
+ libdir = File.dirname(lib)
83
+ $LIBPATH << libdir
84
+ # the bundle must find libyeptris at require time; the gem root is
85
+ # stable within an installation
86
+ $LDFLAGS << " -Wl,-rpath,#{libdir}" if RUBY_PLATFORM =~ /linux|darwin/
87
+
88
+ if have_library("yeptris", "yep_json_string") && have_library("yeptris", "yeptris_visit_json")
89
+ # Windows resolves DLL dependencies beside the loading module —
90
+ # install the dll beside the built bundle
91
+ if RUBY_PLATFORM =~ /mswin|mingw/ && File.dirname(lib) != gem_root
92
+ ($INSTALLFILES ||= []) << [lib, "$(RUBYARCHDIR)/yeptris"]
93
+ end
94
+ $CFLAGS << " -O3 -fvisibility=hidden" unless RUBY_PLATFORM =~ /mswin|mingw/
95
+ create_makefile("yeptris/native")
96
+ else
97
+ write_dummy_makefile("yeptris: materializer link probe failed; the FFI ladder carries the load")
98
+ end
99
+ end