From: Martin Mares Date: Tue, 28 Jan 2014 15:27:54 +0000 (+0100) Subject: Gary: GARY_PUSH and GARY_POP have lost the 2nd argument X-Git-Tag: v5.99~20 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=cfae7ebef2a2f2f50cfb9a45eb2d6ce0905680fe;p=libucw.git Gary: GARY_PUSH and GARY_POP have lost the 2nd argument Having to tell "yessir, just one element" on each call was just too inconvenient. --- diff --git a/ucw/doc/relnotes.txt b/ucw/doc/relnotes.txt index 2b413448..9ab1921f 100644 --- a/ucw/doc/relnotes.txt +++ b/ucw/doc/relnotes.txt @@ -17,6 +17,10 @@ Release notes our <>. The <> module has been obsoleted * `` is automatically included by ``. +* *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 <> 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 <>, 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 <> module for efficient UTF-8-like encoding of 64-bit diff --git a/ucw/gary.c b/ucw/gary.c index 7eb8cabc..10b73288 100644 --- a/ucw/gary.c +++ b/ucw/gary.c @@ -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++) diff --git a/ucw/gary.h b/ucw/gary.h index fc19ae6d..0da8f690 100644 --- a/ucw/gary.h +++ b/ucw/gary.h @@ -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 */ diff --git a/ucw/mainloop.c b/ucw/mainloop.c index b5e54965..5fdc5ef4 100644 --- a/ucw/mainloop.c +++ b/ucw/mainloop.c @@ -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 { diff --git a/ucw/opt-help.c b/ucw/opt-help.c index 4166cc5f..199427d0 100644 --- a/ucw/opt-help.c +++ b/ucw/opt-help.c @@ -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); } }