diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-18 09:58:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-18 09:58:23 +0200 |
commit | a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9 (patch) | |
tree | d976683461a0f427d2f1ef79a8732a048dd0c67b /vmemalloc.c | |
parent | Merge tag '1.3' into since (diff) | |
parent | Update VERSION_MINOR (diff) | |
download | libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.gz libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.bz2 libsimple-a69f0f613687edf6c1f1ee83b462f77e8ea3c9a9.tar.xz |
Merge tag '1.4' into since
Version 1.4
Diffstat (limited to 'vmemalloc.c')
-rw-r--r-- | vmemalloc.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/vmemalloc.c b/vmemalloc.c index 8d92035..d725374 100644 --- a/vmemalloc.c +++ b/vmemalloc.c @@ -1,5 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include "libsimple.h" +#include "common.h" #include <stdalign.h> #ifndef TEST @@ -76,7 +76,7 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap) case LIBSIMPLE_MEMALLOC_CONDITIONAL_ZERO_INIT: if (state->zero_init >= 0) goto inval; - state->zero_init = va_arg(ap, int); + state->zero_init = (char)va_arg(ap, int); state->zero_init = !!state->zero_init; break; @@ -158,23 +158,35 @@ vmemalloc_parse_args(struct memalloc_state *state, size_t n, va_list ap) } } - return 0; inval: errno = EINVAL; return -1; } +LIBSIMPLE_GCC_ONLY__(__attribute__((__const__))) static size_t gcd(size_t u, size_t v) { size_t t; int shift = 0; /* Not needed because u>0, v>0: if (!(u | v)) return u + v; */ - while (!((u | v) & 1)) u >>= 1, v >>= 1, shift++; - while (!(u & 1)) u >>= 1; + while (!((u | v) & 1)) { + u >>= 1; + v >>= 1; + shift++; + } + while (!(u & 1)) { + u >>= 1; + } do { - while (!(v & 1)) v >>= 1; - if (u > v) t = u, u = v, v = t; + while (!(v & 1)) { + v >>= 1; + } + if (u > v) { + t = u; + u = v; + v = t; + } } while (v -= u); return u << shift; } |