quickjs 0.19.0 → 0.20.0.rc1

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: 63b2c2bd84eaf1dbd09250dc14fc8ba158662f51fb82c1bccb355302f870f451
4
- data.tar.gz: 1ad1aa3a1ff28d79fad6fc1d653648e66bf800857872ccecf1858635dadf1c54
3
+ metadata.gz: e96e8ab31794879d095e585c4d3a56a659743f6dc2b3c86ec192f789cdef0954
4
+ data.tar.gz: 33934987b758a3536a8f8dc19036bd3aa4aeff183909f38c3095bab6d52691ac
5
5
  SHA512:
6
- metadata.gz: '08618cb67ac46302c4443851f87d81eafe7b236ddc9dac6a05978ae0eae8e92804a816838bf45f6c42cbd7145d602c9f74f3b375dfae583417eaed7a3418fd42'
7
- data.tar.gz: 1ece2015042543a9183c5191f5325a78e6bb40d242b86dfcb98decfaced4d39310ade0347e184413d85d0e521d4515c5b9327a1783989c97d65b4bc652f031e3
6
+ metadata.gz: 8a33bfbf397a9e08e37870f461a78e4cecfb8de76d99a844c376c3325297295261d3e0f35cfdc58545de58b664dfded9b281f2fe201a85f393096c0eda1e427a
7
+ data.tar.gz: 638e928150c34f0f2fdf878336f31d6bfe3327faf7cca3f2291b785de320d1bd4b38e28d7908aae5290358244cd5cccaa3325d0b0b4bcbaa534eef150b79848e
@@ -100,15 +100,20 @@ void dbuf_init(DynBuf *s)
100
100
  dbuf_init2(s, NULL, NULL);
101
101
  }
102
102
 
103
- /* return < 0 if error */
104
- int dbuf_realloc(DynBuf *s, size_t new_size)
103
+ /* Try to allocate 'len' more bytes. return < 0 if error */
104
+ int dbuf_claim(DynBuf *s, size_t len)
105
105
  {
106
- size_t size;
106
+ size_t new_size, size;
107
107
  uint8_t *new_buf;
108
+ new_size = s->size + len;
109
+ if (new_size < len)
110
+ return -1; /* overflow case */
108
111
  if (new_size > s->allocated_size) {
109
112
  if (s->error)
110
113
  return -1;
111
- size = s->allocated_size * 3 / 2;
114
+ size = s->allocated_size + (s->allocated_size / 2);
115
+ if (size < s->allocated_size)
116
+ return -1; /* overflow case */
112
117
  if (size > new_size)
113
118
  new_size = size;
114
119
  new_buf = s->realloc_func(s->opaque, s->buf, new_size);
@@ -122,22 +127,10 @@ int dbuf_realloc(DynBuf *s, size_t new_size)
122
127
  return 0;
123
128
  }
124
129
 
125
- int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len)
126
- {
127
- size_t end;
128
- end = offset + len;
129
- if (dbuf_realloc(s, end))
130
- return -1;
131
- memcpy(s->buf + offset, data, len);
132
- if (end > s->size)
133
- s->size = end;
134
- return 0;
135
- }
136
-
137
130
  int dbuf_put(DynBuf *s, const uint8_t *data, size_t len)
138
131
  {
139
- if (unlikely((s->size + len) > s->allocated_size)) {
140
- if (dbuf_realloc(s, s->size + len))
132
+ if (unlikely((s->allocated_size - s->size) < len)) {
133
+ if (dbuf_claim(s, len))
141
134
  return -1;
142
135
  }
143
136
  memcpy_no_ub(s->buf + s->size, data, len);
@@ -147,8 +140,8 @@ int dbuf_put(DynBuf *s, const uint8_t *data, size_t len)
147
140
 
148
141
  int dbuf_put_self(DynBuf *s, size_t offset, size_t len)
149
142
  {
150
- if (unlikely((s->size + len) > s->allocated_size)) {
151
- if (dbuf_realloc(s, s->size + len))
143
+ if (unlikely((s->allocated_size - s->size) < len)) {
144
+ if (dbuf_claim(s, len))
152
145
  return -1;
153
146
  }
154
147
  memcpy(s->buf + s->size, s->buf + offset, len);
@@ -156,11 +149,26 @@ int dbuf_put_self(DynBuf *s, size_t offset, size_t len)
156
149
  return 0;
157
150
  }
158
151
 
159
- int dbuf_putc(DynBuf *s, uint8_t c)
152
+ int __dbuf_putc(DynBuf *s, uint8_t c)
160
153
  {
161
154
  return dbuf_put(s, &c, 1);
162
155
  }
163
156
 
157
+ int __dbuf_put_u16(DynBuf *s, uint16_t val)
158
+ {
159
+ return dbuf_put(s, (uint8_t *)&val, 2);
160
+ }
161
+
162
+ int __dbuf_put_u32(DynBuf *s, uint32_t val)
163
+ {
164
+ return dbuf_put(s, (uint8_t *)&val, 4);
165
+ }
166
+
167
+ int __dbuf_put_u64(DynBuf *s, uint64_t val)
168
+ {
169
+ return dbuf_put(s, (uint8_t *)&val, 8);
170
+ }
171
+
164
172
  int dbuf_putstr(DynBuf *s, const char *str)
165
173
  {
166
174
  return dbuf_put(s, (const uint8_t *)str, strlen(str));
@@ -182,7 +190,7 @@ int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
182
190
  /* fast case */
183
191
  return dbuf_put(s, (uint8_t *)buf, len);
184
192
  } else {
185
- if (dbuf_realloc(s, s->size + len + 1))
193
+ if (dbuf_claim(s, len + 1))
186
194
  return -1;
187
195
  va_start(ap, fmt);
188
196
  vsnprintf((char *)(s->buf + s->size), s->allocated_size - s->size,
@@ -307,7 +315,7 @@ int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp)
307
315
 
308
316
  #if 0
309
317
 
310
- #if defined(EMSCRIPTEN) || defined(__ANDROID__)
318
+ #if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
311
319
 
312
320
  static void *rqsort_arg;
313
321
  static int (*rqsort_cmp)(const void *, const void *, void *);
@@ -264,24 +264,58 @@ typedef struct DynBuf {
264
264
 
265
265
  void dbuf_init(DynBuf *s);
266
266
  void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);
267
- int dbuf_realloc(DynBuf *s, size_t new_size);
268
- int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len);
267
+ int dbuf_claim(DynBuf *s, size_t len);
269
268
  int dbuf_put(DynBuf *s, const uint8_t *data, size_t len);
270
269
  int dbuf_put_self(DynBuf *s, size_t offset, size_t len);
271
- int dbuf_putc(DynBuf *s, uint8_t c);
272
270
  int dbuf_putstr(DynBuf *s, const char *str);
271
+ int __dbuf_putc(DynBuf *s, uint8_t c);
272
+ int __dbuf_put_u16(DynBuf *s, uint16_t val);
273
+ int __dbuf_put_u32(DynBuf *s, uint32_t val);
274
+ int __dbuf_put_u64(DynBuf *s, uint64_t val);
275
+
276
+ static inline int dbuf_putc(DynBuf *s, uint8_t val)
277
+ {
278
+ if (unlikely((s->allocated_size - s->size) < 1)) {
279
+ return __dbuf_putc(s, val);
280
+ } else {
281
+ s->buf[s->size++] = val;
282
+ return 0;
283
+ }
284
+ }
285
+
273
286
  static inline int dbuf_put_u16(DynBuf *s, uint16_t val)
274
287
  {
275
- return dbuf_put(s, (uint8_t *)&val, 2);
288
+ if (unlikely((s->allocated_size - s->size) < 2)) {
289
+ return __dbuf_put_u16(s, val);
290
+ } else {
291
+ put_u16(s->buf + s->size, val);
292
+ s->size += 2;
293
+ return 0;
294
+ }
276
295
  }
296
+
277
297
  static inline int dbuf_put_u32(DynBuf *s, uint32_t val)
278
298
  {
279
- return dbuf_put(s, (uint8_t *)&val, 4);
299
+ if (unlikely((s->allocated_size - s->size) < 4)) {
300
+ return __dbuf_put_u32(s, val);
301
+ } else {
302
+ put_u32(s->buf + s->size, val);
303
+ s->size += 4;
304
+ return 0;
305
+ }
280
306
  }
307
+
281
308
  static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
282
309
  {
283
- return dbuf_put(s, (uint8_t *)&val, 8);
310
+ if (unlikely((s->allocated_size - s->size) < 8)) {
311
+ return __dbuf_put_u64(s, val);
312
+ } else {
313
+ put_u64(s->buf + s->size, val);
314
+ s->size += 8;
315
+ return 0;
316
+ }
284
317
  }
318
+
285
319
  int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
286
320
  const char *fmt, ...);
287
321
  void dbuf_free(DynBuf *s);
@@ -31,6 +31,8 @@ DEF(char32, 5)
31
31
  DEF(char32_i, 5)
32
32
  DEF(dot, 1)
33
33
  DEF(any, 1) /* same as dot but match any character including line terminator */
34
+ DEF(space, 1)
35
+ DEF(not_space, 1) /* must come after */
34
36
  DEF(line_start, 1)
35
37
  DEF(line_start_m, 1)
36
38
  DEF(line_end, 1)
@@ -39,17 +41,22 @@ DEF(goto, 5)
39
41
  DEF(split_goto_first, 5)
40
42
  DEF(split_next_first, 5)
41
43
  DEF(match, 1)
44
+ DEF(lookahead_match, 1)
45
+ DEF(negative_lookahead_match, 1) /* must come after */
42
46
  DEF(save_start, 2) /* save start position */
43
47
  DEF(save_end, 2) /* save end position, must come after saved_start */
44
48
  DEF(save_reset, 3) /* reset save positions */
45
- DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
46
- DEF(push_i32, 5) /* push integer on the stack */
47
- DEF(drop, 1)
49
+ DEF(loop, 6) /* decrement the top the stack and goto if != 0 */
50
+ DEF(loop_split_goto_first, 10) /* loop and then split */
51
+ DEF(loop_split_next_first, 10)
52
+ DEF(loop_check_adv_split_goto_first, 10) /* loop and then check advance and split */
53
+ DEF(loop_check_adv_split_next_first, 10)
54
+ DEF(set_i32, 6) /* store the immediate value to a register */
48
55
  DEF(word_boundary, 1)
49
56
  DEF(word_boundary_i, 1)
50
57
  DEF(not_word_boundary, 1)
51
58
  DEF(not_word_boundary_i, 1)
52
- DEF(back_reference, 2)
59
+ DEF(back_reference, 2) /* variable length */
53
60
  DEF(back_reference_i, 2) /* must come after */
54
61
  DEF(backward_back_reference, 2) /* must come after */
55
62
  DEF(backward_back_reference_i, 2) /* must come after */
@@ -58,10 +65,9 @@ DEF(range_i, 3) /* variable length */
58
65
  DEF(range32, 3) /* variable length */
59
66
  DEF(range32_i, 3) /* variable length */
60
67
  DEF(lookahead, 5)
61
- DEF(negative_lookahead, 5)
62
- DEF(push_char_pos, 1) /* push the character position on the stack */
63
- DEF(check_advance, 1) /* pop one stack element and check that it is different from the character position */
68
+ DEF(negative_lookahead, 5) /* must come after */
69
+ DEF(set_char_pos, 2) /* store the character position to a register */
70
+ DEF(check_advance, 2) /* check that the register is different from the character position */
64
71
  DEF(prev, 1) /* go to the previous char */
65
- DEF(simple_greedy_quant, 17)
66
72
 
67
73
  #endif /* DEF */