aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-04-26 23:17:02 +0200
committerMattias Andrée <maandree@kth.se>2016-04-26 23:17:02 +0200
commitc07798feb5475b47562d6f9e90a564fc1121d25e (patch)
treed7c9577a9974ff8f04b000278c3937b26096ed0a
parentzzero1 did not guarantee that all arguments were evaulated exactly once, thus made static inline (diff)
downloadlibzahl-c07798feb5475b47562d6f9e90a564fc1121d25e.tar.gz
libzahl-c07798feb5475b47562d6f9e90a564fc1121d25e.tar.bz2
libzahl-c07798feb5475b47562d6f9e90a564fc1121d25e.tar.xz
Add, and use, libzahl_memfailure for conciseness, also fix possible unset errno
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--src/allocator.c7
-rw-r--r--src/internals.h12
-rw-r--r--src/zsetup.c7
-rw-r--r--src/zstr.c4
4 files changed, 15 insertions, 15 deletions
diff --git a/src/allocator.c b/src/allocator.c
index 80668f1..10170ae 100644
--- a/src/allocator.c
+++ b/src/allocator.c
@@ -22,11 +22,8 @@ libzahl_realloc(z_t a, size_t need)
a->chars = new;
} else {
a->chars = realloc(a->chars, new_size * sizeof(zahl_char_t));
- if (unlikely(!a->chars)) {
- if (!errno) /* sigh... */
- errno = ENOMEM;
- libzahl_failure(errno);
- }
+ if (unlikely(!a->chars))
+ libzahl_memfailure();
}
a->alloced = new_size;
}
diff --git a/src/internals.h b/src/internals.h
index 6454a21..40dd74d 100644
--- a/src/internals.h
+++ b/src/internals.h
@@ -135,6 +135,14 @@ libzahl_failure(int error)
}
static inline void
+libzahl_memfailure()
+{
+ if (!errno) /* sigh... */
+ errno = ENOENT;
+ libzahl_failure(errno);
+}
+
+static inline void
zmemcpy(zahl_char_t *restrict d, const zahl_char_t *restrict s, register size_t n)
{
while (n--)
@@ -322,9 +330,7 @@ zinit_temp(z_t a)
libzahl_temp_stack = realloc(old, 2 * n * sizeof(*libzahl_temp_stack));
if (unlikely(!libzahl_temp_stack)) {
libzahl_temp_stack = old;
- if (!errno) /* sigh... */
- errno = ENOMEM;
- libzahl_failure(errno);
+ libzahl_memfailure();
}
libzahl_temp_stack_head = libzahl_temp_stack + n;
libzahl_temp_stack_end = libzahl_temp_stack_head + n;
diff --git a/src/zsetup.c b/src/zsetup.c
index e36bff3..212a1e9 100644
--- a/src/zsetup.c
+++ b/src/zsetup.c
@@ -45,11 +45,8 @@ zsetup(jmp_buf env)
zinit(libzahl_tmp_divmod_ds[i]);
libzahl_temp_stack = malloc(256 * sizeof(*libzahl_temp_stack));
- if (unlikely(!libzahl_temp_stack)) {
- if (!errno) /* sigh... */
- errno = ENOMEM;
- libzahl_failure(errno);
- }
+ if (unlikely(!libzahl_temp_stack))
+ libzahl_memfailure();
libzahl_temp_stack_head = libzahl_temp_stack;
libzahl_temp_stack_end = libzahl_temp_stack + 256;
}
diff --git a/src/zstr.c b/src/zstr.c
index cd237df..d10cdff 100644
--- a/src/zstr.c
+++ b/src/zstr.c
@@ -63,7 +63,7 @@ zstr(z_t a, char *b)
if (unlikely(zzero(a))) {
if (unlikely(!b) && unlikely(!(b = malloc(2))))
- libzahl_failure(errno);
+ libzahl_memfailure();
b[0] = '0';
b[1] = 0;
return b;
@@ -72,7 +72,7 @@ zstr(z_t a, char *b)
n = zstr_length(a, 10);
if (unlikely(!b) && unlikely(!(b = malloc(n + 1))))
- libzahl_failure(errno);
+ libzahl_memfailure();
neg = znegative(a);
zabs(num, a);