From 03f37879ef167dba6f5944716c06da81902e436e Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 20 Sep 2019 19:55:29 +0000 Subject: We're down to ONE rogue sysdep, boys. ONE. --- src/include/skalibs/alloc.h | 10 ++++---- src/libstddjb/alloc-internal.h | 21 ----------------- src/libstddjb/alloc.c | 44 ++---------------------------------- src/libstddjb/alloc_0.c | 13 ----------- src/libstddjb/alloc_realloc.c | 12 ++++++++++ src/libstddjb/stralloc_ready_tuned.c | 2 +- src/libstddjb/stralloc_shrink.c | 2 +- src/sysdeps/output-types.c | 25 -------------------- src/sysdeps/tryemptyregex.c | 16 ------------- src/sysdeps/trynullispointer.c | 12 ---------- 10 files changed, 20 insertions(+), 137 deletions(-) delete mode 100644 src/libstddjb/alloc-internal.h delete mode 100644 src/libstddjb/alloc_0.c create mode 100644 src/libstddjb/alloc_realloc.c delete mode 100644 src/sysdeps/output-types.c delete mode 100644 src/sysdeps/tryemptyregex.c delete mode 100644 src/sysdeps/trynullispointer.c (limited to 'src') diff --git a/src/include/skalibs/alloc.h b/src/include/skalibs/alloc.h index 85f02f2..a1afdce 100644 --- a/src/include/skalibs/alloc.h +++ b/src/include/skalibs/alloc.h @@ -3,15 +3,13 @@ #ifndef ALLOC_H #define ALLOC_H -#include +#include #include -typedef char aligned_char gccattr_aligned ; -typedef aligned_char *aligned_char_ref, **aligned_char_ref_ref ; +extern void *alloc (size_t) ; +#define alloc_free(p) free(p) -extern aligned_char *alloc (size_t) ; -extern void alloc_free (void *) ; #define alloc_re(p, old, new) alloc_realloc(p, new) -extern int alloc_realloc (aligned_char **, size_t) ; +extern int alloc_realloc (void **, size_t) ; #endif diff --git a/src/libstddjb/alloc-internal.h b/src/libstddjb/alloc-internal.h deleted file mode 100644 index 6fd312e..0000000 --- a/src/libstddjb/alloc-internal.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ISC license. */ - -#ifndef ALLOC_INTERNAL_H -#define ALLOC_INTERNAL_H - -#include -#include - -#ifdef SKALIBS_HASMALLOC0 - -#include - -#define alloc_0 (aligned_char_ref)malloc(0) - -#else - -extern aligned_char_ref alloc_0 ; - -#endif - -#endif diff --git a/src/libstddjb/alloc.c b/src/libstddjb/alloc.c index 95a5df9..d223a56 100644 --- a/src/libstddjb/alloc.c +++ b/src/libstddjb/alloc.c @@ -1,49 +1,9 @@ /* ISC license. */ -#include -#include #include #include -#include "alloc-internal.h" -#ifdef DEBUG_ALLOC -# include "buffer.h" -# include "strerr2.h" -# include "lolstdio.h" -# define PLM(...) (bprintf(buffer_2, "%s: debug_alloc: ", PROG), bprintf(buffer_2, __VA_ARGS__), buffer_putflush(buffer_2, "\n", 1)) -#endif - -aligned_char *alloc (size_t n) -{ - aligned_char *p = n ? (aligned_char *)malloc(n) : (aligned_char *)alloc_0 ; -#ifdef DEBUG_ALLOC - static unsigned int counter = 0 ; - PLM("alloc(%u): %p. Allocated: %u", n, p, ++counter) ; -#endif - return p ; -} - -void alloc_free (void *p) -{ - int e = errno ; -#ifdef DEBUG_ALLOC - static unsigned int counter = 0 ; - PLM("alloc_free(%p). Freed: %u", p, ++counter) ; -#endif -#ifndef SKALIBS_HASMALLOC0 - if (p != alloc_0) -#endif - free(p) ; - errno = e ; -} - -int alloc_realloc (aligned_char **x, size_t n) +void *alloc (size_t n) { - aligned_char *y = n ? (aligned_char *)realloc(*x, n) : (free(*x), alloc_0) ; -#ifdef DEBUG_ALLOC - PLM("alloc_realloc(&%p) -> new address = %p", *x, y) ; -#endif - if (!y) return 0 ; - *x = y ; - return 1 ; + return malloc(n ? n : 1) ; } diff --git a/src/libstddjb/alloc_0.c b/src/libstddjb/alloc_0.c deleted file mode 100644 index bdd42a4..0000000 --- a/src/libstddjb/alloc_0.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include -#include -#include "alloc-internal.h" - -#ifndef SKALIBS_HASMALLOC0 - -#define ALIGNMENT 16 -static union { unsigned char blah[ALIGNMENT] ; long double ld ; } const zeroblock ; -aligned_char *alloc_0 = (aligned_char_ref)(&zeroblock) ; - -#endif diff --git a/src/libstddjb/alloc_realloc.c b/src/libstddjb/alloc_realloc.c new file mode 100644 index 0000000..8787291 --- /dev/null +++ b/src/libstddjb/alloc_realloc.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include +#include + +int alloc_realloc (void **x, size_t n) +{ + void *y = n ? realloc(*x, n) : (free(*x), alloc(0)) ; + if (!y) return 0 ; + *x = y ; + return 1 ; +} diff --git a/src/libstddjb/stralloc_ready_tuned.c b/src/libstddjb/stralloc_ready_tuned.c index d365d6e..f292f22 100644 --- a/src/libstddjb/stralloc_ready_tuned.c +++ b/src/libstddjb/stralloc_ready_tuned.c @@ -19,7 +19,7 @@ int stralloc_ready_tuned (stralloc *sa, size_t n, size_t base, size_t a, size_t } else if (n > sa->a) { - if (!alloc_re(&sa->s, sa->a, t)) return 0 ; + if (!alloc_re((void **)&sa->s, sa->a, t)) return 0 ; sa->a = t ; } return 1 ; diff --git a/src/libstddjb/stralloc_shrink.c b/src/libstddjb/stralloc_shrink.c index 0dceca2..a372084 100644 --- a/src/libstddjb/stralloc_shrink.c +++ b/src/libstddjb/stralloc_shrink.c @@ -7,7 +7,7 @@ int stralloc_shrink (stralloc *sa) { if (sa->a > sa->len) { - if (!alloc_re(&sa->s, sa->a, sa->len)) return 0 ; + if (!alloc_re((void **)&sa->s, sa->a, sa->len)) return 0 ; sa->a = sa->len ; } return 1 ; diff --git a/src/sysdeps/output-types.c b/src/sysdeps/output-types.c deleted file mode 100644 index 22e6093..0000000 --- a/src/sysdeps/output-types.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ISC license. */ - -#include -#include - -#define p(type) printf("sizeof" #type ": %u\nsigned" #type ": %s\n", \ - (unsigned int)sizeof(type##_t), \ - (type##_t)-1 < 0 ? "yes" : "no") ; - -#define q(abbr, type) printf("sizeof" #abbr ": %u\n", (unsigned int)sizeof(type)) ; - -int main (void) -{ - q(ushort, unsigned short) ; - q(uint, unsigned int) ; - q(ulong, unsigned long) ; - p(size) ; - p(uid) ; - p(gid) ; - p(pid) ; - p(time) ; - p(dev) ; - p(ino) ; - return 0 ; -} diff --git a/src/sysdeps/tryemptyregex.c b/src/sysdeps/tryemptyregex.c deleted file mode 100644 index a2243f7..0000000 --- a/src/sysdeps/tryemptyregex.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include - -int main (void) -{ - regex_t re ; - int r = regcomp(&re, "", REG_EXTENDED | REG_NOSUB) ; - switch (r) - { - case 0 : break ; - case REG_ESPACE : return 111 ; - default : return 1 ; - } - return !!regexec(&re, "a", 0, 0, 0) ; -} diff --git a/src/sysdeps/trynullispointer.c b/src/sysdeps/trynullispointer.c deleted file mode 100644 index cbb3340..0000000 --- a/src/sysdeps/trynullispointer.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -/* Explanation: http://www.openwall.com/lists/musl/2013/01/09/13 */ - -#include - -int main (void) -{ - char s[1][1+(int)NULL] ; - int i = 0 ; - return sizeof s[i++], !i ; -} -- cgit v1.2.3