ww: make allocation failures stage-equivalent
This commit is contained in:
@@ -1010,6 +1010,23 @@ fn sepmakeints(count: i32, out: *[]i32) bool = {
|
||||
return false;
|
||||
};
|
||||
|
||||
fn sepmakeptrs(count: i32, out: *[]*u8) bool = {
|
||||
if (count < 0) {
|
||||
sepfailsize();
|
||||
return false;
|
||||
};
|
||||
let allocation: ([]*u8 | nomem) = sepallocptrs(count);
|
||||
match (allocation) {
|
||||
case let value: []*u8 => {
|
||||
value.len = count;
|
||||
*out = value;
|
||||
return true;
|
||||
};
|
||||
case nomem => { sepfailnomem(); return false; };
|
||||
};
|
||||
return false;
|
||||
};
|
||||
|
||||
fn sepreservepackages(g: *sepgraph, need: i32) bool = {
|
||||
if (need <= g.pkg.len) { return true; };
|
||||
let cap: i32 = sepgrowcap(g.pkg.len, need);
|
||||
@@ -2599,6 +2616,7 @@ fn sepreverseimportbase(g: *sepgraph, p: *seppkg, context: i32,
|
||||
root.ptr = searchpath + pos;
|
||||
root.len = (end - pos): i32;
|
||||
let canonroot: *u8 = canonicaldir(root);
|
||||
if (canonroot == nil && sepfatalallocation) { return -1; };
|
||||
if (canonroot != nil) {
|
||||
let rn: u64 = cstrlen(canonroot);
|
||||
let dn: u64 = cstrlen(p.canon);
|
||||
@@ -2623,6 +2641,9 @@ fn sepreverseimportbase(g: *sepgraph, p: *seppkg, context: i32,
|
||||
cstrlen(rel));
|
||||
if (selected != nil) {
|
||||
let selectedcanon: *u8 = canonicaldir(pathstr(selected));
|
||||
if (selectedcanon == nil && sepfatalallocation) {
|
||||
return -1;
|
||||
};
|
||||
if (selectedcanon != nil
|
||||
&& cstreq(selectedcanon, p.canon)) {
|
||||
return 1;
|
||||
@@ -4485,20 +4506,21 @@ fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
|
||||
let inccap: u64 = 1u64;
|
||||
let capi: i32 = start;
|
||||
for (capi < argc) {
|
||||
inccap += cstrlen(argv[capi]) + 1u64;
|
||||
if (!sepaddbytes(&inccap, cstrlen(argv[capi]))
|
||||
|| !sepaddbytes(&inccap, 1u64)) { return 1; };
|
||||
capi += 1;
|
||||
};
|
||||
let incs: []u8 = alloc([], inccap)!;
|
||||
incs.len = inccap: i32;
|
||||
let incs: []u8;
|
||||
if (!sepmakebytes(inccap, &incs)) { return 1; };
|
||||
let incoff: u64 = 0u64;
|
||||
cstrseal(incs.ptr, 0u64);
|
||||
|
||||
let maxlflags: i32 = 32;
|
||||
let libdirs: []*u8 = alloc([], maxlflags: u64)!;
|
||||
libdirs.len = maxlflags;
|
||||
let libdirs: []*u8;
|
||||
if (!sepmakeptrs(maxlflags, &libdirs)) { return 1; };
|
||||
let nlibdirs: i32 = 0;
|
||||
let libs: []*u8 = alloc([], maxlflags: u64)!;
|
||||
libs.len = maxlflags;
|
||||
let libs: []*u8;
|
||||
if (!sepmakeptrs(maxlflags, &libs)) { return 1; };
|
||||
let nlibs: i32 = 0;
|
||||
|
||||
let i: i32 = start;
|
||||
@@ -4696,20 +4718,21 @@ fn dorun(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
|
||||
let inccap: u64 = 1u64;
|
||||
let capi: i32 = start;
|
||||
for (capi < argc) {
|
||||
inccap += cstrlen(argv[capi]) + 1u64;
|
||||
if (!sepaddbytes(&inccap, cstrlen(argv[capi]))
|
||||
|| !sepaddbytes(&inccap, 1u64)) { return 1; };
|
||||
capi += 1;
|
||||
};
|
||||
let incs: []u8 = alloc([], inccap)!;
|
||||
incs.len = inccap: i32;
|
||||
let incs: []u8;
|
||||
if (!sepmakebytes(inccap, &incs)) { return 1; };
|
||||
let incoff: u64 = 0u64;
|
||||
cstrseal(incs.ptr, 0u64);
|
||||
|
||||
let maxlflags: i32 = 32;
|
||||
let libdirs: []*u8 = alloc([], maxlflags: u64)!;
|
||||
libdirs.len = maxlflags;
|
||||
let libdirs: []*u8;
|
||||
if (!sepmakeptrs(maxlflags, &libdirs)) { return 1; };
|
||||
let nlibdirs: i32 = 0;
|
||||
let libs: []*u8 = alloc([], maxlflags: u64)!;
|
||||
libs.len = maxlflags;
|
||||
let libs: []*u8;
|
||||
if (!sepmakeptrs(maxlflags, &libs)) { return 1; };
|
||||
let nlibs: i32 = 0;
|
||||
|
||||
let i: i32 = start;
|
||||
@@ -5001,11 +5024,12 @@ fn dotest(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
|
||||
let inccap: u64 = 1u64;
|
||||
let capi: i32 = start;
|
||||
for (capi < argc) {
|
||||
inccap += cstrlen(argv[capi]) + 1u64;
|
||||
if (!sepaddbytes(&inccap, cstrlen(argv[capi]))
|
||||
|| !sepaddbytes(&inccap, 1u64)) { return 1; };
|
||||
capi += 1;
|
||||
};
|
||||
let incs: []u8 = alloc([], inccap)!;
|
||||
incs.len = inccap: i32;
|
||||
let incs: []u8;
|
||||
if (!sepmakebytes(inccap, &incs)) { return 1; };
|
||||
let incoff: u64 = 0u64;
|
||||
cstrseal(incs.ptr, 0u64);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user