diff options
author | whitequark <whitequark@whitequark.org> | 2020-12-29 13:35:31 +0000 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2021-11-12 12:38:41 +0100 |
commit | e289a8059eac7d0514f8a20ffe6464fc18db1450 (patch) | |
tree | 9cd00ced8077caeb9bdf376911ab1b4e3b5fe355 | |
parent | d2d6bbd9f86f61fc9b5cc7d703e1386bbd6ad6a2 (diff) | |
download | abc-e289a8059eac7d0514f8a20ffe6464fc18db1450.tar.gz abc-e289a8059eac7d0514f8a20ffe6464fc18db1450.tar.bz2 abc-e289a8059eac7d0514f8a20ffe6464fc18db1450.zip |
Add WASI platform support to bsat2 and glucose.
Abort on OOM since there are no C++ exceptions yet.
Signed-off-by: Miodrag Milanovic <mmicko@gmail.com>
-rw-r--r-- | src/sat/bsat2/Alloc.h | 8 | ||||
-rw-r--r-- | src/sat/bsat2/Vec.h | 4 | ||||
-rw-r--r-- | src/sat/bsat2/XAlloc.h | 4 | ||||
-rw-r--r-- | src/sat/glucose/Alloc.h | 8 | ||||
-rw-r--r-- | src/sat/glucose/Vec.h | 4 | ||||
-rw-r--r-- | src/sat/glucose/XAlloc.h | 4 |
6 files changed, 32 insertions, 0 deletions
diff --git a/src/sat/bsat2/Alloc.h b/src/sat/bsat2/Alloc.h index 7f506cb5..9a65cf0c 100644 --- a/src/sat/bsat2/Alloc.h +++ b/src/sat/bsat2/Alloc.h @@ -97,7 +97,11 @@ void RegionAllocator<T>::capacity(uint32_t min_cap) cap += delta; if (cap <= prev_cap) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } // printf(" .. (%p) cap = %u\n", this, cap); @@ -119,7 +123,11 @@ RegionAllocator<T>::alloc(int size) // Handle overflow: if (sz < prev_sz) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif return prev_sz; } diff --git a/src/sat/bsat2/Vec.h b/src/sat/bsat2/Vec.h index f0e07d01..5eea6174 100644 --- a/src/sat/bsat2/Vec.h +++ b/src/sat/bsat2/Vec.h @@ -97,7 +97,11 @@ void vec<T>::capacity(int min_cap) { if (cap >= min_cap) return; int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } diff --git a/src/sat/bsat2/XAlloc.h b/src/sat/bsat2/XAlloc.h index 1da17602..33741e33 100644 --- a/src/sat/bsat2/XAlloc.h +++ b/src/sat/bsat2/XAlloc.h @@ -34,7 +34,11 @@ static inline void* xrealloc(void *ptr, size_t size) { void* mem = realloc(ptr, size); if (mem == NULL && errno == ENOMEM){ +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif }else return mem; } diff --git a/src/sat/glucose/Alloc.h b/src/sat/glucose/Alloc.h index e56b5441..a63de032 100644 --- a/src/sat/glucose/Alloc.h +++ b/src/sat/glucose/Alloc.h @@ -100,7 +100,11 @@ void RegionAllocator<T>::capacity(uint32_t min_cap) cap += delta; if (cap <= prev_cap) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } //printf(" .. (%p) cap = %u\n", this, cap); @@ -122,7 +126,11 @@ RegionAllocator<T>::alloc(int size) // Handle overflow: if (sz < prev_sz) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif return prev_sz; } diff --git a/src/sat/glucose/Vec.h b/src/sat/glucose/Vec.h index dd1bc20a..d2781635 100644 --- a/src/sat/glucose/Vec.h +++ b/src/sat/glucose/Vec.h @@ -100,7 +100,11 @@ void vec<T>::capacity(int min_cap) { if (cap >= min_cap) return; int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } diff --git a/src/sat/glucose/XAlloc.h b/src/sat/glucose/XAlloc.h index 233f834e..d1f1062a 100644 --- a/src/sat/glucose/XAlloc.h +++ b/src/sat/glucose/XAlloc.h @@ -39,7 +39,11 @@ static inline void* xrealloc(void *ptr, size_t size) { void* mem = realloc(ptr, size); if (mem == NULL && errno == ENOMEM){ +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif }else { return mem; } |