yeptris 0.6.17.1-powerpc64le-linux → 0.6.18.2-powerpc64le-linux

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: 36cb17a206c740954fafe1ce7b1fcbb6f94a47179e22beeee390498d20b1d07f
4
- data.tar.gz: 8db951649c7030a30d94fdbba0778fefef872d222ed479a83d459a1c0a36cfd9
3
+ metadata.gz: acff06db51e1b2f75561cdf73ea0e73555687c81fbcd347cc622ac0ec6b68fd5
4
+ data.tar.gz: dd5ebf0312542655c8f85c25426746310e1acfd362a88ce0facde164a7690928
5
5
  SHA512:
6
- metadata.gz: 19b0c83147c2c5f0882efb9bc32bedd6be9c7c8d80b50c86b985f36ddc6fe0d051b31c7a0795ee9340cf47dab64825072d0012d1dede882ad8497f24dbb45e85
7
- data.tar.gz: 3146be4e5e094c747fa2bb0335bba6bf35a7fdee4190428d6883341f8003f472a50505e63d60c6ba59428031e7204cb70f64a1e169d2dc1932abc0604c3bc06a
6
+ metadata.gz: 9cb10bafe45359a09efd903970613995b1665a6aa6137c1a5f8d1cd3b6d13cea142a01ac2061892e3d3ebcc1c003c17c9153aeddc54f196ced37f0ec3ef8eb46
7
+ data.tar.gz: 625deef05e540b5dfc35d73943324cf62f3fbf59a617d515dcf0499b8ef6950197c2907345dfa14083457a12299b954c93c64cc8f11f609856765c293fcd8b0e
data/lib/yeptris/cbor.rb CHANGED
@@ -121,7 +121,7 @@ module Yeptris
121
121
  def take_buffer(ptr, len_ptr)
122
122
  raise UnencodableError, ::Yeptris::FFI.last_error_message if ptr.null?
123
123
 
124
- len = len_ptr.read_uint64
124
+ len = Yeptris::FFI.read_c_size_t(len_ptr)
125
125
  ptr.read_bytes(len).force_encoding(Encoding::BINARY)
126
126
  ensure
127
127
  ::Yeptris::FFI.yeptris_free(ptr) if ptr && !ptr.null?
@@ -164,7 +164,7 @@ class Yeptris::Document
164
164
 
165
165
  def serialize(canonical: false, best_width: 0, explicit_doc_start: false)
166
166
  ensure_alive!
167
- len = ::FFI::MemoryPointer.new(:uint64)
167
+ len = ::FFI::MemoryPointer.new(:size_t)
168
168
  ptr =
169
169
  if canonical || best_width.positive? || explicit_doc_start
170
170
  opts = Yeptris::FFI::EmitOptions.new
@@ -180,13 +180,13 @@ class Yeptris::Document
180
180
  end
181
181
 
182
182
  def serialize_json_compact
183
- len = ::FFI::MemoryPointer.new(:uint64)
183
+ len = ::FFI::MemoryPointer.new(:size_t)
184
184
  Yeptris::FFI::Owned.string(Yeptris::FFI.yeptris_serialize_json_ex(@c_ptr, len, 1), len)
185
185
  end
186
186
 
187
187
  def serialize_json
188
188
  ensure_alive!
189
- len = ::FFI::MemoryPointer.new(:uint64)
189
+ len = ::FFI::MemoryPointer.new(:size_t)
190
190
  Yeptris::FFI::Owned.string(Yeptris::FFI.yeptris_serialize_json(@c_ptr, len), len)
191
191
  end
192
192
 
data/lib/yeptris/ffi.rb CHANGED
@@ -301,6 +301,17 @@ module Yeptris
301
301
  end
302
302
  end
303
303
 
304
+ # C out-params are size_t — native width (8 everywhere we ship
305
+ # except ILP32 armv7, where it is 4). The ffi gem (1.17.4) has no
306
+ # read_size_t, so dispatch on the measured type size: read_uint64
307
+ # on a 4-byte :size_t buffer ran out of bounds on arm-linux (the
308
+ # 0.6.18.1 armv7 smoke, valueml.rb:118).
309
+ SIZE_T_WIDTH = ::FFI.type_size(:size_t)
310
+
311
+ def self.read_c_size_t(ptr)
312
+ SIZE_T_WIDTH == 8 ? ptr.read_uint64 : ptr.read_uint32
313
+ end
314
+
304
315
  module Owned
305
316
  module_function
306
317
 
@@ -310,7 +321,7 @@ module Yeptris
310
321
  def string(ptr, len_out = nil)
311
322
  return nil if ptr.null?
312
323
 
313
- len = len_out&.read_uint64
324
+ len = len_out && Yeptris::FFI.read_c_size_t(len_out)
314
325
  s = if len && len > 0
315
326
  ptr.read_bytes(len).force_encoding(Encoding::UTF_8)
316
327
  else
@@ -78,10 +78,10 @@ module Yeptris
78
78
  end
79
79
  count_p = ::FFI::MemoryPointer.new(:size_t)
80
80
  records = Yeptris::FFI.yeptris_recorder_records(rec, count_p)
81
- count = count_p.read_uint64
81
+ count = Yeptris::FFI.read_c_size_t(count_p)
82
82
  arena_len = ::FFI::MemoryPointer.new(:size_t)
83
83
  arena_ptr = Yeptris::FFI.yeptris_recorder_arena(rec, arena_len)
84
- arena_len_v = arena_len.read_uint64
84
+ arena_len_v = Yeptris::FFI.read_c_size_t(arena_len)
85
85
  arena = arena_ptr.null? || arena_len_v.zero? ? +"" : arena_ptr.read_bytes(arena_len_v)
86
86
  flat = records.read_bytes(count * RECORD_SIZE)
87
87
  .unpack(RECORD_UNPACK * count)
data/lib/yeptris/node.rb CHANGED
@@ -50,11 +50,11 @@ class Yeptris::Node
50
50
 
51
51
  # Scalar content / alias name (UTF-8 String), nil for collections.
52
52
  def value
53
- len = ::FFI::MemoryPointer.new(:uint64)
53
+ len = ::FFI::MemoryPointer.new(:size_t)
54
54
  ptr = alive { Yeptris::FFI.yeptris_node_value(@c_ptr, len) }
55
55
  return nil if ptr.null?
56
56
 
57
- ptr.read_bytes(len.read_uint64).force_encoding(Encoding::UTF_8)
57
+ ptr.read_bytes(Yeptris::FFI.read_c_size_t(len)).force_encoding(Encoding::UTF_8)
58
58
  end
59
59
 
60
60
  STYLES = {
@@ -71,19 +71,19 @@ class Yeptris::Node
71
71
 
72
72
  # Explicit tag URI when present, else nil.
73
73
  def tag
74
- len = ::FFI::MemoryPointer.new(:uint64)
74
+ len = ::FFI::MemoryPointer.new(:size_t)
75
75
  ptr = alive { Yeptris::FFI.yeptris_node_tag(@c_ptr, len) }
76
76
  return nil if ptr.null?
77
77
 
78
- ptr.read_bytes(len.read_uint64).force_encoding(Encoding::UTF_8)
78
+ ptr.read_bytes(Yeptris::FFI.read_c_size_t(len)).force_encoding(Encoding::UTF_8)
79
79
  end
80
80
 
81
81
  def anchor
82
- len = ::FFI::MemoryPointer.new(:uint64)
82
+ len = ::FFI::MemoryPointer.new(:size_t)
83
83
  ptr = alive { Yeptris::FFI.yeptris_node_anchor(@c_ptr, len) }
84
84
  return nil if ptr.null?
85
85
 
86
- ptr.read_bytes(len.read_uint64).force_encoding(Encoding::UTF_8)
86
+ ptr.read_bytes(Yeptris::FFI.read_c_size_t(len)).force_encoding(Encoding::UTF_8)
87
87
  end
88
88
 
89
89
  def alias_target
@@ -293,7 +293,7 @@ class Yeptris::Node
293
293
  elsif st != Yeptris::FFI::OK
294
294
  raise Yeptris::ParseError, Yeptris::FFI.last_error_message
295
295
  else
296
- bytes = out_p.read_pointer.read_bytes(olen_p.read_uint64)
296
+ bytes = out_p.read_pointer.read_bytes(Yeptris::FFI.read_c_size_t(olen_p))
297
297
  bytes.force_encoding(Encoding::ASCII_8BIT)
298
298
  ::Marshal.load(bytes)
299
299
  end
@@ -38,9 +38,9 @@ module Yeptris
38
38
  yaml = Yeptris.read_input(yaml)
39
39
  yaml = yaml.to_s
40
40
  vals_p = ::FFI::MemoryPointer.new(:pointer)
41
- count_p = ::FFI::MemoryPointer.new(:uint64)
41
+ count_p = ::FFI::MemoryPointer.new(:size_t)
42
42
  arena_p = ::FFI::MemoryPointer.new(:pointer)
43
- alen_p = ::FFI::MemoryPointer.new(:uint64)
43
+ alen_p = ::FFI::MemoryPointer.new(:size_t)
44
44
  st = FFI.yeptris_value_drain(
45
45
  yaml, yaml.bytesize,
46
46
  schema == :compat_11 ? FFI::SCHEMA_11_COMPAT : FFI::SCHEMA_12_CORE,
@@ -51,9 +51,9 @@ module Yeptris
51
51
  vals = vals_p.read_pointer
52
52
  arena = arena_p.read_pointer
53
53
  begin
54
- count = count_p.read_uint64
54
+ count = Yeptris::FFI.read_c_size_t(count_p)
55
55
  flat = vals.read_bytes(count * VALUE_SIZE).unpack(UNPACK * count)
56
- arena_bytes = arena.read_bytes(alen_p.read_uint64)
56
+ arena_bytes = arena.read_bytes(Yeptris::FFI.read_c_size_t(alen_p))
57
57
  arena_bytes.force_encoding(Encoding::UTF_8)
58
58
  walk(flat, arena_bytes, schema == :compat_11)
59
59
  ensure
@@ -115,7 +115,7 @@ module Yeptris
115
115
  return nil if st == FFI::ERROR_UNSUPPORTED
116
116
  raise ParseError, FFI.last_error_message if st != FFI::OK
117
117
  buf = out_p.read_pointer
118
- len = olen_p.read_uint64
118
+ len = Yeptris::FFI.read_c_size_t(olen_p)
119
119
  bytes = buf.read_bytes(len)
120
120
  bytes.force_encoding(Encoding::ASCII_8BIT)
121
121
  ::Marshal.load(bytes)
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.17.1".freeze
6
+ VERSION = "0.6.18.2".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
data/libyeptris.so CHANGED
Binary file
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(yeptris
6
- VERSION 0.6.17
6
+ VERSION 0.6.18
7
7
  DESCRIPTION "Ultra-fast YAML 1.2 parser, emitter and streamer in C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -23,10 +23,13 @@
23
23
 
24
24
  #include "emit/float/api.h"
25
25
 
26
- #if defined(__SIZEOF_INT128__)
26
+ /* YEP_FLOAT_FORCE_LIMBS: test hook — exercises the portable lo/hi
27
+ * tier on hosts that also have __int128 (the limbs math is otherwise
28
+ * only compiled on 32-bit targets). */
29
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS) && !defined(YEP_FLOAT_FORCE_LIMBS)
27
30
  typedef unsigned __int128 yep_u128;
28
31
  #define YEP_MUL64(a, b) ((yep_u128)(uint64_t)(a) * (uint64_t)(b))
29
- #elif defined(_MSC_VER)
32
+ #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64))
30
33
  #include <intrin.h>
31
34
  /* MSVC has no __int128: the lo/hi pair behind the SAME helper surface
32
35
  * (print.c's interval loop rides only these — no operator arithmetic
@@ -35,10 +38,17 @@ typedef struct {
35
38
  uint64_t lo, hi;
36
39
  } yep_u128;
37
40
  #define YEP_MUL64(a, b) yep_u128_mul64(a, b)
41
+ #else
42
+ /* Any compiler without __int128 (32-bit GCC/Clang, MSVC x86-32): the
43
+ * same lo/hi pair; multiplication via 32-bit limbs (below). */
44
+ typedef struct {
45
+ uint64_t lo, hi;
46
+ } yep_u128;
47
+ #define YEP_MUL64(a, b) yep_u128_mul64(a, b)
38
48
  #endif
39
49
 
40
50
  static inline yep_u128 yep_u128_of(uint64_t v) {
41
- #if defined(__SIZEOF_INT128__)
51
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
42
52
  return (yep_u128)v;
43
53
  #else
44
54
  yep_u128 r = {v, 0};
@@ -47,7 +57,7 @@ static inline yep_u128 yep_u128_of(uint64_t v) {
47
57
  }
48
58
 
49
59
  static inline yep_u128 yep_u128_max(void) {
50
- #if defined(__SIZEOF_INT128__)
60
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
51
61
  return ~(yep_u128)0;
52
62
  #else
53
63
  yep_u128 r = {~(uint64_t)0, ~(uint64_t)0};
@@ -56,7 +66,7 @@ static inline yep_u128 yep_u128_max(void) {
56
66
  }
57
67
 
58
68
  static inline yep_u128 yep_u128_add(yep_u128 a, yep_u128 b) {
59
- #if defined(__SIZEOF_INT128__)
69
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
60
70
  return a + b;
61
71
  #else
62
72
  yep_u128 r;
@@ -67,7 +77,7 @@ static inline yep_u128 yep_u128_add(yep_u128 a, yep_u128 b) {
67
77
  }
68
78
 
69
79
  static inline yep_u128 yep_u128_sub(yep_u128 a, yep_u128 b) {
70
- #if defined(__SIZEOF_INT128__)
80
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
71
81
  return a - b;
72
82
  #else
73
83
  yep_u128 r;
@@ -79,7 +89,7 @@ static inline yep_u128 yep_u128_sub(yep_u128 a, yep_u128 b) {
79
89
 
80
90
  /* n < 128 */
81
91
  static inline yep_u128 yep_u128_shl(yep_u128 a, unsigned n) {
82
- #if defined(__SIZEOF_INT128__)
92
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
83
93
  return a << n;
84
94
  #else
85
95
  yep_u128 r = {0, 0};
@@ -98,7 +108,7 @@ static inline yep_u128 yep_u128_shl(yep_u128 a, unsigned n) {
98
108
 
99
109
  /* n < 128 */
100
110
  static inline yep_u128 yep_u128_shr(yep_u128 a, unsigned n) {
101
- #if defined(__SIZEOF_INT128__)
111
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
102
112
  return a >> n;
103
113
  #else
104
114
  yep_u128 r = {0, 0};
@@ -116,7 +126,7 @@ static inline yep_u128 yep_u128_shr(yep_u128 a, unsigned n) {
116
126
  }
117
127
 
118
128
  static inline int yep_u128_cmp(yep_u128 a, yep_u128 b) {
119
- #if defined(__SIZEOF_INT128__)
129
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
120
130
  return a < b ? -1 : (a > b ? 1 : 0);
121
131
  #else
122
132
  if (a.hi != b.hi) {
@@ -142,29 +152,47 @@ static inline yep_u128 yep_u128_mul64(uint64_t a, uint64_t b) {
142
152
  r.lo = a * b;
143
153
  return r;
144
154
  }
155
+ #elif !defined(__SIZEOF_INT128__) || defined(YEP_FLOAT_FORCE_LIMBS)
156
+ /* portable: 32-bit limbs, exact (the struct tier only) */
157
+ static inline yep_u128 yep_u128_mul64(uint64_t a, uint64_t b) {
158
+ uint64_t a0 = (uint32_t)a, a1 = a >> 32;
159
+ uint64_t b0 = (uint32_t)b, b1 = b >> 32;
160
+ uint64_t ll = a0 * b0;
161
+ uint64_t lh = a0 * b1;
162
+ uint64_t hl = a1 * b0;
163
+ uint64_t mid = (ll >> 32) + (uint32_t)lh + (uint32_t)hl;
164
+ yep_u128 r;
165
+ r.lo = (mid << 32) | (uint32_t)ll;
166
+ r.hi = (a1 * b1) + (lh >> 32) + (hl >> 32) + (mid >> 32);
167
+ return r;
168
+ }
145
169
  #endif
146
170
 
147
171
  /* x * 10 stays in range */
148
172
  static inline int yep_u128_fits10(yep_u128 x) {
149
- #if defined(__SIZEOF_INT128__)
173
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
150
174
  return x <= (~(yep_u128)0) / 10;
151
175
  #else
152
- /* exact: hi*10 must not overflow 64 bits (with the lo carry) */
153
- uint64_t hi_prod_hi = __umulh(x.hi, 10u);
154
- uint64_t hi_prod_lo = x.hi * 10u;
155
- uint64_t lo_carry = __umulh(x.lo, 10u);
156
- return hi_prod_hi == 0 && hi_prod_lo + lo_carry >= hi_prod_lo;
176
+ /* exact: x*10 = (hi*10 << 64) + lo*10 — overflow iff hi*10
177
+ * escapes 64 bits or the lo-carry wraps the sum */
178
+ yep_u128 hp = YEP_MUL64(x.hi, 10u);
179
+ if (hp.hi != 0) {
180
+ return 0;
181
+ }
182
+ yep_u128 lp = YEP_MUL64(x.lo, 10u);
183
+ return hp.lo + lp.hi >= hp.lo;
157
184
  #endif
158
185
  }
159
186
 
160
187
  /* m small (< 2^32); caller guarantees no overflow (fits10 guarded) */
161
188
  static inline yep_u128 yep_u128_mul_small(yep_u128 a, uint32_t m) {
162
- #if defined(__SIZEOF_INT128__)
189
+ #if defined(__SIZEOF_INT128__) && !defined(YEP_FLOAT_FORCE_LIMBS)
163
190
  return a * m;
164
191
  #else
165
192
  yep_u128 r;
166
- r.lo = a.lo * m;
167
- r.hi = a.hi * m + __umulh(a.lo, m);
193
+ yep_u128 lp = YEP_MUL64(a.lo, m);
194
+ r.lo = lp.lo;
195
+ r.hi = a.hi * m + lp.hi;
168
196
  return r;
169
197
  #endif
170
198
  }
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.17.1
4
+ version: 0.6.18.2
5
5
  platform: powerpc64le-linux
6
6
  authors:
7
7
  - Ribose Inc.