@scriptc/cli-darwin-x64 0.2.3 → 0.2.5
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/dist/THIRD_PARTY_NOTICES +1 -1
- package/dist/bin/scriptc +0 -0
- package/dist/bin/scriptc.json +1 -1
- package/dist/lib/declarations/scriptc-node-fallback.d.ts +915 -215
- package/dist/lib/declarations/scriptc-overrides.d.ts +5 -1
- package/dist/lib/declarations/scriptc.d.ts +22 -2
- package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
- package/dist/lib/llvm/package.json +1 -1
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/package.json +1 -1
- package/dist/lib/runtime-darwin-x64/runtime-pack.json +215 -215
- package/dist/lib/runtime-sources/package.json +1 -1
- package/dist/lib/runtime-sources/src/scr_array.c +317 -40
- package/dist/lib/runtime-sources/src/scr_async.test.ts +16 -6
- package/dist/lib/runtime-sources/src/scr_bigint.c +15 -0
- package/dist/lib/runtime-sources/src/scr_bytes.c +437 -216
- package/dist/lib/runtime-sources/src/scr_bytes.test.c +85 -0
- package/dist/lib/runtime-sources/src/scr_bytes_io.c +0 -34
- package/dist/lib/runtime-sources/src/scr_copying.c +12 -2
- package/dist/lib/runtime-sources/src/scr_cycle.c +84 -60
- package/dist/lib/runtime-sources/src/scr_json.c +494 -161
- package/dist/lib/runtime-sources/src/scr_json.test.c +323 -1
- package/dist/lib/runtime-sources/src/scr_json.test.ts +58 -25
- package/dist/lib/runtime-sources/src/scr_key.h +68 -0
- package/dist/lib/runtime-sources/src/scr_lib.c +177 -89
- package/dist/lib/runtime-sources/src/scr_map.c +268 -96
- package/dist/lib/runtime-sources/src/scr_number.c +2 -4
- package/dist/lib/runtime-sources/src/scr_numeric.h +25 -0
- package/dist/lib/runtime-sources/src/scr_numeric.test.c +37 -0
- package/dist/lib/runtime-sources/src/scr_numeric.test.ts +33 -0
- package/dist/lib/runtime-sources/src/scr_regex.c +255 -145
- package/dist/lib/runtime-sources/src/scr_runtime.h +76 -19
- package/dist/lib/runtime-sources/src/scr_string.c +184 -42
- package/package.json +1 -1
|
@@ -2299,34 +2299,125 @@ static FILE *scr_fs_fopen(const ScrStr *path, const char *mode) {
|
|
|
2299
2299
|
#endif
|
|
2300
2300
|
}
|
|
2301
2301
|
|
|
2302
|
+
/* File sizes are hints, never EOF. Pseudo-files, pipes and concurrently
|
|
2303
|
+
* changing files still read to EOF; descriptor reads keep their position
|
|
2304
|
+
* and ownership. Limit individual reads for the CRT and small ssize_t. */
|
|
2305
|
+
typedef struct {
|
|
2306
|
+
ScrStr *text;
|
|
2307
|
+
uint8_t *bytes;
|
|
2308
|
+
size_t len, cap;
|
|
2309
|
+
} ScrFileRead;
|
|
2310
|
+
|
|
2311
|
+
static size_t scr_file_read_hint(FILE *stream, int fd) {
|
|
2312
|
+
if (stream) fd = fileno(stream);
|
|
2313
|
+
#ifdef _WIN32
|
|
2314
|
+
struct _stat64 st;
|
|
2315
|
+
if (_fstat64(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_size <= 0) return 4096;
|
|
2316
|
+
int64_t position = stream ? 0 : _lseeki64(fd, 0, SEEK_CUR);
|
|
2317
|
+
#else
|
|
2318
|
+
struct stat st;
|
|
2319
|
+
if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_size <= 0) return 4096;
|
|
2320
|
+
off_t position = stream ? 0 : lseek(fd, 0, SEEK_CUR);
|
|
2321
|
+
#endif
|
|
2322
|
+
if (position < 0 || position >= st.st_size) return 4096;
|
|
2323
|
+
uintmax_t remaining = (uintmax_t)st.st_size - (uintmax_t)position;
|
|
2324
|
+
/* A bounded initial allocation also tolerates sparse files that shrink
|
|
2325
|
+
* between metadata and the first read without reserving their full size. */
|
|
2326
|
+
size_t limit = 64 * 1024 * 1024;
|
|
2327
|
+
return remaining > limit ? limit : (size_t)remaining;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
static uint8_t *scr_file_read_data(ScrFileRead *out) {
|
|
2331
|
+
return out->text ? (uint8_t *)out->text->data : out->bytes;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
static void scr_file_read_grow(ScrFileRead *out) {
|
|
2335
|
+
size_t limit = SIZE_MAX - sizeof(ScrStr) - 1;
|
|
2336
|
+
if (out->cap >= limit) scr_trap("scriptc: file too large\n");
|
|
2337
|
+
size_t cap = out->cap > limit / 2 ? limit : out->cap * 2;
|
|
2338
|
+
if (out->text) {
|
|
2339
|
+
out->text->len = out->len;
|
|
2340
|
+
out->text = scr_str_regrow(out->text, cap);
|
|
2341
|
+
} else {
|
|
2342
|
+
uint8_t *grown = realloc(out->bytes, cap);
|
|
2343
|
+
if (!grown) scr_trap("scriptc: out of memory\n");
|
|
2344
|
+
out->bytes = grown;
|
|
2345
|
+
}
|
|
2346
|
+
out->cap = cap;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
/* Fill the final allocation. At a full capacity, probe one byte before
|
|
2350
|
+
* growing so an exact-size regular file never doubles its retained space. */
|
|
2351
|
+
static int scr_file_read_all(FILE *stream, int fd, bool text, ScrFileRead *out) {
|
|
2352
|
+
*out = (ScrFileRead){0};
|
|
2353
|
+
out->cap = scr_file_read_hint(stream, fd);
|
|
2354
|
+
if (text) {
|
|
2355
|
+
out->text = scr_str_alloc_raw(0, out->cap);
|
|
2356
|
+
out->cap = out->text->cap;
|
|
2357
|
+
out->text->data[0] = '\0';
|
|
2358
|
+
} else {
|
|
2359
|
+
out->bytes = malloc(out->cap);
|
|
2360
|
+
if (!out->bytes) scr_trap("scriptc: out of memory\n");
|
|
2361
|
+
}
|
|
2362
|
+
for (;;) {
|
|
2363
|
+
uint8_t extra;
|
|
2364
|
+
bool full = out->len == out->cap;
|
|
2365
|
+
size_t room = full ? 1 : out->cap - out->len;
|
|
2366
|
+
if (room > 512 * 1024) room = 512 * 1024;
|
|
2367
|
+
uint8_t *dest = full ? &extra : scr_file_read_data(out) + out->len;
|
|
2368
|
+
size_t count;
|
|
2369
|
+
int error = 0;
|
|
2370
|
+
if (stream) {
|
|
2371
|
+
count = fread(dest, 1, room, stream);
|
|
2372
|
+
if (ferror(stream)) error = errno ? errno : EIO;
|
|
2373
|
+
} else {
|
|
2374
|
+
ssize_t n = read(fd, dest, room);
|
|
2375
|
+
if (n < 0) { count = 0; error = errno; }
|
|
2376
|
+
else count = (size_t)n;
|
|
2377
|
+
}
|
|
2378
|
+
if (count) {
|
|
2379
|
+
if (full) {
|
|
2380
|
+
scr_file_read_grow(out);
|
|
2381
|
+
scr_file_read_data(out)[out->len] = extra;
|
|
2382
|
+
}
|
|
2383
|
+
out->len += count;
|
|
2384
|
+
}
|
|
2385
|
+
if (error == EINTR) {
|
|
2386
|
+
if (stream) clearerr(stream);
|
|
2387
|
+
continue;
|
|
2388
|
+
}
|
|
2389
|
+
if (error) {
|
|
2390
|
+
/* Raw strings must be safe for the normal cache-aware destructor. */
|
|
2391
|
+
if (out->text) { out->text->len = out->len; out->text->data[out->len] = '\0'; }
|
|
2392
|
+
scr_str_release(out->text);
|
|
2393
|
+
free(out->bytes);
|
|
2394
|
+
*out = (ScrFileRead){0};
|
|
2395
|
+
return error;
|
|
2396
|
+
}
|
|
2397
|
+
if (!count) break;
|
|
2398
|
+
}
|
|
2399
|
+
if (out->text) { out->text->len = out->len; out->text->data[out->len] = '\0'; }
|
|
2400
|
+
// Do not retain a large hint after truncation or a tiny pipe result.
|
|
2401
|
+
if (out->cap > 256 && out->len < out->cap / 2) {
|
|
2402
|
+
if (out->text) out->text = scr_str_regrow(out->text, out->len);
|
|
2403
|
+
else {
|
|
2404
|
+
uint8_t *trimmed = realloc(out->bytes, out->len ? out->len : 1);
|
|
2405
|
+
if (trimmed) out->bytes = trimmed;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
return 0;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2302
2411
|
static ScrStr *scr_fs_read_file_core(ScrStr *path, bool env_file) {
|
|
2303
2412
|
FILE *f = scr_fs_fopen(path, "rb");
|
|
2304
2413
|
if (!f) {
|
|
2305
2414
|
scr_fs_throw(errno, "open", path);
|
|
2306
2415
|
return NULL;
|
|
2307
2416
|
}
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
}
|
|
2313
|
-
for (;;) {
|
|
2314
|
-
if (cap - len < 2048) {
|
|
2315
|
-
cap *= 2;
|
|
2316
|
-
char *grown = realloc(buf, cap);
|
|
2317
|
-
if (!grown) {
|
|
2318
|
-
scr_trap("scriptc: out of memory\n");
|
|
2319
|
-
}
|
|
2320
|
-
buf = grown;
|
|
2321
|
-
}
|
|
2322
|
-
size_t n = fread(buf + len, 1, cap - len, f);
|
|
2323
|
-
len += n;
|
|
2324
|
-
if (n == 0) break;
|
|
2325
|
-
}
|
|
2326
|
-
if (ferror(f)) {
|
|
2327
|
-
int e = errno;
|
|
2328
|
-
fclose(f);
|
|
2329
|
-
free(buf);
|
|
2417
|
+
ScrFileRead out;
|
|
2418
|
+
int error = scr_file_read_all(f, -1, true, &out);
|
|
2419
|
+
fclose(f);
|
|
2420
|
+
if (error) {
|
|
2330
2421
|
if (env_file) {
|
|
2331
2422
|
ScrJsonBuf b;
|
|
2332
2423
|
scr_jb_init(&b);
|
|
@@ -2336,13 +2427,20 @@ static ScrStr *scr_fs_read_file_core(ScrStr *path, bool env_file) {
|
|
|
2336
2427
|
ScrStr *message = scr_jb_finish(&b);
|
|
2337
2428
|
scr_throw_error_msg_code(SCR_ERR_TYPE, message->data, message->len, "ERR_INVALID_ARG_TYPE");
|
|
2338
2429
|
scr_str_release(message);
|
|
2339
|
-
} else scr_fs_throw(
|
|
2430
|
+
} else scr_fs_throw(error, "read", path);
|
|
2340
2431
|
return NULL;
|
|
2341
2432
|
}
|
|
2433
|
+
return out.text;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
ScrBytes *scr_fs_read_file_bytes(ScrStr *path) {
|
|
2437
|
+
FILE *f = scr_fs_fopen(path, "rb");
|
|
2438
|
+
if (!f) { scr_fs_throw(errno, "open", path); return NULL; }
|
|
2439
|
+
ScrFileRead out;
|
|
2440
|
+
int error = scr_file_read_all(f, -1, false, &out);
|
|
2342
2441
|
fclose(f);
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
return s;
|
|
2442
|
+
if (error) { scr_fs_throw(error, "read", path); return NULL; }
|
|
2443
|
+
return scr_bytes_take_data(out.bytes, out.len);
|
|
2346
2444
|
}
|
|
2347
2445
|
|
|
2348
2446
|
ScrStr *scr_fs_read_file(ScrStr *path) {
|
|
@@ -3799,57 +3897,18 @@ static void scr_fs_throw_nopath(int e, const char *op) {
|
|
|
3799
3897
|
scr_throw_error_msg_code(SCR_ERR_ERROR, msg, (size_t)len, name);
|
|
3800
3898
|
}
|
|
3801
3899
|
|
|
3802
|
-
/* read(2) loop to EOF from the CURRENT position — Node's
|
|
3803
|
-
* readFileSync(fd) semantics for pipes and files alike (the stdin
|
|
3804
|
-
* pattern: readFileSync(0, "utf8")). Returns the malloc'd buffer and
|
|
3805
|
-
* its length, or NULL with the exception pending. */
|
|
3806
|
-
static char *scr_read_fd_all(double fd, size_t *out_len) {
|
|
3807
|
-
size_t cap = 4096, len = 0;
|
|
3808
|
-
char *buf = malloc(cap);
|
|
3809
|
-
if (!buf) {
|
|
3810
|
-
scr_trap("scriptc: out of memory\n");
|
|
3811
|
-
}
|
|
3812
|
-
for (;;) {
|
|
3813
|
-
if (cap - len < 2048) {
|
|
3814
|
-
cap *= 2;
|
|
3815
|
-
char *grown = realloc(buf, cap);
|
|
3816
|
-
if (!grown) {
|
|
3817
|
-
scr_trap("scriptc: out of memory\n");
|
|
3818
|
-
}
|
|
3819
|
-
buf = grown;
|
|
3820
|
-
}
|
|
3821
|
-
ssize_t n = read((int)fd, buf + len, cap - len);
|
|
3822
|
-
if (n < 0) {
|
|
3823
|
-
if (errno == EINTR) continue;
|
|
3824
|
-
int e = errno;
|
|
3825
|
-
free(buf);
|
|
3826
|
-
scr_fs_throw_nopath(e, "read");
|
|
3827
|
-
return NULL;
|
|
3828
|
-
}
|
|
3829
|
-
if (n == 0) break;
|
|
3830
|
-
len += (size_t)n;
|
|
3831
|
-
}
|
|
3832
|
-
*out_len = len;
|
|
3833
|
-
return buf;
|
|
3834
|
-
}
|
|
3835
|
-
|
|
3836
3900
|
ScrStr *scr_fs_read_fd(double fd) {
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
if (
|
|
3840
|
-
|
|
3841
|
-
free(buf);
|
|
3842
|
-
return s;
|
|
3901
|
+
ScrFileRead out;
|
|
3902
|
+
int error = scr_file_read_all(NULL, (int)fd, true, &out);
|
|
3903
|
+
if (error) { scr_fs_throw_nopath(error, "read"); return NULL; }
|
|
3904
|
+
return out.text;
|
|
3843
3905
|
}
|
|
3844
3906
|
|
|
3845
3907
|
ScrBytes *scr_fs_read_fd_bytes(double fd) {
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
if (
|
|
3849
|
-
|
|
3850
|
-
if (len > 0) memcpy(b->data, buf, len);
|
|
3851
|
-
free(buf);
|
|
3852
|
-
return b;
|
|
3908
|
+
ScrFileRead out;
|
|
3909
|
+
int error = scr_file_read_all(NULL, (int)fd, false, &out);
|
|
3910
|
+
if (error) { scr_fs_throw_nopath(error, "read"); return NULL; }
|
|
3911
|
+
return scr_bytes_take_data(out.bytes, out.len);
|
|
3853
3912
|
}
|
|
3854
3913
|
|
|
3855
3914
|
/* ── Atomics.wait: the synchronous-sleep idiom ───────────────────────
|
|
@@ -7345,33 +7404,62 @@ void *scr_caught_check_obj(const ScrCaught *c, size_t pre, size_t post,
|
|
|
7345
7404
|
* walk folded into one call; no user code runs mid-drain, so the
|
|
7346
7405
|
* live-iteration rules are moot). Borrows the set; the array is +1,
|
|
7347
7406
|
* string elements retained into it by the iter_key read. */
|
|
7407
|
+
static bool scr_set_to_arr_sparse(const ScrMap *s, ScrArr *out) {
|
|
7408
|
+
if (out->cap >= s->nlive) return false;
|
|
7409
|
+
/* Large capacities deliberately use sparse array storage. Keep the
|
|
7410
|
+
* ordinary append path when the allocator declined dense storage. */
|
|
7411
|
+
for (size_t i = 0; i < s->nentries; i++) {
|
|
7412
|
+
if (!s->entries[i].hash) continue;
|
|
7413
|
+
if (out->elem == SCR_ELEM_F64) scr_arr_push_f64(out, scr_map_iter_key_f64(s, (double)i));
|
|
7414
|
+
else if (out->elem == SCR_ELEM_BOOL) scr_arr_push_bool(out, scr_map_iter_key_bool(s, (double)i));
|
|
7415
|
+
else if (out->elem == SCR_ELEM_STR) scr_arr_push_ref(out, scr_map_iter_key_str(s, (double)i));
|
|
7416
|
+
else scr_arr_push_ref(out, scr_map_iter_key_ref(s, (double)i));
|
|
7417
|
+
}
|
|
7418
|
+
return true;
|
|
7419
|
+
}
|
|
7420
|
+
|
|
7348
7421
|
ScrArr *scr_set_to_arr_f64(const ScrMap *s) {
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
for (size_t i = 0; i <
|
|
7352
|
-
if (!
|
|
7353
|
-
|
|
7422
|
+
ScrArr *out = scr_arr_new(SCR_ELEM_F64, s->nlive);
|
|
7423
|
+
if (scr_set_to_arr_sparse(s, out)) return out;
|
|
7424
|
+
for (size_t i = 0; i < s->nentries; i++) {
|
|
7425
|
+
if (!s->entries[i].hash) continue;
|
|
7426
|
+
out->data[out->len] = s->entries[i].key;
|
|
7427
|
+
out->present[out->len++] = SCR_ARR_VALUE;
|
|
7428
|
+
}
|
|
7429
|
+
return out;
|
|
7430
|
+
}
|
|
7431
|
+
|
|
7432
|
+
ScrArr *scr_set_to_arr_bool(const ScrMap *s) {
|
|
7433
|
+
ScrArr *out = scr_arr_new(SCR_ELEM_BOOL, s->nlive);
|
|
7434
|
+
if (scr_set_to_arr_sparse(s, out)) return out;
|
|
7435
|
+
for (size_t i = 0; i < s->nentries; i++) {
|
|
7436
|
+
if (!s->entries[i].hash) continue;
|
|
7437
|
+
out->data[out->len] = s->entries[i].key;
|
|
7438
|
+
out->present[out->len++] = SCR_ARR_VALUE;
|
|
7354
7439
|
}
|
|
7355
7440
|
return out;
|
|
7356
7441
|
}
|
|
7357
7442
|
|
|
7358
7443
|
ScrArr *scr_set_to_arr_str(const ScrMap *s) {
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
for (size_t i = 0; i <
|
|
7362
|
-
if (!
|
|
7363
|
-
|
|
7444
|
+
ScrArr *out = scr_arr_new(SCR_ELEM_STR, s->nlive);
|
|
7445
|
+
if (scr_set_to_arr_sparse(s, out)) return out;
|
|
7446
|
+
for (size_t i = 0; i < s->nentries; i++) {
|
|
7447
|
+
if (!s->entries[i].hash) continue;
|
|
7448
|
+
scr_str_retain((ScrStr *)(uintptr_t)s->entries[i].key);
|
|
7449
|
+
out->data[out->len] = s->entries[i].key;
|
|
7450
|
+
out->present[out->len++] = SCR_ARR_VALUE;
|
|
7364
7451
|
}
|
|
7365
7452
|
return out;
|
|
7366
7453
|
}
|
|
7367
7454
|
|
|
7368
7455
|
ScrArr *scr_set_to_arr_ref(const ScrMap *s) {
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7456
|
+
ScrArr *out = scr_arr_new_ref(s->key_retain, s->key_release, s->key_trace, s->nlive);
|
|
7457
|
+
if (scr_set_to_arr_sparse(s, out)) return out;
|
|
7458
|
+
for (size_t i = 0; i < s->nentries; i++) {
|
|
7459
|
+
if (!s->entries[i].hash) continue;
|
|
7460
|
+
s->key_retain((void *)(uintptr_t)s->entries[i].key);
|
|
7461
|
+
out->data[out->len] = s->entries[i].key;
|
|
7462
|
+
out->present[out->len++] = SCR_ARR_VALUE;
|
|
7375
7463
|
}
|
|
7376
7464
|
return out;
|
|
7377
7465
|
}
|