Replaced all remaining uses of NSAutoreleasePool with @autoreleasepool blocks (bugzilla #2680.)
authorAlex Szpakowski <slime73@gmail.com>
Tue, 05 May 2015 19:01:55 -0300
changeset 958718979eac0a35
parent 9586 037074526d4c
child 9588 2c2b2c13450b
Replaced all remaining uses of NSAutoreleasePool with @autoreleasepool blocks (bugzilla #2680.)
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoashape.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Tue May 05 16:24:05 2015 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Tue May 05 19:01:55 2015 -0300
     1.3 @@ -150,8 +150,8 @@
     1.4  
     1.5  SDL_GLContext
     1.6  Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
     1.7 +{ @autoreleasepool
     1.8  {
     1.9 -    NSAutoreleasePool *pool;
    1.10      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.11      SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
    1.12      SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
    1.13 @@ -173,8 +173,6 @@
    1.14          return NULL;
    1.15      }
    1.16  
    1.17 -    pool = [[NSAutoreleasePool alloc] init];
    1.18 -
    1.19      /* specify a profile if we're on Lion (10.7) or later. */
    1.20      if (lion_or_later) {
    1.21          NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
    1.22 @@ -239,7 +237,6 @@
    1.23      fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
    1.24      if (fmt == nil) {
    1.25          SDL_SetError("Failed creating OpenGL pixel format");
    1.26 -        [pool release];
    1.27          return NULL;
    1.28      }
    1.29  
    1.30 @@ -253,12 +250,9 @@
    1.31  
    1.32      if (context == nil) {
    1.33          SDL_SetError("Failed creating OpenGL context");
    1.34 -        [pool release];
    1.35          return NULL;
    1.36      }
    1.37  
    1.38 -    [pool release];
    1.39 -
    1.40      if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
    1.41          Cocoa_GL_DeleteContext(_this, context);
    1.42          SDL_SetError("Failed making OpenGL context current");
    1.43 @@ -306,15 +300,12 @@
    1.44          /*_this->gl_config.minor_version = glversion_minor;*/
    1.45      }
    1.46      return context;
    1.47 -}
    1.48 +}}
    1.49  
    1.50  int
    1.51  Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    1.52 +{ @autoreleasepool
    1.53  {
    1.54 -    NSAutoreleasePool *pool;
    1.55 -
    1.56 -    pool = [[NSAutoreleasePool alloc] init];
    1.57 -
    1.58      if (context) {
    1.59          SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
    1.60          [nscontext setWindow:window];
    1.61 @@ -324,9 +315,8 @@
    1.62          [NSOpenGLContext clearCurrentContext];
    1.63      }
    1.64  
    1.65 -    [pool release];
    1.66      return 0;
    1.67 -}
    1.68 +}}
    1.69  
    1.70  void
    1.71  Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
    1.72 @@ -352,8 +342,8 @@
    1.73  
    1.74  int
    1.75  Cocoa_GL_SetSwapInterval(_THIS, int interval)
    1.76 +{ @autoreleasepool
    1.77  {
    1.78 -    NSAutoreleasePool *pool;
    1.79      NSOpenGLContext *nscontext;
    1.80      GLint value;
    1.81      int status;
    1.82 @@ -362,8 +352,6 @@
    1.83          return SDL_SetError("Late swap tearing currently unsupported");
    1.84      }
    1.85  
    1.86 -    pool = [[NSAutoreleasePool alloc] init];
    1.87 -
    1.88      nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
    1.89      if (nscontext != nil) {
    1.90          value = interval;
    1.91 @@ -373,57 +361,44 @@
    1.92          status = SDL_SetError("No current OpenGL context");
    1.93      }
    1.94  
    1.95 -    [pool release];
    1.96      return status;
    1.97 -}
    1.98 +}}
    1.99  
   1.100  int
   1.101  Cocoa_GL_GetSwapInterval(_THIS)
   1.102 +{ @autoreleasepool
   1.103  {
   1.104 -    NSAutoreleasePool *pool;
   1.105      NSOpenGLContext *nscontext;
   1.106      GLint value;
   1.107      int status = 0;
   1.108  
   1.109 -    pool = [[NSAutoreleasePool alloc] init];
   1.110 -
   1.111      nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
   1.112      if (nscontext != nil) {
   1.113          [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   1.114          status = (int)value;
   1.115      }
   1.116  
   1.117 -    [pool release];
   1.118      return status;
   1.119 -}
   1.120 +}}
   1.121  
   1.122  void
   1.123  Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
   1.124 +{ @autoreleasepool
   1.125  {
   1.126 -    NSAutoreleasePool *pool;
   1.127 -
   1.128 -    pool = [[NSAutoreleasePool alloc] init];
   1.129 -
   1.130      SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
   1.131      [nscontext flushBuffer];
   1.132      [nscontext updateIfNeeded];
   1.133 -
   1.134 -    [pool release];
   1.135 -}
   1.136 +}}
   1.137  
   1.138  void
   1.139  Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
   1.140 +{ @autoreleasepool
   1.141  {
   1.142 -    NSAutoreleasePool *pool;
   1.143      SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
   1.144  
   1.145 -    pool = [[NSAutoreleasePool alloc] init];
   1.146 -
   1.147      [nscontext setWindow:NULL];
   1.148      [nscontext release];
   1.149 -
   1.150 -    [pool release];
   1.151 -}
   1.152 +}}
   1.153  
   1.154  #endif /* SDL_VIDEO_OPENGL_CGL */
   1.155  
     2.1 --- a/src/video/cocoa/SDL_cocoashape.m	Tue May 05 16:24:05 2015 -0300
     2.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Tue May 05 19:01:55 2015 -0300
     2.3 @@ -75,11 +75,11 @@
     2.4  
     2.5  int
     2.6  Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
     2.7 +{ @autoreleasepool
     2.8  {
     2.9      SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
    2.10      SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
    2.11      SDL_CocoaClosure closure;
    2.12 -    NSAutoreleasePool *pool = NULL;
    2.13      if(data->saved == SDL_TRUE) {
    2.14          [data->context restoreGraphicsState];
    2.15          data->saved = SDL_FALSE;
    2.16 @@ -93,16 +93,14 @@
    2.17      NSRectFill([[windata->nswindow contentView] frame]);
    2.18      data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
    2.19  
    2.20 -    pool = [[NSAutoreleasePool alloc] init];
    2.21      closure.view = [windata->nswindow contentView];
    2.22      closure.path = [NSBezierPath bezierPath];
    2.23      closure.window = shaper->window;
    2.24      SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
    2.25      [closure.path addClip];
    2.26 -    [pool release];
    2.27  
    2.28      return 0;
    2.29 -}
    2.30 +}}
    2.31  
    2.32  int
    2.33  Cocoa_ResizeWindowShape(SDL_Window *window)
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue May 05 16:24:05 2015 -0300
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue May 05 19:01:55 2015 -0300
     3.3 @@ -1000,8 +1000,8 @@
     3.4  
     3.5  static int
     3.6  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
     3.7 +{ @autoreleasepool
     3.8  {
     3.9 -    NSAutoreleasePool *pool;
    3.10      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    3.11      SDL_WindowData *data;
    3.12  
    3.13 @@ -1016,8 +1016,6 @@
    3.14      data->videodata = videodata;
    3.15      data->nscontexts = [[NSMutableArray alloc] init];
    3.16  
    3.17 -    pool = [[NSAutoreleasePool alloc] init];
    3.18 -
    3.19      /* Create an event listener for the window */
    3.20      data->listener = [[Cocoa_WindowListener alloc] init];
    3.21  
    3.22 @@ -1079,16 +1077,15 @@
    3.23      [nswindow setOneShot:NO];
    3.24  
    3.25      /* All done! */
    3.26 -    [pool release];
    3.27      window->driverdata = data;
    3.28      return 0;
    3.29 -}
    3.30 +}}
    3.31  
    3.32  int
    3.33  Cocoa_CreateWindow(_THIS, SDL_Window * window)
    3.34 +{ @autoreleasepool
    3.35  {
    3.36      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    3.37 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    3.38      NSWindow *nswindow;
    3.39      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    3.40      NSRect rect;
    3.41 @@ -1123,9 +1120,7 @@
    3.42          nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
    3.43      }
    3.44      @catch (NSException *e) {
    3.45 -        SDL_SetError("%s", [[e reason] UTF8String]);
    3.46 -        [pool release];
    3.47 -        return -1;
    3.48 +        return SDL_SetError("%s", [[e reason] UTF8String]);
    3.49      }
    3.50      [nswindow setBackgroundColor:[NSColor blackColor]];
    3.51  
    3.52 @@ -1155,63 +1150,54 @@
    3.53      /* Allow files and folders to be dragged onto the window by users */
    3.54      [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
    3.55  
    3.56 -    [pool release];
    3.57 -
    3.58      if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
    3.59          [nswindow release];
    3.60          return -1;
    3.61      }
    3.62      return 0;
    3.63 -}
    3.64 +}}
    3.65  
    3.66  int
    3.67  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
    3.68 +{ @autoreleasepool
    3.69  {
    3.70 -    NSAutoreleasePool *pool;
    3.71      NSWindow *nswindow = (NSWindow *) data;
    3.72      NSString *title;
    3.73  
    3.74 -    pool = [[NSAutoreleasePool alloc] init];
    3.75 -
    3.76      /* Query the title from the existing window */
    3.77      title = [nswindow title];
    3.78      if (title) {
    3.79          window->title = SDL_strdup([title UTF8String]);
    3.80      }
    3.81  
    3.82 -    [pool release];
    3.83 -
    3.84      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
    3.85 -}
    3.86 +}}
    3.87  
    3.88  void
    3.89  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
    3.90 +{ @autoreleasepool
    3.91  {
    3.92 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    3.93      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
    3.94      NSString *string = [[NSString alloc] initWithUTF8String:window->title];
    3.95      [nswindow setTitle:string];
    3.96      [string release];
    3.97 -    [pool release];
    3.98 -}
    3.99 +}}
   3.100  
   3.101  void
   3.102  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
   3.103 +{ @autoreleasepool
   3.104  {
   3.105 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.106      NSImage *nsimage = Cocoa_CreateImage(icon);
   3.107  
   3.108      if (nsimage) {
   3.109          [NSApp setApplicationIconImage:nsimage];
   3.110      }
   3.111 -
   3.112 -    [pool release];
   3.113 -}
   3.114 +}}
   3.115  
   3.116  void
   3.117  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
   3.118 +{ @autoreleasepool
   3.119  {
   3.120 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.121      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   3.122      NSWindow *nswindow = windata->nswindow;
   3.123      NSRect rect;
   3.124 @@ -1229,14 +1215,12 @@
   3.125      s_moveHack = moveHack;
   3.126  
   3.127      ScheduleContextUpdates(windata);
   3.128 -
   3.129 -    [pool release];
   3.130 -}
   3.131 +}}
   3.132  
   3.133  void
   3.134  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
   3.135 +{ @autoreleasepool
   3.136  {
   3.137 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.138      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   3.139      NSWindow *nswindow = windata->nswindow;
   3.140      NSSize size;
   3.141 @@ -1246,14 +1230,12 @@
   3.142      [nswindow setContentSize:size];
   3.143  
   3.144      ScheduleContextUpdates(windata);
   3.145 -
   3.146 -    [pool release];
   3.147 -}
   3.148 +}}
   3.149  
   3.150  void
   3.151  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
   3.152 +{ @autoreleasepool
   3.153  {
   3.154 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.155      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   3.156  
   3.157      NSSize minSize;
   3.158 @@ -1261,14 +1243,12 @@
   3.159      minSize.height = window->min_h;
   3.160  
   3.161      [windata->nswindow setContentMinSize:minSize];
   3.162 -
   3.163 -    [pool release];
   3.164 -}
   3.165 +}}
   3.166  
   3.167  void
   3.168  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
   3.169 +{ @autoreleasepool
   3.170  {
   3.171 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.172      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   3.173  
   3.174      NSSize maxSize;
   3.175 @@ -1276,14 +1256,12 @@
   3.176      maxSize.height = window->max_h;
   3.177  
   3.178      [windata->nswindow setContentMaxSize:maxSize];
   3.179 -
   3.180 -    [pool release];
   3.181 -}
   3.182 +}}
   3.183  
   3.184  void
   3.185  Cocoa_ShowWindow(_THIS, SDL_Window * window)
   3.186 +{ @autoreleasepool
   3.187  {
   3.188 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.189      SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
   3.190      NSWindow *nswindow = windowData->nswindow;
   3.191  
   3.192 @@ -1292,23 +1270,21 @@
   3.193          [nswindow makeKeyAndOrderFront:nil];
   3.194          [windowData->listener resumeVisibleObservation];
   3.195      }
   3.196 -    [pool release];
   3.197 -}
   3.198 +}}
   3.199  
   3.200  void
   3.201  Cocoa_HideWindow(_THIS, SDL_Window * window)
   3.202 +{ @autoreleasepool
   3.203  {
   3.204 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.205      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   3.206  
   3.207      [nswindow orderOut:nil];
   3.208 -    [pool release];
   3.209 -}
   3.210 +}}
   3.211  
   3.212  void
   3.213  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
   3.214 +{ @autoreleasepool
   3.215  {
   3.216 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.217      SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
   3.218      NSWindow *nswindow = windowData->nswindow;
   3.219  
   3.220 @@ -1321,28 +1297,24 @@
   3.221          [nswindow makeKeyAndOrderFront:nil];
   3.222      }
   3.223      [windowData->listener resumeVisibleObservation];
   3.224 -
   3.225 -    [pool release];
   3.226 -}
   3.227 +}}
   3.228  
   3.229  void
   3.230  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
   3.231 +{ @autoreleasepool
   3.232  {
   3.233 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.234      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   3.235      NSWindow *nswindow = windata->nswindow;
   3.236  
   3.237      [nswindow zoom:nil];
   3.238  
   3.239      ScheduleContextUpdates(windata);
   3.240 -
   3.241 -    [pool release];
   3.242 -}
   3.243 +}}
   3.244  
   3.245  void
   3.246  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   3.247 +{ @autoreleasepool
   3.248  {
   3.249 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.250      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   3.251      NSWindow *nswindow = data->nswindow;
   3.252  
   3.253 @@ -1351,13 +1323,12 @@
   3.254      } else {
   3.255          [nswindow miniaturize:nil];
   3.256      }
   3.257 -    [pool release];
   3.258 -}
   3.259 +}}
   3.260  
   3.261  void
   3.262  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
   3.263 +{ @autoreleasepool
   3.264  {
   3.265 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.266      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   3.267  
   3.268      if ([nswindow isMiniaturized]) {
   3.269 @@ -1365,8 +1336,7 @@
   3.270      } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   3.271          [nswindow zoom:nil];
   3.272      }
   3.273 -    [pool release];
   3.274 -}
   3.275 +}}
   3.276  
   3.277  static NSWindow *
   3.278  Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
   3.279 @@ -1391,21 +1361,20 @@
   3.280  
   3.281  void
   3.282  Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
   3.283 +{ @autoreleasepool
   3.284  {
   3.285 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.286      if (SetWindowStyle(window, GetWindowStyle(window))) {
   3.287          if (bordered) {
   3.288              Cocoa_SetWindowTitle(_this, window);  /* this got blanked out. */
   3.289          }
   3.290      }
   3.291 -    [pool release];
   3.292 -}
   3.293 +}}
   3.294  
   3.295  
   3.296  void
   3.297  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   3.298 +{ @autoreleasepool
   3.299  {
   3.300 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.301      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   3.302      NSWindow *nswindow = data->nswindow;
   3.303      NSRect rect;
   3.304 @@ -1479,9 +1448,7 @@
   3.305      }
   3.306  
   3.307      ScheduleContextUpdates(data);
   3.308 -
   3.309 -    [pool release];
   3.310 -}
   3.311 +}}
   3.312  
   3.313  int
   3.314  Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
   3.315 @@ -1564,8 +1531,8 @@
   3.316  
   3.317  void
   3.318  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
   3.319 +{ @autoreleasepool
   3.320  {
   3.321 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.322      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   3.323  
   3.324      if (data) {
   3.325 @@ -1585,9 +1552,7 @@
   3.326          SDL_free(data);
   3.327      }
   3.328      window->driverdata = NULL;
   3.329 -
   3.330 -    [pool release];
   3.331 -}
   3.332 +}}
   3.333  
   3.334  SDL_bool
   3.335  Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   3.336 @@ -1619,9 +1584,9 @@
   3.337  
   3.338  SDL_bool
   3.339  Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
   3.340 +{ @autoreleasepool
   3.341  {
   3.342      SDL_bool succeeded = SDL_FALSE;
   3.343 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   3.344      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   3.345  
   3.346      if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
   3.347 @@ -1642,10 +1607,8 @@
   3.348          }
   3.349      }
   3.350  
   3.351 -    [pool release];
   3.352 -
   3.353      return succeeded;
   3.354 -}
   3.355 +}}
   3.356  
   3.357  int
   3.358  Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)