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
@@ -0,0 +1,572 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+
5
+ module Yeptris
6
+ # Every public C declaration, attached exactly once (the leptris-ruby
7
+ # seam discipline: status checking and owned-pointer reading live in
8
+ # check_status / read_owned_string, never hand-rolled at call sites).
9
+ module FFI
10
+ extend ::FFI::Library
11
+
12
+ begin
13
+ ffi_lib [
14
+ ENV["YEPTRIS_LIB_PATH"],
15
+ File.expand_path("../../libyeptris.dylib", __dir__),
16
+ File.expand_path("../../libyeptris.so", __dir__),
17
+ File.expand_path("../../libyeptris.dll", __dir__),
18
+ "/usr/local/lib/libyeptris.dylib",
19
+ "/usr/local/lib/libyeptris.so",
20
+ "yeptris",
21
+ ].compact
22
+ rescue LoadError => e
23
+ raise LoadError, <<~MSG
24
+ yeptris: cannot load the libyeptris library.
25
+ Set YEPTRIS_LIB_PATH to a libyeptris.{so,dylib,dll}, or vendor
26
+ the library next to the gem's lib/ directory.
27
+ (Underlying error: #{e.message})
28
+ MSG
29
+ end
30
+
31
+ class << self
32
+ # #138's class, hit again by the oiml-cs report: a stale
33
+ # libyeptris on the machine (the Windows base-name dedupe makes
34
+ # a system copy win) lacks newer symbols, and a raising attach
35
+ # aborts this file mid-evaluation — every constant after it
36
+ # never defines, so the next autoload dies with
37
+ # 'uninitialized constant Yeptris::FFI::NODE_SCALAR'. Attaches
38
+ # now record the miss and define a raising stub of the same
39
+ # name: the load completes, optional surfaces fail with a clear
40
+ # message at USE, and the ESSENTIAL self-check at the bottom of
41
+ # this file raises the friendly load error for truly old
42
+ # engines.
43
+ def attach_function(name, args, ret, opts = {})
44
+ super
45
+ rescue ::FFI::NotFoundError, ::FFI::TypeError
46
+ define_singleton_method(name) do |*_a, **_kw|
47
+ raise ::FFI::NotFoundError,
48
+ "yeptris: #{name} is unavailable — the loaded " \
49
+ "libyeptris is older than this gem. Update the engine " \
50
+ "library (or clear the stale copy shadowing it)."
51
+ end
52
+ (@missing ||= []) << name
53
+ nil
54
+ end
55
+ end
56
+
57
+
58
+ typedef :pointer, :yeptris_document
59
+ typedef :pointer, :yeptris_stream_iter
60
+ typedef :pointer, :yeptris_node
61
+ typedef :pointer, :yeptris_status_out
62
+ typedef :int, :yeptris_status
63
+
64
+ # YeptrisParseOptions (parse.h): schema, max_depth, strict,
65
+ # tab_policy, recover. ABI-frozen field order.
66
+ class ParseOptions < ::FFI::Struct
67
+ layout :schema, :int,
68
+ :max_depth, :int,
69
+ :strict, :int,
70
+ :tab_policy, :int,
71
+ :recover, :int
72
+ end
73
+
74
+ # yeptris_emit_options (emit.h): versioned by size.
75
+ class EmitOptions < ::FFI::Struct
76
+ layout :size, :uint32,
77
+ :canonical, :int,
78
+ :best_width, :int,
79
+ :explicit_doc_start, :int
80
+ end
81
+
82
+ attach_function :yeptris_version, [], :string
83
+
84
+ attach_function :yeptris_last_error, [:pointer, :pointer], :string
85
+
86
+ attach_function :yeptris_parse, %i[pointer size_t yeptris_status_out], :yeptris_document
87
+ attach_function :yeptris_parse_ex,
88
+ %i[pointer size_t pointer yeptris_status_out], :yeptris_document
89
+ attach_function :yeptris_parse_json, %i[pointer size_t yeptris_status_out], :yeptris_document
90
+
91
+ # The tolerant per-document stream iterator (engine #921): frames
92
+ # documents scanner-accurately, reports failures per document (the
93
+ # failed run's line/col ARE that document's own), resyncs to the
94
+ # next line-start marker. On an engine older than the iterator the
95
+ # attach stubs above raise the stale-engine message at USE
96
+ # (each_document's caller sees it directly — no separate gate
97
+ # constant, the @missing law covers it).
98
+ attach_function :yeptris_stream_iter_new, %i[pointer size_t pointer], :yeptris_stream_iter
99
+ attach_function :yeptris_stream_iter_next,
100
+ %i[yeptris_stream_iter pointer pointer], :yeptris_status
101
+ attach_function :yeptris_stream_iter_status,
102
+ %i[yeptris_stream_iter pointer pointer], :yeptris_status
103
+ attach_function :yeptris_stream_iter_free, [:yeptris_stream_iter], :void
104
+ # the capability probe (evaluated AFTER the attaches above — the
105
+ # CBOR.available? pattern): specs and hosts gate on it; at USE a
106
+ # stale engine still raises the stub's message
107
+ STREAM_ITER = !(@missing ||= []).include?(:yeptris_stream_iter_new)
108
+
109
+ # The JSON tape (TODO.restructure/85; the JSON surface's load
110
+ # engine — issue #81): ONE call, three bulk columns, spans borrow
111
+ # the caller's string (no arena copy, no second validating parse).
112
+ # v2 records: numbers are spans at parse; yeptris_tape_convert
113
+ # materializes them in one bulk call.
114
+ # v3 (libyeptris 0.6.9): the interleaved records (recs) are the
115
+ # primary storage on the lenient route; the strict route keeps the
116
+ # columns eager. The layout MUST mirror yeptris_json_tape — a stale
117
+ # layout makes C write past the FFI buffer (a silent heap overflow
118
+ # that only some allocators catch; the 0.6.9.1 windows crash).
119
+ class JsonTape < ::FFI::Struct
120
+ layout :count, :size_t, :kinds, :pointer, :offs, :pointer,
121
+ :lens, :pointer, :recs, :pointer, :_cols_ready, :int,
122
+ :_rec_primary, :int, :int_min, :int64, :_src, :pointer,
123
+ :_srclen, :size_t, :_block, :pointer
124
+ end
125
+
126
+ attach_function :yeptris_parse_json_tape, %i[pointer size_t pointer], :int
127
+ attach_function :yeptris_tape_free, [:pointer], :void
128
+ attach_function :yeptris_tape_convert, %i[pointer size_t size_t pointer pointer], :size_t
129
+
130
+ # the compiled plan walk (#293 / TODO.restructure/87): compile a
131
+ # strict-JSON spec once, apply it to a parsed tape in one C pass,
132
+ # read the typed COLUMNAR result
133
+ attach_function :yeptris_plan_compile, %i[pointer size_t pointer], :pointer
134
+ attach_function :yeptris_plan_free, [:pointer], :void
135
+ attach_function :yeptris_plan_column_count, [:pointer], :size_t
136
+ attach_function :yeptris_tape_plan_walk, %i[pointer pointer pointer], :pointer
137
+ attach_function :yeptris_plan_result_free, [:pointer], :void
138
+ attach_function :yeptris_plan_result_rows, [:pointer], :size_t
139
+ attach_function :yeptris_plan_result_kind, %i[pointer size_t], :int
140
+ attach_function :yeptris_plan_result_ints, %i[pointer size_t], :pointer
141
+ attach_function :yeptris_plan_result_floats, %i[pointer size_t], :pointer
142
+ attach_function :yeptris_plan_result_str_offs, %i[pointer size_t], :pointer
143
+ attach_function :yeptris_plan_result_str_lens, %i[pointer size_t], :pointer
144
+ attach_function :yeptris_plan_result_nulls, %i[pointer size_t], :pointer
145
+
146
+ # the DOM (YAML) leg of the plan walk (#293 slice three): same
147
+ # compiled plan over a parsed document; str columns expose
148
+ # (ptr,len) views into the document's regions
149
+ attach_function :yeptris_document_plan_walk, %i[yeptris_document pointer pointer], :pointer
150
+ attach_function :yeptris_plan_result_strs, %i[pointer size_t], :pointer
151
+
152
+ # yeptris_plan_str (plan.h): one string view
153
+ class PlanStr < ::FFI::Struct
154
+ layout :p, :pointer, :len, :size_t
155
+ end
156
+
157
+ attach_function :yeptris_document_free, [:yeptris_document], :void
158
+ attach_function :yeptris_document_count, [:yeptris_document], :size_t
159
+ attach_function :yeptris_document_root, [:yeptris_document, :size_t], :yeptris_node
160
+
161
+ # construction (TODO.impl/11 phase 3)
162
+ attach_function :yeptris_document_new, [], :yeptris_document
163
+ attach_function :yeptris_document_new_schema, [:int], :yeptris_document
164
+ attach_function :yeptris_document_set_root,
165
+ %i[yeptris_document yeptris_node], :int
166
+ attach_function :yeptris_node_new_mapping, [:yeptris_document], :yeptris_node
167
+ attach_function :yeptris_node_new_sequence, [:yeptris_document], :yeptris_node
168
+ attach_function :yeptris_node_new_scalar,
169
+ %i[yeptris_document pointer size_t int], :yeptris_node
170
+ attach_function :yeptris_node_map_add,
171
+ %i[yeptris_node pointer size_t yeptris_node], :int
172
+ attach_function :yeptris_node_map_add_node,
173
+ %i[yeptris_node yeptris_node yeptris_node], :int
174
+ attach_function :yeptris_node_map_set,
175
+ %i[yeptris_node pointer size_t yeptris_node], :int
176
+ attach_function :yeptris_node_map_del, %i[yeptris_node pointer size_t], :int
177
+ attach_function :yeptris_node_seq_add, %i[yeptris_node yeptris_node], :int
178
+ attach_function :yeptris_node_seq_del, %i[yeptris_node size_t], :int
179
+ attach_function :yeptris_node_set_anchor, %i[yeptris_node pointer size_t], :int
180
+ attach_function :yeptris_node_set_tag, %i[yeptris_node pointer size_t], :int
181
+ attach_function :yeptris_node_new_alias,
182
+ %i[yeptris_document yeptris_node pointer size_t], :yeptris_node
183
+
184
+ attach_function :yeptris_node_kind, [:yeptris_node], :int
185
+ attach_function :yeptris_node_id, [:yeptris_node], :uint32
186
+ attach_function :yeptris_node_value, %i[yeptris_node pointer], :pointer
187
+ attach_function :yeptris_node_style, [:yeptris_node], :int
188
+ attach_function :yeptris_node_tag, %i[yeptris_node pointer], :pointer
189
+ attach_function :yeptris_node_anchor, %i[yeptris_node pointer], :pointer
190
+ attach_function :yeptris_node_alias_target, [:yeptris_node], :yeptris_node
191
+ attach_function :yeptris_node_tag_id, [:yeptris_node], :int
192
+ attach_function :yeptris_node_int, %i[yeptris_node pointer], :yeptris_status
193
+ attach_function :yeptris_node_float, %i[yeptris_node pointer], :yeptris_status
194
+ attach_function :yeptris_node_bool, %i[yeptris_node pointer], :yeptris_status
195
+ attach_function :yeptris_node_seq_count, [:yeptris_node], :size_t
196
+ attach_function :yeptris_node_seq_at, %i[yeptris_node size_t], :yeptris_node
197
+ attach_function :yeptris_node_children,
198
+ %i[yeptris_node pointer size_t], :size_t
199
+ attach_function :yeptris_node_map_count, [:yeptris_node], :size_t
200
+ attach_function :yeptris_node_map_get, %i[yeptris_node pointer size_t], :yeptris_node
201
+ attach_function :yeptris_node_map_at,
202
+ %i[yeptris_node size_t pointer pointer], :int
203
+
204
+ attach_function :yeptris_tag_uri, [:int], :string
205
+
206
+ # recorder (TODO.impl/12): bulk records + string arena, one drain
207
+ attach_function :yeptris_recorder_new, [], :pointer
208
+ attach_function :yeptris_recorder_new_ex, [:int], :pointer
209
+ attach_function :yeptris_recorder_feed,
210
+ %i[pointer pointer size_t int], :int
211
+ attach_function :yeptris_recorder_records, %i[pointer pointer], :pointer
212
+ attach_function :yeptris_recorder_arena, %i[pointer pointer], :pointer
213
+ attach_function :yeptris_recorder_free, [:pointer], :void
214
+
215
+ # value stream (TODO.impl/15 phase F): one drain of pre-converted
216
+ # typed values — the materialization fast path
217
+ attach_function :yeptris_value_drain,
218
+ %i[pointer size_t int pointer pointer pointer pointer], :int
219
+ attach_function :yeptris_value_free, %i[pointer pointer], :void
220
+
221
+ # Columnar drain (libyeptris > 0.1.1): the same stream as parallel
222
+ # typed buffers, one carved allocation. Feature-detected — the
223
+ # record API is the fallback on older libraries.
224
+ COLUMNS = begin
225
+ attach_function :yeptris_value_drain_columns, %i[pointer size_t int pointer], :int
226
+ attach_function :yeptris_value_free_columns, [:pointer], :void
227
+ true
228
+ rescue ::FFI::NotFoundError
229
+ false
230
+ end
231
+
232
+ class ValueColumns < ::FFI::Struct
233
+ layout :count, :size_t, :arena_len, :size_t,
234
+ :payloads, :pointer, :offs, :pointer, :lens, :pointer,
235
+ :kinds, :pointer, :tags, :pointer, :is_keys, :pointer,
236
+ :bools, :pointer, :arena, :pointer
237
+ end
238
+
239
+ # Marshal 4.8 emission (TODO.restructure/21): the C side converts
240
+ # value records directly into Ruby's wire format; the binding
241
+ # materializes the whole graph with one core-C Marshal.load call
242
+ # instead of walking per-value records in pure Ruby. Same feature-
243
+ # detect discipline as the columnar drain (older libraries fall
244
+ # back to the record walk).
245
+ MARSHAL_ALL_DOCS = 0
246
+ MARSHAL_FIRST_DOC = 1
247
+ attach_function :yeptris_marshal,
248
+ %i[pointer size_t int int pointer pointer], :int
249
+ attach_function :yeptris_marshal_node,
250
+ %i[yeptris_node pointer pointer], :int
251
+ attach_function :yeptris_marshal_node_ex,
252
+ %i[yeptris_node uint32 pointer pointer], :int
253
+ attach_function :yeptris_marshal_free, [:pointer], :void
254
+ # yeptris-ruby#322: the dump face (engine 0.6.45+; the attachment
255
+ # helper records the miss into @missing on older libraries —
256
+ # MARSHAL_JSON goes false and the dump keeps the per-node walk)
257
+ attach_function :yeptris_json_from_marshal,
258
+ %i[pointer size_t int pointer pointer], :int
259
+ # The bulk child drain (#168's quadratic): O(n) iteration for
260
+ # #each/#each_pair. Engines without it fall back to the per-index
261
+ # walk (correct, quadratic).
262
+ CHILDREN_DRAIN = !(@missing ||= []).include?(:yeptris_node_children)
263
+ MARSHAL = !(@missing ||= []).include?(:yeptris_marshal_node)
264
+ # the strict-dup marshal entry (engine 0.6.34+, yeptris-ruby#278):
265
+ # gates the JSON fallback's C route in STRICT mode
266
+ MARSHAL_STRICT_DUP = !(@missing ||= []).include?(:yeptris_marshal_node_ex)
267
+ # the dump face (yeptris-ruby#322, engine 0.6.45+): Ruby
268
+ # Marshal.dump bytes -> JSON text in one C call
269
+ MARSHAL_JSON = !(@missing ||= []).include?(:yeptris_json_from_marshal)
270
+ # engine flag value (yeptris.h: YEPTRIS_MARSHAL_STRICT_DUP_KEYS 1u);
271
+ # defined whether or not the entry exists, because the JSON fallback
272
+ # references it on lanes without a Ruby-version-matched native ext
273
+ # (windows) and a NameError there fails every parse (lutaml-jsonschema
274
+ # CI, x64-mingw-ucrt 0.6.34.2)
275
+ MARSHAL_STRICT_DUP_KEYS = 1
276
+
277
+ # bulk build (TODO.impl/15 phase D): one call raises a document
278
+ BUILD_SCALAR = 1
279
+ BUILD_SEQ = 2
280
+ BUILD_MAP = 3
281
+ BUILD_END = 4
282
+ BUILD_TAG = 5
283
+
284
+ # the ABI-pinned shape; the bulk builder packs these bytes
285
+ # directly (12 per entry)
286
+ class BuildEntry < ::FFI::Struct
287
+ layout op: :uint8, style: :uint8, reserved: :uint16, off: :uint32, len: :uint32
288
+ end
289
+ attach_function :yeptris_document_build,
290
+ %i[yeptris_document pointer size_t pointer size_t], :int
291
+
292
+ attach_function :yeptris_serialize, %i[yeptris_document pointer], :pointer
293
+ attach_function :yeptris_serialize_ex,
294
+ %i[yeptris_document pointer pointer], :pointer
295
+ attach_function :yeptris_serialize_json, %i[yeptris_document pointer], :pointer
296
+
297
+ # compact JSON generation (JSON.generate's shape); absent on
298
+ # libraries before v0.2.5 — the JSON surface feature-detects
299
+ JSON_EX = begin
300
+ attach_function :yeptris_serialize_json_ex, %i[yeptris_document pointer int], :pointer
301
+ true
302
+ rescue ::FFI::NotFoundError
303
+ false
304
+ end
305
+
306
+ # pretty JSON generation (JSON.pretty_generate's shape); the JSON
307
+ # surface feature-detects via the @missing convention below (the
308
+ # deferred stub records the miss at attach, so a begin/rescue
309
+ # never fires)
310
+ attach_function :yeptris_serialize_json_pretty,
311
+ %i[yeptris_document pointer pointer size_t], :pointer
312
+ JSON_PRETTY = !(@missing ||= []).include?(:yeptris_serialize_json_pretty)
313
+
314
+ # CBOR (RFC 8949, TODO.cbor): absent on libraries before the
315
+ # codec's release — the CBOR module feature-detects
316
+ attach_function :yeptris_cbor_decode, %i[pointer size_t uint32 yeptris_status_out],
317
+ :yeptris_document
318
+ callback :cbor_item_cb, %i[pointer yeptris_document size_t], :int
319
+ attach_function :yeptris_cbor_decode_sequence,
320
+ %i[pointer size_t uint32 cbor_item_cb pointer yeptris_status_out], :size_t
321
+ attach_function :yeptris_cbor_encode, %i[yeptris_document uint32 pointer], :pointer
322
+ attach_function :yeptris_cbor_encode_sequence,
323
+ %i[pointer size_t uint32 pointer], :pointer
324
+ CBOR_EX = !(@missing ||= []).include?(:yeptris_cbor_decode)
325
+ # yeptris-ruby#322: Marshal.dump bytes -> one CBOR item in one C
326
+ # call (engine 0.6.49+); MARSHAL_CBOR goes false on older libraries
327
+ # and CBOR.dump keeps the YAMLTree walk
328
+ attach_function :yeptris_cbor_from_marshal,
329
+ %i[pointer size_t uint32 pointer pointer], :int
330
+ MARSHAL_CBOR = !(@missing ||= []).include?(:yeptris_cbor_from_marshal)
331
+
332
+ # Owned char* results (serialize*): one reader, freed exactly once.
333
+ # The release goes through yeptris_free (libyeptris's own
334
+ # allocator-matching free) because ffi's :free attach has no
335
+ # Windows process-symbol fallback — libyeptris.dll doesn't export
336
+ # libc free, so resolving :free against it fails on Windows.
337
+ # A raised attach ABORTS this file mid-evaluation — everything
338
+ # after it (NODE_SCALAR and the kind constants below) never
339
+ # defines, and a lazily autoloaded node.rb then dies with
340
+ # 'uninitialized constant' (#138). Every fallback attaches too.
341
+ YEPTRIS_FREE = begin
342
+ attach_function :yeptris_free, [:pointer], :void
343
+ :direct
344
+ rescue ::FFI::NotFoundError
345
+ begin
346
+ # libyeptris < v0.6.6: POSIX resolves :free through the
347
+ # process symbol table, so the libc attach still works there.
348
+ attach_function :yeptris_free, :free, [:pointer], :void
349
+ :libc
350
+ rescue ::FFI::NotFoundError
351
+ # no owned-buffer release on this lib+platform combination;
352
+ # Owned.string leaks instead of killing the whole file
353
+ :none
354
+ end
355
+ end
356
+
357
+ # C out-params are size_t — native width (8 everywhere we ship
358
+ # except ILP32 armv7, where it is 4). The ffi gem (1.17.4) has no
359
+ # read_size_t, so dispatch on the measured type size: read_uint64
360
+ # on a 4-byte :size_t buffer ran out of bounds on arm-linux (the
361
+ # 0.6.18.1 armv7 smoke, valueml.rb:118).
362
+ SIZE_T_WIDTH = ::FFI.type_size(:size_t)
363
+
364
+ def self.read_c_size_t(ptr)
365
+ SIZE_T_WIDTH == 8 ? ptr.read_uint64 : ptr.read_uint32
366
+ end
367
+
368
+ module Owned
369
+ module_function
370
+
371
+ # Reads a NUL-terminated malloc'd C string into an Encoding
372
+ # UTF_8 String, then frees the buffer. len_out (nullable) is a
373
+ # MemoryPointer carrying the byte length from the producing call.
374
+ def string(ptr, len_out = nil)
375
+ return nil if ptr.null?
376
+
377
+ len = len_out && Yeptris::FFI.read_c_size_t(len_out)
378
+ s = if len && len > 0
379
+ ptr.read_bytes(len).force_encoding(Encoding::UTF_8)
380
+ else
381
+ ptr.read_string.force_encoding(Encoding::UTF_8)
382
+ end
383
+ ::Yeptris::FFI.yeptris_free(ptr) if ::Yeptris::FFI::YEPTRIS_FREE != :none
384
+ s
385
+ end
386
+ end
387
+
388
+ module_function
389
+
390
+ # Non-OK status -> ParseError carrying the C error channel's
391
+ # message with line/column. NULL-document failures route through
392
+ # here too (parse detail lives on the same channel).
393
+ def check_status(status, action)
394
+ return if status.zero?
395
+
396
+ raise Yeptris::ParseError, "#{action} failed: #{last_error_message}"
397
+ end
398
+
399
+ def last_error_message
400
+ line = ::FFI::MemoryPointer.new(:uint32)
401
+ col = ::FFI::MemoryPointer.new(:uint32)
402
+ msg = yeptris_last_error(line, col)
403
+ detail = msg.to_s
404
+ l = line.read_uint32
405
+ c = col.read_uint32
406
+ l.positive? ? "#{detail} at line #{l}, column #{c}" : detail
407
+ end
408
+
409
+ # Pinned enum values (test_abi): the constants the binding relies
410
+ # on without a C header at runtime.
411
+ NODE_SCALAR = 0
412
+ NODE_SEQUENCE = 1
413
+ NODE_MAPPING = 2
414
+ NODE_ALIAS = 3
415
+
416
+ STYLE_PLAIN = 1
417
+ STYLE_SINGLE_QUOTED = 2
418
+ STYLE_DOUBLE_QUOTED = 3
419
+ STYLE_LITERAL = 4
420
+ STYLE_FOLDED = 5
421
+
422
+ TAG_STR = 0
423
+ TAG_INT = 1
424
+ TAG_FLOAT = 2
425
+ TAG_BOOL = 3
426
+ TAG_NULL = 4
427
+ TAG_TIMESTAMP = 5
428
+ TAG_BINARY = 8
429
+
430
+ # the schema-descriptor API (issue #238; TODO.restructure/83)
431
+ DESC_ABI = 1
432
+ SCHEMA_ERROR = 9
433
+
434
+ class DescNode < ::FFI::Struct
435
+ layout :wire_name, :pointer, :kind, :uint8, :type_tag, :uint8,
436
+ :flags, :uint16, :child_index, :uint32, :child_count, :uint32,
437
+ :reserved, :uint32
438
+ end
439
+
440
+ class SchemaColumn < ::FFI::Struct
441
+ layout :data, :pointer, :capacity, :uint32, :count, :uint32
442
+ end
443
+
444
+ attach_function :yeptris_schema_load,
445
+ %i[pointer size_t int pointer uint32 uint32 pointer], :int
446
+
447
+ SCHEMA_12_CORE = 0
448
+ SCHEMA_11_COMPAT = 1
449
+ # resolve.h's third kind (spec 10.2): plain scalars must match a
450
+ # JSON production; the validate face's schema-family walk rides it.
451
+ SCHEMA_12_JSON = 2
452
+
453
+ OK = 0
454
+ ERROR_PARSE = 1
455
+ ERROR_MEMORY = 2
456
+ ERROR_DEPTH = 3
457
+ ERROR_ENCODING = 4
458
+ ERROR_IO = 5
459
+ ERROR_ARG = 6
460
+ ERROR_UNSUPPORTED = 7
461
+ ERROR_INTERNAL = 8
462
+
463
+ # ---- the validation face (validate.h; #882, engine 0.6.59+) ----
464
+ # Whole reports: one call produces a report the caller drains
465
+ # (count/at) and frees once. SCHEMA_ERROR (9, defined above) means
466
+ # the walk completed and the instance is INVALID — drain the
467
+ # report. Absent on older libraries: the attachment helper records
468
+ # the miss and VALIDATION gates the Ruby face with the friendly
469
+ # error at use.
470
+
471
+ typedef :pointer, :yeptris_schema
472
+ typedef :pointer, :yeptris_validate_report
473
+
474
+ # yeptris_diagnostic (validate.h): ABI-frozen — four uint32 facts
475
+ # then two bounded NUL-terminated texts. 16 + 256 + 128 bytes.
476
+ class CDiagnostic < ::FFI::Struct
477
+ layout :code, :uint32,
478
+ :line, :uint32,
479
+ :col, :uint32,
480
+ :offset, :uint32,
481
+ :path, [:char, 256],
482
+ :detail, [:char, 128]
483
+ end
484
+
485
+ # The schema-family walk: parse + validate fused (tag consistency,
486
+ # canonical-form key uniqueness; the JSON family's string-key +
487
+ # JSON-production rules under SCHEMA_12_JSON).
488
+ attach_function :yeptris_validate, %i[pointer size_t int pointer], :int
489
+ # An already-parsed document (or stream) against the family walk.
490
+ attach_function :yeptris_validate_document, %i[yeptris_document int pointer], :int
491
+ # JSON Schema draft 2020-12 subset, one-shot (schema bytes parsed
492
+ # per call).
493
+ attach_function :yeptris_json_schema_validate,
494
+ %i[pointer size_t pointer size_t pointer], :int
495
+ # The compiled-schema economy (#885 item 3): parse once, validate
496
+ # many. NULL from compile = failure (yeptris_last_error carries why).
497
+ attach_function :yeptris_schema_compile, %i[pointer size_t], :yeptris_schema
498
+ attach_function :yeptris_schema_validate,
499
+ %i[yeptris_schema pointer size_t pointer], :int
500
+ attach_function :yeptris_schema_free, [:yeptris_schema], :void
501
+ attach_function :yeptris_validate_report_count,
502
+ [:yeptris_validate_report], :size_t
503
+ attach_function :yeptris_validate_report_at,
504
+ %i[yeptris_validate_report size_t], :pointer
505
+ attach_function :yeptris_validate_report_free,
506
+ [:yeptris_validate_report], :void
507
+
508
+ # The diag codes (validate.h's YeptrisDiagCode, appending-only;
509
+ # pinned values — the engine's test_abi pins the head).
510
+ DIAG_NONE = 0
511
+ DIAG_TAG_MISMATCH = 1
512
+ DIAG_KEY_NOT_STRING = 2
513
+ DIAG_NON_JSON_TYPE = 3
514
+ DIAG_DUPLICATE_KEY = 4
515
+ DIAG_TYPE = 5
516
+ DIAG_REQUIRED = 6
517
+ DIAG_ENUM = 7
518
+ DIAG_CONST = 8
519
+ DIAG_PATTERN = 9
520
+ DIAG_MINIMUM = 10
521
+ DIAG_MAXIMUM = 11
522
+ DIAG_EXCLUSIVE_MINIMUM = 12
523
+ DIAG_EXCLUSIVE_MAXIMUM = 13
524
+ DIAG_MIN_LENGTH = 14
525
+ DIAG_MAX_LENGTH = 15
526
+ DIAG_MIN_ITEMS = 16
527
+ DIAG_MAX_ITEMS = 17
528
+ DIAG_UNIQUE_ITEMS = 18
529
+ DIAG_ADDITIONAL_PROPERTY = 19
530
+ DIAG_ANY_OF = 20
531
+ DIAG_ONE_OF = 21
532
+ DIAG_NOT = 22
533
+ DIAG_REF = 23
534
+ DIAG_FALSE_SCHEMA = 24
535
+ DIAG_DEPTH = 25
536
+ DIAG_LIMIT = 26
537
+ DIAG_MULTIPLE_OF = 27
538
+ DIAG_MIN_PROPERTIES = 28
539
+ DIAG_MAX_PROPERTIES = 29
540
+ DIAG_CONTAINS = 30
541
+ DIAG_MIN_CONTAINS = 31
542
+ DIAG_MAX_CONTAINS = 32
543
+ DIAG_DEPENDENT_REQUIRED = 33
544
+
545
+ # The face's availability (engine 0.6.59+); the Validation module
546
+ # raises the friendly error at use when the loaded library predates
547
+ # the attachments (the stubs above would raise NotFoundError raw).
548
+ VALIDATION = !(@missing ||= []).include?(:yeptris_validate) &&
549
+ !(@missing ||= []).include?(:yeptris_schema_compile) &&
550
+ !(@missing ||= []).include?(:yeptris_validate_report_at)
551
+
552
+ # The load-time essentials (the read path + the ownership
553
+ # contract): absent on engines far older than the optional
554
+ # surfaces — raise the friendly error once every constant has
555
+ # fully defined, so no partial-module state leaks into autoloads
556
+ # (the #138 class, closed at the root).
557
+ ESSENTIAL = %i[
558
+ yeptris_version yeptris_last_error yeptris_parse yeptris_parse_ex
559
+ yeptris_parse_json yeptris_document_free yeptris_document_count
560
+ yeptris_document_root yeptris_node_kind yeptris_node_value
561
+ yeptris_node_tag_id yeptris_node_style yeptris_document_new
562
+ yeptris_document_set_root yeptris_serialize yeptris_serialize_ex
563
+ ].freeze
564
+ missing_core = ESSENTIAL & (@missing ||= [])
565
+ raise ::FFI::NotFoundError,
566
+ "yeptris: the loaded libyeptris is older than this gem " \
567
+ "requires (missing: #{missing_core.join(', ')}). Update the " \
568
+ "engine library, or clear the stale copy shadowing it." \
569
+ unless missing_core.empty?
570
+
571
+ end
572
+ end