moxml 0.6.6 → 0.6.8

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: 0ce816a587b7b04d7e380e081043eaa7c7f950ab1663dd4cad60203da4ce104b
4
- data.tar.gz: 83f30fb1c549b17a7b9a3930da3867c535bd37c344cca4df2e879eaa51befae1
3
+ metadata.gz: 8536f48b75689cbcc22414adaeac301263c491a66418cf5bc8ea71435b53d9ed
4
+ data.tar.gz: f24cc023a8712e3128923860cc647af54fb57e8d70f3c8e426a1b2c291553422
5
5
  SHA512:
6
- metadata.gz: b14b18373ed2190b8088c0baa461170b85026c4b23397a82d36c118467ab58cbaeda1ad4dba317bab04463474c1dccf5d3193660bd3756ab58135152694c022d
7
- data.tar.gz: 21411b8ca1fb7d8a609f4987ae5bf208d9f12c07c335bcd8741869bcf1e1826a364e2d7fd0e6c8126a194e2cdbd0beb2447c8a39e88dd6b146af91b087ed9fbe
6
+ metadata.gz: b0226b4d3d7f9ddea1cc8bd69034b8c243950240c0859d30507920dc1d0f35e27c7fc5ffe5ca11197f8f07e713362c91058376ca7c4991e06e5ee4ddcf3890ae
7
+ data.tar.gz: 5da68f6cdae48d0b8c9289780473a6c83d13e140266b9891f92654ec38b53538515b05e6d7198513deabb14ca420a9ca7992ff5ffb734d3b73124921ad93bb34
@@ -1097,8 +1097,31 @@ module Moxml
1097
1097
  # IS the wrapper. Prime in place with a self-marker
1098
1098
  # (never a shell, never the WeakMap round trip).
1099
1099
  if NATIVE_C_MINT && node.is_a?(::Moxml::Node)
1100
+ # #340 admits ANY NativeNode subclass as a registered
1101
+ # wrapper klass, and consumers register their own
1102
+ # (define_hot_readers subclasses, leptris-ruby#629) —
1103
+ # the exact-class hash answers only the Identity
1104
+ # originals, so a subclass minted nil here and every
1105
+ # walk-yielded node dropped from results (XPath
1106
+ # answered zero rows with subclasses registered).
1107
+ # Resolve the kind subclass-aware; the hash still
1108
+ # serves the exact originals without the ladder.
1100
1109
  type = IDENTITY_WALK_TYPE[node.class]
1101
- return nil unless type
1110
+ unless type
1111
+ type = case node
1112
+ when Identity::ELEMENT
1113
+ :element
1114
+ when Identity::TEXT
1115
+ :text
1116
+ when Identity::CDATA
1117
+ :cdata
1118
+ when Identity::COMMENT
1119
+ :comment
1120
+ when Identity::PROCESSING_INSTRUCTION
1121
+ :processing_instruction
1122
+ end
1123
+ return nil unless type
1124
+ end
1102
1125
 
1103
1126
  node.prime_contract(node, context, self, type)
1104
1127
  node.instance_variable_set(:@moxml_wrapper, node)
@@ -3207,6 +3230,21 @@ module Moxml
3207
3230
  SET_ATTRIBUTE_NATIVE =
3208
3231
  NATIVE_READ_LAYER && NN.method_defined?(:set_attribute)
3209
3232
 
3233
+ # TODO.perf/41 (leptris-ruby#622 ask 3): the module-level C
3234
+ # entry Native.set_binding_attribute(document, addr, name,
3235
+ # value) — free/readonly gates + binding-version bump + engine
3236
+ # set in one crossing. It serves the (document, address) pairs
3237
+ # the TypedData instance face cannot reach: AddressNode tokens
3238
+ # on the address-native lane and native nodes on exts without
3239
+ # the instance method. Semantically the bridge's twin: the
3240
+ # version bump IS the binding-memo invalidation (both
3241
+ # surfaces' memos drop on mutation), and callers invalidate
3242
+ # the wrapper caches exactly as before.
3243
+ SET_BINDING_ATTRIBUTE =
3244
+ NATIVE_READ_LAYER &&
3245
+ defined?(::Leptris::XML::Native) &&
3246
+ ::Leptris::XML::Native.respond_to?(:set_binding_attribute)
3247
+
3210
3248
  def set_attribute(element, name, value)
3211
3249
  # Native write face (leptris-ruby#204's nn_set_attribute):
3212
3250
  # gates + version bump + engine set in one C frame on the
@@ -3218,6 +3256,18 @@ module Moxml
3218
3256
  return element.set_attribute(name.to_s, value.to_s)
3219
3257
  end
3220
3258
 
3259
+ # TODO.perf/41: the module-level entry for the addressed
3260
+ # lane — one crossing instead of to_binding's Pointer wrap
3261
+ # + registry mint + memo'd hash write.
3262
+ if SET_BINDING_ATTRIBUTE
3263
+ doc, addr = attr_packet_target(element)
3264
+ if doc
3265
+ return ::Leptris::XML::Native.set_binding_attribute(
3266
+ doc, addr, name.to_s, value.to_s
3267
+ )
3268
+ end
3269
+ end
3270
+
3221
3271
  element = to_binding(element) if NATIVE_READ_LAYER
3222
3272
  element[name.to_s] = value.to_s
3223
3273
  end
@@ -4146,10 +4196,11 @@ module Moxml
4146
4196
  # AST walk is per-expression, so the verdict caches too.
4147
4197
  PARENT_AXIS_CACHE = XPath::Cache.new(100)
4148
4198
 
4149
- def xpath(node, expression, namespaces = {})
4199
+ def xpath(node, expression, namespaces = {}, context: nil)
4150
4200
  namespaces = normalize_xpath_namespaces(namespaces)
4151
4201
  node = to_binding(node) if NATIVE_READ_LAYER
4152
- native = native_xpath(node, expression, namespaces)
4202
+ native = native_xpath(node, expression, namespaces,
4203
+ context: context)
4153
4204
  return native unless native.nil?
4154
4205
 
4155
4206
  engine_xpath(node, expression, namespaces)
@@ -4178,9 +4229,10 @@ module Moxml
4178
4229
  hit.is_a?(::Moxml::Node) ? hit : node
4179
4230
  end
4180
4231
 
4181
- def at_xpath(node, expression, namespaces = {})
4232
+ def at_xpath(node, expression, namespaces = {}, context: nil)
4182
4233
  namespaces = normalize_xpath_namespaces(namespaces)
4183
- native = native_xpath(node, expression, namespaces, first_only: true)
4234
+ native = native_xpath(node, expression, namespaces,
4235
+ first_only: true, context: context)
4184
4236
  return native unless native.nil?
4185
4237
 
4186
4238
  result = engine_xpath(node, expression, namespaces)
@@ -4199,7 +4251,8 @@ module Moxml
4199
4251
 
4200
4252
  # @return [Array, Object, nil] native results, or nil when the
4201
4253
  # query must run on the Ruby engine
4202
- def native_xpath(node, expression, namespaces, first_only: false)
4254
+ def native_xpath(node, expression, namespaces, first_only: false,
4255
+ context: nil)
4203
4256
  # Canonical natives (the #219 unification) are bare TypedData
4204
4257
  # wrappers — no Searchable methods, no document handle for
4205
4258
  # the gates below. The memoized bridge recovers the binding
@@ -4321,7 +4374,8 @@ module Moxml
4321
4374
  # The one-crossing mint is deferred: a caller that only
4322
4375
  # asks #size never pays for the rows (#527). The holder
4323
4376
  # runs Document#xpath_result_rows_bulk on first read.
4324
- return Moxml::LazyBulkRows.new(document, result_ptr)
4377
+ return Moxml::LazyBulkRows.new(document, result_ptr,
4378
+ context, self)
4325
4379
  end
4326
4380
 
4327
4381
  # The binding's #to_a mints one Ruby wrapper per result
@@ -1086,7 +1086,10 @@ module Moxml
1086
1086
  end
1087
1087
  end
1088
1088
 
1089
- def xpath(node, expression, namespaces = nil)
1089
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
1090
+ # priming triple; engines without a bulk mint ignore it
1091
+ def xpath(node, expression, namespaces = nil, context: nil)
1092
+ # rubocop:enable Lint/UnusedMethodArgument
1090
1093
  native_node = unpatch_node(node)
1091
1094
  return [] unless native_node
1092
1095
 
@@ -647,7 +647,10 @@ module Moxml
647
647
  native.system_id
648
648
  end
649
649
 
650
- def xpath(node, expression, namespaces = nil)
650
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
651
+ # priming triple; engines without a bulk mint ignore it
652
+ def xpath(node, expression, namespaces = nil, context: nil)
653
+ # rubocop:enable Lint/UnusedMethodArgument
651
654
  if empty_default_namespace_binding?(namespaces)
652
655
  return Moxml::XPath.evaluate_natives(node, expression,
653
656
  namespaces,
@@ -587,7 +587,10 @@ module Moxml
587
587
  end
588
588
  end
589
589
 
590
- def xpath(node, expression, namespaces = nil)
590
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
591
+ # priming triple; engines without a bulk mint ignore it
592
+ def xpath(node, expression, namespaces = nil, context: nil)
593
+ # rubocop:enable Lint/UnusedMethodArgument
591
594
  # oga's engine has no xmlns: default-namespace idiom
592
595
  # (D-01); the reference engine implements it (model,
593
596
  # Names and namespaces).
@@ -715,7 +715,10 @@ module Moxml
715
715
  # with HeadedOx and Leptris). Ox's locate() only covers a
716
716
  # small XPath subset; the engine provides all axes,
717
717
  # predicates, functions and variables.
718
- def xpath(node, expression, namespaces = {})
718
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
719
+ # priming triple; engines without a bulk mint ignore it
720
+ def xpath(node, expression, namespaces = {}, context: nil)
721
+ # rubocop:enable Lint/UnusedMethodArgument
719
722
  wrapped = if node.is_a?(Moxml::Node)
720
723
  node
721
724
  else
@@ -640,7 +640,10 @@ module Moxml
640
640
  ns
641
641
  end
642
642
 
643
- def xpath(node, expression, namespaces = {})
643
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
644
+ # priming triple; engines without a bulk mint ignore it
645
+ def xpath(node, expression, namespaces = {}, context: nil)
646
+ # rubocop:enable Lint/UnusedMethodArgument
644
647
  # REXML's engine answers no text nodes for text() node
645
648
  # tests (D-07, both axes); the reference engine does
646
649
  # (model, XPath evaluation).
@@ -296,7 +296,8 @@ module Moxml
296
296
  def xpath(expression, namespaces = nil)
297
297
  expression = lax_document_path(expression) if relative_name_test?(expression)
298
298
 
299
- result = adapter.xpath(@native, expression, namespaces)
299
+ result = adapter.xpath(@native, expression, namespaces,
300
+ context: context)
300
301
 
301
302
  # Handle different result types:
302
303
  # - Scalar values (from functions): return directly
@@ -16,9 +16,17 @@ module Moxml
16
16
  class LazyBulkRows
17
17
  include LazyNodeSet
18
18
 
19
- def initialize(document, result_ptr)
19
+ # (context, adapter): the consumer contract triple for the primed
20
+ # mint (TODO.perf/40, leptris-ruby#622 ask 2) — the bulk face
21
+ # writes @mx_context/@mx_adapter in C and extends all-native
22
+ # results with BulkIdentityRows, so NodeSet's per-row wrap prime
23
+ # disappears from the iterate-every-result lane. nil (older
24
+ # bindings) keeps the unprimed mint.
25
+ def initialize(document, result_ptr, context = nil, adapter = nil)
20
26
  @document = document
21
27
  @ptr = result_ptr
28
+ @context = context
29
+ @adapter = adapter
22
30
  @rows = nil
23
31
  ObjectSpace.define_finalizer(
24
32
  self, self.class.finalizer(result_ptr.address)
@@ -62,7 +70,7 @@ module Moxml
62
70
  return @rows if @rows
63
71
 
64
72
  ObjectSpace.undefine_finalizer(self)
65
- @rows = @document.xpath_result_rows_bulk(@ptr)
73
+ @rows = @document.xpath_result_rows_bulk(@ptr, @context, @adapter)
66
74
  @ptr = nil
67
75
  @rows
68
76
  end
data/lib/moxml/node.rb CHANGED
@@ -415,7 +415,8 @@ module Moxml
415
415
  end
416
416
 
417
417
  def xpath(expression, namespaces = {})
418
- result = adapter.xpath(@native, expression, namespaces)
418
+ result = adapter.xpath(@native, expression, namespaces,
419
+ context: context)
419
420
  # Adapter contract: Array<native> | LazyNodeSet | scalar.
420
421
  # Scalars (count(), string-length(), booleans) pass through
421
422
  # unwrapped; the set forms wrap lazily.
@@ -476,7 +477,8 @@ module Moxml
476
477
  def css(expression)
477
478
  NodeSet.new(
478
479
  adapter.xpath(@native, Css.to_xpath(expression,
479
- absolute: document?)),
480
+ absolute: document?),
481
+ context: context),
480
482
  context,
481
483
  )
482
484
  end
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.6.6"
4
+ VERSION = "0.6.8"
5
5
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # leptris-ruby#629 — registering SUBCLASSES as wrapper klasses made
6
+ # XPath answer zero rows: wrap_binding_node resolved the node kind
7
+ # through the exact-class hash (IDENTITY_WALK_TYPE), so a subclass
8
+ # minted nil there and every walk-yielded node dropped from results.
9
+ # #340's register_wrapper_klasses admits ANY NativeNode subclass and
10
+ # consumers register their own (define_hot_readers subclasses,
11
+ # leptris-ruby#627) — the resolution must be subclass-aware.
12
+ RSpec.describe "leptris registered-subclass wraps" do
13
+ let(:ctx) { Moxml.new(:leptris) }
14
+
15
+ before do
16
+ unless
17
+ defined?(Leptris::XML::Native.define_hot_readers) &&
18
+ ctx.parse("<r/>").native
19
+ .instance_variable_get(:@doc_klass_map)
20
+ skip "binding lacks the C-mint registered-klass face"
21
+ end
22
+ end
23
+
24
+ def parse_with_map(map)
25
+ ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
26
+ .tap do |doc|
27
+ doc.native.instance_variable_set(:@doc_klass_map, map) if map
28
+ end
29
+ end
30
+
31
+ it "matches with the exact classes the adapter registered" do
32
+ doc = parse_with_map(nil) # the adapter registers at parse
33
+ expect(doc.at_xpath("//xmlns:leaf", "xmlns" => "")&.name).to eq("leaf")
34
+ end
35
+
36
+ it "matches with a plain Class.new of the registered element klass" do
37
+ doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
38
+ orig = doc.native.instance_variable_get(:@doc_klass_map)
39
+ map = [Class.new(orig[0]), orig[1], orig[2], orig[3], orig[4]]
40
+ doc.native.instance_variable_set(:@doc_klass_map, map)
41
+ expect(doc.at_xpath("//xmlns:leaf", "xmlns" => "")&.name).to eq("leaf")
42
+ end
43
+
44
+ it "matches with a define_hot_readers subclass registered" do
45
+ doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
46
+ orig = doc.native.instance_variable_get(:@doc_klass_map)
47
+ hot = Class.new(orig[0]) do
48
+ Leptris::XML::Native.define_hot_readers(self)
49
+ end
50
+ doc.native.instance_variable_set(:@doc_klass_map,
51
+ [hot, orig[1], orig[2], orig[3], orig[4]])
52
+ row = doc.at_xpath("//xmlns:leaf", "xmlns" => "")
53
+ expect(row&.name).to eq("leaf")
54
+ expect(row).to be_a(hot) # the consumer's klass mints on walks
55
+ end
56
+
57
+ it "matches with a subclass of every kind registered" do
58
+ doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
59
+ orig = doc.native.instance_variable_get(:@doc_klass_map)
60
+ map = orig.map { |k| k.is_a?(Class) ? Class.new(k) : k }
61
+ doc.native.instance_variable_set(:@doc_klass_map, map)
62
+ expect(doc.at_xpath("//xmlns:leaf", "xmlns" => "")&.name).to eq("leaf")
63
+ end
64
+
65
+ it "keeps the mint klass through the walk (contract rides the subclass)" do
66
+ doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
67
+ orig = doc.native.instance_variable_get(:@doc_klass_map)
68
+ map = orig.map { |k| k.is_a?(Class) ? Class.new(k) : k }
69
+ doc.native.instance_variable_set(:@doc_klass_map, map)
70
+ row = doc.at_xpath("//xmlns:leaf", "xmlns" => "")
71
+ expect(row.class).to eq(map[0])
72
+ expect(row).to be_a(Moxml::Node) # the contract still rides
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-12 00:00:00.000000000 Z
11
+ date: 2026-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Moxml is a unified XML manipulation library that provides a common API
@@ -498,6 +498,7 @@ files:
498
498
  - spec/moxml/adapter/leptris_parse_lint_spec.rb
499
499
  - spec/moxml/adapter/leptris_parse_skips_spec.rb
500
500
  - spec/moxml/adapter/leptris_record_driver_spec.rb
501
+ - spec/moxml/adapter/leptris_registered_subclass_spec.rb
501
502
  - spec/moxml/adapter/leptris_sax_dup_attr_spec.rb
502
503
  - spec/moxml/adapter/leptris_sax_records_spec.rb
503
504
  - spec/moxml/adapter/leptris_spec.rb