Updates SDL to 2.0.12

This commit is contained in:
Areloch 2020-08-12 11:56:18 -05:00
parent 3108a08650
commit a526029f2f
861 changed files with 25596 additions and 8904 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 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
@ -888,7 +888,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
}
stringsize = inbytesleft > 4 ? inbytesleft : 4;
string = SDL_malloc(stringsize);
string = (char *) SDL_malloc(stringsize);
if (!string) {
SDL_iconv_close(cd);
return NULL;
@ -898,13 +898,14 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
SDL_memset(outbuf, 0, 4);
while (inbytesleft > 0) {
const size_t oldinbytesleft = inbytesleft;
retCode = SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
switch (retCode) {
case SDL_ICONV_E2BIG:
{
char *oldstring = string;
stringsize *= 2;
string = SDL_realloc(string, stringsize);
string = (char *) SDL_realloc(string, stringsize);
if (!string) {
SDL_iconv_close(cd);
return NULL;
@ -925,6 +926,11 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
inbytesleft = 0;
break;
}
/* Avoid infinite loops when nothing gets converted */
if (oldinbytesleft == inbytesleft)
{
break;
}
}
SDL_iconv_close(cd);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 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
@ -64,7 +64,7 @@ SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, c
/*
This code came from Gareth McCaughan, under the zlib license.
Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.14
Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.15
Everything below this comment until the HAVE_QSORT #endif was from Gareth
(any minor changes will be noted inline).
@ -143,6 +143,10 @@ benefit!
* 2016-02-21 v1.14 Replace licence with 2-clause BSD,
* and clarify a couple of things in
* comments. No code changes.
* 2016-03-10 v1.15 Fix bug kindly reported by Ryan Gordon
* (pre-insertion-sort messed up).
* Disable DEBUG_QSORT by default.
* Tweak comments very slightly.
*/
/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
@ -151,9 +155,9 @@ benefit!
#include <stdlib.h>
#include <string.h>
#define DEBUG_QSORT
#undef DEBUG_QSORT
static char _ID[]="<qsort.c gjm 1.14 2016-02-21>";
static char _ID[]="<qsort.c gjm 1.15 2016-03-10>";
#endif
/* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
@ -316,7 +320,9 @@ typedef struct { char * first; char * last; } stack_entry;
* We find the smallest element from the first |nmemb|,
* or the first |limit|, whichever is smaller;
* therefore we must have ensured that the globally smallest
* element is in the first |limit|.
* element is in the first |limit| (because our
* quicksort recursion bottoms out only once we
* reach subarrays smaller than |limit|).
*/
#define PreInsertion(swapper,limit,sz) \
first=base; \
@ -499,7 +505,7 @@ fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)
Recurse(TRUNC_words)
}
}
PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES);
PreInsertion(SWAP_words,TRUNC_words/WORD_BYTES,WORD_BYTES);
/* Now do insertion sort. */
last=((char*)base)+nmemb*WORD_BYTES;
for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) {
@ -527,7 +533,6 @@ extern void qsortG(void *base, size_t nmemb, size_t size,
qsort_words(base,nmemb,compare);
}
#endif /* HAVE_QSORT */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 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
@ -438,11 +438,15 @@ int SDL_abs(int x)
#if defined(HAVE_CTYPE_H)
int SDL_isdigit(int x) { return isdigit(x); }
int SDL_isspace(int x) { return isspace(x); }
int SDL_isupper(int x) { return isupper(x); }
int SDL_islower(int x) { return islower(x); }
int SDL_toupper(int x) { return toupper(x); }
int SDL_tolower(int x) { return tolower(x); }
#else
int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
int SDL_isupper(int x) { return ((x) >= 'A') && ((x) <= 'Z'); }
int SDL_islower(int x) { return ((x) >= 'a') && ((x) <= 'z'); }
int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
#endif

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2020 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
@ -421,17 +421,6 @@ SDL_strlen(const char *string)
#endif /* HAVE_STRLEN */
}
wchar_t *
SDL_wcsdup(const wchar_t *string)
{
size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t));
wchar_t *newstr = (wchar_t *)SDL_malloc(len);
if (newstr) {
SDL_memcpy(newstr, string, len);
}
return newstr;
}
size_t
SDL_wcslen(const wchar_t * string)
{
@ -477,6 +466,34 @@ SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t max
#endif /* HAVE_WCSLCAT */
}
wchar_t *
SDL_wcsdup(const wchar_t *string)
{
size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t));
wchar_t *newstr = (wchar_t *)SDL_malloc(len);
if (newstr) {
SDL_memcpy(newstr, string, len);
}
return newstr;
}
wchar_t *
SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle)
{
#if defined(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;
#endif /* HAVE_WCSSTR */
}
int
SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
{
@ -493,6 +510,22 @@ SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
#endif /* HAVE_WCSCMP */
}
int
SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
{
#if defined(HAVE_WCSNCMP)
return wcsncmp(str1, str2, maxlen);
#else
while (*str1 && *str2) {
if (*str1 != *str2)
break;
++str1;
++str2;
}
return (int)(*str1 - *str2);
#endif /* HAVE_WCSNCMP */
}
size_t
SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
@ -549,7 +582,7 @@ SDL_utf8strlen(const char *str)
const char *p = str;
char ch;
while ((ch = *(p++))) {
while ((ch = *(p++)) != 0) {
/* if top two bits are 1 and 0, it's a continuation byte. */
if ((ch & 0xc0) != 0x80) {
retval++;
@ -818,7 +851,7 @@ int SDL_atoi(const char *string)
double SDL_atof(const char *string)
{
#ifdef HAVE_ATOF
return (double) atof(string);
return atof(string);
#else
return SDL_strtod(string, NULL);
#endif /* HAVE_ATOF */
@ -1387,15 +1420,18 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str
sz = SDL_strlen(string);
if (info && info->width > 0 && (size_t)info->width > sz) {
char fill = info->pad_zeroes ? '0' : ' ';
const char fill = info->pad_zeroes ? '0' : ' ';
size_t width = info->width - sz;
size_t filllen;
if (info->precision >= 0 && (size_t)info->precision < sz)
width += sz - (size_t)info->precision;
while (width-- > 0 && maxlen > 0) {
*text++ = fill;
++length;
--maxlen;
}
filllen = SDL_min(width, maxlen);
SDL_memset(text, fill, filllen);
text += filllen;
length += filllen;
maxlen -= filllen;
}
slen = SDL_strlcpy(text, string, maxlen);
@ -1580,7 +1616,7 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
width = info->width - (int)(text - textstart);
if (width > 0) {
char fill = info->pad_zeroes ? '0' : ' ';
const char fill = info->pad_zeroes ? '0' : ' ';
char *end = text+left-1;
len = (text - textstart);
for (len = (text - textstart); len--; ) {
@ -1596,10 +1632,10 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
text += len;
left -= len;
}
while (len--) {
if (textstart+len < end) {
textstart[len] = fill;
}
if (end != textstart) {
const size_t filllen = SDL_min(len, ((size_t) (end - textstart)) - 1);
SDL_memset(textstart, fill, filllen);
}
}

View file

@ -0,0 +1,103 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#if defined(__clang_analyzer__)
#define SDL_DISABLE_ANALYZE_MACROS 1
#endif
#include "../SDL_internal.h"
#include "SDL_stdinc.h"
char *SDL_strtokr(char *s1, const char *s2, char **ptr)
{
#if defined(HAVE_STRTOK_R)
return strtok_r(s1, s2, ptr);
#elif defined(_MSC_VER) && defined(HAVE_STRTOK_S)
return strtok_s(s1, s2, ptr);
#else /* SDL implementation */
/*
* Adapted from _PDCLIB_strtok() of PDClib library at
* https://github.com/DevSolar/pdclib.git
*
* The code was under CC0 license:
* https://creativecommons.org/publicdomain/zero/1.0/legalcode :
*
* No Copyright
*
* The person who associated a work with this deed has dedicated the
* work to the public domain by waiving all of his or her rights to
* the work worldwide under copyright law, including all related and
* neighboring rights, to the extent allowed by law.
*
* You can copy, modify, distribute and perform the work, even for
* commercial purposes, all without asking permission. See Other
* Information below.
*/
const char *p = s2;
if (!s2 || !ptr || (!s1 && !*ptr)) return NULL;
if (s1 != NULL) { /* new string */
*ptr = s1;
} else { /* old string continued */
if (*ptr == NULL) {
/* No old string, no new string, nothing to do */
return NULL;
}
s1 = *ptr;
}
/* skip leading s2 characters */
while (*p && *s1) {
if (*s1 == *p) {
/* found separator; skip and start over */
++s1;
p = s2;
continue;
}
++p;
}
if (! *s1) { /* no more to parse */
*ptr = s1;
return NULL;
}
/* skipping non-s2 characters */
*ptr = s1;
while (**ptr) {
p = s2;
while (*p) {
if (**ptr == *p++) {
/* found separator; overwrite with '\0', position *ptr, return */
*((*ptr)++) = '\0';
return s1;
}
}
++(*ptr);
}
/* parsed to end of string */
return s1;
#endif
}