yeptris 0.6.78.0-arm-linux-eabihf → 0.6.80.0-arm-linux-eabihf

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.
data/lib/yeptris/ffi.rb CHANGED
@@ -9,22 +9,67 @@ module Yeptris
9
9
  module FFI
10
10
  extend ::FFI::Library
11
11
 
12
- begin
13
- ffi_lib [
12
+ # The per-OS vendor directory of the platform gem (the org
13
+ # native-layer contract, leptris-ruby#671 clause 1.2): engine
14
+ # binaries under lib/yeptris/vendor/<platform>/. Returns [] on
15
+ # gems without the vendor tree (the source gem) and on windows
16
+ # (the DLL is gem-local flat, candidate clause 1.3). The mapping
17
+ # itself lives in NativeLayout — the SSOT the packaging script and
18
+ # the CI gates consume too.
19
+ def self.vendor_platforms_for(ruby_platform)
20
+ NativeLayout.vendor_platforms_for(ruby_platform)
21
+ end
22
+
23
+ def self.vendor_dirs
24
+ NativeLayout.vendor_platforms_for(RUBY_PLATFORM)
25
+ .map { |d| File.expand_path("../yeptris/vendor/#{d}", __dir__) }
26
+ .select { |dir| File.directory?(dir) }
27
+ end
28
+
29
+ # THE libyeptris candidate list, in order — the org native-layer
30
+ # contract clause 1. Single source of truth: every face that
31
+ # loads the library resolves through this list, and the native
32
+ # materializer bundle rides the image it picked. Two
33
+ # differently-pathed copies load as two images with split
34
+ # per-document state — never resolve through a second list.
35
+ def self.lib_candidates
36
+ [
14
37
  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__),
38
+ *vendor_dirs.flat_map { |d|
39
+ %w[libyeptris.dylib libyeptris.so libyeptris.dll]
40
+ .map { |n| File.join(d, n) }
41
+ },
42
+ # the flat lib/ layout (contract clause 1.3)
43
+ File.expand_path("../libyeptris.dylib", __dir__),
44
+ File.expand_path("../libyeptris.so", __dir__),
45
+ File.expand_path("../libyeptris.dll", __dir__),
18
46
  "/usr/local/lib/libyeptris.dylib",
19
47
  "/usr/local/lib/libyeptris.so",
20
48
  "yeptris",
21
49
  ].compact
50
+ end
51
+
52
+ begin
53
+ ffi_lib lib_candidates
22
54
  rescue LoadError => e
55
+ # the named-remedy law (contract clause 1): never a bare
56
+ # LoadError — name the installed variant and the command that
57
+ # fixes it
23
58
  raise LoadError, <<~MSG
24
59
  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})
60
+
61
+ You may have installed the ruby-platform variant of this gem
62
+ (#{begin
63
+ Gem.loaded_specs["yeptris"]&.full_name
64
+ rescue StandardError
65
+ "unknown"
66
+ end}), which does not vendor the native library. Fix one of:
67
+
68
+ gem install yeptris --platform <your platform> # the vendored variant
69
+ bundle update yeptris # force platform gems
70
+ YEPTRIS_LIB_PATH=/path/to/libyeptris.so # an explicit library
71
+
72
+ Original error: #{e.message}
28
73
  MSG
29
74
  end
30
75
 
@@ -124,6 +169,11 @@ module Yeptris
124
169
  end
125
170
 
126
171
  attach_function :yeptris_parse_json_tape, %i[pointer size_t pointer], :int
172
+ attach_function :yeptris_parse_json_tape_lenient, %i[pointer size_t pointer], :int
173
+ # the columns-lazy law (tape.h): when the interleaved records are
174
+ # the primary storage (the lenient route), consumers reading the
175
+ # column pointers directly must materialize them once first
176
+ attach_function :yeptris_tape_columns, [:pointer], :int
127
177
  attach_function :yeptris_tape_free, [:pointer], :void
128
178
  attach_function :yeptris_tape_convert, %i[pointer size_t size_t pointer pointer], :size_t
129
179
 
@@ -553,6 +603,41 @@ module Yeptris
553
603
  !(@missing ||= []).include?(:yeptris_schema_compile) &&
554
604
  !(@missing ||= []).include?(:yeptris_validate_report_at)
555
605
 
606
+ # ---- the streaming faces (events.h; #411, the pull cursor and
607
+ # the document-at-a-time iterparse) ----
608
+ # One event with string fields into the owning model's storage:
609
+ # the puller's arena, valid until the next pull call — the Ruby
610
+ # face copies at hand-out, nothing borrowed crosses.
611
+ # ABI-frozen field order (events.h's YeptrisEvent); the C enum is
612
+ # an int on every ABI we ship.
613
+ class CEvent < ::FFI::Struct
614
+ layout :type, :int, :style, :int, :flow, :int, :explicit_marker, :int,
615
+ :implicit, :int,
616
+ :value, :pointer, :value_len, :size_t,
617
+ :anchor, :pointer, :anchor_len, :size_t,
618
+ :tag, :pointer, :tag_len, :size_t,
619
+ :line, :uint32, :col, :uint32, :end_line, :uint32, :end_col, :uint32
620
+ end
621
+
622
+ typedef :pointer, :yeptris_pull
623
+ typedef :pointer, :yeptris_iterparse
624
+
625
+ attach_function :yeptris_pull_new, %i[pointer size_t], :yeptris_pull
626
+ attach_function :yeptris_pull_next, [:yeptris_pull], :pointer
627
+ # the bulk cursor (the FFI shape): up to max events per call
628
+ attach_function :yeptris_pull_next_batch, %i[yeptris_pull pointer size_t], :size_t
629
+ attach_function :yeptris_pull_status, %i[yeptris_pull pointer pointer], :int
630
+ attach_function :yeptris_pull_free, [:yeptris_pull], :void
631
+
632
+ attach_function :yeptris_iterparse_new, %i[pointer size_t], :yeptris_iterparse
633
+ attach_function :yeptris_iterparse_next, %i[yeptris_iterparse pointer], :pointer
634
+ attach_function :yeptris_iterparse_status, %i[yeptris_iterparse pointer pointer], :int
635
+ attach_function :yeptris_iterparse_free, [:yeptris_iterparse], :void
636
+
637
+ EVENTS = !(@missing ||= []).include?(:yeptris_pull_new) &&
638
+ !(@missing ||= []).include?(:yeptris_iterparse_new)
639
+
640
+
556
641
  # The load-time essentials (the read path + the ownership
557
642
  # contract): absent on engines far older than the optional
558
643
  # surfaces — raise the friendly error once every constant has
@@ -0,0 +1,243 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yeptris"
4
+
5
+ module Yeptris
6
+ module JSON
7
+ # The public columnar tape face (engine tape.h; yeptris-ruby#411):
8
+ # ONE fused strict parse per document, records exposed as typed
9
+ # columns — no Ruby tree materializes. {Yeptris::JSON.load} rides
10
+ # this engine internally; the face hands the columnar data to the
11
+ # caller (the simdjson-class shape the C users and the rs/ts
12
+ # siblings share).
13
+ #
14
+ # tape = Yeptris::JSON::Tape.parse('{"a":[1,2],"b":"x"}')
15
+ # tape.kinds # => [:map_open, :str, :seq_open, :int, :int, :close, :str, :close]
16
+ # tape.value(i) # => the record's scalar (nil for structure)
17
+ #
18
+ # The spans borrow the caller's bytes: the tape retains the source
19
+ # string (the borrow law), and #value/#kinds answer plain Ruby.
20
+ # #free releases the engine's block; a tape left to GC still
21
+ # frees (the Document finalizer pattern).
22
+ class Tape
23
+ # Shared between the instance and its GC finalizer (Procs close
24
+ # over variables by reference — the Document pattern).
25
+ Freed = Struct.new(:flag)
26
+
27
+ # tape.h's record kinds (the kinds column), ABI-pinned.
28
+ RECORD_KINDS = {
29
+ 0 => :doc, 1 => :null, 2 => :true, 3 => :false,
30
+ 4 => :int, 5 => :float, 6 => :str,
31
+ 7 => :seq_open, 8 => :map_open, 9 => :close,
32
+ 10 => :num, # the lenient route's deferred number
33
+ }.freeze
34
+ private_constant :RECORD_KINDS
35
+
36
+ SPAN_KINDS = %i[int float str num].freeze
37
+ private_constant :SPAN_KINDS
38
+
39
+ # Raised when a deferred (lenient) number span fails the
40
+ # convert pass, or an INT span exceeds int64.
41
+ class Error < ::Yeptris::JSON::Error; end
42
+
43
+ # Parses strict JSON (or, with +lenient:+, the deferred-number
44
+ # route whose structural checks run at parse and the NUMBER
45
+ # grammar defers to materialize). Raises
46
+ # {Yeptris::JSON::ParseError} with the engine's detail.
47
+ def self.parse(json, lenient: false)
48
+ src = ::Yeptris.read_input(json).to_s
49
+ tape = ::Yeptris::FFI::JsonTape.new
50
+ rc = lenient ? ::Yeptris::FFI.yeptris_parse_json_tape_lenient(src, src.bytesize, tape)
51
+ : ::Yeptris::FFI.yeptris_parse_json_tape(src, src.bytesize, tape)
52
+ raise ::Yeptris::JSON::ParseError,
53
+ ::Yeptris::FFI.last_error_message unless rc == ::Yeptris::FFI::OK
54
+
55
+ # the columns-lazy law (tape.h): the lenient route stores the
56
+ # interleaved records as primary; consumers reading the
57
+ # column pointers materialize them once first
58
+ unless ::Yeptris::FFI.yeptris_tape_columns(tape.to_ptr).zero?
59
+ ::Yeptris::FFI.yeptris_tape_free(tape.to_ptr)
60
+ raise Error, "yeptris: tape column materialization failed"
61
+ end
62
+
63
+ new(src, tape, Freed.new(false))
64
+ end
65
+
66
+ # @api private — minted by .parse
67
+ def initialize(src, tape, freed)
68
+ # the spans borrow the source: retain it or every later span
69
+ # read points at collected memory (the Document @source law)
70
+ @source = src
71
+ @tape = tape
72
+ @c_ptr = tape
73
+ @freed = freed
74
+ ObjectSpace.define_finalizer(self, self.class.finalize(tape.to_ptr, freed))
75
+ end
76
+
77
+ def self.finalize(ptr, freed)
78
+ proc do
79
+ next if freed.flag
80
+
81
+ freed.flag = true
82
+ ::Yeptris::FFI.yeptris_tape_free(ptr)
83
+ end
84
+ end
85
+
86
+ # The record count (one record per token; the :doc boundary
87
+ # record leads).
88
+ def count
89
+ ensure_alive!
90
+ @tape[:count]
91
+ end
92
+ alias size count
93
+
94
+ # Every record's kind, as symbols (tape.h's record kinds).
95
+ def kinds
96
+ ensure_alive!
97
+ @kinds ||= @tape[:kinds].read_bytes(@tape[:count]).unpack("C*")
98
+ .map { |k| RECORD_KINDS.fetch(k, k) }
99
+ end
100
+
101
+ # The record's source span as [offset, length] into the parsed
102
+ # bytes (INT/FLOAT/STR/NUM records; nil for the others —
103
+ # container records carry LINKS in the offset, read those with
104
+ # #match).
105
+ def span(i)
106
+ ensure_alive!
107
+ return nil unless SPAN_KINDS.include?(kinds[i])
108
+
109
+ [offs[i], lens[i]]
110
+ end
111
+
112
+ # The record's scalar value materialized: nil / true / false,
113
+ # Integer, Float, decoded String. Structure records (:doc,
114
+ # opens, :close) answer nil. NUM records that fail the convert
115
+ # pass and int64-overflowing INT spans raise {Error}.
116
+ def value(i)
117
+ ensure_alive!
118
+ case kinds[i]
119
+ when :null then nil
120
+ when :true then true
121
+ when :false then false
122
+ when :int, :float, :num then number(i)
123
+ when :str then ::Yeptris::JSON.decode_span(@source, offs[i], lens[i])
124
+ else nil # :doc and the container structure
125
+ end
126
+ end
127
+
128
+ # The container link: SEQ_OPEN/MAP_OPEN answer the index of the
129
+ # matching CLOSE; CLOSE answers its matching OPEN. nil elsewhere.
130
+ def match(i)
131
+ ensure_alive!
132
+ k = kinds[i]
133
+ return nil unless %i[seq_open map_open close].include?(k)
134
+
135
+ offs[i]
136
+ end
137
+
138
+ def free
139
+ return if @freed.flag
140
+
141
+ @freed.flag = true
142
+ ObjectSpace.undefine_finalizer(self)
143
+ ::Yeptris::FFI.yeptris_tape_free(@tape.to_ptr)
144
+ nil
145
+ end
146
+
147
+ def freed?
148
+ @freed.flag
149
+ end
150
+
151
+ # Applies a compiled {Yeptris::Plan} to this tape in one C pass
152
+ # (the tape leg of the plan walk): typed columns, no per-record
153
+ # host dispatch.
154
+ def plan_walk(plan)
155
+ ::Yeptris::Plan.walk_tape(self, plan)
156
+ end
157
+
158
+ # @api private — the raw FFI struct (Plan's tape-leg reader)
159
+ attr_reader :c_ptr
160
+
161
+ # @api private — the retained source (Plan's tape-leg reader
162
+ # decodes string columns from it)
163
+ attr_reader :source
164
+
165
+ private
166
+
167
+ def ensure_alive!
168
+ return unless @freed.flag
169
+
170
+ raise Error, "the tape was freed"
171
+ end
172
+
173
+ def offs
174
+ @offs ||= @tape[:offs].read_bytes(@tape[:count] * 4).unpack("V*")
175
+ end
176
+
177
+ def lens
178
+ @lens ||= @tape[:lens].read_bytes(@tape[:count] * 4).unpack("V*")
179
+ end
180
+
181
+ # One bulk convert pass over the number spans (the engine's
182
+ # materialize step — v2: parse records spans only). The strict
183
+ # route's spans are grammar-validated at parse, so the bulk
184
+ # call cannot fail; the lenient NUM records convert per record
185
+ # with the deferred verdict.
186
+ def bulk_convert!
187
+ return if @ivals
188
+
189
+ n = count
190
+ ivp = ::FFI::MemoryPointer.new(:int64, n, true)
191
+ dvp = ::FFI::MemoryPointer.new(:double, n, true)
192
+ rc = ::Yeptris::FFI.yeptris_tape_convert(@tape.to_ptr, 0, n, ivp, dvp)
193
+ # convert answers the NUMBER records converted (not the token
194
+ # count) — SIZE_MAX would mean a span that does not re-scan
195
+ expected = kinds.count { |k| k == :int || k == :float || k == :num }
196
+ raise Error, "yeptris: strict tape convert failed (#{rc})" if rc != expected
197
+
198
+ @ivals = ivp.read_bytes(n * 8).unpack("q<*")
199
+ @dvals = dvp.read_bytes(n * 8).unpack("E*")
200
+ # any integer text beyond int64: exact Bignum rebuilds from
201
+ # the spans (the JSON.load parity contract, int_min is the
202
+ # engine's materialize-time discovery)
203
+ @exact_ints = @tape[:int_min] != 0
204
+ end
205
+
206
+ def number(i)
207
+ case kinds[i]
208
+ when :int
209
+ bulk_convert!
210
+ @exact_ints ? Integer(@source.byteslice(offs[i], lens[i]), 10) : @ivals[i]
211
+ when :float
212
+ bulk_convert!
213
+ @dvals[i]
214
+ else # :num — the lenient route's deferred classification
215
+ convert_record!(i)
216
+ end
217
+ end
218
+
219
+ # Per-record convert for a deferred NUM span: the engine scans,
220
+ # validates, and classifies (shape 0 = integer, else float).
221
+ def convert_record!(i)
222
+ ivals = ::FFI::MemoryPointer.new(:int64)
223
+ dvals = ::FFI::MemoryPointer.new(:double)
224
+ converted = ::Yeptris::FFI.yeptris_tape_convert(
225
+ @tape.to_ptr, i, i + 1, ivals, dvals
226
+ )
227
+ if converted != 1
228
+ raise Error,
229
+ "the number span at record #{i} " \
230
+ "(#{@source.byteslice(offs[i], lens[i]).inspect}) is not a " \
231
+ "valid number — the lenient route's deferred verdict"
232
+ end
233
+
234
+ text = @source.byteslice(offs[i], lens[i])
235
+ if text.include?(".") || text.include?("e") || text.include?("E")
236
+ dvals.read_double
237
+ else
238
+ ivals.read_int64
239
+ end
240
+ end
241
+ end
242
+ end
243
+ end
data/lib/yeptris/json.rb CHANGED
@@ -23,6 +23,7 @@ module Yeptris
23
23
  class ParseError < Error; end
24
24
 
25
25
  autoload :Descriptor, "yeptris/json/descriptor"
26
+ autoload :Tape, "yeptris/json/tape"
26
27
 
27
28
  # json gem 3.0 made duplicate keys an error by DEFAULT; 2.x is
28
29
  # last-wins. The parity target is the RESOLVED json gem's own
Binary file
Binary file
Binary file
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yeptris
4
+ # The native layout SSOT (the org native-layer contract,
5
+ # leptris-ruby#671): the vendor-tree dir spellings and the per-minor
6
+ # DOT-FREE bundle naming, in ONE ffi-free file so the loader, the
7
+ # packaging script, and the CI gates consume the same mapping —
8
+ # never a second list (the two-images law extended to layout).
9
+ module NativeLayout
10
+ module_function
11
+
12
+ # Dir-name candidates for a RUBY_PLATFORM string, in preference
13
+ # order (glibc before musl — dlopen falls through on musl hosts).
14
+ # These name the cells under lib/yeptris/vendor/<platform>/.
15
+ def vendor_platforms_for(ruby_platform)
16
+ # JVM engines report "x86_64-java" or bare "java" — the OS
17
+ # (and sometimes the arch) is lost. Rebuild cpu-os from
18
+ # RbConfig so the native vendor binaries resolve there too.
19
+ if ruby_platform =~ /java/
20
+ host_os = RbConfig::CONFIG["host_os"].to_s
21
+ if host_os =~ /mingw|mswin|windows/
22
+ return [] # no windows vendor tree; the .dll is gem-local
23
+ end
24
+ cpu = RbConfig::CONFIG["host_cpu"].to_s
25
+ cpu = "aarch64" if cpu.empty?
26
+ # RbConfig says "powerpc64le"; the gem/vendor tier is
27
+ # "ppc64le-linux" (the gem platform spelling).
28
+ cpu = "ppc64le" if cpu == "powerpc64le"
29
+ os = host_os =~ /darwin/ ? "darwin" : "linux"
30
+ ruby_platform = "#{cpu}-#{os}"
31
+ end
32
+ case ruby_platform
33
+ when /arm64.*darwin|aarch64.*darwin/ then %w[arm64-darwin]
34
+ when /x86_64.*darwin/ then %w[x86_64-darwin]
35
+ when /aarch64.*linux/ then %w[aarch64-linux aarch64-linux-musl]
36
+ when /x86_64.*linux/ then %w[x86_64-linux x86_64-linux-musl]
37
+ # 32-bit ARM (armv[567l]: "arm-linux", "armv7l-linux",
38
+ # "armeb-linux", ...). Never matches aarch64 ("aarch" has
39
+ # no "arm" substring).
40
+ when /arm.*linux/ then %w[arm-linux arm-linux-musl]
41
+ # POWER8+ little-endian and IBM Z (qemu-built platform gems).
42
+ # A real CRuby reports powerpc64le (RbConfig host_cpu), the gem
43
+ # vendor tier is the platform spelling ppc64le-linux — both
44
+ # spellings must resolve or the gem stages no vendor tree (the
45
+ # run 45407198542 ppc64le leg's "RUBY_PLATFORM: unbound
46
+ # variable" — the [] lookup fell into the diagnostic, which set
47
+ # -u then killed on the unset shell var)
48
+ when /ppc64le.*linux/ then %w[ppc64le-linux]
49
+ when /powerpc64le.*linux/ then %w[ppc64le-linux]
50
+ when /s390x.*linux/ then %w[s390x-linux s390x-linux-musl]
51
+ # the trixie distro-ruby leg (no musl ruby image ships the port)
52
+ when /riscv64.*linux/ then %w[riscv64-linux]
53
+ else []
54
+ end
55
+ end
56
+
57
+ # The per-minor DOT-FREE bundle feature name (contract clause 2):
58
+ # yeptris/native_<major>_<minor> — MRI derives the init symbol
59
+ # from the feature basename cut at the first dot, so the file name
60
+ # carries no dot (native_3_4.so resolves Init_native_3_4; the old
61
+ # native-<minor>.so name asked for the untypeable "Init_native-3",
62
+ # #157).
63
+ def bundle_feature(version = RUBY_VERSION)
64
+ minor = version[/\A\d+\.\d+/].tr(".", "_")
65
+ "yeptris/native_#{minor}"
66
+ end
67
+ end
68
+ end