From 882280e6bd17eb372063247d4edaa7ac1a0bcbdd Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 21 May 2021 16:08:10 +0300 Subject: [PATCH] check fread/fwrite result and otherwise make gcc builds happy --- build | 1 + buildg | 3 ++- debugBuild | 2 +- src/file.c | 9 +++++---- src/h.h | 2 +- src/mut.c | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/build b/build index 0c63c2d6..12a7b53c 100755 --- a/build +++ b/build @@ -1,2 +1,3 @@ #!/usr/bin/env bash clang -std=gnu11 -O3 -Wall -Wno-microsoft-anon-tag -fms-extensions $@ -o BQN src/main.c -lm +# gcc -std=gnu11 -O3 -Wall -Wno-parentheses -Wno-misleading-indentation -fms-extensions $@ -o BQN src/main.c -lm diff --git a/buildg b/buildg index 88ffeb0e..7a6257a3 100755 --- a/buildg +++ b/buildg @@ -1,2 +1,3 @@ #!/usr/bin/env bash -clang -std=gnu11 -O3 -g -Wall -Wno-microsoft-anon-tag -fms-extensions $@ -fno-omit-frame-pointer -o BQN src/main.c -lm +clang -std=gnu11 -O3 -g -Wall -Wno-microsoft-anon-tag -fms-extensions -fno-omit-frame-pointer $@ -o BQN src/main.c -lm +# gcc -std=gnu11 -O3 -g -Wall -Wno-parentheses -Wno-misleading-indentation -fms-extensions -fno-omit-frame-pointer $@ -o BQN src/main.c -lm diff --git a/debugBuild b/debugBuild index dffd0139..a169c201 100755 --- a/debugBuild +++ b/debugBuild @@ -1,3 +1,3 @@ #!/usr/bin/env bash clang -DDEBUG -std=gnu11 -g -Wall -Wno-microsoft-anon-tag -fms-extensions $@ -o BQN src/main.c -lm -# clang -DDEBUG -std=gnu11 -g -Wall -Wno-microsoft-anon-tag -fms-extensions -o BQN -lm src/main.c +# gcc -DDEBUG -std=gnu11 -g -Wall -Wno-parentheses -Wno-misleading-indentation -fms-extensions $@ -o BQN src/main.c -lm diff --git a/src/file.c b/src/file.c index b07f7381..82061a0c 100644 --- a/src/file.c +++ b/src/file.c @@ -3,7 +3,7 @@ typedef struct TmpFile { // to be turned into a proper I8Arr i8 a[]; } TmpFile; -FILE* file_open(B path, char* desc, char* mode) { // consumes path; can error +FILE* file_open(B path, char* desc, char* mode) { // doesn't consume; can error u64 plen = utf8lenB(path); TALLOC(char, p, plen+1); toUTF8(path, p); @@ -11,7 +11,6 @@ FILE* file_open(B path, char* desc, char* mode) { // consumes path; can error FILE* f = fopen(p, mode); TFREE(p); if (f==NULL) thrF("Couldn't %S file \"%R\"", desc, path); - dec(path); return f; } @@ -22,7 +21,8 @@ TmpFile* file_bytes(B path) { // consumes; may throw fseek(f, 0, SEEK_SET); TmpFile* src = mm_allocN(fsizeof(TmpFile,a,u8,len), t_i8arr); arr_shVec(tag(src,ARR_TAG), len); - fread((char*)src->a, 1, len, f); + if (fread((char*)src->a, 1, len, f)!=len) thrF("Error reading file \"%R\"", path); + dec(path); fclose(f); return src; } @@ -81,7 +81,8 @@ void file_write(B path, B x) { // consumes path TALLOC(char, val, len); toUTF8(x, val); - fwrite(val, 1, len, f); + if (fwrite(val, 1, len, f) != len) thrF("Error writing to file \"%R\"", path); TFREE(val); + dec(path); fclose(f); } diff --git a/src/h.h b/src/h.h index c4f48863..e7897758 100644 --- a/src/h.h +++ b/src/h.h @@ -31,7 +31,7 @@ #define f64 double #define I32_MAX ((i32)((1LL<<31)-1)) #define I32_MIN ((i32)(-(1LL<<31))) -#define I64_MIN ((i64)(-(1LL<<63))) +#define I64_MIN ((i64)(1ULL<<63)) #define CHR_MAX 1114111 #define U16_MAX ((u16)~(u16)0) #define U32_MAX ((u32)~(u32)0) diff --git a/src/mut.c b/src/mut.c index 5c13a447..dc8399b2 100644 --- a/src/mut.c +++ b/src/mut.c @@ -20,7 +20,7 @@ void mut_to(Mut* m, u8 n) { case el_i32: m->val = a(m_i32arrp(&m->ai32, m->ia)); return; case el_f64: m->val = a(m_f64arrp(&m->af64, m->ia)); return; case el_c32: m->val = a(m_c32arrp(&m->ac32, m->ia)); return; - case el_B : HArr_p t = m_harrUp( m->ia); m->val = (Arr*)t.c; m->aB = t.c->a; return; + case el_B :; HArr_p t = m_harrUp( m->ia); m->val = (Arr*)t.c; m->aB = t.c->a; return; } } else { sprnk(m->val, 1);