diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 99e4822f..f2586865 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -500,9 +500,9 @@ B fchars_c2(B d, B w, B x) { } static NFnDesc* fBytesDesc; B fbytes_c1(B d, B x) { - TmpFile* tf = file_bytes(path_resolve(nfn_objU(d), x)); + I8Arr* tf = file_bytes(path_resolve(nfn_objU(d), x)); usz ia = tf->ia; u8* p = (u8*)tf->a; - u32* rp; B r = m_c32arrv(&rp, ia); + u8* rp; B r = m_c8arrv(&rp, ia); for (i64 i = 0; i < ia; i++) rp[i] = p[i]; ptr_dec(tf); return r; diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index dc0a835b..0c6863a2 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -197,13 +197,13 @@ static void* nvm_alloc(u64 sz) { // void* r = mmap(NULL, sz, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON|MAP_32BIT, -1, 0); // if (r==MAP_FAILED) thrM("JIT: Failed to allocate executable memory"); // return r; - TmpFile* src = mmX_allocN(fsizeof(TmpFile,a,u8,sz), t_i8arr); + I8Arr* src = mmX_allocN(fsizeof(I8Arr,a,u8,sz), t_i8arr); src->ia = sz; arr_shVec((Arr*)src); return src->a; } void nvm_free(u8* ptr) { - if (!USE_PERF) mmX_free((Value*)RFLD(ptr, TmpFile, a)); + if (!USE_PERF) mmX_free((Value*)RFLD(ptr, I8Arr, a)); } diff --git a/src/utils/file.c b/src/utils/file.c index e2093c5b..70397faf 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -25,25 +25,25 @@ static DIR* dir_open(B path) { // doesn't consume return f; } -TmpFile* file_bytes(B path) { // consumes +I8Arr* file_bytes(B path) { // consumes FILE* f = file_open(path, "read", "r"); fseek(f, 0, SEEK_END); u64 len = ftell(f); fseek(f, 0, SEEK_SET); - TmpFile* src = m_arr(fsizeof(TmpFile,a,u8,len), t_i8arr, len); arr_shVec((Arr*)src); + I8Arr* src = m_arr(fsizeof(I8Arr,a,u8,len), t_i8arr, len); arr_shVec((Arr*)src); if (fread((char*)src->a, 1, len, f)!=len) thrF("Error reading file \"%R\"", path); dec(path); fclose(f); return src; } B file_chars(B path) { // consumes - TmpFile* c = file_bytes(path); + I8Arr* c = file_bytes(path); B r = fromUTF8((char*)c->a, c->ia); ptr_dec(c); return r; } B file_lines(B path) { // consumes - TmpFile* tf = file_bytes(path); + I8Arr* tf = file_bytes(path); usz ia = tf->ia; u8* p = (u8*)tf->a; usz lineCount = 0; for (usz i = 0; i < ia; i++) { diff --git a/src/utils/file.h b/src/utils/file.h index 0c200214..e1c8e39f 100644 --- a/src/utils/file.h +++ b/src/utils/file.h @@ -1,17 +1,12 @@ #pragma once #include "utf.h" -typedef struct TmpFile { // to be turned into a proper I8Arr - struct Arr; - i8 a[]; -} TmpFile; - B path_resolve(B base, B rel); // consumes rel; assumes base is a char vector or bi_N B path_dir(B path); // consumes; returns directory part of file path, with trailing slash B path_abs(B path); // consumes; returns absolute version of the path; propagates bi_N FILE* file_open(B path, char* desc, char* mode); // doesn't consume path -TmpFile* file_bytes(B path); // consumes +I8Arr* file_bytes(B path); // consumes B file_chars(B path); // consumes B file_lines(B path); // consumes