Removed temporary memory from the API
It was intended to make the API easier to use, but various automatic garbage collection all had flaws, and making the application periodically clean up temporary memory added cognitive load to using the API, and in many cases was it was difficult to restructure threaded code to handle this. So, we're largely going back to the original system, where the API returns allocated results and you free them. In addition, to solve the problems we originally wanted temporary memory for: * Short strings with a finite count, like device names, get stored in a per-thread string pool. * Events continue to use temporary memory internally, which is cleaned up on the next event processing cycle.
This commit is contained in:
@@ -86,9 +86,9 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
int last_clipboard_update_count;
|
||||
int last_clipboard_callback_count;
|
||||
int last_clipboard_cleanup_count;
|
||||
const void *data;
|
||||
void *data;
|
||||
size_t size;
|
||||
const char *text;
|
||||
char *text;
|
||||
const char *expected_text;
|
||||
|
||||
TestClipboardData test_data1 = {
|
||||
@@ -163,11 +163,12 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
clipboard_cleanup_count - last_clipboard_cleanup_count);
|
||||
|
||||
expected_text = "TEST";
|
||||
text = (char *) SDL_GetClipboardText();
|
||||
text = SDL_GetClipboardText();
|
||||
SDLTest_AssertCheck(
|
||||
text && SDL_strcmp(text, expected_text) == 0,
|
||||
"Verify clipboard text, expected \"%s\", got \"%s\"",
|
||||
expected_text, text);
|
||||
SDL_free(text);
|
||||
|
||||
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
|
||||
SDLTest_AssertCheck(
|
||||
@@ -186,6 +187,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == SDL_strlen(expected_text),
|
||||
"Verify test text size, expected %d, got %d",
|
||||
(int)SDL_strlen(expected_text), (int)size);
|
||||
SDL_free(text);
|
||||
|
||||
expected_text = "CUSTOM";
|
||||
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]);
|
||||
@@ -205,6 +207,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == SDL_strlen(expected_text),
|
||||
"Verify test text size, expected %d, got %d",
|
||||
(int)SDL_strlen(expected_text), (int)size);
|
||||
SDL_free(text);
|
||||
|
||||
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]);
|
||||
SDLTest_AssertCheck(
|
||||
@@ -218,6 +221,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == test_data1.data_size,
|
||||
"Verify test data size, expected %d, got %d",
|
||||
(int)test_data1.data_size, (int)size);
|
||||
SDL_free(data);
|
||||
|
||||
boolResult = SDL_HasClipboardData("test/invalid");
|
||||
SDLTest_AssertCheck(
|
||||
@@ -232,6 +236,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == 0,
|
||||
"Verify invalid data size, expected 0, got %d",
|
||||
(int)size);
|
||||
SDL_free(data);
|
||||
|
||||
#if 0 /* There's no guarantee how or when the callback is called */
|
||||
SDLTest_AssertCheck(
|
||||
@@ -260,11 +265,12 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
clipboard_cleanup_count - last_clipboard_cleanup_count);
|
||||
|
||||
expected_text = "TEST";
|
||||
text = (char *) SDL_GetClipboardText();
|
||||
text = SDL_GetClipboardText();
|
||||
SDLTest_AssertCheck(
|
||||
text && SDL_strcmp(text, expected_text) == 0,
|
||||
"Verify clipboard text, expected \"%s\", got \"%s\"",
|
||||
expected_text, text);
|
||||
SDL_free(text);
|
||||
|
||||
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
|
||||
SDLTest_AssertCheck(
|
||||
@@ -283,6 +289,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == SDL_strlen(expected_text),
|
||||
"Verify test text size, expected %d, got %d",
|
||||
(int)SDL_strlen(expected_text), (int)size);
|
||||
SDL_free(text);
|
||||
|
||||
expected_text = "CUSTOM";
|
||||
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]);
|
||||
@@ -302,6 +309,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == SDL_strlen(expected_text),
|
||||
"Verify test text size, expected %d, got %d",
|
||||
(int)SDL_strlen(expected_text), (int)size);
|
||||
SDL_free(text);
|
||||
|
||||
data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size);
|
||||
SDLTest_AssertCheck(
|
||||
@@ -311,6 +319,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == test_data2.data_size,
|
||||
"Verify test data size, expected %d, got %d",
|
||||
(int)test_data2.data_size, (int)size);
|
||||
SDL_free(data);
|
||||
|
||||
data = SDL_GetClipboardData("test/invalid", &size);
|
||||
SDLTest_AssertCheck(
|
||||
@@ -321,6 +330,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
|
||||
size == 0,
|
||||
"Verify invalid data size, expected 0, got %d",
|
||||
(int)size);
|
||||
SDL_free(data);
|
||||
|
||||
#if 0 /* There's no guarantee how or when the callback is called */
|
||||
SDLTest_AssertCheck(
|
||||
@@ -376,7 +386,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
|
||||
char *text = SDL_strdup(textRef);
|
||||
SDL_bool boolResult;
|
||||
int intResult;
|
||||
const char *charResult;
|
||||
char *charResult;
|
||||
int last_clipboard_update_count;
|
||||
|
||||
SDL_AddEventWatch(ClipboardEventWatch, NULL);
|
||||
@@ -393,6 +403,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
|
||||
charResult && SDL_strcmp(charResult, "") == 0,
|
||||
"Verify SDL_GetClipboardText returned \"\", got %s",
|
||||
charResult);
|
||||
SDL_free(charResult);
|
||||
boolResult = SDL_HasClipboardText();
|
||||
SDLTest_AssertCheck(
|
||||
boolResult == SDL_FALSE,
|
||||
@@ -425,6 +436,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
|
||||
charResult && SDL_strcmp(textRef, charResult) == 0,
|
||||
"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
|
||||
textRef, charResult);
|
||||
SDL_free(charResult);
|
||||
SDLTest_AssertCheck(
|
||||
clipboard_update_count == last_clipboard_update_count + 1,
|
||||
"Verify clipboard update count incremented by 1, got %d",
|
||||
@@ -458,7 +470,7 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg)
|
||||
char *text = SDL_strdup(textRef);
|
||||
SDL_bool boolResult;
|
||||
int intResult;
|
||||
const char *charResult;
|
||||
char *charResult;
|
||||
int last_clipboard_update_count;
|
||||
|
||||
SDL_AddEventWatch(ClipboardEventWatch, NULL);
|
||||
@@ -475,6 +487,7 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg)
|
||||
charResult && SDL_strcmp(charResult, "") == 0,
|
||||
"Verify SDL_GetPrimarySelectionText returned \"\", got %s",
|
||||
charResult);
|
||||
SDL_free(charResult);
|
||||
boolResult = SDL_HasPrimarySelectionText();
|
||||
SDLTest_AssertCheck(
|
||||
boolResult == SDL_FALSE,
|
||||
@@ -506,6 +519,7 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg)
|
||||
charResult && SDL_strcmp(textRef, charResult) == 0,
|
||||
"Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'",
|
||||
textRef, charResult);
|
||||
SDL_free(charResult);
|
||||
SDLTest_AssertCheck(
|
||||
clipboard_update_count == last_clipboard_update_count + 1,
|
||||
"Verify clipboard update count incremented by 1, got %d",
|
||||
|
||||
Reference in New Issue
Block a user