always define DEBUG to 1 or 0

This commit is contained in:
dzaima 2025-05-31 18:55:58 +03:00
parent f843c7e96d
commit e2e73a5987
5 changed files with 10 additions and 17 deletions

View File

@ -204,9 +204,7 @@ NOINLINE B leading_axis_arith(FC2 fc2, B w, B x, usz* wsh, usz* xsh, ur mr) { //
assert(isArr(w) && isArr(x) && TI(w,elType)!=el_B && TI(x,elType)!=el_B && IA(w)!=0 && IA(x)!=0);
ur wr = RNK(w);
ur xr = RNK(x);
#if DEBUG
assert(wr!=xr && (mr==wr || mr==xr) && eqShPart(wsh, xsh, mr));
#endif
if (DEBUG) assert(wr!=xr && (mr==wr || mr==xr) && eqShPart(wsh, xsh, mr));
usz cam = shProd(xsh, 0, mr);
B b = mr==wr? x : w; // bigger argument

View File

@ -72,13 +72,13 @@ extern u8 const arrTypeBitsLog[];
#define arrNewType(X) el2t(TIi(X,elType))
SHOULD_INLINE void arr_check_size(u64 sz, u8 type, u64 ia) {
#if DEBUG
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 multWidthLog(usz n, u8 lw) { // Of n elements, 1<<lw bit

View File

@ -109,9 +109,7 @@ NOINLINE bool fillEqualF(B w, B x) { // doesn't consume; both args must be array
B withFill(B x, B fill) { // consumes both
assert(isArr(x));
#if DEBUG
validateFill(fill);
#endif
if (DEBUG) validateFill(fill);
u8 xt = TY(x);
if (noFill(fill) && xt!=t_fillarr && xt!=t_fillslice) return x;
switch(xt) {

11
src/h.h
View File

@ -21,6 +21,9 @@
#ifndef RANDSEED
#define RANDSEED 0
#endif
#ifndef DEBUG
#define DEBUG 0
#endif
#ifndef FFI
#define FFI 2
#ifndef CBQN_EXPORT
@ -655,16 +658,12 @@ static inline B inc(B x) {
return x;
}
static inline void decG(B x) {
#if DEBUG
assert(isVal(x) && v(x)->refc>0);
#endif
if (DEBUG) assert(isVal(x) && v(x)->refc>0);
Value* vx = v(x);
if(!--vx->refc) value_free(vx);
}
FORCE_INLINE void ptr_decT(Arr* x) { // assumes argument is an array and consists of non-heap-allocated elements
#if DEBUG
assert(x->refc>0);
#endif
if (DEBUG) assert(x->refc>0);
if (x->refc==1) TIv(x,freeT)((Value*) x);
else x->refc--;
}

View File

@ -95,9 +95,7 @@ enum {
void gc_onVisit(Value* x) {
switch (visit_mode) { default: UD;
case GC_DEC_REFC:
#if DEBUG
if(x->refc==0) fatal("decrementing refc 0");
#endif
if (DEBUG && x->refc==0) fatal("decrementing refc 0");
x->refc--;
return;