teptris 0.3.25.0 → 0.3.27.0

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: eb38fa932ad53e583f2e55fda5a79bb10f71f566ea271c667844305fbc856684
4
- data.tar.gz: a5455cba7a2362f5a500110d490fccce9c4020485cc33c9d574b4cd1c0a14bc3
3
+ metadata.gz: d196f9d02c3b202cccdc40b0e822321a1e219a2bb88b7825f9cb4d4400e42bf0
4
+ data.tar.gz: b72d8ac0b56dec14170c4c14d3fbaee62c46629a7327415e3b608db12d6a0666
5
5
  SHA512:
6
- metadata.gz: 84fb5ffbf89a11be45fc90f57c30c2ebf835598bc0ed4fb49a1be1f3b66a8dcc3bfa562eb9b7bc07958e363a05a6dbad970a7534d732b296f3a312956b1f5698
7
- data.tar.gz: 6ebaddd5318e24417af4e6f58172c33548930249cafb1d5acf6f101376dedf23c390700e35a93871b3b6c83ae44fb872173061968713fc0c13dcf8e11883c794
6
+ metadata.gz: 5bd084bdc606f9d3a216df35c1ef8afc883313574ef38eb03455c822e5db1aa5ff9c752aeb1df0a35824249473ee47f39e02d1f34ddf74a0fe14c071fd9c7e97
7
+ data.tar.gz: '0412583e35f3923f2fb40ecd2d0edb287b25128c2d7165a37527edfcdc78938bec95f5e309153635c88aaa4dffbda1054ffd5401a40b331f5f448c462291e5f0'
@@ -1,4 +1,4 @@
1
- # libteptris 0.3.25 — vendored source
1
+ # libteptris 0.3.27 — vendored source
2
2
 
3
3
  This directory carries the COMPLETE C source of the engine this
4
4
  gem's extension was built from (the packaging doctrine: compiled
@@ -3,7 +3,7 @@
3
3
 
4
4
  #define TEPTRIS_VERSION_MAJOR 0
5
5
  #define TEPTRIS_VERSION_MINOR 3
6
- #define TEPTRIS_VERSION_PATCH 25
7
- #define TEPTRIS_VERSION_STRING "0.3.25"
6
+ #define TEPTRIS_VERSION_PATCH 27
7
+ #define TEPTRIS_VERSION_STRING "0.3.27"
8
8
 
9
9
  #endif /* TEPTRIS_VERSION_H */
@@ -20,6 +20,12 @@
20
20
  * 0x05 FALSE
21
21
  * 0x06 TRUE
22
22
  * 0x07 DATETIME u8 kind(4..7) <25 B, same layout as flatten>
23
+ * 0x0F DATETIME-TEXT u32 len <bytes> - an RFC 3339 literal carried
24
+ * as raw text (the JS dump's datetime shape); the
25
+ * engine parses it with teptris_datetime_from_str at
26
+ * decode (non-datetime text = ERR_ARG). Emits the
27
+ * same canonical bytes as the structured op - the
28
+ * host never parses datetimes.
23
29
  * 0x08 BEGIN-TABLE section header ([k] / [a.b])
24
30
  * 0x09 BEGIN-ARRAY inline array as a value
25
31
  * 0x0A BEGIN-AOT array-of-tables ([[k]], elements via BEGIN-TABLE)
@@ -36,6 +42,7 @@
36
42
  #include <string.h>
37
43
 
38
44
  #include "emit_shared.h"
45
+ #include "teptris/parse/parse.h"
39
46
  #include "teptris/teptris.h"
40
47
 
41
48
  enum {
@@ -53,7 +60,8 @@ enum {
53
60
  W_BEGIN_INLINE_TABLE = 0x0B,
54
61
  W_CLOSE = 0x0C,
55
62
  W_EMPTY_TABLE = 0x0D,
56
- W_EMPTY_ARRAY = 0x0E
63
+ W_EMPTY_ARRAY = 0x0E,
64
+ W_DATETIME_TEXT = 0x0F
57
65
  };
58
66
 
59
67
  enum {
@@ -409,6 +417,36 @@ teptris_status teptris_writer_feed(teptris_writer *w, const uint8_t *ops,
409
417
  w_end_line(w);
410
418
  break;
411
419
  }
420
+ case W_DATETIME_TEXT: {
421
+ if (i + 4 > len) {
422
+ w->st = TEPTRIS_ERR_ARG;
423
+ break;
424
+ }
425
+ uint32_t tlen = (uint32_t)ops[i] |
426
+ ((uint32_t)ops[i + 1] << 8) |
427
+ ((uint32_t)ops[i + 2] << 16) |
428
+ ((uint32_t)ops[i + 3] << 24);
429
+ i += 4;
430
+ if (i + tlen > len) {
431
+ w->st = TEPTRIS_ERR_ARG;
432
+ break;
433
+ }
434
+ teptris_datetime dt;
435
+ teptris_kind dk;
436
+ if (teptris_datetime_from_str((const char *)ops + i, tlen, &dt,
437
+ &dk) != TEPTRIS_OK) {
438
+ w->st = TEPTRIS_ERR_ARG;
439
+ break;
440
+ }
441
+ i += tlen;
442
+ w_keyed_prefix(w);
443
+ if (w->st != TEPTRIS_OK) {
444
+ break;
445
+ }
446
+ emit_dt(&w->out, &dt, dk);
447
+ w_end_line(w);
448
+ break;
449
+ }
412
450
  case W_BEGIN_TABLE: {
413
451
  wframe *t = w->top;
414
452
  if (t != NULL && (t->kind == F_ARRAY || t->kind == F_ITAB)) {
@@ -68,27 +68,38 @@ static teptris_status finish_node(teptris_parser *ps, teptris_kind kind,
68
68
  return TEPTRIS_OK;
69
69
  }
70
70
 
71
- teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
71
+ /* The datetime grammar core: parse one datetime at p..end into dt.
72
+ * No DOM, no parser state — teptris_parse_datetime wraps this with
73
+ * node creation, and teptris_datetime_from_str uses it to classify a
74
+ * standalone literal (the json-to-toml dump path). Errors come back
75
+ * as ERR_SYNTAX with a message in *err. */
76
+ static teptris_status dt_scan(const char *p, const char *end,
77
+ teptris_datetime *dt, teptris_kind *kind,
78
+ size_t *consumed, const char **err)
72
79
  {
73
- const char *p = ps->p;
74
- const char *end = ps->end;
75
80
  const char *start = p;
76
- teptris_datetime dt;
77
- memset(&dt, 0, sizeof(dt));
81
+ memset(dt, 0, sizeof(*dt));
82
+
83
+ if (end - p < 5) {
84
+ *err = "datetime too short";
85
+ return TEPTRIS_ERR_SYNTAX;
86
+ }
78
87
 
79
- if (p[4] == '-') {
88
+ if (end - p >= 10 && p[4] == '-') {
80
89
  int y = num4(p);
81
90
  int mo = d2(p + 5);
82
91
  int da = d2(p + 8);
83
92
  if (mo < 1 || mo > 12) {
84
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid month");
93
+ *err = "invalid month";
94
+ return TEPTRIS_ERR_SYNTAX;
85
95
  }
86
96
  if (da < 1 || da > days_in_month(y, mo)) {
87
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid day");
97
+ *err = "invalid day";
98
+ return TEPTRIS_ERR_SYNTAX;
88
99
  }
89
- dt.year = (int32_t)y;
90
- dt.month = (uint8_t)mo;
91
- dt.day = (uint8_t)da;
100
+ dt->year = (int32_t)y;
101
+ dt->month = (uint8_t)mo;
102
+ dt->day = (uint8_t)da;
92
103
  p += 10;
93
104
 
94
105
  bool has_time =
@@ -96,42 +107,46 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
96
107
  (size_t)(end - p) >= 6 && is_dig(p + 1) && is_dig(p + 2) &&
97
108
  p[3] == ':' && is_dig(p + 4) && is_dig(p + 5);
98
109
  if (!has_time) {
99
- return finish_node(ps, TEPTRIS_DATE_LOCAL, &dt,
100
- (size_t)(p - start), out);
110
+ *kind = TEPTRIS_DATE_LOCAL;
111
+ *consumed = (size_t)(p - start);
112
+ return TEPTRIS_OK;
101
113
  }
102
114
  p++; /* separator */
103
115
 
104
116
  int h = d2(p);
105
117
  int mi = d2(p + 3);
106
118
  int s = 0; /* TOML 1.1: seconds optional */
107
- size_t consumed = 5;
119
+ size_t sec_consumed = 5;
108
120
  if ((size_t)(end - p) >= 6 && p[5] == ':') {
109
121
  if ((size_t)(end - p) < 8 || !is_dig(p + 6) || !is_dig(p + 7)) {
110
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX,
111
- "invalid second");
122
+ *err = "invalid second";
123
+ return TEPTRIS_ERR_SYNTAX;
112
124
  }
113
125
  s = d2(p + 6);
114
- consumed = 8;
126
+ sec_consumed = 8;
115
127
  }
116
128
  if (h > 23) {
117
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid hour");
129
+ *err = "invalid hour";
130
+ return TEPTRIS_ERR_SYNTAX;
118
131
  }
119
132
  if (mi > 59) {
120
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid minute");
133
+ *err = "invalid minute";
134
+ return TEPTRIS_ERR_SYNTAX;
121
135
  }
122
136
  if (s > 60) {
123
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid second");
137
+ *err = "invalid second";
138
+ return TEPTRIS_ERR_SYNTAX;
124
139
  }
125
- dt.hour = (uint8_t)h;
126
- dt.minute = (uint8_t)mi;
127
- dt.second = (uint8_t)s;
128
- p += consumed;
140
+ dt->hour = (uint8_t)h;
141
+ dt->minute = (uint8_t)mi;
142
+ dt->second = (uint8_t)s;
143
+ p += sec_consumed;
129
144
 
130
145
  if (p < end && *p == '.') {
131
146
  p++;
132
147
  if (p >= end || !is_dig(p)) {
133
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX,
134
- "expected fractional digits");
148
+ *err = "expected fractional digits";
149
+ return TEPTRIS_ERR_SYNTAX;
135
150
  }
136
151
  uint32_t scale = 100000000u; /* 9 digits */
137
152
  uint32_t ns = 0;
@@ -142,14 +157,15 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
142
157
  }
143
158
  p++; /* beyond 9 digits: validated, then truncated */
144
159
  }
145
- dt.nanosecond = ns;
160
+ dt->nanosecond = ns;
146
161
  }
147
162
 
148
163
  if (p < end && (*p == 'Z' || *p == 'z')) {
149
- dt.offset_seconds = 0;
164
+ dt->offset_seconds = 0;
150
165
  p++;
151
- return finish_node(ps, TEPTRIS_DATETIME_OFFSET, &dt,
152
- (size_t)(p - start), out);
166
+ *kind = TEPTRIS_DATETIME_OFFSET;
167
+ *consumed = (size_t)(p - start);
168
+ return TEPTRIS_OK;
153
169
  }
154
170
  if (p < end && (*p == '+' || *p == '-') &&
155
171
  (size_t)(end - p) >= 6 && is_dig(p + 1) && is_dig(p + 2) &&
@@ -158,49 +174,55 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
158
174
  int oh = d2(p + 1);
159
175
  int om = d2(p + 4);
160
176
  if (oh > 23 || om > 59) {
161
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX,
162
- "invalid UTC offset");
177
+ *err = "invalid UTC offset";
178
+ return TEPTRIS_ERR_SYNTAX;
163
179
  }
164
- dt.offset_seconds = sign * (oh * 3600 + om * 60);
180
+ dt->offset_seconds = sign * (oh * 3600 + om * 60);
165
181
  p += 6;
166
- return finish_node(ps, TEPTRIS_DATETIME_OFFSET, &dt,
167
- (size_t)(p - start), out);
182
+ *kind = TEPTRIS_DATETIME_OFFSET;
183
+ *consumed = (size_t)(p - start);
184
+ return TEPTRIS_OK;
168
185
  }
169
- return finish_node(ps, TEPTRIS_DATETIME_LOCAL, &dt,
170
- (size_t)(p - start), out);
186
+ *kind = TEPTRIS_DATETIME_LOCAL;
187
+ *consumed = (size_t)(p - start);
188
+ return TEPTRIS_OK;
171
189
  }
172
190
 
173
191
  /* time-only; TOML 1.1: seconds optional */
174
192
  int h = d2(p);
175
193
  int mi = d2(p + 3);
176
194
  int s = 0;
177
- size_t consumed = 5;
195
+ size_t sec_consumed = 5;
178
196
  if ((size_t)(end - p) >= 8 && p[5] == ':') {
179
197
  if (!is_dig(p + 6) || !is_dig(p + 7)) {
180
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid second");
198
+ *err = "invalid second";
199
+ return TEPTRIS_ERR_SYNTAX;
181
200
  }
182
201
  s = d2(p + 6);
183
- consumed = 8;
202
+ sec_consumed = 8;
184
203
  }
185
204
  if (h > 23) {
186
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid hour");
205
+ *err = "invalid hour";
206
+ return TEPTRIS_ERR_SYNTAX;
187
207
  }
188
208
  if (mi > 59) {
189
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid minute");
209
+ *err = "invalid minute";
210
+ return TEPTRIS_ERR_SYNTAX;
190
211
  }
191
212
  if (s > 60) {
192
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX, "invalid second");
213
+ *err = "invalid second";
214
+ return TEPTRIS_ERR_SYNTAX;
193
215
  }
194
- dt.hour = (uint8_t)h;
195
- dt.minute = (uint8_t)mi;
196
- dt.second = (uint8_t)s;
197
- p += consumed;
216
+ dt->hour = (uint8_t)h;
217
+ dt->minute = (uint8_t)mi;
218
+ dt->second = (uint8_t)s;
219
+ p += sec_consumed;
198
220
 
199
221
  if (p < end && *p == '.') {
200
222
  p++;
201
223
  if (p >= end || !is_dig(p)) {
202
- return tep_fail_at(ps, NULL, TEPTRIS_ERR_SYNTAX,
203
- "expected fractional digits");
224
+ *err = "expected fractional digits";
225
+ return TEPTRIS_ERR_SYNTAX;
204
226
  }
205
227
  uint32_t scale = 100000000u;
206
228
  uint32_t ns = 0;
@@ -211,8 +233,43 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
211
233
  }
212
234
  p++;
213
235
  }
214
- dt.nanosecond = ns;
236
+ dt->nanosecond = ns;
215
237
  }
216
238
 
217
- return finish_node(ps, TEPTRIS_TIME_LOCAL, &dt, (size_t)(p - start), out);
239
+ *kind = TEPTRIS_TIME_LOCAL;
240
+ *consumed = (size_t)(p - start);
241
+ return TEPTRIS_OK;
242
+ }
243
+
244
+ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
245
+ {
246
+ const char *p = ps->p;
247
+ const char *end = ps->end;
248
+ const char *err = NULL;
249
+ teptris_datetime dt;
250
+ teptris_kind kind;
251
+ size_t consumed;
252
+ teptris_status st = dt_scan(p, end, &dt, &kind, &consumed, &err);
253
+ if (st != TEPTRIS_OK) {
254
+ return tep_fail_at(ps, NULL, st, err);
255
+ }
256
+ return finish_node(ps, kind, &dt, consumed, out);
257
+ }
258
+
259
+ teptris_status teptris_datetime_from_str(const char *s, size_t len,
260
+ teptris_datetime *dt,
261
+ teptris_kind *kind)
262
+ {
263
+ const char *err = NULL;
264
+ size_t consumed;
265
+ teptris_status st = dt_scan(s, s + len, dt, kind, &consumed, &err);
266
+ if (st != TEPTRIS_OK) {
267
+ return st;
268
+ }
269
+ /* a standalone literal must be the WHOLE string: trailing bytes
270
+ * make it a plain string, not a datetime */
271
+ if (consumed != len) {
272
+ return TEPTRIS_ERR_SYNTAX;
273
+ }
274
+ return TEPTRIS_OK;
218
275
  }
@@ -64,6 +64,12 @@ teptris_status teptris_parse_key_path(teptris_parser *ps,
64
64
  /* datetime.c */
65
65
  bool teptris_datetime_lookahead(const teptris_parser *ps);
66
66
  teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out);
67
+ /* classify a standalone literal: fills dt + kind when s..s+len is
68
+ * EXACTLY one datetime (trailing bytes -> ERR_SYNTAX, the caller
69
+ * keeps it a plain string) */
70
+ teptris_status teptris_datetime_from_str(const char *s, size_t len,
71
+ teptris_datetime *dt,
72
+ teptris_kind *kind);
67
73
 
68
74
  /* parser.c: skip space/tab (parser loop) — arrays also allow newlines
69
75
  * and comments. Both validate comment contents. */
@@ -9,9 +9,10 @@
9
9
  #include <string.h>
10
10
 
11
11
  #include "json_read.h"
12
+ #include "teptris/common/ryu/ryu_parse.h"
12
13
  #include "teptris/memory/arena.h"
13
14
 
14
- #define JSON_MAX_DEPTH 128
15
+ #define JSON_MAX_DEPTH 512
15
16
 
16
17
  struct jv {
17
18
  jv_kind kind;
@@ -186,9 +187,13 @@ static const char *jstring(jctx *c, size_t *out_len) {
186
187
  return s;
187
188
  }
188
189
  /* escaped string: rebuild into arena memory, carrying the plain
189
- * prefix the fast scan already stepped over */
190
+ * prefix the fast scan already stepped over. Every remaining
191
+ * input byte yields at most one output byte (plain chars are
192
+ * 1:1, escapes consume >=2 input per <=4 output), so the whole
193
+ * remaining span is the tight bound — sizing from the prefix
194
+ * alone overflows on a long plain tail (ASan, nightly 2026-11-06). */
190
195
  size_t plain_len = c->pos - start;
191
- size_t cap = (c->pos - start) * 4 + 16;
196
+ size_t cap = (c->len - start) + 16;
192
197
  char *out = teptris_arena_alloc(c->a, cap);
193
198
  size_t n = plain_len;
194
199
  memcpy(out, c->src + start, plain_len);
@@ -399,7 +404,6 @@ static jv *jvalue(jctx *c) {
399
404
  memcpy(tmp, c->src + start, tlen);
400
405
  tmp[tlen] = '\0';
401
406
  v = teptris_arena_alloc(c->a, sizeof(jv));
402
- *v = (jv){ .num = strtod(tmp, NULL) };
403
407
  if (integral) {
404
408
  errno = 0;
405
409
  char *end = NULL;
@@ -408,10 +412,28 @@ static jv *jvalue(jctx *c) {
408
412
  v->kind = JV_INT;
409
413
  v->i = (int64_t)i;
410
414
  } else {
411
- v->kind = JV_NUM;
415
+ /* out-of-int64 JSON integer: the float view, parsed
416
+ * with the engine's ryu s2d - libc strtod costs
417
+ * ~1.3us/float in wasm (musl), ryu is the same fast
418
+ * correct parse the TOML number path uses */
419
+ double num = 0;
420
+ if (teptris_ryu_s2d_n(tmp, (int)tlen, &num) !=
421
+ TEPTRIS_RYU_SUCCESS) {
422
+ jfail(c, "invalid number");
423
+ c->depth--;
424
+ return NULL;
425
+ }
426
+ *v = (jv){ .kind = JV_NUM, .num = num };
412
427
  }
413
428
  } else {
414
- v->kind = JV_NUM;
429
+ double num = 0;
430
+ if (teptris_ryu_s2d_n(tmp, (int)tlen, &num) !=
431
+ TEPTRIS_RYU_SUCCESS) {
432
+ jfail(c, "invalid number");
433
+ c->depth--;
434
+ return NULL;
435
+ }
436
+ *v = (jv){ .kind = JV_NUM, .num = num };
415
437
  }
416
438
  } else {
417
439
  jfail(c, "unexpected character");
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teptris
4
- VERSION = "0.3.25.0"
4
+ VERSION = "0.3.27.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.25.0
4
+ version: 0.3.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - teptris contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-05 00:00:00.000000000 Z
11
+ date: 2026-11-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A native C extension over libteptris, a C99 TOML 1.1 parser/emitter.
14
14
  API shape mirrors the tomlib gem.