skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 03f37879ef167dba6f5944716c06da81902e436e
parent 90c1f3c1580d8e699c2788262a614a930a33e13e
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri, 20 Sep 2019 19:55:29 +0000

 We're down to ONE rogue sysdep, boys. ONE.

Diffstat:
Mconfigure | 4+---
Mpackage/deps.mak | 5++---
Msrc/include/skalibs/alloc.h | 10++++------
Dsrc/libstddjb/alloc-internal.h | 21---------------------
Msrc/libstddjb/alloc.c | 44++------------------------------------------
Dsrc/libstddjb/alloc_0.c | 13-------------
Asrc/libstddjb/alloc_realloc.c | 12++++++++++++
Msrc/libstddjb/stralloc_ready_tuned.c | 2+-
Msrc/libstddjb/stralloc_shrink.c | 2+-
Dsrc/sysdeps/output-types.c | 25-------------------------
Dsrc/sysdeps/tryemptyregex.c | 16----------------
Dsrc/sysdeps/trynullispointer.c | 12------------
Mtools/gen-types.sh | 2+-
13 files changed, 24 insertions(+), 144 deletions(-)

diff --git a/configure b/configure @@ -558,6 +558,7 @@ else sysdeps=sysdeps.cfg mkdir -p $sysdeps echo "$target" > $sysdeps/target + :> "$sysdeps/sysdeps" exec 3>&1 util_lib= @@ -622,10 +623,7 @@ else choose cl nsgetparent 'NS_GET_PARENT' choose cl explicit_bzero 'explicit_bzero()' - choose clr emptyregex 'regcomp() accept empty regexes' - choose clr nullispointer 'a pointer-typed NULL' choose clr devurandom '/dev/urandom' - choose clr malloc0 'non-NULL malloc(0)' fi diff --git a/package/deps.mak b/package/deps.mak @@ -65,7 +65,6 @@ src/libstdcrypto/md5-internal.h: src/include/skalibs/md5.h src/libstdcrypto/sha1-internal.h: src/include/skalibs/sha1.h src/libstdcrypto/sha256-internal.h: src/include/skalibs/sha256.h src/libstdcrypto/sha512-internal.h: src/include/skalibs/sha512.h -src/libstddjb/alloc-internal.h: src/include/skalibs/alloc.h src/include/skalibs/sysdeps.h src/libstddjb/djbtime-internal.h: src/include/skalibs/uint64.h src/libstddjb/fmtscan-internal.h: src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/selfpipe-internal.h: src/include/skalibs/sig.h src/include/skalibs/sysdeps.h @@ -195,8 +194,8 @@ src/libstddjb/alarm_deadline.o src/libstddjb/alarm_deadline.lo: src/libstddjb/al src/libstddjb/alarm_disable.o src/libstddjb/alarm_disable.lo: src/libstddjb/alarm_disable.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/libstddjb/alarm_milliseconds.o src/libstddjb/alarm_milliseconds.lo: src/libstddjb/alarm_milliseconds.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/libstddjb/alarm_timeout.o src/libstddjb/alarm_timeout.lo: src/libstddjb/alarm_timeout.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h -src/libstddjb/alloc.o src/libstddjb/alloc.lo: src/libstddjb/alloc.c src/libstddjb/alloc-internal.h src/include/skalibs/alloc.h src/include/skalibs/sysdeps.h -src/libstddjb/alloc_0.o src/libstddjb/alloc_0.lo: src/libstddjb/alloc_0.c src/libstddjb/alloc-internal.h src/include/skalibs/alloc.h src/include/skalibs/sysdeps.h +src/libstddjb/alloc.o src/libstddjb/alloc.lo: src/libstddjb/alloc.c src/include/skalibs/alloc.h +src/libstddjb/alloc_realloc.o src/libstddjb/alloc_realloc.lo: src/libstddjb/alloc_realloc.c src/include/skalibs/alloc.h src/libstddjb/allread.o src/libstddjb/allread.lo: src/libstddjb/allread.c src/include/skalibs/allreadwrite.h src/libstddjb/allreadv.o src/libstddjb/allreadv.lo: src/libstddjb/allreadv.c src/include/skalibs/allreadwrite.h src/libstddjb/allreadwrite.o src/libstddjb/allreadwrite.lo: src/libstddjb/allreadwrite.c src/include/skalibs/allreadwrite.h diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ; -} diff --git a/tools/gen-types.sh b/tools/gen-types.sh @@ -4,7 +4,7 @@ sysdeps="$1" shift getbits() { - expr 8 '*' `grep -F sizeof$2: < "$1" | cut -f2 -d' '` + expr 8 '*' `grep -F sizeof$2: < "$1" | awk '{print $2;}'` } cat < src/headers/types-header