Browse code

script engine: rvalue fixes & cleanup

- fixed rval_str_add2()
- more functions are now "public"
- support for optimization levels

Andrei Pelinescu-Onciul authored on 10/12/2008 13:50:36
Showing 2 changed files
... ...
@@ -1099,12 +1099,11 @@ inline static struct rvalue* rval_str_add2(struct run_act_ctx* h,
1099 1099
 		s2=&rv2->v.s;
1100 1100
 	}
1101 1101
 	/* do the actual copy */
1102
-	ret->v.s.len=rv1->v.s.len;
1103
-	memmove(ret->buf+ret->v.s.len, s2->s, s2->len);
1102
+	memmove(ret->buf+rv1->v.s.len, s2->s, s2->len);
1104 1103
 	if (s1){
1105 1104
 		memcpy(ret->buf, s1->s, s1->len);
1106 1105
 	}
1107
-	ret->v.s.len+=s2->len;
1106
+	ret->v.s.len=rv1->v.s.len+s2->len;
1108 1107
 	ret->v.s.s[ret->v.s.len]=0;
1109 1108
 	/* cleanup if needed */
1110 1109
 	if (flags & RV_CNT_ALLOCED_F)
... ...
@@ -1155,17 +1154,6 @@ error:
1155 1155
 
1156 1156
 
1157 1157
 
1158
-/* forward decl. */
1159
-inline static int rval_expr_eval_rvint(struct run_act_ctx* h,
1160
-									   struct sip_msg* msg,
1161
-									   struct rvalue** res_rv,
1162
-									   int* res_i,
1163
-									   struct rval_expr* rve,
1164
-									   struct rval_cache* cache
1165
-									   );
1166
-
1167
-
1168
-
1169 1158
 /** evals an integer expr  to an int.
1170 1159
  * 
1171 1160
  *  *res=(int)eval(rve)
... ...
@@ -1276,7 +1264,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg,
1276 1276
  * modified only if rv_chg_in_place() returns true.
1277 1277
  * @result  0 on success, -1 on error,  sets *res_rv or *res_i.
1278 1278
  */
1279
-inline static int rval_expr_eval_rvint(struct run_act_ctx* h,
1279
+int rval_expr_eval_rvint(			   struct run_act_ctx* h,
1280 1280
 									   struct sip_msg* msg,
1281 1281
 									   struct rvalue** res_rv,
1282 1282
 									   int* res_i,
... ...
@@ -1645,6 +1633,8 @@ struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1,
1645 1645
  */
1646 1646
 static int rve_can_optimize_int(struct rval_expr* rve)
1647 1647
 {
1648
+	if (scr_opt_lev<1)
1649
+		return 0;
1648 1650
 	if (rve->op == RVE_RVAL_OP)
1649 1651
 		return 0;
1650 1652
 	if (rve->left.rve->op != RVE_RVAL_OP)
... ...
@@ -1671,6 +1661,8 @@ static int rve_can_optimize_int(struct rval_expr* rve)
1671 1671
  */
1672 1672
 static int rve_can_optimize_str(struct rval_expr* rve)
1673 1673
 {
1674
+	if (scr_opt_lev<1)
1675
+		return 0;
1674 1676
 	if (rve->op == RVE_RVAL_OP)
1675 1677
 		return 0;
1676 1678
 	DBG("rve_can_optimize_str: left %d, right %d\n", 
... ...
@@ -174,6 +174,11 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg,
174 174
 /** evals a rval expr.. */
175 175
 struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg,
176 176
 								struct rval_expr* rve);
177
+/** evals an integer expr  to an int or rvalue. */
178
+int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg,
179
+						 struct rvalue** rv_res, int* i_res,
180
+						 struct rval_expr* rve, struct rval_cache* cache);
181
+
177 182
 
178 183
 /** guess the type of an expression.  */
179 184
 enum rval_type rve_guess_type(struct rval_expr* rve);