add debug check for correct array size calculation
This commit is contained in:
parent
b8730798c1
commit
55f7baf894
@ -63,6 +63,15 @@ extern u8 const arrTypeBitsLog[];
|
|||||||
#define arrTypeBitsLog(X) arrTypeBitsLog[X]
|
#define arrTypeBitsLog(X) arrTypeBitsLog[X]
|
||||||
#define arrNewType(X) el2t(TIi(X,elType))
|
#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
|
// Log of width in bits: max of 7, and also return 7 if not power of 2
|
||||||
SHOULD_INLINE u8 cellWidthLog(B x) {
|
SHOULD_INLINE u8 cellWidthLog(B x) {
|
||||||
assert(isArr(x) && RNK(x)>=1);
|
assert(isArr(x) && RNK(x)>=1);
|
||||||
|
|||||||
@ -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; })
|
#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);
|
Arr* r = mm_alloc(sz, type);
|
||||||
r->ia = ia;
|
r->ia = ia;
|
||||||
return r;
|
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) {
|
static ShArr* m_shArr(ur r) {
|
||||||
assert(r>1);
|
assert(r>1);
|
||||||
return ((ShArr*)mm_alloc(fsizeof(ShArr, a, usz, r), t_shape));
|
return ((ShArr*)mm_alloc(fsizeof(ShArr, a, usz, r), t_shape));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user