Browse Source

Implementing RPN expression re-initialization

Yann Weber 4 years ago
parent
commit
680b4ee1ff
2 changed files with 35 additions and 5 deletions
  1. 30
    5
      rpn_jit.c
  2. 5
    0
      rpn_jit.h

+ 30
- 5
rpn_jit.c View File

58
 	return 0;
58
 	return 0;
59
 }
59
 }
60
 
60
 
61
+int rpn_expr_reinit(rpn_expr_t* expr)
62
+{
63
+#ifdef DEBUG
64
+	if(!expr)
65
+	{
66
+		dprintf(2, "Error, NULL ptr given as expression to rpn_expr_compile");
67
+		errno = EINVAL;
68
+		return -1;
69
+	}
70
+#endif
71
+	bzero(expr->code_map, expr->code_map_sz);
72
+	bzero(expr->stack, sizeof(unsigned long) * stack_sz);
73
+	if(_rpn_expr_init_map(expr) < 0)
74
+	{
75
+		snprintf(expr->err_reason, 128, 
76
+			"Unable to re-init code map : %s", strerror(errno));
77
+		free(expr->expr);
78
+		expr->state = RPN_ERROR;
79
+		return -1;
80
+	}
81
+}
82
+
61
 int rpn_expr_compile(rpn_expr_t *expr, const char *code)
83
 int rpn_expr_compile(rpn_expr_t *expr, const char *code)
62
 {
84
 {
63
 #ifdef DEBUG
85
 #ifdef DEBUG
445
 
467
 
446
 int _rpn_expr_init_map(rpn_expr_t* expr)
468
 int _rpn_expr_init_map(rpn_expr_t* expr)
447
 {
469
 {
448
-	expr->code_map_sz = RPN_MAP_CHUNK;
449
-	expr->code_map = mmap(NULL, expr->code_map_sz, PROT_READ | PROT_WRITE,
450
-		MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
451
-	if(!expr->code_map)
470
+	if(!expr->code_map_sz)
452
 	{
471
 	{
453
-		return -1;
472
+		expr->code_map_sz = RPN_MAP_CHUNK;
473
+		expr->code_map = mmap(NULL, expr->code_map_sz, PROT_READ | PROT_WRITE,
474
+			MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
475
+		if(!expr->code_map)
476
+		{
477
+			return -1;
478
+		}
454
 	}
479
 	}
455
 	expr->code_map_ptr = expr->code_map;
480
 	expr->code_map_ptr = expr->code_map;
456
 	if(CODE_PART_CPY(expr, rpn_exec))
481
 	if(CODE_PART_CPY(expr, rpn_exec))

+ 5
- 0
rpn_jit.h View File

146
 int rpn_expr_init(rpn_expr_t* expr, const unsigned char stack_sz,
146
 int rpn_expr_init(rpn_expr_t* expr, const unsigned char stack_sz,
147
 	  const size_t args_count);
147
 	  const size_t args_count);
148
 
148
 
149
+/**@brief Reinit an existing @ref rpn_expr_s
150
+ * @param expr
151
+ */
152
+int rpn_expr_reinit(rpn_expr_t* expr);
153
+
149
 /**@brief Starts a new initialized expression from an expression string
154
 /**@brief Starts a new initialized expression from an expression string
150
  * @param expr Pointer on an intialized expression ( see @ref rpn_expr_init )
155
  * @param expr Pointer on an intialized expression ( see @ref rpn_expr_init )
151
  * @param code '\0' terminated string representing the RPN expr
156
  * @param code '\0' terminated string representing the RPN expr

Loading…
Cancel
Save