From 4fc402666077b3a506d9ebb88f509968196a66c6 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 5 May 2015 19:01:55 -0300 Subject: [PATCH] Replaced all remaining uses of NSAutoreleasePool with @autoreleasepool blocks (bugzilla #2680.) --- src/video/cocoa/SDL_cocoaopengl.m | 49 ++++--------- src/video/cocoa/SDL_cocoashape.m | 6 +- src/video/cocoa/SDL_cocoawindow.m | 115 ++++++++++-------------------- 3 files changed, 53 insertions(+), 117 deletions(-) diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 0bbbbcb72de34..02441efa9ea3f 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -150,8 +150,8 @@ - (void)setWindow:(SDL_Window *)newWindow SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6; @@ -173,8 +173,6 @@ - (void)setWindow:(SDL_Window *)newWindow return NULL; } - pool = [[NSAutoreleasePool alloc] init]; - /* specify a profile if we're on Lion (10.7) or later. */ if (lion_or_later) { NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy; @@ -239,7 +237,6 @@ - (void)setWindow:(SDL_Window *)newWindow fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; if (fmt == nil) { SDL_SetError("Failed creating OpenGL pixel format"); - [pool release]; return NULL; } @@ -253,12 +250,9 @@ - (void)setWindow:(SDL_Window *)newWindow if (context == nil) { SDL_SetError("Failed creating OpenGL context"); - [pool release]; return NULL; } - [pool release]; - if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) { Cocoa_GL_DeleteContext(_this, context); SDL_SetError("Failed making OpenGL context current"); @@ -306,15 +300,12 @@ - (void)setWindow:(SDL_Window *)newWindow /*_this->gl_config.minor_version = glversion_minor;*/ } return context; -} +}} int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) +{ @autoreleasepool { - NSAutoreleasePool *pool; - - pool = [[NSAutoreleasePool alloc] init]; - if (context) { SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; [nscontext setWindow:window]; @@ -324,9 +315,8 @@ - (void)setWindow:(SDL_Window *)newWindow [NSOpenGLContext clearCurrentContext]; } - [pool release]; return 0; -} +}} void Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h) @@ -352,8 +342,8 @@ - (void)setWindow:(SDL_Window *)newWindow int Cocoa_GL_SetSwapInterval(_THIS, int interval) +{ @autoreleasepool { - NSAutoreleasePool *pool; NSOpenGLContext *nscontext; GLint value; int status; @@ -362,8 +352,6 @@ - (void)setWindow:(SDL_Window *)newWindow return SDL_SetError("Late swap tearing currently unsupported"); } - pool = [[NSAutoreleasePool alloc] init]; - nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); if (nscontext != nil) { value = interval; @@ -373,57 +361,44 @@ - (void)setWindow:(SDL_Window *)newWindow status = SDL_SetError("No current OpenGL context"); } - [pool release]; return status; -} +}} int Cocoa_GL_GetSwapInterval(_THIS) +{ @autoreleasepool { - NSAutoreleasePool *pool; NSOpenGLContext *nscontext; GLint value; int status = 0; - pool = [[NSAutoreleasePool alloc] init]; - nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext(); if (nscontext != nil) { [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval]; status = (int)value; } - [pool release]; return status; -} +}} void Cocoa_GL_SwapWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool; - - pool = [[NSAutoreleasePool alloc] init]; - SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext(); [nscontext flushBuffer]; [nscontext updateIfNeeded]; - - [pool release]; -} +}} void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context) +{ @autoreleasepool { - NSAutoreleasePool *pool; SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; - pool = [[NSAutoreleasePool alloc] init]; - [nscontext setWindow:NULL]; [nscontext release]; - - [pool release]; -} +}} #endif /* SDL_VIDEO_OPENGL_CGL */ diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index 61d800b6a7fe9..ddba14b2bf942 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -75,11 +75,11 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode) +{ @autoreleasepool { SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata; SDL_CocoaClosure closure; - NSAutoreleasePool *pool = NULL; if(data->saved == SDL_TRUE) { [data->context restoreGraphicsState]; data->saved = SDL_FALSE; @@ -93,16 +93,14 @@ NSRectFill([[windata->nswindow contentView] frame]); data->shape = SDL_CalculateShapeTree(*shape_mode,shape); - pool = [[NSAutoreleasePool alloc] init]; closure.view = [windata->nswindow contentView]; closure.path = [NSBezierPath bezierPath]; closure.window = shaper->window; SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure); [closure.path addClip]; - [pool release]; return 0; -} +}} int Cocoa_ResizeWindowShape(SDL_Window *window) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 2d301e4998903..c44284f08ab40 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -1000,8 +1000,8 @@ - (void)resetCursorRects static int SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) +{ @autoreleasepool { - NSAutoreleasePool *pool; SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; SDL_WindowData *data; @@ -1016,8 +1016,6 @@ - (void)resetCursorRects data->videodata = videodata; data->nscontexts = [[NSMutableArray alloc] init]; - pool = [[NSAutoreleasePool alloc] init]; - /* Create an event listener for the window */ data->listener = [[Cocoa_WindowListener alloc] init]; @@ -1079,16 +1077,15 @@ - (void)resetCursorRects [nswindow setOneShot:NO]; /* All done! */ - [pool release]; window->driverdata = data; return 0; -} +}} int Cocoa_CreateWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); NSRect rect; @@ -1123,9 +1120,7 @@ - (void)resetCursorRects nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen]; } @catch (NSException *e) { - SDL_SetError("%s", [[e reason] UTF8String]); - [pool release]; - return -1; + return SDL_SetError("%s", [[e reason] UTF8String]); } [nswindow setBackgroundColor:[NSColor blackColor]]; @@ -1155,63 +1150,54 @@ - (void)resetCursorRects /* Allow files and folders to be dragged onto the window by users */ [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]]; - [pool release]; - if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) { [nswindow release]; return -1; } return 0; -} +}} int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) +{ @autoreleasepool { - NSAutoreleasePool *pool; NSWindow *nswindow = (NSWindow *) data; NSString *title; - pool = [[NSAutoreleasePool alloc] init]; - /* Query the title from the existing window */ title = [nswindow title]; if (title) { window->title = SDL_strdup([title UTF8String]); } - [pool release]; - return SetupWindowData(_this, window, nswindow, SDL_FALSE); -} +}} void Cocoa_SetWindowTitle(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; NSString *string = [[NSString alloc] initWithUTF8String:window->title]; [nswindow setTitle:string]; [string release]; - [pool release]; -} +}} void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSImage *nsimage = Cocoa_CreateImage(icon); if (nsimage) { [NSApp setApplicationIconImage:nsimage]; } - - [pool release]; -} +}} void Cocoa_SetWindowPosition(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = windata->nswindow; NSRect rect; @@ -1229,14 +1215,12 @@ - (void)resetCursorRects s_moveHack = moveHack; ScheduleContextUpdates(windata); - - [pool release]; -} +}} void Cocoa_SetWindowSize(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = windata->nswindow; NSSize size; @@ -1246,14 +1230,12 @@ - (void)resetCursorRects [nswindow setContentSize:size]; ScheduleContextUpdates(windata); - - [pool release]; -} +}} void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSSize minSize; @@ -1261,14 +1243,12 @@ - (void)resetCursorRects minSize.height = window->min_h; [windata->nswindow setContentMinSize:minSize]; - - [pool release]; -} +}} void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSSize maxSize; @@ -1276,14 +1256,12 @@ - (void)resetCursorRects maxSize.height = window->max_h; [windata->nswindow setContentMaxSize:maxSize]; - - [pool release]; -} +}} void Cocoa_ShowWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata); NSWindow *nswindow = windowData->nswindow; @@ -1292,23 +1270,21 @@ - (void)resetCursorRects [nswindow makeKeyAndOrderFront:nil]; [windowData->listener resumeVisibleObservation]; } - [pool release]; -} +}} void Cocoa_HideWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; [nswindow orderOut:nil]; - [pool release]; -} +}} void Cocoa_RaiseWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata); NSWindow *nswindow = windowData->nswindow; @@ -1321,28 +1297,24 @@ - (void)resetCursorRects [nswindow makeKeyAndOrderFront:nil]; } [windowData->listener resumeVisibleObservation]; - - [pool release]; -} +}} void Cocoa_MaximizeWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = windata->nswindow; [nswindow zoom:nil]; ScheduleContextUpdates(windata); - - [pool release]; -} +}} void Cocoa_MinimizeWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = data->nswindow; @@ -1351,13 +1323,12 @@ - (void)resetCursorRects } else { [nswindow miniaturize:nil]; } - [pool release]; -} +}} void Cocoa_RestoreWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; if ([nswindow isMiniaturized]) { @@ -1365,8 +1336,7 @@ - (void)resetCursorRects } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) { [nswindow zoom:nil]; } - [pool release]; -} +}} static NSWindow * Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style) @@ -1391,21 +1361,20 @@ - (void)resetCursorRects void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; if (SetWindowStyle(window, GetWindowStyle(window))) { if (bordered) { Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */ } } - [pool release]; -} +}} void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; NSWindow *nswindow = data->nswindow; NSRect rect; @@ -1479,9 +1448,7 @@ - (void)resetCursorRects } ScheduleContextUpdates(data); - - [pool release]; -} +}} int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) @@ -1564,8 +1531,8 @@ - (void)resetCursorRects void Cocoa_DestroyWindow(_THIS, SDL_Window * window) +{ @autoreleasepool { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; if (data) { @@ -1585,9 +1552,7 @@ - (void)resetCursorRects SDL_free(data); } window->driverdata = NULL; - - [pool release]; -} +}} SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) @@ -1619,9 +1584,9 @@ - (void)resetCursorRects SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state) +{ @autoreleasepool { SDL_bool succeeded = SDL_FALSE; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; if ([data->listener setFullscreenSpace:(state ? YES : NO)]) { @@ -1642,10 +1607,8 @@ take effect properly (e.g. setting the window size, etc.) } } - [pool release]; - return succeeded; -} +}} int Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)