diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-20 19:55:29 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-20 19:55:29 +0000 |
commit | 03f37879ef167dba6f5944716c06da81902e436e (patch) | |
tree | 46a70f3d85f8de8a8a1b648a53754531b86198a6 /src | |
parent | 90c1f3c1580d8e699c2788262a614a930a33e13e (diff) | |
download | skalibs-03f37879ef167dba6f5944716c06da81902e436e.tar.gz skalibs-03f37879ef167dba6f5944716c06da81902e436e.tar.xz skalibs-03f37879ef167dba6f5944716c06da81902e436e.zip |
We're down to ONE rogue sysdep, boys. ONE.
Diffstat (limited to 'src')
-rw-r--r-- | src/include/skalibs/alloc.h | 10 | ||||
-rw-r--r-- | src/libstddjb/alloc-internal.h | 21 | ||||
-rw-r--r-- | src/libstddjb/alloc.c | 44 | ||||
-rw-r--r-- | src/libstddjb/alloc_0.c | 13 | ||||
-rw-r--r-- | src/libstddjb/alloc_realloc.c | 12 | ||||
-rw-r--r-- | src/libstddjb/stralloc_ready_tuned.c | 2 | ||||
-rw-r--r-- | src/libstddjb/stralloc_shrink.c | 2 | ||||
-rw-r--r-- | src/sysdeps/output-types.c | 25 | ||||
-rw-r--r-- | src/sysdeps/tryemptyregex.c | 16 | ||||
-rw-r--r-- | src/sysdeps/trynullispointer.c | 12 |
10 files changed, 20 insertions, 137 deletions
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 <sys/types.h> +#include <stdlib.h> #include <skalibs/gccattributes.h> -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 <skalibs/sysdeps.h> -#include <skalibs/alloc.h> - -#ifdef SKALIBS_HASMALLOC0 - -#include <stdlib.h> - -#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 <skalibs/sysdeps.h> -#include <errno.h> #include <stdlib.h> #include <skalibs/alloc.h> -#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 <skalibs/sysdeps.h> -#include <skalibs/alloc.h> -#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 <stdlib.h> +#include <skalibs/alloc.h> + +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 <sys/types.h> -#include <stdio.h> - -#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 <regex.h> - -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 <stddef.h> - -int main (void) -{ - char s[1][1+(int)NULL] ; - int i = 0 ; - return sizeof s[i++], !i ; -} |