]> mj.ucw.cz Git - libucw.git/commitdiff
Gary: GARY_PUSH and GARY_POP have lost the 2nd argument
authorMartin Mares <mj@ucw.cz>
Tue, 28 Jan 2014 15:27:54 +0000 (16:27 +0100)
committerMartin Mares <mj@ucw.cz>
Tue, 28 Jan 2014 15:27:54 +0000 (16:27 +0100)
Having to tell "yessir, just one element" on each call was just too
inconvenient.

ucw/doc/relnotes.txt
ucw/gary.c
ucw/gary.h
ucw/mainloop.c
ucw/opt-help.c

index 2b4134483ffb9fbc687ad1268a7f2075c1e90b4e..9ab1921f30b52bdb484b77c221ab36b1d6c23214 100644 (file)
@@ -17,6 +17,10 @@ Release notes
   our <<conf:,configuration file parser>>. The <<conf:getopt_h,getopt>> module
   has been obsoleted
 * `<stdbool.h>` is automatically included by `<ucw/lib.h>`.
+* *Incompatible:* It turned out that almost all users of the growing array
+  module push/pop individual elements. Therefore, we have removed the second
+  argument (item count) of `GARY_PUSH` and `GARY_POP`. If you want to push/pop
+  multiple elements at once, use `GARY_PUSH_MULTI` and `GARY_POP_MULTI`.
 * *Incompatible:* The interface of the <<heap:,heap>> module was cleaned up
    to remove non-systematic side-effects. The `HEAP_INSERT` operation is now
    a proper insert (previously, it was just cleanup after insertion performed
@@ -45,7 +49,7 @@ Release notes
   have been added.
 * The fastbuf I/O layer received a new back-end <<fastbuf:fbmulti,fb_multi>>,
   which concatenates several fastbuf streams to form a single virtual stream.
-* *Incompatible* The `UCW::CGI` Perl module has its custom error handlers
+* *Incompatible:* The `UCW::CGI` Perl module has its custom error handlers
   (which override default Perl error handlers) split off to a separate module
   `UCW::CGI::ErrorHandler`.
 * Added <<varint:,varint>> module for efficient UTF-8-like encoding of 64-bit
index 7eb8cabcb08b026b9a7965f936932cd98f4d1e8d..10b73288d57f250e6a1d1a7f7668e0cd637c001b 100644 (file)
@@ -87,11 +87,11 @@ int main(void)
       a[i] = i+1;
     }
 
-  GARY_PUSH(a, 1);
-  *GARY_PUSH(a, 1) = 10;
-  *GARY_PUSH(a, 1) = 20;
-  *GARY_PUSH(a, 1) = 30;
-  GARY_POP(a, 1);
+  GARY_PUSH(a);
+  *GARY_PUSH(a) = 10;
+  *GARY_PUSH(a) = 20;
+  *GARY_PUSH(a) = 30;
+  GARY_POP(a);
   GARY_FIX(a);
 
   for (int i=0; i<(int)GARY_SIZE(a); i++)
index fc19ae6d0e59a98e4d7a93463204324d8f99e7e4..0da8f690fe95da61e96925d45b8cbeda194528b9 100644 (file)
@@ -34,7 +34,7 @@ struct gary_hdr {
 #define GARY_RESIZE(ptr, n) ((ptr) = gary_set_size((ptr), (n)))
 #define GARY_INIT_OR_RESIZE(ptr, n) (ptr) = (ptr) ? gary_set_size((ptr), (n)) : gary_init(sizeof(*(ptr)), (n), 0)
 
-#define GARY_PUSH(ptr, n) ({                                           \
+#define GARY_PUSH_MULTI(ptr, n) ({                                     \
   struct gary_hdr *_h = GARY_HDR(ptr);                                 \
   typeof(*(ptr)) *_c = &(ptr)[_h->num_elts];                           \
   size_t _n = n;                                                       \
@@ -42,8 +42,10 @@ struct gary_hdr {
   if (_h->num_elts > _h->have_space)                                   \
     (ptr) = gary_push_helper((ptr), _n, (byte **) &_c);                        \
   _c; })
+#define GARY_PUSH(ptr) GARY_PUSH_MULTI(ptr, 1)
 
-#define GARY_POP(ptr, n) GARY_HDR(ptr)->num_elts -= (n)
+#define GARY_POP_MULTI(ptr, n) GARY_HDR(ptr)->num_elts -= (n)
+#define GARY_POP(ptr) GARY_POP_MULTI(ptr, 1)
 #define GARY_FIX(ptr) (ptr) = gary_fix((ptr))
 
 /* Internal functions */
index b5e54965bb87de3e8fab2b3ba877b4c491553832..5fdc5ef42678146b194a0602aeb73e628fc65800 100644 (file)
@@ -277,7 +277,7 @@ timer_add(struct main_timer *tm, timestamp_t expires)
          HEAP_DELETE(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm->index);
          tm->index = 0;
          tm->expires = 0;
-         GARY_POP(m->timer_table, 1);
+         GARY_POP(m->timer_table);
        }
       else
        {
index 4166cc5f717e627e41e993b0a7e7d53dd83f5885..199427d08d4ef77538d7829bcab9481da3b7ea15 100644 (file)
@@ -34,7 +34,7 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
     return;
 
   if (item->cls == OPT_CL_HELP) {
-    struct help_line *l = GARY_PUSH(h->lines, 1);
+    struct help_line *l = GARY_PUSH(h->lines);
     l->extra = item->help ? : "";
     return;
   }
@@ -42,7 +42,7 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
   if (item->letter >= OPT_POSITIONAL_TAIL)
     return;
 
-  struct help_line *first = GARY_PUSH(h->lines, 1);
+  struct help_line *first = GARY_PUSH(h->lines);
   if (item->help) {
     char *text = mp_strdup(h->pool, item->help);
     struct help_line *l = first;
@@ -64,7 +64,7 @@ static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
 
       text = eol;
       if (text)
-       l = GARY_PUSH(h->lines, 1);
+       l = GARY_PUSH(h->lines);
     }
   }