Browse Source

core expr. eval: added bug catcher

Added code for catching an easy to overlook bug (replacing in-line
a referenced rval during optimizing).
Andrei Pelinescu-Onciul 16 years ago
parent
commit
087be8daf0
1 changed files with 9 additions and 0 deletions
  1. 9 0
      rvalue.c

+ 9 - 0
rvalue.c

@@ -47,6 +47,8 @@
 
 #include "rvalue.h"
 
+#include <stdlib.h> /* abort() */
+
 /* minimum size alloc'ed for STR RVs (to accomodate
  * strops without reallocs) */
 #define RV_STR_EXTRA 80
@@ -2577,6 +2579,13 @@ static int rve_replace_with_val(struct rval_expr* rve, enum rval_type type,
 		if (rve_op_unary(rve->op)==0)
 			rve_destroy(rve->right.rve);
 	}else{
+		if (rve->left.rval.refcnt!=1){
+			BUG("trying to replace a referenced rval! (refcnt=%d)\n",
+					rve->left.rval.refcnt);
+			/* try to recover */
+			refcnt=rve->left.rval.refcnt;
+			abort(); /* find bugs quicker -- andrei */
+		}
 		rval_destroy(&rve->left.rval);
 	}
 	rval_init(&rve->left.rval, type, v, flags);