Improvements to stdlib.

All SDL_* functions are always available as real symbols, so you can always
link against them as a stable ABI. By default, however, all the things that
might have dithered down to macros in your application are now force-inlined,
to give you the same effect as before and theoretically better performance,
but still solve the classic macro problems.

Elsewhere, we provide real functions for these things that simply wrap the
inline functions, in case one needs to have a real function available.

Also: this exposed bugs: SDL_abs() does something different if you had the
macro vs the libc function, SDL_memcpy() returns a void* in the function
but not the macro, etc.
This commit is contained in:
Ryan C. Gordon 2013-03-15 01:01:20 -04:00
parent e79e3b2343
commit 7e934f8f75
7 changed files with 626 additions and 414 deletions

View file

@ -194,6 +194,10 @@ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
/** \endcond */
#if !defined(wchar_t) && defined(__NINTENDODS__)
#define wchar_t short /* TODO: figure out why libnds doesn't have this */
#endif
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
@ -202,30 +206,6 @@ extern "C" {
/* *INDENT-ON* */
#endif
#ifdef HAVE_MALLOC
#define SDL_malloc malloc
#else
extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
#endif
#ifdef HAVE_CALLOC
#define SDL_calloc calloc
#else
extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
#endif
#ifdef HAVE_REALLOC
#define SDL_realloc realloc
#else
extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
#endif
#ifdef HAVE_FREE
#define SDL_free free
#else
extern DECLSPEC void SDLCALL SDL_free(void *mem);
#endif
#if defined(HAVE_ALLOCA) && !defined(alloca)
# if defined(HAVE_ALLOCA_H)
# include <alloca.h>
@ -256,380 +236,443 @@ char *alloca();
#define SDL_stack_free(data) SDL_free(data)
#endif
#ifdef HAVE_GETENV
#define SDL_getenv getenv
#else
/* SDL stdinc inline functions:
The theory here is that, by default, we forcibly inline what we can--with
real inline functions that avoid macro side-effects--and your app will use
the inline version by default. However, we expose a non-inline version
too, which internally just wraps the inline version in a real function,
so the symbol is always available in the library even if your app
bypassed it with the inline version. The SDL_*_inline versions aren't
guaranteed to exist, so never call them directly; use SDL_* instead,
and trust the system to give you the right thing.
The benefit here is that you can dlsym() these functions, which you
couldn't if you had macros, you can link against a foreign build of SDL
even if you configured differently, and you can drop the unconfigured SDL
headers into a project without #defining HAVE_MALLOC (etc) and still link.
*/
extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
#ifdef HAVE_MALLOC
SDL_FORCE_INLINE void *SDL_malloc_inline(size_t size) { return malloc(size); }
#define SDL_malloc SDL_malloc_inline
#endif
extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
#ifdef HAVE_CALLOC
SDL_FORCE_INLINE void *SDL_calloc_inline(size_t nmemb, size_t size) { return calloc(nmemb, size); }
#define SDL_calloc SDL_calloc_inline
#endif
extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
#ifdef HAVE_REALLOC
SDL_FORCE_INLINE void *SDL_realloc_inline(void *mem, size_t size) { return realloc(mem, size); }
#define SDL_realloc SDL_realloc_inline
#endif
extern DECLSPEC void SDLCALL SDL_free(void *mem);
#ifdef HAVE_FREE
SDL_FORCE_INLINE void SDL_free_inline(void *mem) { free(mem); }
#define SDL_free SDL_free_inline
#endif
extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
#ifdef HAVE_GETENV
SDL_FORCE_INLINE char *SDL_getenv_inline(const char *name) { return getenv(name); }
#define SDL_getenv SDL_getenv_inline
#endif
/* SDL_putenv() has moved to SDL_compat. */
extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
#ifdef HAVE_SETENV
#define SDL_setenv setenv
#else
extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value,
int overwrite);
SDL_FORCE_INLINE int SDL_setenv_inline(const char *name, const char *value, int overwrite) { return setenv(name, value, overwrite); }
#define SDL_setenv SDL_setenv_inline
#endif
extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
#ifdef HAVE_QSORT
#define SDL_qsort qsort
#else
extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
int (*compare) (const void *,
const void *));
SDL_FORCE_INLINE void SDL_qsort_inline(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { return qsort(base, nmemb, size, compare); }
#define SDL_qsort SDL_qsort_inline
#endif
extern DECLSPEC int SDLCALL SDL_abs(int x);
#ifdef HAVE_ABS
#define SDL_abs abs
SDL_FORCE_INLINE int SDL_abs_inline(int x) { return abs(x); }
#else
#define SDL_abs(X) ((X) < 0 ? -(X) : (X))
SDL_FORCE_INLINE int SDL_abs_inline(int x) { return ((x) < 0 ? -(x) : (x)); }
#endif
#define SDL_abs SDL_abs_inline
#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
/* !!! FIXME: these have side effects. You probably shouldn't use them. */
/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
extern DECLSPEC int SDLCALL SDL_isdigit(int x);
extern DECLSPEC int SDLCALL SDL_isspace(int x);
extern DECLSPEC int SDLCALL SDL_toupper(int x);
extern DECLSPEC int SDLCALL SDL_tolower(int x);
#ifdef HAVE_CTYPE_H
#define SDL_isdigit(X) isdigit(X)
#define SDL_isspace(X) isspace(X)
#define SDL_toupper(X) toupper(X)
#define SDL_tolower(X) tolower(X)
SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return isdigit(x); }
SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return isspace(x); }
SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return toupper(x); }
SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return tolower(x); }
#else
#define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9'))
#define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
#define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
#define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
SDL_FORCE_INLINE int SDL_isdigit_inline(int x) { return ((x) >= '0') && ((x) <= '9'); }
SDL_FORCE_INLINE int SDL_isspace_inline(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
SDL_FORCE_INLINE int SDL_toupper_inline(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
SDL_FORCE_INLINE int SDL_tolower_inline(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
#endif
#define SDL_isdigit SDL_isdigit_inline
#define SDL_isspace SDL_isspace_inline
#define SDL_toupper SDL_toupper_inline
#define SDL_tolower SDL_tolower_inline
#ifdef HAVE_MEMSET
#define SDL_memset memset
#else
extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
#ifdef HAVE_MEMSET
SDL_FORCE_INLINE void *SDL_memset_inline(void *dst, int c, size_t len) { return memset(dst, c, len); }
#define SDL_memset SDL_memset_inline
#endif
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
/* !!! FIXME: does this _really_ beat memset() on any modern platform? */
SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t len)
{
#if defined(__GNUC__) && defined(i386)
#define SDL_memset4(dst, val, len) \
do { \
int u0, u1, u2; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; stosl\n\t" \
: "=&D" (u0), "=&a" (u1), "=&c" (u2) \
: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) \
: "memory" ); \
} while(0)
#endif
#ifndef SDL_memset4
#define SDL_memset4(dst, val, len) \
do { \
unsigned _count = (len); \
unsigned _n = (_count + 3) / 4; \
Uint32 *_p = SDL_static_cast(Uint32 *, dst); \
Uint32 _val = (val); \
if (len == 0) break; \
switch (_count % 4) { \
case 0: do { *_p++ = _val; \
case 3: *_p++ = _val; \
case 2: *_p++ = _val; \
case 1: *_p++ = _val; \
} while ( --_n ); \
} \
} while(0)
int u0, u1, u2;
__asm__ __volatile__ (
"cld \n\t"
"rep ; stosl \n\t"
: "=&D" (u0), "=&a" (u1), "=&c" (u2)
: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))
: "memory"
);
/* !!! FIXME: amd64? */
#else
unsigned int _count = (len);
unsigned int _n = (_count + 3) / 4;
Uint32 *_p = SDL_static_cast(Uint32 *, dst);
Uint32 _val = (val);
if (len == 0)
return;
switch (_count % 4)
{
case 0: do { *_p++ = _val;
case 3: *_p++ = _val;
case 2: *_p++ = _val;
case 1: *_p++ = _val;
} while ( --_n );
}
#endif
}
/* We can count on memcpy existing on Mac OS X and being well-tuned. */
extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
#if defined(__MACOSX__)
#define SDL_memcpy memcpy
SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
{
/* We can count on memcpy existing on Mac OS X and being well-tuned. */
return memcpy(dst, src, len);
}
#define SDL_memcpy SDL_memcpy_inline
#elif defined(__GNUC__) && defined(i386) && !defined(__WIN32__)
#define SDL_memcpy(dst, src, len) \
do { \
int u0, u1, u2; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl\n\t" \
"testb $2,%b4\n\t" \
"je 1f\n\t" \
"movsw\n" \
"1:\ttestb $1,%b4\n\t" \
"je 2f\n\t" \
"movsb\n" \
"2:" \
: "=&c" (u0), "=&D" (u1), "=&S" (u2) \
: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
: "memory" ); \
} while(0)
#endif
#ifndef SDL_memcpy
#ifdef HAVE_MEMCPY
#define SDL_memcpy memcpy
#elif defined(HAVE_BCOPY)
#define SDL_memcpy(d, s, n) bcopy((s), (d), (n))
#else
extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
size_t len);
#endif
SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
{
/* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
/* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
/* !!! FIXME: amd64? */
int u0, u1, u2;
__asm__ __volatile__ (
"cld \n\t"
"rep ; movsl \n\t"
"testb $2,%b4 \n\t"
"je 1f \n\t"
"movsw \n"
"1:\ttestb $1,%b4 \n\t"
"je 2f \n\t"
"movsb \n"
"2:"
: "=&c" (u0), "=&D" (u1), "=&S" (u2)
: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst), "2" (src)
: "memory"
);
return dst;
}
#define SDL_memcpy SDL_memcpy_inline
#elif defined(HAVE_MEMCPY)
SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
{
return memcpy(dst, src, len);
}
#define SDL_memcpy SDL_memcpy_inline
#elif defined(HAVE_BCOPY) /* !!! FIXME: is there _really_ ever a time where you have bcopy and not memcpy? */
SDL_FORCE_INLINE void *SDL_memcpy_inline(void *dst, const void *src, size_t len)
{
bcopy(src, dst, len);
return dst;
}
#define SDL_memcpy SDL_memcpy_inline
#endif
/* We can count on memcpy existing on Mac OS X and being well-tuned. */
SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
{
#if defined(__MACOSX__)
#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2)
/* We can count on memcpy existing on Mac OS X and being well-tuned. */
return memcpy(dst, src, dwords * 4);
#elif defined(__GNUC__) && defined(i386)
#define SDL_memcpy4(dst, src, len) \
do { \
int ecx, edi, esi; \
__asm__ __volatile__ ( \
"cld\n\t" \
"rep ; movsl" \
: "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) \
: "memory" ); \
} while(0)
#endif
#ifndef SDL_memcpy4
#define SDL_memcpy4(dst, src, len) SDL_memcpy((dst), (src), (len) << 2)
/* !!! FIXME: does this _really_ beat memcpy() on any modern platform? */
/* !!! FIXME: shouldn't we just force the inputs to ecx/edi/esi instead of this tapdance with outputs? */
/* !!! FIXME: amd64? */
int ecx, edi, esi;
__asm__ __volatile__ (
"cld \n\t"
"rep ; movsl \n\t"
: "=&c" (ecx), "=&D" (edi), "=&S" (esi)
: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)
: "memory"
);
return dst;
#else
return SDL_memcpy(dst, src, dwords * 4);
#endif
}
extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
#ifdef HAVE_MEMMOVE
#define SDL_memmove memmove
#else
extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src,
size_t len);
SDL_FORCE_INLINE void *SDL_memmove_inline(void *dst, const void *src, size_t len) { return memmove(dst, src, len); }
#define SDL_memmove SDL_memmove_inline
#endif
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
#ifdef HAVE_MEMCMP
#define SDL_memcmp memcmp
#else
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
size_t len);
SDL_FORCE_INLINE int SDL_memcmp_inline(const void *s1, const void *s2, size_t len) { return memcmp(s1, s2, len); }
#define SDL_memcmp SDL_memcmp_inline
#endif
extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
#ifdef HAVE_STRLEN
#define SDL_strlen strlen
#else
extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
SDL_FORCE_INLINE size_t SDL_strlen_inline(const char *str) { return strlen(str); }
#define SDL_strlen SDL_strlen_inline
#endif
extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
#ifdef HAVE_WCSLEN
#define SDL_wcslen wcslen
#else
#if !defined(wchar_t) && defined(__NINTENDODS__)
#define wchar_t short /* TODO: figure out why libnds doesn't have this */
#endif
extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
SDL_FORCE_INLINE size_t SDL_wcslen_inline(const wchar_t *wstr) { return wcslen(wstr); }
#define SDL_wcslen SDL_wcslen_inline
#endif
#ifdef HAVE_WCSLCPY
#define SDL_wcslcpy wcslcpy
#else
extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
#ifdef HAVE_WCSLCPY
SDL_FORCE_INLINE size_t SDL_wcslcpy_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcpy(dst, src, maxlen); }
#define SDL_wcslcpy SDL_wcslcpy_inline
#endif
#ifdef HAVE_WCSLCAT
#define SDL_wcslcat wcslcat
#else
extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
#ifdef HAVE_WCSLCAT
SDL_FORCE_INLINE size_t SDL_wcslcat_inline(wchar_t *dst, const wchar_t *src, size_t maxlen) { return wcslcat(dst, src, maxlen); }
#define SDL_wcslcat SDL_wcslcat_inline
#endif
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
#ifdef HAVE_STRLCPY
#define SDL_strlcpy strlcpy
SDL_FORCE_INLINE size_t SDL_strlcpy_inline(char *dst, const char *src, size_t maxlen) { return strlcpy(dst, src, maxlen); }
#define SDL_strlcpy SDL_strlcpy_inline
#else
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
size_t maxlen);
#endif
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src,
size_t dst_bytes);
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
#ifdef HAVE_STRLCAT
#define SDL_strlcat strlcat
#else
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
size_t maxlen);
SDL_FORCE_INLINE size_t SDL_strlcat_inline(char *dst, const char *src, size_t maxlen) { return strlcat(dst, src, maxlen); }
#define SDL_strlcat SDL_strlcat_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
#ifdef HAVE_STRDUP
#define SDL_strdup strdup
#else
extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
SDL_FORCE_INLINE char *SDL_strdup_inline(const char *str) { return strdup(str); }
#define SDL_strdup SDL_strdup_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
#ifdef HAVE__STRREV
#define SDL_strrev _strrev
#else
extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
SDL_FORCE_INLINE char *SDL_strrev_inline(char *str) { return _strrev(str); }
#define SDL_strrev SDL_strrev_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
#ifdef HAVE__STRUPR
#define SDL_strupr _strupr
#else
extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
SDL_FORCE_INLINE char *SDL_strupr_inline(char *str) { return _strupr(str); }
#define SDL_strupr SDL_strupr_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
#ifdef HAVE__STRLWR
#define SDL_strlwr _strlwr
#else
extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
SDL_FORCE_INLINE char *SDL_strlwr_inline(char *str) { return _strlwr(str); }
#define SDL_strlwr SDL_strlwr_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
#ifdef HAVE_STRCHR
#define SDL_strchr strchr
#elif defined(HAVE_INDEX)
#define SDL_strchr index
#else
extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return strchr(str, c); }
#define SDL_strchr SDL_strchr_inline
#elif defined(HAVE_INDEX) /* !!! FIXME: is there anywhere that has this but not strchr? */
SDL_FORCE_INLINE char *SDL_strchr_inline(const char *str, int c) { return index(str, c); }
#define SDL_strchr SDL_strchr_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
#ifdef HAVE_STRRCHR
#define SDL_strrchr strrchr
#elif defined(HAVE_RINDEX)
#define SDL_strrchr rindex
#else
extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return strrchr(str, c); }
#define SDL_strrchr SDL_strrchr_inline
#elif defined(HAVE_RINDEX) /* !!! FIXME: is there anywhere that has this but not strrchr? */
SDL_FORCE_INLINE char *SDL_strrchr_inline(const char *str, int c) { return rindex(str, c); }
#define SDL_strrchr SDL_strrchr_inline
#endif
extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
#ifdef HAVE_STRSTR
#define SDL_strstr strstr
#else
extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
const char *needle);
#endif
#ifdef HAVE_ITOA
#define SDL_itoa itoa
#else
#define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix)
SDL_FORCE_INLINE char *SDL_strstr_inline(const char *haystack, const char *needle) { return strstr(haystack, needle); }
#define SDL_strstr SDL_strstr_inline
#endif
extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
#ifdef HAVE__LTOA
#define SDL_ltoa _ltoa
#else
extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
SDL_FORCE_INLINE char *SDL_ltoa_inline(long value, char *str, int radix) { return _ltoa(value, str, radix); }
#define SDL_ltoa SDL_ltoa_inline
#endif
#ifdef HAVE__UITOA
#define SDL_uitoa _uitoa
extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
#ifdef HAVE_ITOA
SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return itoa(value, str, radix); }
#else
#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
SDL_FORCE_INLINE char *SDL_itoa_inline(int value, char *str, int radix) { return SDL_ltoa((long)value, str, radix); }
#endif
#define SDL_itoa SDL_itoa_inline
extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
#ifdef HAVE__ULTOA
#define SDL_ultoa _ultoa
#else
extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
int radix);
SDL_FORCE_INLINE char *SDL_ultoa_inline(unsigned long value, char *str, int radix) { return _ultoa(value, str, radix); }
#define SDL_ultoa SDL_ultoa_inline
#endif
extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
#ifdef HAVE__UITOA
SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return _uitoa(value, str, radix); }
#else
SDL_FORCE_INLINE char *SDL_uitoa_inline(unsigned int value, char *str, int radix) { return SDL_ultoa((unsigned long)value, str, radix); }
#endif
#define SDL_uitoa SDL_uitoa_inline
extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
#ifdef HAVE_STRTOL
#define SDL_strtol strtol
#else
extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
int base);
SDL_FORCE_INLINE long SDL_strtol_inline(const char *str, char **endp, int base) { return strtol(str, endp, base); }
#define SDL_strtol SDL_strtol_inline
#endif
extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
#ifdef HAVE_STRTOUL
#define SDL_strtoul strtoul
#else
extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
char **endp, int base);
SDL_FORCE_INLINE unsigned long SDLCALL SDL_strtoul_inline(const char *str, char **endp, int base) { return strtoul(str, endp, base); }
#define SDL_strtoul SDL_strtoul_inline
#endif
extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
#ifdef HAVE__I64TOA
#define SDL_lltoa _i64toa
#else
extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
int radix);
SDL_FORCE_INLINE char *SDL_lltoa_inline(Sint64 value, char *str, int radix) { return _i64toa(value, str, radix); }
#define SDL_lltoa SDL_lltoa_inline
#endif
extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
#ifdef HAVE__UI64TOA
#define SDL_ulltoa _ui64toa
#else
extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
int radix);
SDL_FORCE_INLINE char *SDL_ulltoa_inline(Uint64 value, char *str, int radix) { return _ui64toa(value, str, radix); }
#define SDL_ulltoa SDL_ulltoa_inline
#endif
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
#ifdef HAVE_STRTOLL
#define SDL_strtoll strtoll
#else
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
int base);
SDL_FORCE_INLINE Sint64 SDL_strtoll_inline(const char *str, char **endp, int base) { return strtoll(str, endp, base); }
#define SDL_strtoll SDL_strtoll_inline
#endif
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
#ifdef HAVE_STRTOULL
#define SDL_strtoull strtoull
#else
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
int base);
SDL_FORCE_INLINE Uint64 SDL_strtoull_inline(const char *str, char **endp, int base) { return strtoull(str, endp, base); }
#define SDL_strtoull SDL_strtoull_inline
#endif
extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
#ifdef HAVE_STRTOD
#define SDL_strtod strtod
#else
extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
SDL_FORCE_INLINE Uint64 SDL_strtod_inline(const char *str, char **endp) { return strtod(str, endp); }
#define SDL_strtod SDL_strtod_inline
#endif
extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
#ifdef HAVE_ATOI
#define SDL_atoi atoi
SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return atoi(str); }
#else
#define SDL_atoi(X) SDL_strtol(X, NULL, 0)
SDL_FORCE_INLINE int SDL_atoi_inline(const char *str) { return SDL_strtol(str, NULL, 0); }
#endif
#define SDL_atoi SDL_atoi_inline
extern DECLSPEC double SDLCALL SDL_atof(const char *str);
#ifdef HAVE_ATOF
#define SDL_atof atof
SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return (double) atof(str); }
#else
#define SDL_atof(X) SDL_strtod(X, NULL)
SDL_FORCE_INLINE double SDL_atof_inline(const char *str) { return SDL_strtod(str, NULL); }
#endif
#define SDL_atof SDL_atof_inline
#ifdef HAVE_STRCMP
#define SDL_strcmp strcmp
#else
extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
#ifdef HAVE_STRCMP
SDL_FORCE_INLINE int SDL_strcmp_inline(const char *str1, const char *str2) { return strcmp(str1, str2); }
#define SDL_strcmp SDL_strcmp_inline
#endif
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
#ifdef HAVE_STRNCMP
#define SDL_strncmp strncmp
#else
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
size_t maxlen);
SDL_FORCE_INLINE int SDL_strncmp_inline(const char *str1, const char *str2, size_t maxlen) { return strncmp(str1, str2, maxlen); }
#define SDL_strncmp SDL_strncmp_inline
#endif
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
#ifdef HAVE_STRCASECMP
#define SDL_strcasecmp strcasecmp
SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return strcasecmp(str1, str2); }
#define SDL_strcasecmp SDL_strcasecmp_inline
#elif defined(HAVE__STRICMP)
#define SDL_strcasecmp _stricmp
#else
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
const char *str2);
SDL_FORCE_INLINE int SDL_strcasecmp_inline(const char *str1, const char *str2) { return _stricmp(str1, str2); }
#define SDL_strcasecmp SDL_strcasecmp_inline
#endif
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
#ifdef HAVE_STRNCASECMP
#define SDL_strncasecmp strncasecmp
SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return strncasecmp(str1, str2, len); }
#define SDL_strncasecmp SDL_strncasecmp_inline
#elif defined(HAVE__STRNICMP)
#define SDL_strncasecmp _strnicmp
#else
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
const char *str2, size_t maxlen);
SDL_FORCE_INLINE int SDL_strncasecmp_inline(const char *str1, const char *str2, size_t len) { return _strnicmp(str1, str2, len); }
#define SDL_strncasecmp SDL_strncasecmp_inline
#endif
/* Not doing SDL_*_inline functions for these, because of the varargs. */
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
#ifdef HAVE_SSCANF
#define SDL_sscanf sscanf
#else
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
...);
#define SDL_sscanf sscanf
#endif
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
#ifdef HAVE_SNPRINTF
#define SDL_snprintf snprintf
#else
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
const char *fmt, ...);
#define SDL_snprintf snprintf
#endif
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
#ifdef HAVE_VSNPRINTF
#define SDL_vsnprintf vsnprintf
#else
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
const char *fmt, va_list ap);
SDL_FORCE_INLINE int SDL_vsnprintf_inline(char *text, size_t maxlen, const char *fmt, va_list ap) { return vsnprintf(text, maxlen, fmt, ap); }
#define SDL_vsnprintf SDL_vsnprintf_inline
#endif
#ifndef HAVE_M_PI
@ -638,88 +681,94 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
#endif
#endif
#ifdef HAVE_ATAN
#define SDL_atan atan
#else
extern DECLSPEC double SDLCALL SDL_atan(double x);
#ifdef HAVE_ATAN
SDL_FORCE_INLINE double SDL_atan_inline(double x) { return atan(x); }
#define SDL_atan SDL_atan_inline
#endif
extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
#ifdef HAVE_ATAN2
#define SDL_atan2 atan2
#else
extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
SDL_FORCE_INLINE double SDL_atan2_inline(double x, double y) { return atan2(x, y); }
#define SDL_atan2 SDL_atan2_inline
#endif
extern DECLSPEC double SDLCALL SDL_ceil(double x);
#ifdef HAVE_CEIL
#define SDL_ceil ceil
SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return ceil(x); }
#else
#define SDL_ceil(x) ((double)(int)((x)+0.5))
SDL_FORCE_INLINE double SDL_ceil_inline(double x) { return (double)(int)((x)+0.5); }
#endif
#define SDL_ceil SDL_ceil_inline
#ifdef HAVE_COPYSIGN
#define SDL_copysign copysign
#else
extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
#ifdef HAVE_COPYSIGN
SDL_FORCE_INLINE double SDL_copysign_inline(double x, double y) { return copysign(x, y); }
#define SDL_copysign SDL_copysign_inline
#endif
#ifdef HAVE_COS
#define SDL_cos cos
#else
extern DECLSPEC double SDLCALL SDL_cos(double x);
#ifdef HAVE_COS
SDL_FORCE_INLINE double SDL_cos_inline(double x) { return cos(x); }
#define SDL_cos SDL_cos_inline
#endif
extern DECLSPEC float SDLCALL SDL_cosf(float x);
#ifdef HAVE_COSF
#define SDL_cosf cosf
SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return cosf(x); }
#else
#define SDL_cosf(x) (float)SDL_cos((double)x)
SDL_FORCE_INLINE float SDL_cosf_inline(float x) { return (float)SDL_cos((double)x); }
#endif
#define SDL_cosf SDL_cosf_inline
#ifdef HAVE_FABS
#define SDL_fabs fabs
#else
extern DECLSPEC double SDLCALL SDL_fabs(double x);
#ifdef HAVE_FABS
SDL_FORCE_INLINE double SDL_fabs_inline(double x) { return fabs(x); }
#define SDL_fabs SDL_fabs_inline
#endif
#ifdef HAVE_FLOOR
#define SDL_floor floor
#else
extern DECLSPEC double SDLCALL SDL_floor(double x);
#ifdef HAVE_FLOOR
SDL_FORCE_INLINE double SDL_floor_inline(double x) { return floor(x); }
#define SDL_floor SDL_floor_inline
#endif
#ifdef HAVE_LOG
#define SDL_log log
#else
extern DECLSPEC double SDLCALL SDL_log(double x);
#ifdef HAVE_LOG
SDL_FORCE_INLINE double SDL_log_inline(double x) { return log(x); }
#define SDL_log SDL_log_inline
#endif
#ifdef HAVE_POW
#define SDL_pow pow
#else
extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
#ifdef HAVE_POW
SDL_FORCE_INLINE double SDL_pow_inline(double x, double y) { return pow(x, y); }
#define SDL_pow SDL_pow_inline
#endif
#ifdef HAVE_SCALBN
#define SDL_scalbn scalbn
#else
extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
#ifdef HAVE_SCALBN
SDL_FORCE_INLINE double SDL_scalbn_inline(double x, int n) { return scalbn(x, n); }
#define SDL_scalbn SDL_scalbn_inline
#endif
#ifdef HAVE_SIN
#define SDL_sin sin
#else
extern DECLSPEC double SDLCALL SDL_sin(double x);
#ifdef HAVE_SIN
SDL_FORCE_INLINE double SDL_sin_inline(double x) { return sin(x); }
#define SDL_sin SDL_sin_inline
#endif
extern DECLSPEC float SDLCALL SDL_sinf(float x);
#ifdef HAVE_SINF
#define SDL_sinf sinf
SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return sinf(x); }
#else
#define SDL_sinf(x) (float)SDL_sin((double)x)
SDL_FORCE_INLINE float SDL_sinf_inline(float x) { return (float)SDL_sin((double)x); }
#endif
#define SDL_sinf SDL_sinf_inline
#ifdef HAVE_SQRT
#define SDL_sqrt sqrt
#else
extern DECLSPEC double SDLCALL SDL_sqrt(double x);
#ifdef HAVE_SQRT
SDL_FORCE_INLINE double SDL_sqrt_inline(double x) { return sqrt(x); }
#define SDL_sqrt SDL_sqrt_inline
#endif
/* The SDL implementation of iconv() returns these error codes */
@ -728,16 +777,11 @@ extern DECLSPEC double SDLCALL SDL_sqrt(double x);
#define SDL_ICONV_EILSEQ (size_t)-3
#define SDL_ICONV_EINVAL (size_t)-4
#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
#define SDL_iconv_t iconv_t
#define SDL_iconv_open iconv_open
#define SDL_iconv_close iconv_close
#else
/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
typedef struct _SDL_iconv_t *SDL_iconv_t;
extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
const char *fromcode);
extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
#endif
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
size_t * inbytesleft, char **outbuf,
size_t * outbytesleft);