summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/arrFns.h9
-rw-r--r--src/core/stuff.h7
2 files changed, 15 insertions, 1 deletions
diff --git a/src/core/arrFns.h b/src/core/arrFns.h
index af357f4d..1257c9e0 100644
--- a/src/core/arrFns.h
+++ b/src/core/arrFns.h
@@ -63,6 +63,15 @@ extern u8 const arrTypeBitsLog[];
#define arrTypeBitsLog(X) arrTypeBitsLog[X]
#define arrNewType(X) el2t(TIi(X,elType))
+SHOULD_INLINE void arr_check_size(u64 sz, u8 type, usz ia) {
+ #if DEBUG
+ assert(IS_ANY_ARR(type) || type==t_harrPartial);
+ if (!IS_SLICE(type)) {
+ if (type==t_harr || type==t_harrPartial) assert(sz >= fsizeof(HArr,a,B,ia));
+ else assert(sz >= offsetof(TyArr,a) + (((ia<<arrTypeBitsLog(type))+7)>>3));
+ }
+ #endif
+}
// Log of width in bits: max of 7, and also return 7 if not power of 2
SHOULD_INLINE u8 cellWidthLog(B x) {
assert(isArr(x) && RNK(x)>=1);
diff --git a/src/core/stuff.h b/src/core/stuff.h
index d9cb0687..43f3d725 100644
--- a/src/core/stuff.h
+++ b/src/core/stuff.h
@@ -46,11 +46,16 @@ extern INIT_GLOBAL M_FillF fillFns[el_MAX];
#define WRAP(X,IA,MSG) ({ i64 wV=(i64)(X); u64 iaW=(IA); if(RARE((u64)wV >= iaW)) { if(wV<0) wV+= iaW; if((u64)wV >= iaW) {MSG;} }; (usz)wV; })
-static inline void* m_arr(u64 sz, u8 type, usz ia) {
+static inline void* m_arrUnchecked(u64 sz, u8 type, usz ia) {
Arr* r = mm_alloc(sz, type);
r->ia = ia;
return r;
}
+SHOULD_INLINE void arr_check_size(u64 sz, u8 type, usz ia);
+SHOULD_INLINE void* m_arr(u64 sz, u8 type, usz ia) {
+ arr_check_size(sz, type, ia);
+ return m_arrUnchecked(sz, type, ia);
+}
static ShArr* m_shArr(ur r) {
assert(r>1);
return ((ShArr*)mm_alloc(fsizeof(ShArr, a, usz, r), t_shape));