yeptris 0.6.17.1 → 0.6.18.2
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 +4 -4
- data/lib/yeptris/cbor.rb +1 -1
- data/lib/yeptris/document.rb +3 -3
- data/lib/yeptris/ffi.rb +12 -1
- data/lib/yeptris/materializer.rb +2 -2
- data/lib/yeptris/node.rb +7 -7
- data/lib/yeptris/valueml.rb +5 -5
- data/lib/yeptris.rb +1 -1
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +46 -18
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d2c20e34ee04e8ead36d9dd1d0416a69e3171bdd9d567e724a9781308aa5287
|
|
4
|
+
data.tar.gz: 9e2c440e6ab072af22c568dd7de4262b331d3bcd69d61dad25dae64854d6a925
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3c9fd2d90bd3490fa8070c47088a10288dd5933098926a3a703ad9e78fd44a06bc2fd38c3f5cd4b373ca056faa6db6f0d4004a06d415be964470b6989423acd
|
|
7
|
+
data.tar.gz: 89da80d2595be33241cc7b694ae69a262cf58d8d8dbb955d7330357572783d6a6f07cf9ebb56553fa9313e977361f6460547cc6f4680d63642f30140d73e27ae
|
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
|
|
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?
|
data/lib/yeptris/document.rb
CHANGED
|
@@ -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(:
|
|
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(:
|
|
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(:
|
|
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
|
|
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
|
data/lib/yeptris/materializer.rb
CHANGED
|
@@ -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
|
|
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
|
|
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(:
|
|
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
|
|
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(:
|
|
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
|
|
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(:
|
|
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
|
|
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
|
|
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
|
data/lib/yeptris/valueml.rb
CHANGED
|
@@ -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(:
|
|
41
|
+
count_p = ::FFI::MemoryPointer.new(:size_t)
|
|
42
42
|
arena_p = ::FFI::MemoryPointer.new(:pointer)
|
|
43
|
-
alen_p = ::FFI::MemoryPointer.new(:
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
@@ -23,10 +23,13 @@
|
|
|
23
23
|
|
|
24
24
|
#include "emit/float/api.h"
|
|
25
25
|
|
|
26
|
-
|
|
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:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
167
|
-
r.
|
|
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
|
}
|