Small stack allocations fall back to malloc if they're unexpectedly large.

This commit is contained in:
Ryan C. Gordon
2018-10-22 20:50:32 -04:00
parent eedf2c965d
commit b262b0ebc9
19 changed files with 84 additions and 52 deletions

View File

@@ -901,7 +901,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_TOUCH:
if (data->videodata->GetTouchInputInfo && data->videodata->CloseTouchInputHandle) {
UINT i, num_inputs = LOWORD(wParam);
PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
SDL_bool isstack;
PTOUCHINPUT inputs = SDL_small_alloc(TOUCHINPUT, num_inputs, &isstack);
if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
RECT rect;
float x, y;
@@ -909,7 +910,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (!GetClientRect(hwnd, &rect) ||
(rect.right == rect.left && rect.bottom == rect.top)) {
if (inputs) {
SDL_stack_free(inputs);
SDL_small_free(inputs, isstack);
}
break;
}
@@ -943,7 +944,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
}
SDL_stack_free(inputs);
SDL_small_free(inputs, isstack);
data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
return 0;
@@ -954,17 +955,19 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
UINT i;
HDROP drop = (HDROP) wParam;
SDL_bool isstack;
UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
for (i = 0; i < count; ++i) {
SDL_bool isstack;
UINT size = DragQueryFile(drop, i, NULL, 0) + 1;
LPTSTR buffer = SDL_stack_alloc(TCHAR, size);
LPTSTR buffer = SDL_small_alloc(TCHAR, size, &isstack);
if (buffer) {
if (DragQueryFile(drop, i, buffer, size)) {
char *file = WIN_StringToUTF8(buffer);
SDL_SendDropFile(data->window, file);
SDL_free(file);
}
SDL_stack_free(buffer);
SDL_small_free(buffer, isstack);
}
}
SDL_SendDropComplete(data->window);