Browse code

core: use pointer to pv_spec_t on lvalue union. Use pv_cache_get() on interpreter.

Victor Seva authored on 29/05/2013 10:24:00
Showing 3 changed files
... ...
@@ -2611,17 +2611,10 @@ attr_id_any_str:
2611 2611
 	;
2612 2612
 
2613 2613
 pvar:	PVAR {
2614
-			pv_spec=pkg_malloc(sizeof(*pv_spec));
2615
-			if (!pv_spec) {
2616
-				yyerror("Not enough memory");
2617
-				YYABORT;
2618
-			}
2619
-			memset(pv_spec, 0, sizeof(*pv_spec));
2620 2614
 			s_tmp.s=$1; s_tmp.len=strlen($1);
2621
-			if (pv_parse_spec(&s_tmp, pv_spec)==0){
2622
-				yyerror("unknown script pseudo variable %s", $1 );
2623
-				pkg_free(pv_spec);
2624
-				pv_spec=0;
2615
+			pv_spec=pv_cache_get(&s_tmp);
2616
+			if (!pv_spec) {
2617
+				yyerror("Can't get from cache: %s", $1);
2625 2618
 				YYABORT;
2626 2619
 			}
2627 2620
 			$$=pv_spec;
... ...
@@ -2636,12 +2629,8 @@ avp_pvar:	AVP_OR_PVAR {
2636 2636
 				}
2637 2637
 				memset(lval_tmp, 0, sizeof(*lval_tmp));
2638 2638
 				s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
2639
-				if (pv_parse_spec2(&s_tmp, &lval_tmp->lv.pvs, 1)==0){
2640
-					/* not a pvar, try avps */
2641
-					/* lval_tmp might be partially filled by the failed
2642
-					   pv_parse_spec2() (especially if the avp name is the
2643
-					   same as a pv class) => clean it again */
2644
-					memset(lval_tmp, 0, sizeof(*lval_tmp));
2639
+				lval_tmp->lv.pvs = pv_cache_get(&s_tmp);
2640
+				if (lval_tmp->lv.pvs==NULL){
2645 2641
 					lval_tmp->lv.avps.type|= AVP_NAME_STR;
2646 2642
 					lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
2647 2643
 					lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
... ...
@@ -2688,15 +2677,14 @@ lval: attr_id_ass {
2688 2688
 						yyerror("Not enough memory");
2689 2689
 						YYABORT;
2690 2690
 					}
2691
-					lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=*($1);
2692
-					pkg_free($1); /* free the pvar spec we just copied */
2691
+					lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=$1;
2693 2692
 					$$=lval_tmp;
2694 2693
 				}
2695 2694
 	| avp_pvar    {
2696 2695
 					if (($1)->type==LV_PVAR){
2697
-						if (!pv_is_w(&($1)->lv.pvs))
2696
+						if (!pv_is_w($1->lv.pvs))
2698 2697
 							yyerror("read only pvar in assignment left side");
2699
-						if ($1->lv.pvs.trans!=0)
2698
+						if ($1->lv.pvs->trans!=0)
2700 2699
 							yyerror("pvar with transformations in assignment"
2701 2700
 									" left side");
2702 2701
 					}
... ...
@@ -2715,7 +2703,7 @@ rval: intno			{$$=mk_rve_rval(RV_INT, (void*)$1); }
2715 2715
 									$$=mk_rve_rval(RV_AVP, &$1->lv.avps);
2716 2716
 									break;
2717 2717
 								case LV_PVAR:
2718
-									$$=mk_rve_rval(RV_PVAR, &$1->lv.pvs);
2718
+									$$=mk_rve_rval(RV_PVAR, $1->lv.pvs);
2719 2719
 									break;
2720 2720
 								default:
2721 2721
 									yyerror("BUG: invalid lvalue type ");
... ...
@@ -255,7 +255,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
255 255
 		pv_get_null(msg, 0, &pval)
256 256
 	
257 257
 	destroy_pval=0;
258
-	pvar=&lv->lv.pvs;
258
+	pvar=lv->lv.pvs;
259 259
 	if (unlikely(!pv_is_w(pvar))){
260 260
 		ERR("read only pvar\n");
261 261
 		goto error;
... ...
@@ -35,7 +35,7 @@
35 35
 #include "action.h"
36 36
 
37 37
 union lval_u{
38
-	pv_spec_t pvs;
38
+	pv_spec_t *pvs;
39 39
 	avp_spec_t avps;
40 40
 };
41 41