]> granicus.if.org Git - onig/commitdiff
set slot 1 and 2 in (*COUNT) and (*TOTAL_COUNT)
authorK.Kosako <kosako@sofnec.co.jp>
Thu, 8 Mar 2018 04:21:45 +0000 (13:21 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Thu, 8 Mar 2018 04:21:45 +0000 (13:21 +0900)
src/regexec.c

index d484500e885f8dd35d8cad104907ac476f0657e1..c5323221970db834fbf53cb9b4aa9a504d89add3 100644 (file)
@@ -5351,28 +5351,41 @@ onig_builtin_total_count(OnigCalloutArgs* args, void* user_data ARG_UNUSED)
   if (count_type != '>' && count_type != 'X' && count_type != '<')
     return ONIGERR_INVALID_CALLOUT_ARG;
 
-  slot = 0;
-  r = onig_get_callout_data_by_callout_args_self_dont_clear_old(args, slot,
+  r = onig_get_callout_data_by_callout_args_self_dont_clear_old(args, 0,
                                                                 &type, &val);
   if (r < ONIG_NORMAL)
     return r;
   else if (r > ONIG_NORMAL) {
     /* type == void: initial state */
-    type  = ONIG_TYPE_LONG;
     val.l = 0;
   }
 
   if (args->in == ONIG_CALLOUT_IN_RETRACTION) {
+    slot = 2;
     if (count_type == '<')
       val.l++;
     else if (count_type == 'X')
       val.l--;
   }
   else {
+    slot = 1;
     if (count_type != '<')
       val.l++;
   }
 
+  r = onig_set_callout_data_by_callout_args_self(args, 0, ONIG_TYPE_LONG, &val);
+  if (r != ONIG_NORMAL) return r;
+
+  /* slot 1: in progress counter, slot 2: in retraction counter */
+  r = onig_get_callout_data_by_callout_args_self_dont_clear_old(args, slot,
+                                                                &type, &val);
+  if (r < ONIG_NORMAL)
+    return r;
+  else if (r > ONIG_NORMAL) {
+    val.l = 0;
+  }
+
+  val.l++;
   r = onig_set_callout_data_by_callout_args_self(args, slot, ONIG_TYPE_LONG, &val);
   if (r != ONIG_NORMAL) return r;