Small stack allocations fall back to malloc if they're unexpectedly large. SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Mon, 22 Oct 2018 20:50:32 -0400
branchSDL-ryan-batching-renderer
changeset 12349a67dedb293c8
parent 12300 5d5d45f82f28
child 12350 b1a820d2f1aa
Small stack allocations fall back to malloc if they're unexpectedly large.
src/SDL_assert.c
src/SDL_internal.h
src/SDL_log.c
src/core/android/SDL_android.c
src/file/SDL_rwops.c
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_joystick.c
src/loadso/dlopen/SDL_sysloadso.c
src/main/windows/SDL_windows_main.c
src/render/SDL_render.c
src/render/opengl/SDL_render_gl.c
src/render/opengl/SDL_shaders_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/video/cocoa/SDL_cocoamodes.m
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowsframebuffer.c
src/video/windows/SDL_windowsmouse.c
src/video/windows/SDL_windowswindow.c
     1.1 --- a/src/SDL_assert.c	Sat Oct 06 17:08:04 2018 -0400
     1.2 +++ b/src/SDL_assert.c	Mon Oct 22 20:50:32 2018 -0400
     1.3 @@ -178,6 +178,7 @@
     1.4  
     1.5      (void) userdata;  /* unused in default handler. */
     1.6  
     1.7 +    /* !!! FIXME: why is this using SDL_stack_alloc and not just "char message[SDL_MAX_LOG_MESSAGE];" ? */
     1.8      message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
     1.9      if (!message) {
    1.10          /* Uh oh, we're in real trouble now... */
     2.1 --- a/src/SDL_internal.h	Sat Oct 06 17:08:04 2018 -0400
     2.2 +++ b/src/SDL_internal.h	Mon Oct 22 20:50:32 2018 -0400
     2.3 @@ -35,6 +35,10 @@
     2.4  #define SDL_VARIABLE_LENGTH_ARRAY
     2.5  #endif
     2.6  
     2.7 +#define SDL_MAX_SMALL_ALLOC_STACKSIZE 128
     2.8 +#define SDL_small_alloc(type, count, pisstack) ( (*(pisstack) = ((sizeof(type)*(count)) < SDL_MAX_SMALL_ALLOC_STACKSIZE)), (*(pisstack) ? SDL_stack_alloc(type, count) : (type*)SDL_malloc(sizeof(type)*(count))) )
     2.9 +#define SDL_small_free(ptr, isstack) if ((isstack)) { SDL_stack_free(ptr); } else { SDL_free(ptr); }
    2.10 +
    2.11  #include "dynapi/SDL_dynapi.h"
    2.12  
    2.13  #if SDL_DYNAMIC_API
     3.1 --- a/src/SDL_log.c	Sat Oct 06 17:08:04 2018 -0400
     3.2 +++ b/src/SDL_log.c	Mon Oct 22 20:50:32 2018 -0400
     3.3 @@ -282,6 +282,7 @@
     3.4          return;
     3.5      }
     3.6  
     3.7 +    /* !!! FIXME: why not just "char message[SDL_MAX_LOG_MESSAGE];" ? */
     3.8      message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
     3.9      if (!message) {
    3.10          return;
    3.11 @@ -321,6 +322,7 @@
    3.12          char *output;
    3.13          size_t length;
    3.14          LPTSTR tstr;
    3.15 +        SDL_bool isstack;
    3.16  
    3.17  #if !defined(HAVE_STDIO_H) && !defined(__WINRT__)
    3.18          BOOL attachResult;
    3.19 @@ -364,7 +366,7 @@
    3.20  #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */
    3.21  
    3.22          length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
    3.23 -        output = SDL_stack_alloc(char, length);
    3.24 +        output = SDL_small_alloc(char, length, &isstack);
    3.25          SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
    3.26          tstr = WIN_UTF8ToString(output);
    3.27          
    3.28 @@ -389,7 +391,7 @@
    3.29  #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */
    3.30  
    3.31          SDL_free(tstr);
    3.32 -        SDL_stack_free(output);
    3.33 +        SDL_small_free(output, isstack);
    3.34      }
    3.35  #elif defined(__ANDROID__)
    3.36      {
    3.37 @@ -404,7 +406,7 @@
    3.38      extern void SDL_NSLog(const char *text);
    3.39      {
    3.40          char *text;
    3.41 -
    3.42 +        /* !!! FIXME: why not just "char text[SDL_MAX_LOG_MESSAGE];" ? */
    3.43          text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
    3.44          if (text) {
    3.45              SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
     4.1 --- a/src/core/android/SDL_android.c	Sat Oct 06 17:08:04 2018 -0400
     4.2 +++ b/src/core/android/SDL_android.c	Mon Oct 22 20:50:32 2018 -0400
     4.3 @@ -466,10 +466,11 @@
     4.4              int argc;
     4.5              int len;
     4.6              char **argv;
     4.7 +            SDL_bool isstack;
     4.8  
     4.9              /* Prepare the arguments. */
    4.10              len = (*env)->GetArrayLength(env, array);
    4.11 -            argv = SDL_stack_alloc(char*, 1 + len + 1);
    4.12 +            argv = SDL_small_alloc(char*, 1 + len + 1, &isstack);  /* !!! FIXME: check for NULL */
    4.13              argc = 0;
    4.14              /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
    4.15                 https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start
    4.16 @@ -502,7 +503,7 @@
    4.17              for (i = 0; i < argc; ++i) {
    4.18                  SDL_free(argv[i]);
    4.19              }
    4.20 -            SDL_stack_free(argv);
    4.21 +            SDL_small_free(argv, isstack);
    4.22  
    4.23          } else {
    4.24              __android_log_print(ANDROID_LOG_ERROR, "SDL", "nativeRunMain(): Couldn't find function %s in library %s", function_name, library_file);
     5.1 --- a/src/file/SDL_rwops.c	Sat Oct 06 17:08:04 2018 -0400
     5.2 +++ b/src/file/SDL_rwops.c	Mon Oct 22 20:50:32 2018 -0400
     5.3 @@ -528,6 +528,7 @@
     5.4          char *path;
     5.5          FILE *fp;
     5.6  
     5.7 +        /* !!! FIXME: why not just "char path[PATH_MAX];" ? */
     5.8          path = SDL_stack_alloc(char, PATH_MAX);
     5.9          if (path) {
    5.10              SDL_snprintf(path, PATH_MAX, "%s/%s",
     6.1 --- a/src/joystick/SDL_gamecontroller.c	Sat Oct 06 17:08:04 2018 -0400
     6.2 +++ b/src/joystick/SDL_gamecontroller.c	Mon Oct 22 20:50:32 2018 -0400
     6.3 @@ -203,13 +203,14 @@
     6.4  {
     6.5      int i, num_events;
     6.6      SDL_Event *events;
     6.7 +    SDL_bool isstack;
     6.8  
     6.9      num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
    6.10      if (num_events <= 0) {
    6.11          return;
    6.12      }
    6.13  
    6.14 -    events = SDL_stack_alloc(SDL_Event, num_events);
    6.15 +    events = SDL_small_alloc(SDL_Event, num_events, &isstack);
    6.16      if (!events) {
    6.17          return;
    6.18      }
    6.19 @@ -220,7 +221,7 @@
    6.20      }
    6.21      SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
    6.22  
    6.23 -    SDL_stack_free(events);
    6.24 +    SDL_small_free(events, isstack);
    6.25  }
    6.26  
    6.27  static SDL_bool HasSameOutput(SDL_ExtendedGameControllerBind *a, SDL_ExtendedGameControllerBind *b)
     7.1 --- a/src/joystick/SDL_joystick.c	Sat Oct 06 17:08:04 2018 -0400
     7.2 +++ b/src/joystick/SDL_joystick.c	Mon Oct 22 20:50:32 2018 -0400
     7.3 @@ -752,13 +752,14 @@
     7.4  {
     7.5      int i, num_events;
     7.6      SDL_Event *events;
     7.7 +    SDL_bool isstack;
     7.8  
     7.9      num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
    7.10      if (num_events <= 0) {
    7.11          return;
    7.12      }
    7.13  
    7.14 -    events = SDL_stack_alloc(SDL_Event, num_events);
    7.15 +    events = SDL_small_alloc(SDL_Event, num_events, &isstack);
    7.16      if (!events) {
    7.17          return;
    7.18      }
    7.19 @@ -769,7 +770,7 @@
    7.20      }
    7.21      SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
    7.22  
    7.23 -    SDL_stack_free(events);
    7.24 +    SDL_small_free(events, isstack);
    7.25  }
    7.26  
    7.27  void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
     8.1 --- a/src/loadso/dlopen/SDL_sysloadso.c	Sat Oct 06 17:08:04 2018 -0400
     8.2 +++ b/src/loadso/dlopen/SDL_sysloadso.c	Mon Oct 22 20:50:32 2018 -0400
     8.3 @@ -61,12 +61,13 @@
     8.4      void *symbol = dlsym(handle, name);
     8.5      if (symbol == NULL) {
     8.6          /* append an underscore for platforms that need that. */
     8.7 +        SDL_bool isstack;
     8.8          size_t len = 1 + SDL_strlen(name) + 1;
     8.9 -        char *_name = SDL_stack_alloc(char, len);
    8.10 +        char *_name = SDL_small_alloc(char, len, &isstack);
    8.11          _name[0] = '_';
    8.12          SDL_strlcpy(&_name[1], name, len);
    8.13          symbol = dlsym(handle, _name);
    8.14 -        SDL_stack_free(_name);
    8.15 +        SDL_small_free(_name, isstack);
    8.16          if (symbol == NULL) {
    8.17              SDL_SetError("Failed loading %s: %s", name,
    8.18                           (const char *) dlerror());
     9.1 --- a/src/main/windows/SDL_windows_main.c	Sat Oct 06 17:08:04 2018 -0400
     9.2 +++ b/src/main/windows/SDL_windows_main.c	Mon Oct 22 20:50:32 2018 -0400
     9.3 @@ -131,6 +131,7 @@
     9.4  static int
     9.5  main_getcmdline()
     9.6  {
     9.7 +    SDL_bool isstack;
     9.8      char **argv;
     9.9      int argc;
    9.10      char *cmdline;
    9.11 @@ -150,7 +151,7 @@
    9.12  
    9.13      /* Parse it into argv and argc */
    9.14      argc = ParseCommandLine(cmdline, NULL);
    9.15 -    argv = SDL_stack_alloc(char *, argc + 1);
    9.16 +    argv = SDL_small_alloc(char *, argc + 1, &isstack);
    9.17      if (argv == NULL) {
    9.18          return OutOfMemory();
    9.19      }
    9.20 @@ -158,7 +159,7 @@
    9.21  
    9.22      retval = main_utf8(argc, argv);
    9.23  
    9.24 -    SDL_stack_free(argv);
    9.25 +    SDL_small_free(argv, isstack);
    9.26      SDL_free(cmdline);
    9.27  
    9.28      return retval;
    9.29 @@ -177,8 +178,9 @@
    9.30  int
    9.31  console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
    9.32  {
    9.33 +    SDL_bool isstack;
    9.34      int retval = 0;
    9.35 -    char **argv = SDL_stack_alloc(char*, argc + 1);
    9.36 +    char **argv = SDL_small_alloc(char*, argc + 1, &isstack);
    9.37      int i;
    9.38  
    9.39      for (i = 0; i < argc; ++i) {
    9.40 @@ -189,7 +191,7 @@
    9.41      retval = main_utf8(argc, argv);
    9.42  
    9.43      /* !!! FIXME: we are leaking all the elements of argv we allocated. */
    9.44 -    SDL_stack_free(argv);
    9.45 +    SDL_small_free(argv, isstack);
    9.46  
    9.47      return retval;
    9.48  }
    10.1 --- a/src/render/SDL_render.c	Sat Oct 06 17:08:04 2018 -0400
    10.2 +++ b/src/render/SDL_render.c	Mon Oct 22 20:50:32 2018 -0400
    10.3 @@ -2176,8 +2176,9 @@
    10.4      SDL_FRect *frects;
    10.5      int i;
    10.6      int retval = -1;
    10.7 -
    10.8 -    frects = SDL_stack_alloc(SDL_FRect, count);
    10.9 +    SDL_bool isstack;
   10.10 +
   10.11 +    frects = SDL_small_alloc(SDL_FRect, count, &isstack);
   10.12      if (!frects) {
   10.13          return SDL_OutOfMemory();
   10.14      }
   10.15 @@ -2190,7 +2191,7 @@
   10.16  
   10.17      retval = QueueCmdFillRects(renderer, frects, count);
   10.18  
   10.19 -    SDL_stack_free(frects);
   10.20 +    SDL_small_free(frects, isstack);
   10.21  
   10.22      return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   10.23  }
   10.24 @@ -2202,6 +2203,7 @@
   10.25      SDL_FPoint *fpoints;
   10.26      int i;
   10.27      int retval;
   10.28 +    SDL_bool isstack;
   10.29  
   10.30      CHECK_RENDERER_MAGIC(renderer, -1);
   10.31  
   10.32 @@ -2221,7 +2223,7 @@
   10.33          return RenderDrawPointsWithRects(renderer, points, count);
   10.34      }
   10.35  
   10.36 -    fpoints = SDL_stack_alloc(SDL_FPoint, count);
   10.37 +    fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
   10.38      if (!fpoints) {
   10.39          return SDL_OutOfMemory();
   10.40      }
   10.41 @@ -2232,7 +2234,7 @@
   10.42  
   10.43      retval = QueueCmdDrawPoints(renderer, fpoints, count);
   10.44  
   10.45 -    SDL_stack_free(fpoints);
   10.46 +    SDL_small_free(fpoints, isstack);
   10.47  
   10.48      return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   10.49  }
   10.50 @@ -2258,8 +2260,9 @@
   10.51      SDL_FPoint fpoints[2];
   10.52      int i, nrects = 0;
   10.53      int retval = 0;
   10.54 -
   10.55 -    frects = SDL_stack_alloc(SDL_FRect, count-1);
   10.56 +    SDL_bool isstack;
   10.57 +
   10.58 +    frects = SDL_small_alloc(SDL_FRect, count-1, &isstack);
   10.59      if (!frects) {
   10.60          return SDL_OutOfMemory();
   10.61      }
   10.62 @@ -2295,7 +2298,7 @@
   10.63  
   10.64      retval += QueueCmdFillRects(renderer, frects, nrects);
   10.65  
   10.66 -    SDL_stack_free(frects);
   10.67 +    SDL_small_free(frects, isstack);
   10.68  
   10.69      if (retval < 0) {
   10.70          retval = -1;
   10.71 @@ -2310,6 +2313,7 @@
   10.72      SDL_FPoint *fpoints;
   10.73      int i;
   10.74      int retval;
   10.75 +    SDL_bool isstack;
   10.76  
   10.77      CHECK_RENDERER_MAGIC(renderer, -1);
   10.78  
   10.79 @@ -2329,7 +2333,7 @@
   10.80          return RenderDrawLinesWithRects(renderer, points, count);
   10.81      }
   10.82  
   10.83 -    fpoints = SDL_stack_alloc(SDL_FPoint, count);
   10.84 +    fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
   10.85      if (!fpoints) {
   10.86          return SDL_OutOfMemory();
   10.87      }
   10.88 @@ -2340,7 +2344,7 @@
   10.89  
   10.90      retval = QueueCmdDrawLines(renderer, fpoints, count);
   10.91  
   10.92 -    SDL_stack_free(fpoints);
   10.93 +    SDL_small_free(fpoints, isstack);
   10.94  
   10.95      return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   10.96  }
   10.97 @@ -2426,6 +2430,7 @@
   10.98      SDL_FRect *frects;
   10.99      int i;
  10.100      int retval;
  10.101 +    SDL_bool isstack;
  10.102  
  10.103      CHECK_RENDERER_MAGIC(renderer, -1);
  10.104  
  10.105 @@ -2441,7 +2446,7 @@
  10.106          return 0;
  10.107      }
  10.108  
  10.109 -    frects = SDL_stack_alloc(SDL_FRect, count);
  10.110 +    frects = SDL_small_alloc(SDL_FRect, count, &isstack);
  10.111      if (!frects) {
  10.112          return SDL_OutOfMemory();
  10.113      }
  10.114 @@ -2454,7 +2459,7 @@
  10.115  
  10.116      retval = QueueCmdFillRects(renderer, frects, count);
  10.117  
  10.118 -    SDL_stack_free(frects);
  10.119 +    SDL_small_free(frects, isstack);
  10.120  
  10.121      return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
  10.122  }
    11.1 --- a/src/render/opengl/SDL_render_gl.c	Sat Oct 06 17:08:04 2018 -0400
    11.2 +++ b/src/render/opengl/SDL_render_gl.c	Mon Oct 22 20:50:32 2018 -0400
    11.3 @@ -1348,10 +1348,11 @@
    11.4  
    11.5      /* Flip the rows to be top-down if necessary */
    11.6      if (!renderer->target) {
    11.7 +        SDL_bool isstack;
    11.8          length = rect->w * SDL_BYTESPERPIXEL(temp_format);
    11.9          src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
   11.10          dst = (Uint8*)temp_pixels;
   11.11 -        tmp = SDL_stack_alloc(Uint8, length);
   11.12 +        tmp = SDL_small_alloc(Uint8, length, &isstack);
   11.13          rows = rect->h / 2;
   11.14          while (rows--) {
   11.15              SDL_memcpy(tmp, dst, length);
   11.16 @@ -1360,7 +1361,7 @@
   11.17              dst += temp_pitch;
   11.18              src -= temp_pitch;
   11.19          }
   11.20 -        SDL_stack_free(tmp);
   11.21 +        SDL_small_free(tmp, isstack);
   11.22      }
   11.23  
   11.24      status = SDL_ConvertPixels(rect->w, rect->h,
    12.1 --- a/src/render/opengl/SDL_shaders_gl.c	Sat Oct 06 17:08:04 2018 -0400
    12.2 +++ b/src/render/opengl/SDL_shaders_gl.c	Mon Oct 22 20:50:32 2018 -0400
    12.3 @@ -340,11 +340,12 @@
    12.4      ctx->glCompileShaderARB(shader);
    12.5      ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
    12.6      if (status == 0) {
    12.7 +        SDL_bool isstack;
    12.8          GLint length;
    12.9          char *info;
   12.10  
   12.11          ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
   12.12 -        info = SDL_stack_alloc(char, length+1);
   12.13 +        info = SDL_small_alloc(char, length+1, &isstack);
   12.14          ctx->glGetInfoLogARB(shader, length, NULL, info);
   12.15          SDL_LogError(SDL_LOG_CATEGORY_RENDER,
   12.16              "Failed to compile shader:\n%s%s\n%s", defines, source, info);
   12.17 @@ -352,7 +353,7 @@
   12.18          fprintf(stderr,
   12.19              "Failed to compile shader:\n%s%s\n%s", defines, source, info);
   12.20  #endif
   12.21 -        SDL_stack_free(info);
   12.22 +        SDL_small_free(info, isstack);
   12.23  
   12.24          return SDL_FALSE;
   12.25      } else {
    13.1 --- a/src/render/opengles/SDL_render_gles.c	Sat Oct 06 17:08:04 2018 -0400
    13.2 +++ b/src/render/opengles/SDL_render_gles.c	Mon Oct 22 20:50:32 2018 -0400
    13.3 @@ -972,10 +972,11 @@
    13.4  
    13.5      /* Flip the rows to be top-down if necessary */
    13.6      if (!renderer->target) {
    13.7 +        SDL_bool isstack;
    13.8          length = rect->w * SDL_BYTESPERPIXEL(temp_format);
    13.9          src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
   13.10          dst = (Uint8*)temp_pixels;
   13.11 -        tmp = SDL_stack_alloc(Uint8, length);
   13.12 +        tmp = SDL_small_alloc(Uint8, length, &isstack);
   13.13          rows = rect->h / 2;
   13.14          while (rows--) {
   13.15              SDL_memcpy(tmp, dst, length);
   13.16 @@ -984,7 +985,7 @@
   13.17              dst += temp_pitch;
   13.18              src -= temp_pitch;
   13.19          }
   13.20 -        SDL_stack_free(tmp);
   13.21 +        SDL_small_free(tmp, isstack);
   13.22      }
   13.23  
   13.24      status = SDL_ConvertPixels(rect->w, rect->h,
    14.1 --- a/src/render/opengles2/SDL_render_gles2.c	Sat Oct 06 17:08:04 2018 -0400
    14.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Mon Oct 22 20:50:32 2018 -0400
    14.3 @@ -601,19 +601,20 @@
    14.4          compileSuccessful = GL_TRUE;
    14.5      }
    14.6      if (!compileSuccessful) {
    14.7 +        SDL_bool isstack = SDL_FALSE;
    14.8          char *info = NULL;
    14.9          int length = 0;
   14.10  
   14.11          data->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
   14.12          if (length > 0) {
   14.13 -            info = SDL_stack_alloc(char, length);
   14.14 +            info = SDL_small_alloc(char, length, &isstack);
   14.15              if (info) {
   14.16                  data->glGetShaderInfoLog(entry->id, length, &length, info);
   14.17              }
   14.18          }
   14.19          if (info) {
   14.20              SDL_SetError("Failed to load the shader: %s", info);
   14.21 -            SDL_stack_free(info);
   14.22 +            SDL_small_free(info, isstack);
   14.23          } else {
   14.24              SDL_SetError("Failed to load the shader");
   14.25          }
   14.26 @@ -1814,10 +1815,11 @@
   14.27  
   14.28      /* Flip the rows to be top-down if necessary */
   14.29      if (!renderer->target) {
   14.30 +        SDL_bool isstack;
   14.31          length = rect->w * SDL_BYTESPERPIXEL(temp_format);
   14.32          src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
   14.33          dst = (Uint8*)temp_pixels;
   14.34 -        tmp = SDL_stack_alloc(Uint8, length);
   14.35 +        tmp = SDL_small_alloc(Uint8, length, &isstack);
   14.36          rows = rect->h / 2;
   14.37          while (rows--) {
   14.38              SDL_memcpy(tmp, dst, length);
   14.39 @@ -1826,7 +1828,7 @@
   14.40              dst += temp_pitch;
   14.41              src -= temp_pitch;
   14.42          }
   14.43 -        SDL_stack_free(tmp);
   14.44 +        SDL_small_free(tmp, isstack);
   14.45      }
   14.46  
   14.47      status = SDL_ConvertPixels(rect->w, rect->h,
    15.1 --- a/src/video/cocoa/SDL_cocoamodes.m	Sat Oct 06 17:08:04 2018 -0400
    15.2 +++ b/src/video/cocoa/SDL_cocoamodes.m	Mon Oct 22 20:50:32 2018 -0400
    15.3 @@ -187,6 +187,7 @@
    15.4      CGDisplayErr result;
    15.5      CGDirectDisplayID *displays;
    15.6      CGDisplayCount numDisplays;
    15.7 +    SDL_bool isstack;
    15.8      int pass, i;
    15.9  
   15.10      result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
   15.11 @@ -194,11 +195,11 @@
   15.12          CG_SetError("CGGetOnlineDisplayList()", result);
   15.13          return;
   15.14      }
   15.15 -    displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
   15.16 +    displays = SDL_small_alloc(CGDirectDisplayID, numDisplays, &isstack);
   15.17      result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
   15.18      if (result != kCGErrorSuccess) {
   15.19          CG_SetError("CGGetOnlineDisplayList()", result);
   15.20 -        SDL_stack_free(displays);
   15.21 +        SDL_small_free(displays, isstack);
   15.22          return;
   15.23      }
   15.24  
   15.25 @@ -260,7 +261,7 @@
   15.26              SDL_free(display.name);
   15.27          }
   15.28      }
   15.29 -    SDL_stack_free(displays);
   15.30 +    SDL_small_free(displays, isstack);
   15.31  }}
   15.32  
   15.33  int
    16.1 --- a/src/video/windows/SDL_windowsevents.c	Sat Oct 06 17:08:04 2018 -0400
    16.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Oct 22 20:50:32 2018 -0400
    16.3 @@ -901,7 +901,8 @@
    16.4      case WM_TOUCH:
    16.5          if (data->videodata->GetTouchInputInfo && data->videodata->CloseTouchInputHandle) {
    16.6              UINT i, num_inputs = LOWORD(wParam);
    16.7 -            PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
    16.8 +            SDL_bool isstack;
    16.9 +            PTOUCHINPUT inputs = SDL_small_alloc(TOUCHINPUT, num_inputs, &isstack);
   16.10              if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
   16.11                  RECT rect;
   16.12                  float x, y;
   16.13 @@ -909,7 +910,7 @@
   16.14                  if (!GetClientRect(hwnd, &rect) ||
   16.15                      (rect.right == rect.left && rect.bottom == rect.top)) {
   16.16                      if (inputs) {
   16.17 -                        SDL_stack_free(inputs);
   16.18 +                        SDL_small_free(inputs, isstack);
   16.19                      }
   16.20                      break;
   16.21                  }
   16.22 @@ -943,7 +944,7 @@
   16.23                      }
   16.24                  }
   16.25              }
   16.26 -            SDL_stack_free(inputs);
   16.27 +            SDL_small_free(inputs, isstack);
   16.28  
   16.29              data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
   16.30              return 0;
   16.31 @@ -954,17 +955,19 @@
   16.32          {
   16.33              UINT i;
   16.34              HDROP drop = (HDROP) wParam;
   16.35 +            SDL_bool isstack;
   16.36              UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
   16.37              for (i = 0; i < count; ++i) {
   16.38 +                SDL_bool isstack;
   16.39                  UINT size = DragQueryFile(drop, i, NULL, 0) + 1;
   16.40 -                LPTSTR buffer = SDL_stack_alloc(TCHAR, size);
   16.41 +                LPTSTR buffer = SDL_small_alloc(TCHAR, size, &isstack);
   16.42                  if (buffer) {
   16.43                      if (DragQueryFile(drop, i, buffer, size)) {
   16.44                          char *file = WIN_StringToUTF8(buffer);
   16.45                          SDL_SendDropFile(data->window, file);
   16.46                          SDL_free(file);
   16.47                      }
   16.48 -                    SDL_stack_free(buffer);
   16.49 +                    SDL_small_free(buffer, isstack);
   16.50                  }
   16.51              }
   16.52              SDL_SendDropComplete(data->window);
    17.1 --- a/src/video/windows/SDL_windowsframebuffer.c	Sat Oct 06 17:08:04 2018 -0400
    17.2 +++ b/src/video/windows/SDL_windowsframebuffer.c	Mon Oct 22 20:50:32 2018 -0400
    17.3 @@ -27,6 +27,7 @@
    17.4  int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
    17.5  {
    17.6      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    17.7 +    SDL_bool isstack;
    17.8      size_t size;
    17.9      LPBITMAPINFO info;
   17.10      HBITMAP hbm;
   17.11 @@ -41,7 +42,7 @@
   17.12  
   17.13      /* Find out the format of the screen */
   17.14      size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
   17.15 -    info = (LPBITMAPINFO)SDL_stack_alloc(Uint8, size);
   17.16 +    info = (LPBITMAPINFO)SDL_small_alloc(Uint8, size, &isstack);
   17.17      if (!info) {
   17.18          return SDL_OutOfMemory();
   17.19      }
   17.20 @@ -85,7 +86,7 @@
   17.21  
   17.22      data->mdc = CreateCompatibleDC(data->hdc);
   17.23      data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);
   17.24 -    SDL_stack_free(info);
   17.25 +    SDL_small_free(info, isstack);
   17.26  
   17.27      if (!data->hbm) {
   17.28          return WIN_SetError("Unable to create DIB");
    18.1 --- a/src/video/windows/SDL_windowsmouse.c	Sat Oct 06 17:08:04 2018 -0400
    18.2 +++ b/src/video/windows/SDL_windowsmouse.c	Mon Oct 22 20:50:32 2018 -0400
    18.3 @@ -97,6 +97,7 @@
    18.4      LPVOID pixels;
    18.5      LPVOID maskbits;
    18.6      size_t maskbitslen;
    18.7 +    SDL_bool isstack;
    18.8      ICONINFO ii;
    18.9  
   18.10      SDL_zero(bmh);
   18.11 @@ -112,7 +113,7 @@
   18.12      bmh.bV4BlueMask  = 0x000000FF;
   18.13  
   18.14      maskbitslen = ((surface->w + (pad - (surface->w % pad))) / 8) * surface->h;
   18.15 -    maskbits = SDL_stack_alloc(Uint8,maskbitslen);
   18.16 +    maskbits = SDL_small_alloc(Uint8,maskbitslen);
   18.17      if (maskbits == NULL) {
   18.18          SDL_OutOfMemory();
   18.19          return NULL;
   18.20 @@ -129,7 +130,7 @@
   18.21      ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
   18.22      ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, maskbits);
   18.23      ReleaseDC(NULL, hdc);
   18.24 -    SDL_stack_free(maskbits);
   18.25 +    SDL_small_free(maskbits, isstack);
   18.26  
   18.27      SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
   18.28      SDL_assert(surface->pitch == surface->w * 4);
    19.1 --- a/src/video/windows/SDL_windowswindow.c	Sat Oct 06 17:08:04 2018 -0400
    19.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Oct 22 20:50:32 2018 -0400
    19.3 @@ -380,10 +380,11 @@
    19.4      HWND hwnd = (HWND) data;
    19.5      LPTSTR title;
    19.6      int titleLen;
    19.7 +    SDL_bool isstack;
    19.8  
    19.9      /* Query the title from the existing window */
   19.10      titleLen = GetWindowTextLength(hwnd);
   19.11 -    title = SDL_stack_alloc(TCHAR, titleLen + 1);
   19.12 +    title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack);
   19.13      if (title) {
   19.14          titleLen = GetWindowText(hwnd, title, titleLen);
   19.15      } else {
   19.16 @@ -393,7 +394,7 @@
   19.17          window->title = WIN_StringToUTF8(title);
   19.18      }
   19.19      if (title) {
   19.20 -        SDL_stack_free(title);
   19.21 +        SDL_small_free(title, isstack);
   19.22      }
   19.23  
   19.24      if (SetupWindowData(_this, window, hwnd, GetParent(hwnd), SDL_FALSE) < 0) {
   19.25 @@ -443,14 +444,15 @@
   19.26      BYTE *icon_bmp;
   19.27      int icon_len, mask_len, y;
   19.28      SDL_RWops *dst;
   19.29 +    SDL_bool isstack;
   19.30  
   19.31      /* Create temporary buffer for ICONIMAGE structure */
   19.32      mask_len = (icon->h * (icon->w + 7)/8);
   19.33      icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
   19.34 -    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
   19.35 +    icon_bmp = SDL_small_alloc(BYTE, icon_len, &isstack);
   19.36      dst = SDL_RWFromMem(icon_bmp, icon_len);
   19.37      if (!dst) {
   19.38 -        SDL_stack_free(icon_bmp);
   19.39 +        SDL_small_free(icon_bmp, isstack);
   19.40          return;
   19.41      }
   19.42  
   19.43 @@ -481,7 +483,7 @@
   19.44      hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
   19.45  
   19.46      SDL_RWclose(dst);
   19.47 -    SDL_stack_free(icon_bmp);
   19.48 +    SDL_small_free(icon_bmp, isstack);
   19.49  
   19.50      /* Set the icon for the window */
   19.51      SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);