yeptris 0.6.5.4 → 0.6.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec5a8bfeb0851d4287965e0f7c162cf13b71c90bdbb1f423a2bb0a8f508d22e4
4
- data.tar.gz: d757361d8e14a3f94f34419e71334c4c139dc60aaab7aaf638c9dd88239811c5
3
+ metadata.gz: 8192f177ce03a9524f7ec6bd078d1a5854bbcf533b53ed8c8d2d7982d07c1761
4
+ data.tar.gz: 470e8b180e8f1f632c2e616dc9e6b1762ec99b93fc642aa25a988ea3d1214722
5
5
  SHA512:
6
- metadata.gz: 75c1451044793867918c6d9972ba7c452d79684c00e7b92a59a30f392bb741fe6c04b6e6571c3c7e6b956c14e7511bd48ba81ab79e552f54675d6726c2dd24d7
7
- data.tar.gz: debf5f3377d19dfba238bb412145e7335480dbde4f5c3cff8b8d51aea7426f26038a8913caf1902a92e633684377c52994f10a342e39d2a67a68a5739468ba45
6
+ metadata.gz: acac433987243971017823d89f3ab5edefd89b3b3770d9a85555c71c0296ed50d144c543a7cc2fbbdb2c432b0c5482209db680e1dc8a89ba5e9b4b6a5dc97c9d
7
+ data.tar.gz: 5dbed07e836272d52b90c1e398ba0bdbb6e82b324498a66e053dd267a0cdba68c6f59f888eaab220270a2e1f05f2c298022899b9716030280396a88218cc6454
data/lib/yeptris/ffi.rb CHANGED
@@ -28,17 +28,6 @@ module Yeptris
28
28
  MSG
29
29
  end
30
30
 
31
- # :c_free (:free, line ~240) must resolve against the C runtime.
32
- # Linux/macOS fall through to the process symbol table, but
33
- # Windows has no such fallback — without LIBC attached the
34
- # ffi.rb load DIED at that attach (leaving every later constant
35
- # undefined: the mingw gem's missing NODE_* / #318).
36
- begin
37
- ffi_lib FFI::Library::LIBC
38
- rescue StandardError
39
- # no LIBC handle: the c_free attach below surfaces the failure
40
- # exactly where it used to, on non-Windows platforms only
41
- end
42
31
 
43
32
  typedef :pointer, :yeptris_document
44
33
  typedef :pointer, :yeptris_node
@@ -242,9 +231,17 @@ module Yeptris
242
231
  end
243
232
 
244
233
  # Owned char* results (serialize*): one reader, freed exactly once.
245
- # The buffers are plain malloc'd C memory (the header contract says
246
- # "caller frees"), so the release is libc free.
247
- attach_function :c_free, :free, [:pointer], :void
234
+ # The release goes through yeptris_free (libyeptris's own
235
+ # allocator-matching free) because ffi's :free attach has no
236
+ # Windows process-symbol fallback — libyeptris.dll doesn't export
237
+ # libc free, so resolving :free against it fails on Windows.
238
+ begin
239
+ attach_function :yeptris_free, [:pointer], :void
240
+ rescue ::FFI::NotFoundError
241
+ # libyeptris < v0.6.6: POSIX resolves :free through the process
242
+ # symbol table, so the direct libc attach still works there.
243
+ attach_function :yeptris_free, :free, [:pointer], :void
244
+ end
248
245
 
249
246
  module Owned
250
247
  module_function
@@ -261,7 +258,7 @@ module Yeptris
261
258
  else
262
259
  ptr.read_string.force_encoding(Encoding::UTF_8)
263
260
  end
264
- ::Yeptris::FFI.c_free(ptr)
261
+ ::Yeptris::FFI.yeptris_free(ptr)
265
262
  s
266
263
  end
267
264
  end
data/lib/yeptris/json.rb CHANGED
@@ -71,7 +71,7 @@ module Yeptris
71
71
  return s unless s.include?("\\")
72
72
 
73
73
  b = s.b
74
- out = +"".b
74
+ out = String.new(encoding: Encoding::BINARY)
75
75
  i = 0
76
76
  n = b.bytesize
77
77
  while i < n
@@ -154,7 +154,10 @@ module Yeptris
154
154
  stack.pop
155
155
  key_sets&.pop
156
156
  when T_STR
157
- text = lens[i] == 0 ? +"".force_encoding(Encoding::UTF_8) : decode_span(src, offs[i], lens[i])
157
+ # empty-string literals are frozen+shared since Ruby 3.4
158
+ # (and `+""` binds after the method chain anyway), so the
159
+ # fresh copy must come from the encoding call itself
160
+ text = lens[i] == 0 ? String.new(encoding: Encoding::UTF_8) : decode_span(src, offs[i], lens[i])
158
161
  if pending_key.nil? && !stack.empty? && stack.last.is_a?(Hash)
159
162
  if key_sets && key_sets.last.key?(text)
160
163
  raise ParseError, %(duplicate key "#{text}" in JSON object)
data/lib/yeptris/psych.rb CHANGED
@@ -4,6 +4,11 @@ require "date"
4
4
  require "time"
5
5
  require "set"
6
6
 
7
+ # Self-sufficient (the #95 yaml.rb fix, same class): the standalone
8
+ # require "yeptris/psych" must register the Document/FFI machinery —
9
+ # consumers load this face directly under the drop-in.
10
+ require "yeptris"
11
+
7
12
  # The Psych drop-in namespace (TODO.impl/15 phase C).
8
13
  #
9
14
  # `require "yeptris/psych"` loads this namespace WITHOUT touching the
@@ -130,7 +135,7 @@ module Yeptris
130
135
  # Psych 5: load is safe — plain data structures only. Tagged
131
136
  # nodes raise DisallowedClass unless their class is permitted
132
137
  # (Date/Time/Symbol are built in; they are plain data here).
133
- def load(yaml, permitted_classes: [], aliases: false, **)
138
+ def load(yaml, permitted_classes: [::Date, ::Time], aliases: false, **)
134
139
  safe_load(yaml, permitted_classes: permitted_classes, aliases: aliases)
135
140
  end
136
141
 
@@ -144,10 +149,78 @@ module Yeptris
144
149
  Visitors::ToRuby.visit(tree.children.first)
145
150
  end
146
151
 
147
- def safe_load(yaml, permitted_classes: [], aliases: false, **)
152
+ def safe_load(yaml, permitted_classes: [::Date, ::Time], aliases: false, **)
153
+ doc = Yeptris::Document.parse(yaml, schema: :compat_11)
154
+ begin
155
+ force_utf8_scalars(walk_safe(doc.root(0), permitted_classes, aliases))
156
+ ensure
157
+ doc.free
158
+ end
159
+ end
160
+
161
+ # A YAML stream is a Unicode character stream: stdlib psych tags
162
+ # non-ASCII scalars UTF-8 even when the input String is BINARY
163
+ # (#135). ASCII-only values keep their (binary) encoding — a
164
+ # re-tag would be observable there and stdlib does not either.
165
+ def force_utf8_scalars(obj)
166
+ case obj
167
+ when ::String
168
+ obj.force_encoding(::Encoding::UTF_8) if obj.encoding == ::Encoding::ASCII_8BIT && !obj.ascii_only?
169
+ obj
170
+ when ::Hash
171
+ obj.each { |k, v| force_utf8_scalars(k); force_utf8_scalars(v) }
172
+ when ::Array
173
+ obj.each { |v| force_utf8_scalars(v) }
174
+ else
175
+ obj
176
+ end
177
+ end
178
+
179
+ # stdlib's file-level faces (#135): BOM-tolerant UTF-8 reads with
180
+ # the fallback contract (load_file path, fallback: false default).
181
+ def load_file(path, fallback: false, **kwargs)
182
+ File.open(path, "r:bom|utf-8") { |f| load(f, **kwargs) }
183
+ rescue Errno::ENOENT
184
+ raise unless fallback
185
+
186
+ false
187
+ end
188
+
189
+ def safe_load_file(path, fallback: false, **kwargs)
190
+ File.open(path, "r:bom|utf-8") { |f| safe_load(f, **kwargs) }
191
+ rescue Errno::ENOENT
192
+ raise unless fallback
193
+
194
+ false
195
+ end
196
+
197
+ def unsafe_load_file(path, fallback: false, **kwargs)
198
+ File.open(path, "r:bom|utf-8") { |f| unsafe_load(f, **kwargs) }
199
+ rescue Errno::ENOENT
200
+ raise unless fallback
201
+
202
+ false
203
+ end
204
+
205
+ def parse_file(path, **kwargs)
206
+ File.open(path, "r:bom|utf-8") { |f| parse(f, **kwargs) }
207
+ end
208
+
209
+
210
+
211
+ # stdlib's deprecated safe/dump split — same output here (every
212
+ # value this loader produces is safe data)
213
+ def safe_dump(obj, io = nil, options = {})
214
+ ::Yeptris::Psych.dump(obj, io, options)
215
+ end
216
+
217
+ def load_stream(yaml, **kwargs)
218
+ # materialize each document's root directly — the stream
219
+ # children share one C document, so their handles would all
220
+ # resolve to the first document's tree
148
221
  doc = Yeptris::Document.parse(yaml, schema: :compat_11)
149
222
  begin
150
- walk_safe(doc.root(0), permitted_classes, aliases)
223
+ (0...doc.document_count).map { |i| doc.root(i).to_ruby }
151
224
  ensure
152
225
  doc.free
153
226
  end
data/lib/yeptris.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Yeptris
4
4
  # The gem's version lives in the parent namespace's file — the last
5
5
  # internal require (yeptris/version) retired with it.
6
- VERSION = "0.6.5.4".freeze
6
+ VERSION = "0.6.7.1".freeze
7
7
  # The error hierarchy lives in THIS file (the parent namespace's
8
8
  # own file): nested constants do not trigger a parent-constant
9
9
  # autoload, and the law forbids internal requires — defining the
@@ -44,14 +44,15 @@ module Yeptris
44
44
  autoload :ValueML, "yeptris/valueml"
45
45
  autoload :Psych, "yeptris/psych"
46
46
  autoload :Schema, "yeptris/schema"
47
-
48
- # The safe_load error names, aliased at the top level so consumers
49
- # writing rescues need no nesting knowledge (issue #73's naming
50
- # note): Yeptris::DisallowedClass is Yeptris::Psych::DisallowedClass.
51
- DisallowedClass = Psych::DisallowedClass
52
- AliasesError = Psych::AliasesError
53
47
  end
54
48
 
49
+ # NOTE (the #318 poisoned-process class): the Psych error-name aliases
50
+ # live BELOW the ffi require — reading Psych here would trigger the
51
+ # psych autoload BEFORE the native library resolves, and a mid-load
52
+ # ffi failure under a drop-in rebind left ::Psych rebound against a
53
+ # half-initialized FFI module (every to_yaml in the process died).
54
+ # With this order an ffi failure is a clean, loud require failure.
55
+
55
56
  # Eager native-library resolution (leptris-ruby lesson): fail at
56
57
  # require time, not at first parse. The ffi require MUST come after
57
58
  # the autoload registrations — ffi.rb opens module Yeptris, and
@@ -67,6 +68,25 @@ rescue LoadError => e
67
68
  MSG
68
69
  end
69
70
 
71
+
72
+ # The safe_load error names, aliased at the top level so consumers
73
+ # writing rescues need no nesting knowledge (issue #73's naming
74
+ # note): Yeptris::DisallowedClass is Yeptris::Psych::DisallowedClass.
75
+ # LAZY (const_missing): a standalone require "yeptris/psych" loads
76
+ # yeptris.rb MID-psych — an eager alias here would re-enter the
77
+ # half-loaded psych.rb through the autoload and NameError. At first
78
+ # touch psych is complete in every load order.
79
+ module Yeptris
80
+ def self.const_missing(name)
81
+ case name
82
+ when :DisallowedClass, :AliasesError
83
+ const_set(name, Psych.const_get(name))
84
+ else
85
+ super
86
+ end
87
+ end
88
+ end
89
+
70
90
  # Optional C-API materializer (TODO.restructure/22): fused visit →
71
91
  # Ruby objects via the Ruby C API. Feature-detected — LoadError leaves
72
92
  # the FFI ladder (Marshal → columns → records) as the sole path.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5.4
4
+ version: 0.6.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.