early-access version 2847

This commit is contained in:
pineappleEA
2022-07-19 05:48:31 +02:00
parent ba74a2373c
commit 05e3c38e7f
498 changed files with 16027 additions and 27028 deletions

View File

@@ -48,7 +48,7 @@ int
SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
}
@@ -59,7 +59,7 @@ int
SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
}
@@ -82,7 +82,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
char *new_variable;
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
}
@@ -115,7 +115,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
char *new_variable;
/* Input validation */
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
}
@@ -181,7 +181,7 @@ SDL_getenv(const char *name)
#endif
/* Input validation */
if (!name || *name == '\0') {
if (!name || !*name) {
return NULL;
}
@@ -194,7 +194,7 @@ SDL_getenv(const char *name)
size_t bufferlen;
/* Input validation */
if (!name || *name == '\0') {
if (!name || SDL_strlen(name)==0) {
return NULL;
}
@@ -222,7 +222,7 @@ SDL_getenv(const char *name)
char *value;
/* Input validation */
if (!name || *name == '\0') {
if (!name || SDL_strlen(name)==0) {
return NULL;
}

View File

@@ -36,6 +36,18 @@
#define LIBICONV_PLUG 1
#endif
#include <iconv.h>
/* Depending on which standard the iconv() was implemented with,
iconv() may or may not use const char ** for the inbuf param.
If we get this wrong, it's just a warning, so no big deal.
*/
#if defined(_XGP6) || defined(__APPLE__) || defined(__RISCOS__) || defined(__FREEBSD__) || \
defined(__EMSCRIPTEN__) || \
(defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \
(defined(_NEWLIB_VERSION)))
#define ICONV_INBUF_NONCONST
#endif
#include <errno.h>
SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t));
@@ -57,9 +69,12 @@ SDL_iconv(SDL_iconv_t cd,
const char **inbuf, size_t * inbytesleft,
char **outbuf, size_t * outbytesleft)
{
/* iconv's second parameter may or may not be `const char const *` depending on the
C runtime's whims. Casting to void * seems to make everyone happy, though. */
const size_t retCode = iconv((iconv_t) ((uintptr_t) cd), (void *) inbuf, inbytesleft, outbuf, outbytesleft);
size_t retCode;
#ifdef ICONV_INBUF_NONCONST
retCode = iconv((iconv_t) ((uintptr_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft);
#else
retCode = iconv((iconv_t) ((uintptr_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
#endif
if (retCode == (size_t) - 1) {
switch (errno) {
case E2BIG:
@@ -126,7 +141,7 @@ static struct
const char *name;
int format;
} encodings[] = {
/* *INDENT-OFF* */ /* clang-format off */
/* *INDENT-OFF* */
{ "ASCII", ENCODING_ASCII },
{ "US-ASCII", ENCODING_ASCII },
{ "8859-1", ENCODING_LATIN1 },
@@ -160,7 +175,7 @@ static struct
{ "UCS-4LE", ENCODING_UCS4LE },
{ "UCS-4BE", ENCODING_UCS4BE },
{ "UCS-4-INTERNAL", ENCODING_UCS4NATIVE },
/* *INDENT-ON* */ /* clang-format on */
/* *INDENT-ON* */
};
static const char *

View File

@@ -733,7 +733,7 @@ extern "C"
maximum supported value of n differs across systems, but is in all
cases less than the maximum representable value of a size_t.
*/
void * SDLCALL dlmalloc(size_t);
void *dlmalloc(size_t);
/*
free(void* p)
@@ -742,14 +742,14 @@ extern "C"
It has no effect if p is null. If p was not malloced or already
freed, free(p) will by default cause the current program to abort.
*/
void SDLCALL dlfree(void *);
void dlfree(void *);
/*
calloc(size_t n_elements, size_t element_size);
Returns a pointer to n_elements * element_size bytes, with all locations
set to zero.
*/
void * SDLCALL dlcalloc(size_t, size_t);
void *dlcalloc(size_t, size_t);
/*
realloc(void* p, size_t n)
@@ -774,7 +774,7 @@ extern "C"
to be used as an argument to realloc is not supported.
*/
void * SDLCALL dlrealloc(void *, size_t);
void *dlrealloc(void *, size_t);
/*
memalign(size_t alignment, size_t n);
@@ -5305,10 +5305,10 @@ History:
#endif /* !HAVE_MALLOC */
#ifdef HAVE_MALLOC
static void* SDLCALL real_malloc(size_t s) { return malloc(s); }
static void* SDLCALL real_calloc(size_t n, size_t s) { return calloc(n, s); }
static void* SDLCALL real_realloc(void *p, size_t s) { return realloc(p,s); }
static void SDLCALL real_free(void *p) { free(p); }
#define real_malloc malloc
#define real_calloc calloc
#define real_realloc realloc
#define real_free free
#else
#define real_malloc dlmalloc
#define real_calloc dlcalloc

View File

@@ -534,38 +534,5 @@ extern void qsortG(void *base, size_t nmemb, size_t size,
#endif /* HAVE_QSORT */
void *
SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *))
{
#if defined(HAVE_BSEARCH)
return bsearch(key, base, nmemb, size, compare);
#else
/* SDL's replacement: Taken from the Public Domain C Library (PDCLib):
Permission is granted to use, modify, and / or redistribute at will.
*/
const void *pivot;
size_t corr;
int rc;
while (nmemb) {
/* algorithm needs -1 correction if remaining elements are an even number. */
corr = nmemb % 2;
nmemb /= 2;
pivot = (const char *)base + (nmemb * size);
rc = compare(key, pivot);
if (rc > 0) {
base = (const char *)pivot + size;
/* applying correction */
nmemb -= (1 - corr);
} else if (rc == 0) {
return (void *)pivot;
}
}
return NULL;
#endif /* HAVE_BSEARCH */
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -549,9 +549,8 @@ int SDL_isblank(int x) { return ((x) == ' ') || ((x) == '\t'); }
__declspec(selectany) int _fltused = 1;
#endif
/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
Always provide it for the SDL2 DLL, but skip it when building static lib w/ static runtime. */
#if (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT))
/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls */
#if _MSC_VER >= 1400
extern void *memcpy(void* dst, const void* src, size_t len);
#pragma intrinsic(memcpy)
@@ -571,7 +570,7 @@ memset(void *dst, int c, size_t len)
{
return SDL_memset(dst, c, len);
}
#endif /* (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT)) */
#endif /* _MSC_VER >= 1400 */
#ifdef _M_IX86

View File

@@ -27,7 +27,12 @@
/* This file contains portable string manipulation functions for SDL */
#include "SDL_stdinc.h"
#include "SDL_vacopy.h"
#if defined(_MSC_VER) && _MSC_VER <= 1800
/* Visual Studio 2013 tries to link with _vacopy in the C runtime. Newer versions do an inline assignment */
#undef va_copy
#define va_copy(dst, src) dst = src
#endif
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
@@ -263,6 +268,108 @@ SDL_ScanFloat(const char *text, double *valuep)
}
#endif
void *
SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
{
#if defined(HAVE_MEMSET)
return memset(dst, c, len);
#else
size_t left;
Uint32 *dstp4;
Uint8 *dstp1 = (Uint8 *) dst;
Uint8 value1;
Uint32 value4;
/* The value used in memset() is a byte, passed as an int */
c &= 0xff;
/* The destination pointer needs to be aligned on a 4-byte boundary to
* execute a 32-bit set. Set first bytes manually if needed until it is
* aligned. */
value1 = (Uint8)c;
while ((uintptr_t)dstp1 & 0x3) {
if (len--) {
*dstp1++ = value1;
} else {
return dst;
}
}
value4 = ((Uint32)c | ((Uint32)c << 8) | ((Uint32)c << 16) | ((Uint32)c << 24));
dstp4 = (Uint32 *) dstp1;
left = (len % 4);
len /= 4;
while (len--) {
*dstp4++ = value4;
}
dstp1 = (Uint8 *) dstp4;
switch (left) {
case 3:
*dstp1++ = value1;
case 2:
*dstp1++ = value1;
case 1:
*dstp1++ = value1;
}
return dst;
#endif /* HAVE_MEMSET */
}
void *
SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{
#ifdef __GNUC__
/* Presumably this is well tuned for speed.
On my machine this is twice as fast as the C code below.
*/
return __builtin_memcpy(dst, src, len);
#elif defined(HAVE_MEMCPY)
return memcpy(dst, src, len);
#elif defined(HAVE_BCOPY)
bcopy(src, dst, len);
return dst;
#else
/* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
using Uint32* pointers, so we need to make sure the pointers are
aligned before we loop using them.
*/
if (((uintptr_t)src & 0x3) || ((uintptr_t)dst & 0x3)) {
/* Do an unaligned byte copy */
Uint8 *srcp1 = (Uint8 *)src;
Uint8 *dstp1 = (Uint8 *)dst;
while (len--) {
*dstp1++ = *srcp1++;
}
} else {
size_t left = (len % 4);
Uint32 *srcp4, *dstp4;
Uint8 *srcp1, *dstp1;
srcp4 = (Uint32 *) src;
dstp4 = (Uint32 *) dst;
len /= 4;
while (len--) {
*dstp4++ = *srcp4++;
}
srcp1 = (Uint8 *) srcp4;
dstp1 = (Uint8 *) dstp4;
switch (left) {
case 3:
*dstp1++ = *srcp1++;
case 2:
*dstp1++ = *srcp1++;
case 1:
*dstp1++ = *srcp1++;
}
}
return dst;
#endif /* __GNUC__ */
}
void *
SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{
@@ -532,16 +639,19 @@ SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_
size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
size_t i = 0;
unsigned char trailing_bytes = 0;
if (bytes) {
if (bytes)
{
unsigned char c = (unsigned char)src[bytes - 1];
if (UTF8_IsLeadByte(c)) {
if (UTF8_IsLeadByte(c))
--bytes;
} else if (UTF8_IsTrailingByte(c)) {
for (i = bytes - 1; i != 0; --i) {
else if (UTF8_IsTrailingByte(c))
{
for (i = bytes - 1; i != 0; --i)
{
c = (unsigned char)src[i];
trailing_bytes = UTF8_TrailingBytes(c);
if (trailing_bytes) {
if (trailing_bytes)
{
if (bytes - i != trailing_bytes + 1)
bytes = i;
@@ -552,7 +662,6 @@ SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_
SDL_memcpy(dst, src, bytes);
}
dst[bytes] = '\0';
return bytes;
}
@@ -573,23 +682,6 @@ SDL_utf8strlen(const char *str)
return retval;
}
size_t
SDL_utf8strnlen(const char *str, size_t bytes)
{
size_t retval = 0;
const char *p = str;
unsigned char ch;
while ((ch = *(p++)) != 0 && bytes-- > 0) {
/* if top two bits are 1 and 0, it's a continuation byte. */
if ((ch & 0xc0) != 0x80) {
retval++;
}
}
return retval;
}
size_t
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
@@ -978,16 +1070,13 @@ SDL_strcmp(const char *str1, const char *str2)
#if defined(HAVE_STRCMP)
return strcmp(str1, str2);
#else
int result;
while(1) {
result = (int)((unsigned char) *str1 - (unsigned char) *str2);
if (result != 0 || (*str1 == '\0'/* && *str2 == '\0'*/))
while (*str1 && *str2) {
if (*str1 != *str2)
break;
++str1;
++str2;
}
return result;
return (int)((unsigned char) *str1 - (unsigned char) *str2);
#endif /* HAVE_STRCMP */
}
@@ -997,20 +1086,17 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
#if defined(HAVE_STRNCMP)
return strncmp(str1, str2, maxlen);
#else
int result;
while (maxlen) {
result = (int) (unsigned char) *str1 - (unsigned char) *str2;
if (result != 0 || *str1 == '\0'/* && *str2 == '\0'*/)
while (*str1 && *str2 && maxlen) {
if (*str1 != *str2)
break;
++str1;
++str2;
--maxlen;
}
if (!maxlen) {
result = 0;
return 0;
}
return result;
return (int) ((unsigned char) *str1 - (unsigned char) *str2);
#endif /* HAVE_STRNCMP */
}
@@ -1022,18 +1108,19 @@ SDL_strcasecmp(const char *str1, const char *str2)
#elif defined(HAVE__STRICMP)
return _stricmp(str1, str2);
#else
int a, b, result;
while (1) {
char a = 0;
char b = 0;
while (*str1 && *str2) {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/)
if (a != b)
break;
++str1;
++str2;
}
return result;
a = SDL_toupper(*str1);
b = SDL_toupper(*str2);
return (int) ((unsigned char) a - (unsigned char) b);
#endif /* HAVE_STRCASECMP */
}
@@ -1045,21 +1132,24 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
#elif defined(HAVE__STRNICMP)
return _strnicmp(str1, str2, maxlen);
#else
int a, b, result;
while (maxlen) {
char a = 0;
char b = 0;
while (*str1 && *str2 && maxlen) {
a = SDL_tolower((unsigned char) *str1);
b = SDL_tolower((unsigned char) *str2);
result = a - b;
if (result != 0 || a == 0 /*&& b == 0*/)
if (a != b)
break;
++str1;
++str2;
--maxlen;
}
if (maxlen == 0)
result = 0;
return result;
if (maxlen == 0) {
return 0;
} else {
a = SDL_tolower((unsigned char) *str1);
b = SDL_tolower((unsigned char) *str2);
return (int) ((unsigned char) a - (unsigned char) b);
}
#endif /* HAVE_STRNCASECMP */
}