@scriptc/runtime 0.0.4 → 0.0.6

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.
package/src/scr_url.c CHANGED
@@ -69,8 +69,7 @@ static void ub_init(UrlBuf *b) {
69
69
  b->len = 0;
70
70
  b->data = malloc(b->cap);
71
71
  if (!b->data) {
72
- fputs("scriptc: out of memory\n", stderr);
73
- abort();
72
+ scr_trap("scriptc: out of memory\n");
74
73
  }
75
74
  }
76
75
 
@@ -79,8 +78,7 @@ static void ub_append(UrlBuf *b, const char *bytes, size_t n) {
79
78
  while (b->len + n > b->cap) b->cap *= 2;
80
79
  char *grown = realloc(b->data, b->cap);
81
80
  if (!grown) {
82
- fputs("scriptc: out of memory\n", stderr);
83
- abort();
81
+ scr_trap("scriptc: out of memory\n");
84
82
  }
85
83
  b->data = grown;
86
84
  }
@@ -182,8 +180,7 @@ static ScrStr *parse_rooted_path(const char *raw, size_t len, bool special) {
182
180
  size_t seg_starts_cap = 8, seg_count = 0;
183
181
  size_t *seg_starts = malloc(seg_starts_cap * sizeof(size_t));
184
182
  if (!seg_starts) {
185
- fputs("scriptc: out of memory\n", stderr);
186
- abort();
183
+ scr_trap("scriptc: out of memory\n");
187
184
  }
188
185
  size_t i = 0;
189
186
  /* One leading separator opens the first segment (rooted). */
@@ -206,7 +203,7 @@ static ScrStr *parse_rooted_path(const char *raw, size_t len, bool special) {
206
203
  if (seg_count == seg_starts_cap) {
207
204
  seg_starts_cap *= 2;
208
205
  seg_starts = realloc(seg_starts, seg_starts_cap * sizeof(size_t));
209
- if (!seg_starts) abort();
206
+ if (!seg_starts) scr_trap("scriptc: out of memory\n");
210
207
  }
211
208
  seg_starts[seg_count++] = out.len;
212
209
  }
@@ -215,7 +212,7 @@ static ScrStr *parse_rooted_path(const char *raw, size_t len, bool special) {
215
212
  if (seg_count == seg_starts_cap) {
216
213
  seg_starts_cap *= 2;
217
214
  seg_starts = realloc(seg_starts, seg_starts_cap * sizeof(size_t));
218
- if (!seg_starts) abort();
215
+ if (!seg_starts) scr_trap("scriptc: out of memory\n");
219
216
  }
220
217
  seg_starts[seg_count++] = out.len;
221
218
  }
@@ -224,8 +221,7 @@ static ScrStr *parse_rooted_path(const char *raw, size_t len, bool special) {
224
221
  seg_starts_cap *= 2;
225
222
  seg_starts = realloc(seg_starts, seg_starts_cap * sizeof(size_t));
226
223
  if (!seg_starts) {
227
- fputs("scriptc: out of memory\n", stderr);
228
- abort();
224
+ scr_trap("scriptc: out of memory\n");
229
225
  }
230
226
  }
231
227
  seg_starts[seg_count++] = out.len;
@@ -355,8 +351,7 @@ ScrUrl *scr_url_new(ScrStr *input) {
355
351
  while (e > b && (unsigned char)raw[e - 1] <= 0x20) e--;
356
352
  char *buf = malloc(e - b + 1);
357
353
  if (!buf) {
358
- fputs("scriptc: out of memory\n", stderr);
359
- abort();
354
+ scr_trap("scriptc: out of memory\n");
360
355
  }
361
356
  size_t len = 0;
362
357
  for (size_t i = b; i < e; i++) {
@@ -526,8 +521,7 @@ ScrUrl *scr_url_new(ScrStr *input) {
526
521
 
527
522
  ScrUrl *u = malloc(sizeof(ScrUrl));
528
523
  if (!u) {
529
- fputs("scriptc: out of memory\n", stderr);
530
- abort();
524
+ scr_trap("scriptc: out of memory\n");
531
525
  }
532
526
  u->rc = 1;
533
527
  u->scheme = scheme_str;
@@ -738,8 +732,7 @@ ScrStr *scr_url_str_to_path(ScrStr *input) {
738
732
  static ScrUrl *scr_url_new_file(ScrStr *host, ScrStr *encoded_path) {
739
733
  ScrUrl *u = malloc(sizeof(ScrUrl));
740
734
  if (!u) {
741
- fputs("scriptc: out of memory\n", stderr);
742
- abort();
735
+ scr_trap("scriptc: out of memory\n");
743
736
  }
744
737
  u->rc = 1;
745
738
  u->scheme = scr_str_new("file", 4);
@@ -26,8 +26,7 @@ static void ub_init(UrlBuf *b) {
26
26
  b->len = 0;
27
27
  b->data = malloc(b->cap);
28
28
  if (!b->data) {
29
- fputs("scriptc: out of memory\n", stderr);
30
- abort();
29
+ scr_trap("scriptc: out of memory\n");
31
30
  }
32
31
  }
33
32
 
@@ -36,8 +35,7 @@ static void ub_append(UrlBuf *b, const char *bytes, size_t n) {
36
35
  while (b->len + n > b->cap) b->cap *= 2;
37
36
  char *grown = realloc(b->data, b->cap);
38
37
  if (!grown) {
39
- fputs("scriptc: out of memory\n", stderr);
40
- abort();
38
+ scr_trap("scriptc: out of memory\n");
41
39
  }
42
40
  b->data = grown;
43
41
  }
@@ -94,8 +92,7 @@ struct ScrSearchParams {
94
92
  static ScrSearchParams *sp_alloc(void) {
95
93
  ScrSearchParams *sp = malloc(sizeof(ScrSearchParams));
96
94
  if (!sp) {
97
- fputs("scriptc: out of memory\n", stderr);
98
- abort();
95
+ scr_trap("scriptc: out of memory\n");
99
96
  }
100
97
  sp->rc = 1;
101
98
  sp->len = 0;
@@ -103,8 +100,7 @@ static ScrSearchParams *sp_alloc(void) {
103
100
  sp->names = malloc(sp->cap * sizeof(ScrStr *));
104
101
  sp->vals = malloc(sp->cap * sizeof(ScrStr *));
105
102
  if (!sp->names || !sp->vals) {
106
- fputs("scriptc: out of memory\n", stderr);
107
- abort();
103
+ scr_trap("scriptc: out of memory\n");
108
104
  }
109
105
  sp->owner = NULL;
110
106
  return sp;
@@ -142,8 +138,7 @@ static void sp_push(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
142
138
  ScrStr **gn = realloc(sp->names, sp->cap * sizeof(ScrStr *));
143
139
  ScrStr **gv = realloc(sp->vals, sp->cap * sizeof(ScrStr *));
144
140
  if (!gn || !gv) {
145
- fputs("scriptc: out of memory\n", stderr);
146
- abort();
141
+ scr_trap("scriptc: out of memory\n");
147
142
  }
148
143
  sp->names = gn;
149
144
  sp->vals = gv;
@@ -161,8 +156,7 @@ static ScrStr *sp_scrub_utf8(const char *in_c, size_t n) {
161
156
  const unsigned char *in = (const unsigned char *)in_c;
162
157
  char *out = malloc(n * 3 + 1);
163
158
  if (!out) {
164
- fputs("scriptc: out of memory\n", stderr);
165
- abort();
159
+ scr_trap("scriptc: out of memory\n");
166
160
  }
167
161
  size_t o = 0;
168
162
  uint32_t cp = 0;
package/src/scr_zlib.c CHANGED
@@ -18,8 +18,7 @@
18
18
  #include <zlib.h>
19
19
 
20
20
  static void scr_zlib_oom(void) {
21
- fputs("scriptc: out of memory\n", stderr);
22
- abort();
21
+ scr_trap("scriptc: out of memory\n");
23
22
  }
24
23
 
25
24
  ScrBytes *scr_zlib_deflate(const ScrBytes *data) {