Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -40,7 +40,7 @@ static size_t SDL_envmemlen = 0;
int SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return -1;
}
@ -50,7 +50,7 @@ int SDL_setenv(const char *name, const char *value, int overwrite)
int SDL_setenv(const char *name, const char *value, int overwrite)
{
/* Input validation */
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return -1;
}
@ -72,7 +72,7 @@ int SDL_setenv(const char *name, const char *value, int overwrite)
char *new_variable;
/* Input validation */
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return -1;
}
@ -87,7 +87,7 @@ int SDL_setenv(const char *name, const char *value, int overwrite)
/* This leaks. Sorry. Get a better OS so we don't have to do this. */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *)SDL_malloc(len);
if (new_variable == NULL) {
if (!new_variable) {
return -1;
}
@ -104,7 +104,7 @@ int SDL_setenv(const char *name, const char *value, int overwrite)
char *new_variable;
/* Input validation */
if (name == NULL || *name == '\0' || SDL_strchr(name, '=') != NULL || value == NULL) {
if (!name || *name == '\0' || SDL_strchr(name, '=') != NULL || !value) {
return -1;
}
@ -116,7 +116,7 @@ int SDL_setenv(const char *name, const char *value, int overwrite)
/* Allocate memory for the variable */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *)SDL_malloc(len);
if (new_variable == NULL) {
if (!new_variable) {
return -1;
}
@ -169,7 +169,7 @@ char *SDL_getenv(const char *name)
#endif
/* Input validation */
if (name == NULL || *name == '\0') {
if (!name || *name == '\0') {
return NULL;
}
@ -181,7 +181,7 @@ char *SDL_getenv(const char *name)
size_t bufferlen;
/* Input validation */
if (name == NULL || *name == '\0') {
if (!name || *name == '\0') {
return NULL;
}
@ -192,7 +192,7 @@ char *SDL_getenv(const char *name)
}
if (bufferlen > SDL_envmemlen) {
char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
if (newmem == NULL) {
if (!newmem) {
return NULL;
}
SDL_envmem = newmem;
@ -208,14 +208,14 @@ char *SDL_getenv(const char *name)
char *value;
/* Input validation */
if (name == NULL || *name == '\0') {
if (!name || *name == '\0') {
return NULL;
}
value = (char *)0;
if (SDL_env) {
len = SDL_strlen(name);
for (i = 0; SDL_env[i] && value == NULL; ++i) {
for (i = 0; SDL_env[i] && !value; ++i) {
if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
(SDL_env[i][len] == '=')) {
value = &SDL_env[i][len + 1];

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,7 +23,7 @@
/* This file contains portable iconv functions for SDL */
#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
#ifdef __FreeBSD__
#ifndef SDL_USE_LIBICONV
/* Define LIBICONV_PLUG to use iconv from the base instead of ports and avoid linker errors. */
#define LIBICONV_PLUG 1
#endif
@ -158,28 +158,28 @@ static const char *getlocale(char *buffer, size_t bufsize)
char *ptr;
lang = SDL_getenv("LC_ALL");
if (lang == NULL) {
if (!lang) {
lang = SDL_getenv("LC_CTYPE");
}
if (lang == NULL) {
if (!lang) {
lang = SDL_getenv("LC_MESSAGES");
}
if (lang == NULL) {
if (!lang) {
lang = SDL_getenv("LANG");
}
if (lang == NULL || !*lang || SDL_strcmp(lang, "C") == 0) {
if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) {
lang = "ASCII";
}
/* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */
ptr = SDL_strchr(lang, '.');
if (ptr != NULL) {
if (ptr) {
lang = ptr + 1;
}
SDL_strlcpy(buffer, lang, bufsize);
ptr = SDL_strchr(buffer, '@');
if (ptr != NULL) {
if (ptr) {
*ptr = '\0'; /* chop end of string. */
}
@ -194,10 +194,10 @@ SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
char fromcode_buffer[64];
char tocode_buffer[64];
if (fromcode == NULL || !*fromcode) {
if (!fromcode || !*fromcode) {
fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer));
}
if (tocode == NULL || !*tocode) {
if (!tocode || !*tocode) {
tocode = getlocale(tocode_buffer, sizeof(tocode_buffer));
}
for (i = 0; i < SDL_arraysize(encodings); ++i) {
@ -236,11 +236,11 @@ size_t SDL_iconv(SDL_iconv_t cd,
Uint32 ch = 0;
size_t total;
if (inbuf == NULL || !*inbuf) {
if (!inbuf || !*inbuf) {
/* Reset the context */
return 0;
}
if (outbuf == NULL || !*outbuf || outbytesleft == NULL || !*outbytesleft) {
if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) {
return SDL_ICONV_E2BIG;
}
src = *inbuf;
@ -786,24 +786,20 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
size_t outbytesleft;
size_t retCode = 0;
cd = SDL_iconv_open(tocode, fromcode);
if (cd == (SDL_iconv_t)-1) {
/* See if we can recover here (fixes iconv on Solaris 11) */
if (tocode == NULL || !*tocode) {
tocode = "UTF-8";
}
if (fromcode == NULL || !*fromcode) {
fromcode = "UTF-8";
}
cd = SDL_iconv_open(tocode, fromcode);
if (!tocode || !*tocode) {
tocode = "UTF-8";
}
if (!fromcode || !*fromcode) {
fromcode = "UTF-8";
}
cd = SDL_iconv_open(tocode, fromcode);
if (cd == (SDL_iconv_t)-1) {
return NULL;
}
stringsize = inbytesleft;
string = (char *)SDL_malloc(stringsize + sizeof(Uint32));
if (string == NULL) {
if (!string) {
SDL_iconv_close(cd);
return NULL;
}
@ -820,7 +816,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
char *oldstring = string;
stringsize *= 2;
string = (char *)SDL_realloc(string, stringsize + sizeof(Uint32));
if (string == NULL) {
if (!string) {
SDL_free(oldstring);
SDL_iconv_close(cd);
return NULL;

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -5287,7 +5287,10 @@ void *SDL_malloc(size_t size)
mem = s_mem.malloc_func(size);
if (mem) {
SDL_AtomicIncRef(&s_mem.num_allocations);
} else {
SDL_OutOfMemory();
}
return mem;
}
@ -5303,7 +5306,10 @@ void *SDL_calloc(size_t nmemb, size_t size)
mem = s_mem.calloc_func(nmemb, size);
if (mem) {
SDL_AtomicIncRef(&s_mem.num_allocations);
} else {
SDL_OutOfMemory();
}
return mem;
}
@ -5318,7 +5324,10 @@ void *SDL_realloc(void *ptr, size_t size)
mem = s_mem.realloc_func(ptr, size);
if (mem && !ptr) {
SDL_AtomicIncRef(&s_mem.num_allocations);
} else if (!mem) {
SDL_OutOfMemory();
}
return mem;
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -696,8 +696,80 @@ RETZERO:
/* *INDENT-ON* */
}
void __declspec(naked) _chkstk(void)
{
__asm {
push ecx
mov ecx,esp ; lea ecx,dword ptr [esp]+4
add ecx,4
sub ecx,eax
sbb eax,eax
not eax
and ecx,eax
mov eax,esp
and eax,0xfffff000
L1:
cmp ecx,eax
jb short L2
mov eax,ecx
pop ecx
xchg esp,eax
mov eax,dword ptr [eax]
mov dword ptr [esp],eax
ret
L2:
sub eax,0x1000
test dword ptr [eax],eax
jmp short L1
}
}
void __declspec(naked) _alloca_probe_8(void)
{
/* *INDENT-OFF* */
__asm {
push ecx
mov ecx,esp ; lea ecx,dword ptr [esp]+8
add ecx,8
sub ecx,eax
and ecx,0x7
add eax,ecx
sbb ecx,ecx
or eax,ecx
pop ecx
jmp _chkstk
}
/* *INDENT-ON* */
}
void __declspec(naked) _alloca_probe_16(void)
{
/* *INDENT-OFF* */
__asm {
push ecx
mov ecx,esp ; lea ecx,dword ptr [esp]+8
add ecx,8
sub ecx,eax
and ecx,0xf
add eax,ecx
sbb ecx,ecx
or eax,ecx
pop ecx
jmp _chkstk
}
/* *INDENT-ON* */
}
#endif /* _M_IX86 */
#ifdef _M_ARM64
void __chkstk(void);
void __chkstk() {
}
#endif
#endif /* MSC_VER */
#ifdef __ICL

View File

@ -0,0 +1,29 @@
include ksamd64.inc
text SEGMENT EXECUTE
public __chkstk
__chkstk:
sub rsp,010h
mov QWORD PTR [rsp],r10
mov QWORD PTR [rsp+08h],r11
xor r11,r11
lea r10,[rsp+018h]
sub r10,rax
cmovb r10,r11
mov r11,QWORD PTR gs:[TeStackLimit]
cmp r10,r11
jae chkstk_finish
and r10w,0f000h
chkstk_loop:
lea r11,[r11-PAGE_SIZE]
mov BYTE PTR [r11],0h
cmp r10,r11
jne chkstk_loop
chkstk_finish:
mov r10,QWORD PTR [rsp]
mov r11,QWORD PTR [rsp+08h]
add rsp,010h
ret
end

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -468,19 +468,28 @@ wchar_t *SDL_wcsdup(const wchar_t *string)
return newstr;
}
wchar_t *SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
{
size_t length = SDL_wcslen(needle);
if (length == 0) {
return (wchar_t *)haystack;
}
while (maxlen >= length && *haystack) {
if (maxlen >= length && SDL_wcsncmp(haystack, needle, length) == 0) {
return (wchar_t *)haystack;
}
++haystack;
--maxlen;
}
return NULL;
}
wchar_t *SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
{
#ifdef HAVE_WCSSTR
return SDL_const_cast(wchar_t *, wcsstr(haystack, needle));
#else
size_t length = SDL_wcslen(needle);
while (*haystack) {
if (SDL_wcsncmp(haystack, needle, length) == 0) {
return (wchar_t *)haystack;
}
++haystack;
}
return NULL;
return SDL_wcsnstr(haystack, needle, SDL_wcslen(haystack));
#endif /* HAVE_WCSSTR */
}
@ -821,19 +830,32 @@ char *SDL_strrchr(const char *string, int c)
#endif /* HAVE_STRRCHR */
}
char *SDL_strnstr(const char *haystack, const char *needle, size_t maxlen)
{
#ifdef HAVE_STRNSTR
return SDL_const_cast(char *, strnstr(haystack, needle, maxlen));
#else
size_t length = SDL_strlen(needle);
if (length == 0) {
return (char *)haystack;
}
while (maxlen >= length && *haystack) {
if (SDL_strncmp(haystack, needle, length) == 0) {
return (char *)haystack;
}
++haystack;
--maxlen;
}
return NULL;
#endif /* HAVE_STRSTR */
}
char *SDL_strstr(const char *haystack, const char *needle)
{
#ifdef HAVE_STRSTR
return SDL_const_cast(char *, strstr(haystack, needle));
#else
size_t length = SDL_strlen(needle);
while (*haystack) {
if (SDL_strncmp(haystack, needle, length) == 0) {
return (char *)haystack;
}
++haystack;
}
return NULL;
return SDL_strnstr(haystack, needle, SDL_strlen(haystack));
#endif /* HAVE_STRSTR */
}
@ -1199,12 +1221,45 @@ int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
return vsscanf(text, fmt, ap);
}
#else
static SDL_bool CharacterMatchesSet(char c, const char *set, size_t set_len)
{
SDL_bool invert = SDL_FALSE;
SDL_bool result = SDL_FALSE;
if (*set == '^') {
invert = SDL_TRUE;
++set;
--set_len;
}
while (set_len > 0 && !result) {
if (set_len >= 3 && set[1] == '-') {
char low_char = SDL_min(set[0], set[2]);
char high_char = SDL_max(set[0], set[2]);
if (c >= low_char && c <= high_char) {
result = SDL_TRUE;
}
set += 3;
set_len -= 3;
} else {
if (c == *set) {
result = SDL_TRUE;
}
++set;
--set_len;
}
}
if (invert) {
result = !result;
}
return result;
}
/* NOLINTNEXTLINE(readability-non-const-parameter) */
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap)
{
int retval = 0;
if (text == NULL || !*text) {
if (!text || !*text) {
return -1;
}
@ -1472,6 +1527,44 @@ int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
}
done = SDL_TRUE;
break;
case '[':
{
const char *set = fmt + 1;
while (*fmt && *fmt != ']') {
++fmt;
}
if (*fmt) {
size_t set_len = (fmt - set);
if (suppress) {
while (CharacterMatchesSet(*text, set, set_len)) {
++text;
if (count) {
if (--count == 0) {
break;
}
}
}
} else {
SDL_bool had_match = SDL_FALSE;
char *valuep = va_arg(ap, char *);
while (CharacterMatchesSet(*text, set, set_len)) {
had_match = SDL_TRUE;
*valuep++ = *text++;
if (count) {
if (--count == 0) {
break;
}
}
}
*valuep = '\0';
if (had_match) {
++retval;
}
}
}
}
done = SDL_TRUE;
break;
default:
done = SDL_TRUE;
break;
@ -1570,7 +1663,7 @@ static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, c
size_t length = 0;
size_t slen, sz;
if (string == NULL) {
if (!string) {
string = "(null)";
}
@ -1630,7 +1723,7 @@ static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *inf
{ /* left-pad num with zeroes. */
size_t sz, pad, have_sign;
if (info == NULL) {
if (!info) {
return;
}
@ -1829,7 +1922,7 @@ static size_t SDL_PrintPointer(char *text, size_t maxlen, SDL_FormatInfo *info,
}
/* NOLINTNEXTLINE(readability-non-const-parameter) */
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
{
size_t length = 0;
@ -2053,7 +2146,7 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *f
#undef TEXT_AND_LEN_ARGS
#endif /* HAVE_VSNPRINTF */
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap)
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap)
{
char *text_utf8 = NULL, *fmt_utf8 = NULL;
int retval;
@ -2108,7 +2201,7 @@ int SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
return retval;
}
int SDL_vasprintf(char **strp, const char *fmt, va_list ap)
int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
{
int retval;
int size = 100; /* Guess we need no more than 100 bytes */
@ -2118,7 +2211,7 @@ int SDL_vasprintf(char **strp, const char *fmt, va_list ap)
*strp = NULL;
p = (char *)SDL_malloc(size);
if (p == NULL) {
if (!p) {
return -1;
}
@ -2130,6 +2223,7 @@ int SDL_vasprintf(char **strp, const char *fmt, va_list ap)
/* Check error code */
if (retval < 0) {
SDL_free(p);
return retval;
}
@ -2143,7 +2237,7 @@ int SDL_vasprintf(char **strp, const char *fmt, va_list ap)
size = retval + 1; /* Precisely what is needed */
np = (char *)SDL_realloc(p, size);
if (np == NULL) {
if (!np) {
SDL_free(p);
return -1;
} else {

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages