diff options
Diffstat (limited to 'missing')
-rw-r--r-- | missing/dtoa.c | 14 | ||||
-rw-r--r-- | missing/erf.c | 15 | ||||
-rw-r--r-- | missing/explicit_bzero.c | 5 | ||||
-rw-r--r-- | missing/finite.c | 9 | ||||
-rw-r--r-- | missing/flock.c | 9 | ||||
-rw-r--r-- | missing/isinf.c | 69 | ||||
-rw-r--r-- | missing/isnan.c | 32 | ||||
-rw-r--r-- | missing/langinfo.c | 2 | ||||
-rw-r--r-- | missing/procstat_vm.c | 34 | ||||
-rw-r--r-- | missing/setproctitle.c | 41 | ||||
-rw-r--r-- | missing/signbit.c | 19 | ||||
-rw-r--r-- | missing/tgamma.c | 15 |
12 files changed, 74 insertions, 190 deletions
diff --git a/missing/dtoa.c b/missing/dtoa.c index a940eabd91..bce2cb22a1 100644 --- a/missing/dtoa.c +++ b/missing/dtoa.c @@ -183,7 +183,10 @@ #undef Long #undef ULong +#include <assert.h> #include <limits.h> +#include <stddef.h> +#include <stdint.h> #if (INT_MAX >> 30) && !(INT_MAX >> 31) #define Long int @@ -195,7 +198,7 @@ #error No 32bit integer #endif -#if HAVE_LONG_LONG +#if defined(HAVE_LONG_LONG) && (HAVE_LONG_LONG) #define Llong LONG_LONG #else #define NO_LONG_LONG @@ -221,12 +224,12 @@ #ifdef MALLOC extern void *MALLOC(size_t); #else -#define MALLOC xmalloc +#define MALLOC malloc #endif #ifdef FREE extern void FREE(void*); #else -#define FREE xfree +#define FREE free #endif #ifndef NO_SANITIZE #define NO_SANITIZE(x, y) y @@ -502,7 +505,7 @@ extern double rnd_prod(double, double), rnd_quot(double, double); #endif #ifndef ATOMIC_PTR_CAS -#define ATOMIC_PTR_CAS(var, old, new) ((var) = (new), (old)) +#define ATOMIC_PTR_CAS(var, old, new) ((var) = (new), (void *)(old)) #endif #ifndef LIKELY #define LIKELY(x) (x) @@ -1552,6 +1555,7 @@ break2: if (!*++s || !(s1 = strchr(hexdigit, *s))) goto ret0; if (*s == '0') { while (*++s == '0'); + if (!*s) goto ret; s1 = strchr(hexdigit, *s); } if (s1 != NULL) { @@ -1574,7 +1578,7 @@ break2: for (; *s && (s1 = strchr(hexdigit, *s)); ++s) { adj += aadj * ((s1 - hexdigit) & 15); if ((aadj /= 16) == 0.0) { - while (strchr(hexdigit, *++s)); + while (*++s && strchr(hexdigit, *s)); break; } } diff --git a/missing/erf.c b/missing/erf.c index d72c4eaf4e..c2c9d5f7e9 100644 --- a/missing/erf.c +++ b/missing/erf.c @@ -7,21 +7,6 @@ reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten #include <stdio.h> #include <math.h> -#ifdef _WIN32 -# include <float.h> -# if !defined __MINGW32__ || defined __NO_ISOCEXT -# ifndef isnan -# define isnan(x) _isnan(x) -# endif -# ifndef isinf -# define isinf(x) (!_finite(x) && !_isnan(x)) -# endif -# ifndef finite -# define finite(x) _finite(x) -# endif -# endif -#endif - static double q_gamma(double, double, double); /* Incomplete gamma function diff --git a/missing/explicit_bzero.c b/missing/explicit_bzero.c index 1220e5f9ad..59417e158e 100644 --- a/missing/explicit_bzero.c +++ b/missing/explicit_bzero.c @@ -1,12 +1,9 @@ #ifndef __STDC_WANT_LIB_EXT1__ -#define __STDC_WANT_LIB_EXT1__ 1 +#define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s() */ #endif #include "ruby/missing.h" #include <string.h> -#ifdef HAVE_MEMSET_S -# include <string.h> -#endif #ifdef _WIN32 #include <windows.h> diff --git a/missing/finite.c b/missing/finite.c deleted file mode 100644 index ab7686317b..0000000000 --- a/missing/finite.c +++ /dev/null @@ -1,9 +0,0 @@ -/* public domain rewrite of finite(3) */ - -#include "ruby/missing.h" - -int -finite(double n) -{ - return !isnan(n) && !isinf(n); -} diff --git a/missing/flock.c b/missing/flock.c index c0b3f80601..0b76961762 100644 --- a/missing/flock.c +++ b/missing/flock.c @@ -2,6 +2,15 @@ #include "ruby/ruby.h" #if defined _WIN32 +#elif defined __wasi__ +#include <errno.h> + +int +flock(int fd, int operation) +{ + errno = EINVAL; + return -1; +} #elif defined HAVE_FCNTL && defined HAVE_FCNTL_H /* These are the flock() constants. Since this systems doesn't have diff --git a/missing/isinf.c b/missing/isinf.c deleted file mode 100644 index ba24b7768b..0000000000 --- a/missing/isinf.c +++ /dev/null @@ -1,69 +0,0 @@ -/* public domain rewrite of isinf(3) */ - -#ifdef __osf__ - -#define _IEEE 1 -#include <nan.h> - -int -isinf(double n) -{ - if (IsNANorINF(n) && IsINF(n)) { - return 1; - } - else { - return 0; - } -} - -#else - -#include "ruby/internal/config.h" - -#if defined(HAVE_FINITE) && defined(HAVE_ISNAN) - -#include <math.h> -#ifdef HAVE_IEEEFP_H -#include <ieeefp.h> -#endif - -/* - * isinf may be provided only as a macro. - * ex. HP-UX, Solaris 10 - * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html - */ -#ifndef isinf -int -isinf(double n) -{ - return (!finite(n) && !isnan(n)); -} -#endif - -#else - -#ifdef HAVE_STRING_H -# include <string.h> -#else -# include <strings.h> -#endif - -static double zero(void) { return 0.0; } -static double one (void) { return 1.0; } -static double inf (void) { return one() / zero(); } - -int -isinf(double n) -{ - static double pinf = 0.0; - static double ninf = 0.0; - - if (pinf == 0.0) { - pinf = inf(); - ninf = -pinf; - } - return memcmp(&n, &pinf, sizeof n) == 0 - || memcmp(&n, &ninf, sizeof n) == 0; -} -#endif -#endif diff --git a/missing/isnan.c b/missing/isnan.c deleted file mode 100644 index ed10bf5cd6..0000000000 --- a/missing/isnan.c +++ /dev/null @@ -1,32 +0,0 @@ -/* public domain rewrite of isnan(3) */ - -#include "ruby/missing.h" - -/* - * isnan() may be a macro, a function or both. - * (The C99 standard defines that isnan() is a macro, though.) - * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html - * - * macro only: uClibc - * both: GNU libc - * - * This file is compile if no isnan() function is available. - * (autoconf AC_REPLACE_FUNCS detects only the function.) - * The macro is detected by following #ifndef. - */ - -#ifndef isnan -static int double_ne(double n1, double n2); - -int -isnan(double n) -{ - return double_ne(n, n); -} - -static int -double_ne(double n1, double n2) -{ - return n1 != n2; -} -#endif diff --git a/missing/langinfo.c b/missing/langinfo.c index 9ba06b15f6..0274a378f5 100644 --- a/missing/langinfo.c +++ b/missing/langinfo.c @@ -140,7 +140,7 @@ char *nl_langinfo(nl_item item) #ifdef TEST #include <stdio.h> -int main() +int main(void) { printf("%s\n", nl_langinfo(CODESET)); return 0; diff --git a/missing/procstat_vm.c b/missing/procstat_vm.c index 76fd8f61ba..155ee355d1 100644 --- a/missing/procstat_vm.c +++ b/missing/procstat_vm.c @@ -6,7 +6,7 @@ # define KVME_TYPE_MGTDEVICE 8 # endif void -procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp) +procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp, FILE *errout) { struct kinfo_vmentry *freep, *kve; int ptrwidth; @@ -17,7 +17,7 @@ procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp) #else ptrwidth = 2*sizeof(void *) + 2; #endif - fprintf(stderr, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n", + fprintf(errout, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n", ptrwidth, "START", ptrwidth, "END", "PRT", "RES", "P""RES", "REF", "SHD", "FL", "TP", "PATH"); @@ -30,20 +30,20 @@ procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp) return; for (i = 0; i < cnt; i++) { kve = &freep[i]; - fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start); - fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end); - fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-"); - fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-"); - fprintf(stderr, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-"); - fprintf(stderr, "%4d ", kve->kve_resident); - fprintf(stderr, "%4d ", kve->kve_private_resident); - fprintf(stderr, "%3d ", kve->kve_ref_count); - fprintf(stderr, "%3d ", kve->kve_shadow_count); - fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-"); - fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" : + fprintf(errout, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start); + fprintf(errout, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end); + fprintf(errout, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-"); + fprintf(errout, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-"); + fprintf(errout, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-"); + fprintf(errout, "%4d ", kve->kve_resident); + fprintf(errout, "%4d ", kve->kve_private_resident); + fprintf(errout, "%3d ", kve->kve_ref_count); + fprintf(errout, "%3d ", kve->kve_shadow_count); + fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-"); + fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" : "-"); - fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-"); - fprintf(stderr, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" : + fprintf(errout, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-"); + fprintf(errout, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" : kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-"); switch (kve->kve_type) { case KVME_TYPE_NONE: @@ -78,8 +78,8 @@ procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp) str = "??"; break; } - fprintf(stderr, "%-2s ", str); - fprintf(stderr, "%-s\n", kve->kve_path); + fprintf(errout, "%-2s ", str); + fprintf(errout, "%-s\n", kve->kve_path); } free(freep); } diff --git a/missing/setproctitle.c b/missing/setproctitle.c index 811829c060..f90886671c 100644 --- a/missing/setproctitle.c +++ b/missing/setproctitle.c @@ -80,10 +80,20 @@ static char **argv1_addr = NULL; #endif /* HAVE_SETPROCTITLE */ +#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV +# define ALLOCATE_ENVIRON 1 +#else +# define ALLOCATE_ENVIRON 0 +#endif + +#if ALLOCATE_ENVIRON +static char **orig_environ = NULL; +#endif + void compat_init_setproctitle(int argc, char *argv[]) { -#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV +#if ALLOCATE_ENVIRON extern char **environ; char *lastargv = NULL; char *lastenvp = NULL; @@ -100,9 +110,10 @@ compat_init_setproctitle(int argc, char *argv[]) return; /* Fail if we can't allocate room for the new environment */ - for (i = 0; envp[i] != NULL; i++) - ; - if ((environ = calloc(i + 1, sizeof(*environ))) == NULL) { + for (i = 0; envp[i] != NULL; i++); + + orig_environ = environ = xcalloc(i + 1, sizeof(*environ)); + if (environ == NULL) { environ = envp; /* put it back */ return; } @@ -134,7 +145,29 @@ compat_init_setproctitle(int argc, char *argv[]) #endif /* SPT_REUSEARGV */ } +void +ruby_free_proctitle(void) +{ +#if ALLOCATE_ENVIRON + extern char **environ; + + if (!orig_environ) return; /* environ is allocated by OS */ + + /* ruby_setenv could allocate a new environ, so we need to free orig_environ + * in that case. */ + if (environ != orig_environ) { + for (int i = 0; orig_environ[i] != NULL; i++) { + xfree(orig_environ[i]); + } + + xfree(orig_environ); + orig_environ = NULL; + } +#endif +} + #ifndef HAVE_SETPROCTITLE + void setproctitle(const char *fmt, ...) { diff --git a/missing/signbit.c b/missing/signbit.c deleted file mode 100644 index 2f7ce8c601..0000000000 --- a/missing/signbit.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <limits.h> -#include "ruby.h" - -int -signbit(double x) -{ - enum {double_per_long = sizeof(double) / sizeof(long)}; - enum {long_msb = sizeof(long) * CHAR_BIT - 1}; - union {double d; unsigned long i[double_per_long];} u; - unsigned long l; - - u.d = x; -#ifdef WORDS_BIGENDIAN - l = u.i[0]; -#else - l = u.i[double_per_long - 1]; -#endif - return (int)(l >> long_msb); -} diff --git a/missing/tgamma.c b/missing/tgamma.c index c8638eab2b..82d614d755 100644 --- a/missing/tgamma.c +++ b/missing/tgamma.c @@ -14,21 +14,6 @@ reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten #include <math.h> #include <errno.h> -#ifdef _WIN32 -# include <float.h> -# if !defined __MINGW32__ || defined __NO_ISOCEXT -# ifndef isnan -# define isnan(x) _isnan(x) -# endif -# ifndef isinf -# define isinf(x) (!_finite(x) && !_isnan(x)) -# endif -# ifndef finite -# define finite(x) _finite(x) -# endif -# endif -#endif - #ifndef HAVE_LGAMMA_R #include <errno.h> |