diff --git a/src/miniacc.h b/src/miniacc.h index 178a1a52..f6e11a03 100644 --- a/src/miniacc.h +++ b/src/miniacc.h @@ -27,7 +27,7 @@ #ifndef __ACC_H_INCLUDED #define __ACC_H_INCLUDED 1 -#define ACC_VERSION 20200116L +#define ACC_VERSION 20220904L #if defined(__CYGWIN32__) && !defined(__CYGWIN__) # define __CYGWIN__ __CYGWIN32__ #endif @@ -435,6 +435,14 @@ # define ACC_EXTERN_C_BEGIN /*empty*/ # define ACC_EXTERN_C_END /*empty*/ #endif +#if !defined(ACC_nullptr) +#if defined(__cplusplus) && (__cplusplus-0 >= 201103L) +# define ACC_nullptr nullptr +#endif +#endif +#if !defined(ACC_nullptr) +# define ACC_nullptr NULL +#endif #if !defined(__ACC_OS_OVERRIDE) #if (ACC_OS_FREESTANDING) # define ACC_INFO_OS "freestanding" @@ -3844,9 +3852,9 @@ ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(acc_int_fast64_t) == sizeof(acc_uint_fast6 # if (ACC_CC_GNUC < 0x025f00ul) # undef HAVE_SNPRINTF # undef HAVE_VSNPRINTF -# else -//# define snprintf _snprintf -//# define vsnprintf _vsnprintf +# elif 0 +# define snprintf _snprintf +# define vsnprintf _vsnprintf # endif #elif (ACC_OS_WIN32 && ACC_LIBC_MSL) # if (__MSL__ < 0x8000ul) @@ -4786,6 +4794,8 @@ void __ACC_UA_SET_LE32(__acc_ua_volatile void* pp, unsigned long v) { #define __ACC_FALLBACK_STDDEF_H_INCLUDED 1 #if defined(__PTRDIFF_TYPE__) typedef __PTRDIFF_TYPE__ acc_fallback_ptrdiff_t; +#elif defined(_WIN64) +typedef long long acc_fallback_ptrdiff_t; #elif defined(__MIPS_PSX2__) typedef int acc_fallback_ptrdiff_t; #else @@ -4793,8 +4803,10 @@ typedef long acc_fallback_ptrdiff_t; #endif #if defined(__SIZE_TYPE__) typedef __SIZE_TYPE__ acc_fallback_size_t; +#elif defined(_WIN64) +typedef unsigned long long acc_fallback_ptrdiff_t; #elif defined(__MIPS_PSX2__) -typedef unsigned int acc_fallback_size_t; +typedef unsigned acc_fallback_size_t; #else typedef unsigned long acc_fallback_size_t; #endif @@ -4816,17 +4828,19 @@ typedef unsigned short wchar_t; #define _WCHAR_T_DEFINED 1 #endif #endif -#ifndef nullptr -#if defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ >= 4) -#define nullptr __null +#ifndef NULL +#if defined(__cplusplus) && (__cplusplus-0 >= 201103L) +#define NULL nullptr +#elif defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ >= 4) +#define NULL __null #elif defined(__cplusplus) -#define nullptr 0 +#define NULL 0 #else -#define nullptr ((void*)0) +#define NULL ((void*)0) #endif #endif #ifndef offsetof -#define offsetof(s,m) ((size_t)((ptrdiff_t)&(((s*)nullptr)->m))) +#define offsetof(s,m) ((size_t)((ptrdiff_t)&(((s*)NULL)->m))) #endif #endif #elif (ACC_LIBC_FREESTANDING) @@ -5540,7 +5554,7 @@ ACCLIB_EXTERN(int, acc_spawnve) (int mode, const char* fn, const char* const * a #if defined(ACC_CXX_TRIGGER_FUNCTION_IMPL) #else # define ACC_CXX_TRIGGER_FUNCTION_IMPL(klass) \ - const void* klass::acc_cxx_trigger_function() const { return ACC_STATIC_CAST(const void *, 0); } + const void* klass::acc_cxx_trigger_function() const { return ACC_STATIC_CAST(const void *, ACC_nullptr); } #endif #endif #endif @@ -5740,8 +5754,8 @@ ACCLIB_EXTERN(int, acc_spawnve) (int mode, const char* fn, const char* const * a ACCCHK_ASSERT(sizeof(short) == ACC_SIZEOF_SHORT) #endif ACCCHK_ASSERT_IS_SIGNED_T(int) - ACCCHK_ASSERT_IS_UNSIGNED_T(unsigned int) - ACCCHK_ASSERT(sizeof(int) == sizeof(unsigned int)) + ACCCHK_ASSERT_IS_UNSIGNED_T(unsigned) + ACCCHK_ASSERT(sizeof(int) == sizeof(unsigned)) #if !(ACC_ABI_I8LP16) ACCCHK_ASSERT(sizeof(int) >= 2) #endif @@ -5775,9 +5789,13 @@ ACCLIB_EXTERN(int, acc_spawnve) (int mode, const char* fn, const char* const * a ACCCHK_ASSERT(sizeof(ptrdiff_t) >= sizeof(int)) ACCCHK_ASSERT(sizeof(ptrdiff_t) >= sizeof(size_t)) #if !(ACC_BROKEN_SIZEOF) - ACCCHK_ASSERT(sizeof(ptrdiff_t) == sizeof(ACC_STATIC_CAST(char*, nullptr) - ACC_STATIC_CAST(char*, nullptr))) +#if (ACC_CC_CLANG) && !defined(__cplusplus) + ACCCHK_ASSERT(sizeof(ptrdiff_t) == sizeof(ACC_REINTERPRET_CAST(char*, 1) - ACC_REINTERPRET_CAST(char*, 1))) +#else + ACCCHK_ASSERT(sizeof(ptrdiff_t) == sizeof(ACC_STATIC_CAST(char*, ACC_nullptr) - ACC_STATIC_CAST(char*, ACC_nullptr))) +#endif # if (ACC_HAVE_MM_HUGE_PTR) - ACCCHK_ASSERT(4 == sizeof(ACC_STATIC_CAST(char __huge*, nullptr) - ACC_STATIC_CAST(char __huge*, nullptr))) + ACCCHK_ASSERT(4 == sizeof(ACC_STATIC_CAST(char __huge*, 0) - ACC_STATIC_CAST(char __huge*, 0))) # endif #endif #if (ACC_SIZEOF_PTRDIFF_T > 0) @@ -6320,9 +6338,9 @@ ACCLIB_PUBLIC(void, acc_ua_set_le64) (acc_hvoid_p p, acc_uint64l_t v) #endif extern void* volatile acc_vget_ptr__; #if (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x030400ul) || ACC_CC_LLVM) -void* volatile __attribute__((__used__)) acc_vget_ptr__ = ACC_STATIC_CAST(void *, nullptr); +void* volatile __attribute__((__used__)) acc_vget_ptr__ = ACC_STATIC_CAST(void *, ACC_nullptr); #else -void* volatile acc_vget_ptr__ = ACC_STATIC_CAST(void *, nullptr); +void* volatile acc_vget_ptr__ = ACC_STATIC_CAST(void *, ACC_nullptr); #endif #ifndef __ACCLIB_VGET_BODY #define __ACCLIB_VGET_BODY(T) \ @@ -6753,6 +6771,7 @@ static int __ACCLIB_FUNCNAME(acc_getopt_rotate) (char **p, int first, int middle } static int __ACCLIB_FUNCNAME(acc_getopt_perror) (acc_getopt_p g, int ret, const char *f, ...) { + ++g->errcount; if (g->opterr) { #if defined(HAVE_STDARG_H) && (HAVE_STDARG_H) struct { va_list ap; } s; @@ -6760,10 +6779,9 @@ static int __ACCLIB_FUNCNAME(acc_getopt_perror) (acc_getopt_p g, int ret, const g->opterr(g, f, &s); va_end(s.ap); #else - g->opterr(g, f, nullptr); + g->opterr(g, f, ACC_nullptr); #endif } - ++g->errcount; return ret; } ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g, @@ -6781,7 +6799,7 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g, if (*shortopts == ':') missing_arg_ret = *shortopts++; } - g->optarg = nullptr; + g->optarg = ACC_nullptr; if (g->optopt == -1) g->optopt = g->bad_option; if (longind) @@ -6805,8 +6823,8 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g, if (a[0] == '-' && a[1] == '-') { size_t l = 0; const acc_getopt_longopt_p o; - const acc_getopt_longopt_p o1 = nullptr; - const acc_getopt_longopt_p o2 = nullptr; + const acc_getopt_longopt_p o1 = ACC_nullptr; + const acc_getopt_longopt_p o2 = ACC_nullptr; int need_exact = 0; ++g->optind; if (!a[2]) @@ -6868,7 +6886,7 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g, const char *s; acc_label_next_shortopt: a = g->argv[g->optind] + ++g->shortpos; - c = (unsigned char) *a++; s = nullptr; + c = (unsigned char) *a++; s = ACC_nullptr; if (c != ':' && shortopts) s = strchr(shortopts, c); if (!s || s[1] != ':') { @@ -6894,8 +6912,8 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g, return c; } if (ordering == ACC_GETOPT_RETURN_IN_ORDER) { - ++g->optind; g->optarg = a; + ++g->optind; return 1; } acc_label_eof: @@ -6947,13 +6965,13 @@ ACC_EXTERN_C int __far __pascal GlobalUnlock(const void __near*); #endif ACCLIB_PUBLIC(acc_hvoid_p, acc_halloc) (acc_hsize_t size) { - acc_hvoid_p p = ACC_STATIC_CAST(acc_hvoid_p, 0); + acc_hvoid_p p = ACC_STATIC_CAST(acc_hvoid_p, ACC_nullptr); if (!(size > 0)) return p; #if 0 && defined(__palmos__) p = MemPtrNew(size); #elif !(ACC_HAVE_MM_HUGE_PTR) - if (size < ACC_STATIC_CAST(size_t, -1)) + if (size < (~(ACC_STATIC_CAST(size_t, 0)) & ~(ACC_STATIC_CAST(acc_hsize_t, 0)))) p = malloc(ACC_STATIC_CAST(size_t, size)); #else if (ACC_STATIC_CAST(long, size) <= 0) @@ -7203,6 +7221,7 @@ ACCLIB_PUBLIC(long, acc_safe_hwrite) (int fd, const acc_hvoid_p buf, long size) __acc_static_noinline long acc_pclock_syscall_clock_gettime(long clockid, struct timespec *ts) { unsigned long r = 228; + ACC_COMPILE_TIME_ASSERT(sizeof(*ts) == 16); __asm__ __volatile__("syscall\n" : "=a" (r), "=m" (*ts) : "0" (r), "D" (clockid), "S" (ts) __ACC_ASM_CLOBBER_LIST_CC); return ACC_ICAST(long, r); } @@ -7213,7 +7232,7 @@ __acc_static_noinline long acc_pclock_syscall_clock_gettime(long clockid, struct #endif __acc_static_noinline long acc_pclock_syscall_clock_gettime(long clockid, struct timespec *ts) { - unsigned long r = 265; + unsigned long r = 265 + ((sizeof(*ts) > 8) * (403 - 265)); __asm__ __volatile__("pushl %%ebx\n pushl %%edx\n popl %%ebx\n int $0x80\n popl %%ebx\n": "=a" (r), "=m" (*ts) : "0" (r), "d" (clockid), "c" (ts) __ACC_ASM_CLOBBER_LIST_CC); return ACC_ICAST(long, r); } @@ -7239,7 +7258,7 @@ static int acc_pclock_read_clock_gettime_r_syscall(acc_pclock_handle_p h, acc_pc static int acc_pclock_read_gettimeofday(acc_pclock_handle_p h, acc_pclock_p c) { struct timeval tv; - if (gettimeofday(&tv, nullptr) != 0) + if (gettimeofday(&tv, ACC_nullptr) != 0) return -1; #if defined(acc_int64l_t) c->tv_sec = tv.tv_sec; @@ -7432,8 +7451,8 @@ ACCLIB_PUBLIC(int, acc_pclock_open) (acc_pclock_handle_p h, int mode) h->h = ACC_STATIC_CAST(acclib_handle_t, 0); h->mode = -1; h->read_error = 2; - h->name = nullptr; - h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, 0); + h->name = ACC_nullptr; + h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, ACC_nullptr); #if defined(acc_int64l_t) h->ticks_base = 0; #endif @@ -7560,8 +7579,8 @@ ACCLIB_PUBLIC(int, acc_pclock_close) (acc_pclock_handle_p h) { h->h = ACC_STATIC_CAST(acclib_handle_t, 0); h->mode = -1; - h->name = nullptr; - h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, 0); + h->name = ACC_nullptr; + h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, ACC_nullptr); return 0; } ACCLIB_PUBLIC(void, acc_pclock_read) (acc_pclock_handle_p h, acc_pclock_p c)