Replaced manual NSAutoreleasePool handing with @autorelease
authorstopiccot
Sun, 06 Jan 2013 19:04:53 +0300
changeset 6832156e608ec4ef
parent 6831 935b871e1ffe
child 6833 c34a64af7751
Replaced manual NSAutoreleasePool handing with @autorelease
src/file/cocoa/SDL_rwopsbundlesupport.m
src/video/cocoa/SDL_cocoaclipboard.m
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoakeyboard.m
src/video/cocoa/SDL_cocoamessagebox.m
src/video/cocoa/SDL_cocoamouse.m
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoashape.m
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.m
test/automated/rwops/TestSupportRWops_Cocoa.m
     1.1 --- a/src/file/cocoa/SDL_rwopsbundlesupport.m	Fri Feb 01 17:09:01 2013 -0800
     1.2 +++ b/src/file/cocoa/SDL_rwopsbundlesupport.m	Sun Jan 06 19:04:53 2013 +0300
     1.3 @@ -20,25 +20,22 @@
     1.4  		return fopen(file, mode);
     1.5  	}
     1.6  
     1.7 -	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
     1.8 -
     1.9 +	@autoreleasepool {
    1.10 +        NSFileManager* file_manager = [NSFileManager defaultManager];
    1.11 +        NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.12  
    1.13 -	NSFileManager* file_manager = [NSFileManager defaultManager];
    1.14 -	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.15 -
    1.16 -	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.17 +        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.18  
    1.19 -	NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    1.20 -	if([file_manager fileExistsAtPath:full_path_with_file_to_try])
    1.21 -	{
    1.22 -		fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    1.23 -	}
    1.24 -	else
    1.25 -	{
    1.26 -		fp = fopen(file, mode);
    1.27 -	}
    1.28 -
    1.29 -	[autorelease_pool drain];
    1.30 +        NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    1.31 +        if([file_manager fileExistsAtPath:full_path_with_file_to_try])
    1.32 +        {
    1.33 +            fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    1.34 +        }
    1.35 +        else
    1.36 +        {
    1.37 +            fp = fopen(file, mode);
    1.38 +        }
    1.39 +    }
    1.40  
    1.41  	return fp;
    1.42  }
     2.1 --- a/src/video/cocoa/SDL_cocoaclipboard.m	Fri Feb 01 17:09:01 2013 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoaclipboard.m	Sun Jan 06 19:04:53 2013 +0300
     2.3 @@ -45,51 +45,46 @@
     2.4  Cocoa_SetClipboardText(_THIS, const char *text)
     2.5  {
     2.6      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     2.7 -    NSAutoreleasePool *pool;
     2.8 +
     2.9      NSPasteboard *pasteboard;
    2.10      NSString *format = GetTextFormat(_this);
    2.11  
    2.12 -    pool = [[NSAutoreleasePool alloc] init];
    2.13 -
    2.14 -    pasteboard = [NSPasteboard generalPasteboard];
    2.15 -    data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
    2.16 -    [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
    2.17 -
    2.18 -    [pool release];
    2.19 -
    2.20 +    @autoreleasepool {
    2.21 +        pasteboard = [NSPasteboard generalPasteboard];
    2.22 +        data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
    2.23 +        [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
    2.24 +    }
    2.25 +    
    2.26      return 0;
    2.27  }
    2.28  
    2.29  char *
    2.30  Cocoa_GetClipboardText(_THIS)
    2.31  {
    2.32 -    NSAutoreleasePool *pool;
    2.33      NSPasteboard *pasteboard;
    2.34      NSString *format = GetTextFormat(_this);
    2.35      NSString *available;
    2.36      char *text;
    2.37  
    2.38 -    pool = [[NSAutoreleasePool alloc] init];
    2.39 -
    2.40 -    pasteboard = [NSPasteboard generalPasteboard];
    2.41 -    available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
    2.42 -    if ([available isEqualToString:format]) {
    2.43 -        NSString* string;
    2.44 -        const char *utf8;
    2.45 +    @autoreleasepool {
    2.46 +        pasteboard = [NSPasteboard generalPasteboard];
    2.47 +        available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
    2.48 +        if ([available isEqualToString:format]) {
    2.49 +            NSString* string;
    2.50 +            const char *utf8;
    2.51  
    2.52 -        string = [pasteboard stringForType:format];
    2.53 -        if (string == nil) {
    2.54 -            utf8 = "";
    2.55 +            string = [pasteboard stringForType:format];
    2.56 +            if (string == nil) {
    2.57 +                utf8 = "";
    2.58 +            } else {
    2.59 +                utf8 = [string UTF8String];
    2.60 +            }
    2.61 +            text = SDL_strdup(utf8);
    2.62          } else {
    2.63 -            utf8 = [string UTF8String];
    2.64 +            text = SDL_strdup("");
    2.65          }
    2.66 -        text = SDL_strdup(utf8);
    2.67 -    } else {
    2.68 -        text = SDL_strdup("");
    2.69      }
    2.70 -
    2.71 -    [pool release];
    2.72 -
    2.73 +    
    2.74      return text;
    2.75  }
    2.76  
    2.77 @@ -108,22 +103,19 @@
    2.78  void
    2.79  Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
    2.80  {
    2.81 -    NSAutoreleasePool *pool;
    2.82      NSPasteboard *pasteboard;
    2.83      NSInteger count;
    2.84  
    2.85 -    pool = [[NSAutoreleasePool alloc] init];
    2.86 -
    2.87 -    pasteboard = [NSPasteboard generalPasteboard];
    2.88 -    count = [pasteboard changeCount];
    2.89 -    if (count != data->clipboard_count) {
    2.90 -        if (data->clipboard_count) {
    2.91 -            SDL_SendClipboardUpdate();
    2.92 +    @autoreleasepool {
    2.93 +        pasteboard = [NSPasteboard generalPasteboard];
    2.94 +        count = [pasteboard changeCount];
    2.95 +        if (count != data->clipboard_count) {
    2.96 +            if (data->clipboard_count) {
    2.97 +                SDL_SendClipboardUpdate();
    2.98 +            }
    2.99 +            data->clipboard_count = count;
   2.100          }
   2.101 -        data->clipboard_count = count;
   2.102      }
   2.103 -
   2.104 -    [pool release];
   2.105  }
   2.106  
   2.107  #endif /* SDL_VIDEO_DRIVER_COCOA */
     3.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Fri Feb 01 17:09:01 2013 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Sun Jan 06 19:04:53 2013 +0300
     3.3 @@ -158,33 +158,30 @@
     3.4  {
     3.5      /* This can get called more than once! Be careful what you initialize! */
     3.6      ProcessSerialNumber psn;
     3.7 -    NSAutoreleasePool *pool;
     3.8  
     3.9      if (!GetCurrentProcess(&psn)) {
    3.10          TransformProcessType(&psn, kProcessTransformToForegroundApplication);
    3.11          SetFrontProcess(&psn);
    3.12      }
    3.13  
    3.14 -    pool = [[NSAutoreleasePool alloc] init];
    3.15 -    if (NSApp == nil) {
    3.16 -        [NSApplication sharedApplication];
    3.17 +    @autoreleasepool {
    3.18 +        if (NSApp == nil) {
    3.19 +            [NSApplication sharedApplication];
    3.20  
    3.21 -        if ([NSApp mainMenu] == nil) {
    3.22 -            CreateApplicationMenus();
    3.23 +            if ([NSApp mainMenu] == nil) {
    3.24 +                CreateApplicationMenus();
    3.25 +            }
    3.26 +            [NSApp finishLaunching];
    3.27          }
    3.28 -        [NSApp finishLaunching];
    3.29 +        if ([NSApp delegate] == nil) {
    3.30 +            [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
    3.31 +        }
    3.32      }
    3.33 -    if ([NSApp delegate] == nil) {
    3.34 -        [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
    3.35 -    }
    3.36 -    [pool release];
    3.37  }
    3.38  
    3.39  void
    3.40  Cocoa_PumpEvents(_THIS)
    3.41  {
    3.42 -    NSAutoreleasePool *pool;
    3.43 -
    3.44      /* Update activity every 30 seconds to prevent screensaver */
    3.45      if (_this->suspend_screensaver) {
    3.46          SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
    3.47 @@ -196,39 +193,39 @@
    3.48          }
    3.49      }
    3.50  
    3.51 -    pool = [[NSAutoreleasePool alloc] init];
    3.52 -    for ( ; ; ) {
    3.53 -        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    3.54 -        if ( event == nil ) {
    3.55 -            break;
    3.56 +    @autoreleasepool {
    3.57 +        for ( ; ; ) {
    3.58 +            NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    3.59 +            if ( event == nil ) {
    3.60 +                break;
    3.61 +            }
    3.62 +            
    3.63 +            switch ([event type]) {
    3.64 +            case NSLeftMouseDown:
    3.65 +            case NSOtherMouseDown:
    3.66 +            case NSRightMouseDown:
    3.67 +            case NSLeftMouseUp:
    3.68 +            case NSOtherMouseUp:
    3.69 +            case NSRightMouseUp:
    3.70 +            case NSLeftMouseDragged:
    3.71 +            case NSRightMouseDragged:
    3.72 +            case NSOtherMouseDragged: /* usually middle mouse dragged */
    3.73 +            case NSMouseMoved:
    3.74 +            case NSScrollWheel:
    3.75 +                Cocoa_HandleMouseEvent(_this, event);
    3.76 +                break;
    3.77 +            case NSKeyDown:
    3.78 +            case NSKeyUp:
    3.79 +            case NSFlagsChanged:
    3.80 +                Cocoa_HandleKeyEvent(_this, event);
    3.81 +                break;
    3.82 +            default:
    3.83 +                break;
    3.84 +            }
    3.85 +            /* Pass through to NSApp to make sure everything stays in sync */
    3.86 +            [NSApp sendEvent:event];
    3.87          }
    3.88 -		
    3.89 -        switch ([event type]) {
    3.90 -        case NSLeftMouseDown:
    3.91 -        case NSOtherMouseDown:
    3.92 -        case NSRightMouseDown:
    3.93 -        case NSLeftMouseUp:
    3.94 -        case NSOtherMouseUp:
    3.95 -        case NSRightMouseUp:
    3.96 -        case NSLeftMouseDragged:
    3.97 -        case NSRightMouseDragged:
    3.98 -        case NSOtherMouseDragged: /* usually middle mouse dragged */
    3.99 -        case NSMouseMoved:
   3.100 -        case NSScrollWheel:
   3.101 -            Cocoa_HandleMouseEvent(_this, event);
   3.102 -            break;
   3.103 -        case NSKeyDown:
   3.104 -        case NSKeyUp:
   3.105 -        case NSFlagsChanged:
   3.106 -            Cocoa_HandleKeyEvent(_this, event);
   3.107 -            break;
   3.108 -        default:
   3.109 -            break;
   3.110 -        }
   3.111 -        /* Pass through to NSApp to make sure everything stays in sync */
   3.112 -        [NSApp sendEvent:event];
   3.113      }
   3.114 -    [pool release];
   3.115  }
   3.116  
   3.117  #endif /* SDL_VIDEO_DRIVER_COCOA */
     4.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Fri Feb 01 17:09:01 2013 -0800
     4.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Sun Jan 06 19:04:53 2013 +0300
     4.3 @@ -625,28 +625,27 @@
     4.4  Cocoa_StartTextInput(_THIS)
     4.5  {
     4.6      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     4.7 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     4.8 -    NSView *parentView = [[NSApp keyWindow] contentView];
     4.9 +    @autoreleasepool {
    4.10 +        NSView *parentView = [[NSApp keyWindow] contentView];
    4.11  
    4.12 -    /* We only keep one field editor per process, since only the front most
    4.13 -     * window can receive text input events, so it make no sense to keep more
    4.14 -     * than one copy. When we switched to another window and requesting for
    4.15 -     * text input, simply remove the field editor from its superview then add
    4.16 -     * it to the front most window's content view */
    4.17 -    if (!data->fieldEdit) {
    4.18 -        data->fieldEdit =
    4.19 -            [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
    4.20 -    }
    4.21 +        /* We only keep one field editor per process, since only the front most
    4.22 +         * window can receive text input events, so it make no sense to keep more
    4.23 +         * than one copy. When we switched to another window and requesting for
    4.24 +         * text input, simply remove the field editor from its superview then add
    4.25 +         * it to the front most window's content view */
    4.26 +        if (!data->fieldEdit) {
    4.27 +            data->fieldEdit =
    4.28 +                [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
    4.29 +        }
    4.30  
    4.31 -    if (![[data->fieldEdit superview] isEqual: parentView])
    4.32 -    {
    4.33 -        // DEBUG_IME(@"add fieldEdit to window contentView");
    4.34 -        [data->fieldEdit removeFromSuperview];
    4.35 -        [parentView addSubview: data->fieldEdit];
    4.36 -        [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
    4.37 +        if (![[data->fieldEdit superview] isEqual: parentView])
    4.38 +        {
    4.39 +            // DEBUG_IME(@"add fieldEdit to window contentView");
    4.40 +            [data->fieldEdit removeFromSuperview];
    4.41 +            [parentView addSubview: data->fieldEdit];
    4.42 +            [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
    4.43 +        }
    4.44      }
    4.45 -
    4.46 -    [pool release];
    4.47  }
    4.48  
    4.49  void
    4.50 @@ -655,11 +654,11 @@
    4.51      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    4.52  
    4.53      if (data && data->fieldEdit) {
    4.54 -        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.55 -        [data->fieldEdit removeFromSuperview];
    4.56 -        [data->fieldEdit release];
    4.57 -        data->fieldEdit = nil;
    4.58 -        [pool release];
    4.59 +        @autoreleasepool {
    4.60 +            [data->fieldEdit removeFromSuperview];
    4.61 +            [data->fieldEdit release];
    4.62 +            data->fieldEdit = nil;
    4.63 +        }
    4.64      }
    4.65  }
    4.66  
     5.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m	Fri Feb 01 17:09:01 2013 -0800
     5.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m	Sun Jan 06 19:04:53 2013 +0300
     5.3 @@ -39,41 +39,39 @@
     5.4  {
     5.5      Cocoa_RegisterApp();
     5.6  
     5.7 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     5.8 -
     5.9 -    NSAlert* alert = [[NSAlert alloc] init];
    5.10 +    @autoreleasepool {
    5.11 +        NSAlert* alert = [[NSAlert alloc] init];
    5.12  
    5.13 -    if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.14 -        [alert setAlertStyle:NSCriticalAlertStyle];
    5.15 -    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.16 -        [alert setAlertStyle:NSWarningAlertStyle];
    5.17 -    } else {
    5.18 -        [alert setAlertStyle:NSInformationalAlertStyle];
    5.19 -    }
    5.20 +        if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.21 +            [alert setAlertStyle:NSCriticalAlertStyle];
    5.22 +        } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.23 +            [alert setAlertStyle:NSWarningAlertStyle];
    5.24 +        } else {
    5.25 +            [alert setAlertStyle:NSInformationalAlertStyle];
    5.26 +        }
    5.27  
    5.28 -    [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.29 -    [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.30 +        [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.31 +        [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.32  
    5.33 -    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.34 -    int i;
    5.35 -    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.36 -        NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
    5.37 -        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.38 -            [button setKeyEquivalent:@"\r"];
    5.39 -        } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.40 -            [button setKeyEquivalent:@"\033"];
    5.41 -        } else {
    5.42 -            [button setKeyEquivalent:@""];
    5.43 +        const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.44 +        int i;
    5.45 +        for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.46 +            NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
    5.47 +            if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.48 +                [button setKeyEquivalent:@"\r"];
    5.49 +            } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.50 +                [button setKeyEquivalent:@"\033"];
    5.51 +            } else {
    5.52 +                [button setKeyEquivalent:@""];
    5.53 +            }
    5.54          }
    5.55 +
    5.56 +        NSInteger clicked = [alert runModal];
    5.57 +        clicked -= NSAlertFirstButtonReturn;
    5.58 +        *buttonid = buttons[clicked].buttonid;
    5.59 +        [alert release];
    5.60      }
    5.61  
    5.62 -    NSInteger clicked = [alert runModal];
    5.63 -    clicked -= NSAlertFirstButtonReturn;
    5.64 -    *buttonid = buttons[clicked].buttonid;
    5.65 -    [alert release];
    5.66 -
    5.67 -    [pool release];
    5.68 -
    5.69      return 0;
    5.70  }
    5.71  
     6.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Fri Feb 01 17:09:01 2013 -0800
     6.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Sun Jan 06 19:04:53 2013 +0300
     6.3 @@ -32,140 +32,134 @@
     6.4  static SDL_Cursor *
     6.5  Cocoa_CreateDefaultCursor()
     6.6  {
     6.7 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     6.8 -    NSCursor *nscursor;
     6.9 -    SDL_Cursor *cursor = NULL;
    6.10 +    @autoreleasepool {
    6.11 +        NSCursor *nscursor;
    6.12 +        SDL_Cursor *cursor = NULL;
    6.13  
    6.14 -    nscursor = [NSCursor arrowCursor];
    6.15 +        nscursor = [NSCursor arrowCursor];
    6.16  
    6.17 -    if (nscursor) {
    6.18 -        cursor = SDL_calloc(1, sizeof(*cursor));
    6.19 -        if (cursor) {
    6.20 -            cursor->driverdata = nscursor;
    6.21 -            [nscursor retain];
    6.22 +        if (nscursor) {
    6.23 +            cursor = SDL_calloc(1, sizeof(*cursor));
    6.24 +            if (cursor) {
    6.25 +                cursor->driverdata = nscursor;
    6.26 +                [nscursor retain];
    6.27 +            }
    6.28          }
    6.29 +        
    6.30 +        return cursor;
    6.31      }
    6.32 -
    6.33 -    [pool release];
    6.34 -
    6.35 -    return cursor;
    6.36  }
    6.37  
    6.38  static SDL_Cursor *
    6.39  Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
    6.40  {
    6.41 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.42 -    NSImage *nsimage;
    6.43 -    NSCursor *nscursor = NULL;
    6.44 -    SDL_Cursor *cursor = NULL;
    6.45 +    @autoreleasepool {
    6.46 +        NSImage *nsimage;
    6.47 +        NSCursor *nscursor = NULL;
    6.48 +        SDL_Cursor *cursor = NULL;
    6.49  
    6.50 -    nsimage = Cocoa_CreateImage(surface);
    6.51 -    if (nsimage) {
    6.52 -        nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    6.53 -    }
    6.54 +        nsimage = Cocoa_CreateImage(surface);
    6.55 +        if (nsimage) {
    6.56 +            nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    6.57 +        }
    6.58  
    6.59 -    if (nscursor) {
    6.60 -        cursor = SDL_calloc(1, sizeof(*cursor));
    6.61 -        if (cursor) {
    6.62 -            cursor->driverdata = nscursor;
    6.63 +        if (nscursor) {
    6.64 +            cursor = SDL_calloc(1, sizeof(*cursor));
    6.65 +            if (cursor) {
    6.66 +                cursor->driverdata = nscursor;
    6.67 +            }
    6.68          }
    6.69 +        
    6.70 +        return cursor;
    6.71      }
    6.72 -
    6.73 -    [pool release];
    6.74 -
    6.75 -    return cursor;
    6.76  }
    6.77  
    6.78  static SDL_Cursor *
    6.79  Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    6.80  {
    6.81 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.82 -    NSCursor *nscursor = NULL;
    6.83 -    SDL_Cursor *cursor = NULL;
    6.84 +    @autoreleasepool {
    6.85 +        NSCursor *nscursor = NULL;
    6.86 +        SDL_Cursor *cursor = NULL;
    6.87  
    6.88 -    switch(id)
    6.89 -    {
    6.90 -    case SDL_SYSTEM_CURSOR_ARROW:
    6.91 -        nscursor = [NSCursor arrowCursor];
    6.92 -        break;
    6.93 -    case SDL_SYSTEM_CURSOR_IBEAM:
    6.94 -        nscursor = [NSCursor IBeamCursor];
    6.95 -        break;
    6.96 -    case SDL_SYSTEM_CURSOR_WAIT:
    6.97 -        nscursor = [NSCursor arrowCursor];
    6.98 -        break;
    6.99 -    case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.100 -        nscursor = [NSCursor crosshairCursor];
   6.101 -        break;
   6.102 -    case SDL_SYSTEM_CURSOR_WAITARROW:
   6.103 -        nscursor = [NSCursor arrowCursor];
   6.104 -        break;
   6.105 -    case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.106 -    case SDL_SYSTEM_CURSOR_SIZENESW:
   6.107 -        nscursor = [NSCursor closedHandCursor];
   6.108 -        break;
   6.109 -    case SDL_SYSTEM_CURSOR_SIZEWE:
   6.110 -        nscursor = [NSCursor resizeLeftRightCursor];
   6.111 -        break;
   6.112 -    case SDL_SYSTEM_CURSOR_SIZENS:
   6.113 -        nscursor = [NSCursor resizeUpDownCursor];
   6.114 -        break;
   6.115 -    case SDL_SYSTEM_CURSOR_SIZEALL:
   6.116 -        nscursor = [NSCursor closedHandCursor];
   6.117 -        break;
   6.118 -    case SDL_SYSTEM_CURSOR_NO:
   6.119 -        nscursor = [NSCursor operationNotAllowedCursor];
   6.120 -        break;
   6.121 -    case SDL_SYSTEM_CURSOR_HAND:
   6.122 -        nscursor = [NSCursor pointingHandCursor];
   6.123 -        break;
   6.124 -    default:
   6.125 -        SDL_assert(!"Unknown system cursor");
   6.126 -        return NULL;
   6.127 +        switch(id)
   6.128 +        {
   6.129 +        case SDL_SYSTEM_CURSOR_ARROW:
   6.130 +            nscursor = [NSCursor arrowCursor];
   6.131 +            break;
   6.132 +        case SDL_SYSTEM_CURSOR_IBEAM:
   6.133 +            nscursor = [NSCursor IBeamCursor];
   6.134 +            break;
   6.135 +        case SDL_SYSTEM_CURSOR_WAIT:
   6.136 +            nscursor = [NSCursor arrowCursor];
   6.137 +            break;
   6.138 +        case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.139 +            nscursor = [NSCursor crosshairCursor];
   6.140 +            break;
   6.141 +        case SDL_SYSTEM_CURSOR_WAITARROW:
   6.142 +            nscursor = [NSCursor arrowCursor];
   6.143 +            break;
   6.144 +        case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.145 +        case SDL_SYSTEM_CURSOR_SIZENESW:
   6.146 +            nscursor = [NSCursor closedHandCursor];
   6.147 +            break;
   6.148 +        case SDL_SYSTEM_CURSOR_SIZEWE:
   6.149 +            nscursor = [NSCursor resizeLeftRightCursor];
   6.150 +            break;
   6.151 +        case SDL_SYSTEM_CURSOR_SIZENS:
   6.152 +            nscursor = [NSCursor resizeUpDownCursor];
   6.153 +            break;
   6.154 +        case SDL_SYSTEM_CURSOR_SIZEALL:
   6.155 +            nscursor = [NSCursor closedHandCursor];
   6.156 +            break;
   6.157 +        case SDL_SYSTEM_CURSOR_NO:
   6.158 +            nscursor = [NSCursor operationNotAllowedCursor];
   6.159 +            break;
   6.160 +        case SDL_SYSTEM_CURSOR_HAND:
   6.161 +            nscursor = [NSCursor pointingHandCursor];
   6.162 +            break;
   6.163 +        default:
   6.164 +            SDL_assert(!"Unknown system cursor");
   6.165 +            return NULL;
   6.166 +        }
   6.167 +
   6.168 +        if (nscursor) {
   6.169 +            cursor = SDL_calloc(1, sizeof(*cursor));
   6.170 +            if (cursor) {
   6.171 +                // We'll free it later, so retain it here
   6.172 +                [nscursor retain];
   6.173 +                cursor->driverdata = nscursor;
   6.174 +            }
   6.175 +        }
   6.176 +            
   6.177 +        return cursor;
   6.178      }
   6.179 -
   6.180 -    if (nscursor) {
   6.181 -        cursor = SDL_calloc(1, sizeof(*cursor));
   6.182 -        if (cursor) {
   6.183 -            // We'll free it later, so retain it here
   6.184 -            [nscursor retain];
   6.185 -            cursor->driverdata = nscursor;
   6.186 -        }
   6.187 -    }
   6.188 -
   6.189 -    [pool release];
   6.190 -
   6.191 -    return cursor;
   6.192  }
   6.193  
   6.194  static void
   6.195  Cocoa_FreeCursor(SDL_Cursor * cursor)
   6.196  {
   6.197 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.198 -    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.199 +    @autoreleasepool {
   6.200 +        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.201  
   6.202 -    [nscursor release];
   6.203 -    SDL_free(cursor);
   6.204 -
   6.205 -    [pool release];
   6.206 +        [nscursor release];
   6.207 +        SDL_free(cursor);
   6.208 +    }
   6.209  }
   6.210  
   6.211  static int
   6.212  Cocoa_ShowCursor(SDL_Cursor * cursor)
   6.213  {
   6.214 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.215 -
   6.216 -    if (cursor) {
   6.217 -        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.218 +    @autoreleasepool {
   6.219 +        if (cursor) {
   6.220 +            NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.221  
   6.222 -        [nscursor set];
   6.223 -        [NSCursor unhide];
   6.224 -    } else {
   6.225 -        [NSCursor hide];
   6.226 +            [nscursor set];
   6.227 +            [NSCursor unhide];
   6.228 +        } else {
   6.229 +            [NSCursor hide];
   6.230 +        }
   6.231      }
   6.232  
   6.233 -    [pool release];
   6.234 -
   6.235      return 0;
   6.236  }
   6.237  
     7.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Fri Feb 01 17:09:01 2013 -0800
     7.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Sun Jan 06 19:04:53 2013 +0300
     7.3 @@ -80,7 +80,6 @@
     7.4      const int wantver = (_this->gl_config.major_version << 8) |
     7.5                          (_this->gl_config.minor_version);
     7.6      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     7.7 -    NSAutoreleasePool *pool;
     7.8      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     7.9      SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
    7.10      NSOpenGLPixelFormatAttribute attr[32];
    7.11 @@ -100,121 +99,116 @@
    7.12          return NULL;
    7.13      }
    7.14  
    7.15 -    pool = [[NSAutoreleasePool alloc] init];
    7.16 +    @autoreleasepool {
    7.17 +        /* specify a profile if we're on Lion (10.7) or later. */
    7.18 +        if (data->osversion >= 0x1070) {
    7.19 +            NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
    7.20 +            if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
    7.21 +                if (wantver == 0x0302) {
    7.22 +                    profile = kCGLOGLPVersion_3_2_Core;
    7.23 +                }
    7.24 +            }
    7.25 +            attr[i++] = kCGLPFAOpenGLProfile;
    7.26 +            attr[i++] = profile;
    7.27 +        }
    7.28 +
    7.29 +    #ifndef FULLSCREEN_TOGGLEABLE
    7.30 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.31 +            attr[i++] = NSOpenGLPFAFullScreen;
    7.32 +        }
    7.33 +    #endif
    7.34 +
    7.35 +        attr[i++] = NSOpenGLPFAColorSize;
    7.36 +        attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
    7.37 +
    7.38 +        attr[i++] = NSOpenGLPFADepthSize;
    7.39 +        attr[i++] = _this->gl_config.depth_size;
    7.40 +
    7.41 +        if (_this->gl_config.double_buffer) {
    7.42 +            attr[i++] = NSOpenGLPFADoubleBuffer;
    7.43 +        }
    7.44  
    7.45 -    /* specify a profile if we're on Lion (10.7) or later. */
    7.46 -    if (data->osversion >= 0x1070) {
    7.47 -        NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
    7.48 -        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
    7.49 -            if (wantver == 0x0302) {
    7.50 -                profile = kCGLOGLPVersion_3_2_Core;
    7.51 +        if (_this->gl_config.stereo) {
    7.52 +            attr[i++] = NSOpenGLPFAStereo;
    7.53 +        }
    7.54 +
    7.55 +        if (_this->gl_config.stencil_size) {
    7.56 +            attr[i++] = NSOpenGLPFAStencilSize;
    7.57 +            attr[i++] = _this->gl_config.stencil_size;
    7.58 +        }
    7.59 +
    7.60 +        if ((_this->gl_config.accum_red_size +
    7.61 +             _this->gl_config.accum_green_size +
    7.62 +             _this->gl_config.accum_blue_size +
    7.63 +             _this->gl_config.accum_alpha_size) > 0) {
    7.64 +            attr[i++] = NSOpenGLPFAAccumSize;
    7.65 +            attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
    7.66 +        }
    7.67 +
    7.68 +        if (_this->gl_config.multisamplebuffers) {
    7.69 +            attr[i++] = NSOpenGLPFASampleBuffers;
    7.70 +            attr[i++] = _this->gl_config.multisamplebuffers;
    7.71 +        }
    7.72 +
    7.73 +        if (_this->gl_config.multisamplesamples) {
    7.74 +            attr[i++] = NSOpenGLPFASamples;
    7.75 +            attr[i++] = _this->gl_config.multisamplesamples;
    7.76 +            attr[i++] = NSOpenGLPFANoRecovery;
    7.77 +        }
    7.78 +
    7.79 +        if (_this->gl_config.accelerated >= 0) {
    7.80 +            if (_this->gl_config.accelerated) {
    7.81 +                attr[i++] = NSOpenGLPFAAccelerated;
    7.82 +            } else {
    7.83 +                attr[i++] = NSOpenGLPFARendererID;
    7.84 +                attr[i++] = kCGLRendererGenericFloatID;
    7.85              }
    7.86          }
    7.87 -        attr[i++] = kCGLPFAOpenGLProfile;
    7.88 -        attr[i++] = profile;
    7.89 -    }
    7.90  
    7.91 -#ifndef FULLSCREEN_TOGGLEABLE
    7.92 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.93 -        attr[i++] = NSOpenGLPFAFullScreen;
    7.94 -    }
    7.95 -#endif
    7.96 +        attr[i++] = NSOpenGLPFAScreenMask;
    7.97 +        attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
    7.98 +        attr[i] = 0;
    7.99  
   7.100 -    attr[i++] = NSOpenGLPFAColorSize;
   7.101 -    attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
   7.102 -
   7.103 -    attr[i++] = NSOpenGLPFADepthSize;
   7.104 -    attr[i++] = _this->gl_config.depth_size;
   7.105 +        fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.106 +        if (fmt == nil) {
   7.107 +            SDL_SetError ("Failed creating OpenGL pixel format");
   7.108 +            return NULL;
   7.109 +        }
   7.110  
   7.111 -    if (_this->gl_config.double_buffer) {
   7.112 -        attr[i++] = NSOpenGLPFADoubleBuffer;
   7.113 -    }
   7.114 +        context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.115 +
   7.116 +        [fmt release];
   7.117  
   7.118 -    if (_this->gl_config.stereo) {
   7.119 -        attr[i++] = NSOpenGLPFAStereo;
   7.120 -    }
   7.121 +        if (context == nil) {
   7.122 +            SDL_SetError ("Failed creating OpenGL context");
   7.123 +            return NULL;
   7.124 +        }
   7.125  
   7.126 -    if (_this->gl_config.stencil_size) {
   7.127 -        attr[i++] = NSOpenGLPFAStencilSize;
   7.128 -        attr[i++] = _this->gl_config.stencil_size;
   7.129 -    }
   7.130 -
   7.131 -    if ((_this->gl_config.accum_red_size +
   7.132 -         _this->gl_config.accum_green_size +
   7.133 -         _this->gl_config.accum_blue_size +
   7.134 -         _this->gl_config.accum_alpha_size) > 0) {
   7.135 -        attr[i++] = NSOpenGLPFAAccumSize;
   7.136 -        attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
   7.137 -    }
   7.138 +        /*
   7.139 +         * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.140 +         *  "You are blowing a couple of the internal OpenGL function caches. This
   7.141 +         *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.142 +         *  the cache size by issuing the following calls right after you create
   7.143 +         *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.144 +         */
   7.145  
   7.146 -    if (_this->gl_config.multisamplebuffers) {
   7.147 -        attr[i++] = NSOpenGLPFASampleBuffers;
   7.148 -        attr[i++] = _this->gl_config.multisamplebuffers;
   7.149 -    }
   7.150 +        #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.151 +        #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.152 +        #endif
   7.153  
   7.154 -    if (_this->gl_config.multisamplesamples) {
   7.155 -        attr[i++] = NSOpenGLPFASamples;
   7.156 -        attr[i++] = _this->gl_config.multisamplesamples;
   7.157 -        attr[i++] = NSOpenGLPFANoRecovery;
   7.158 -    }
   7.159 +        #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.160 +        #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.161 +        #endif
   7.162  
   7.163 -    if (_this->gl_config.accelerated >= 0) {
   7.164 -        if (_this->gl_config.accelerated) {
   7.165 -            attr[i++] = NSOpenGLPFAAccelerated;
   7.166 -        } else {
   7.167 -            attr[i++] = NSOpenGLPFARendererID;
   7.168 -            attr[i++] = kCGLRendererGenericFloatID;
   7.169 +        {
   7.170 +            GLint cache_max = 64;
   7.171 +            CGLContextObj ctx = [context CGLContextObj];
   7.172 +            CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.173 +            CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.174          }
   7.175      }
   7.176 -
   7.177 -    attr[i++] = NSOpenGLPFAScreenMask;
   7.178 -    attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
   7.179 -    attr[i] = 0;
   7.180 -
   7.181 -    fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.182 -    if (fmt == nil) {
   7.183 -        SDL_SetError ("Failed creating OpenGL pixel format");
   7.184 -        [pool release];
   7.185 -        return NULL;
   7.186 -    }
   7.187 -
   7.188 -    context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.189 -
   7.190 -    [fmt release];
   7.191 -
   7.192 -    if (context == nil) {
   7.193 -        SDL_SetError ("Failed creating OpenGL context");
   7.194 -        [pool release];
   7.195 -        return NULL;
   7.196 -    }
   7.197 -
   7.198 -    /*
   7.199 -     * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.200 -     *  "You are blowing a couple of the internal OpenGL function caches. This
   7.201 -     *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.202 -     *  the cache size by issuing the following calls right after you create
   7.203 -     *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.204 -     */
   7.205 -
   7.206 -    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.207 -    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.208 -    #endif
   7.209 -
   7.210 -    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.211 -    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.212 -    #endif
   7.213 -
   7.214 -    {
   7.215 -        GLint cache_max = 64;
   7.216 -        CGLContextObj ctx = [context CGLContextObj];
   7.217 -        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.218 -        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.219 -    }
   7.220 -
   7.221      /* End Wisdom from Apple Engineer section. --ryan. */
   7.222  
   7.223 -    [pool release];
   7.224 -
   7.225      if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
   7.226          Cocoa_GL_DeleteContext(_this, context);
   7.227          return NULL;
   7.228 @@ -226,107 +220,94 @@
   7.229  int
   7.230  Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   7.231  {
   7.232 -    NSAutoreleasePool *pool;
   7.233 -
   7.234 -    pool = [[NSAutoreleasePool alloc] init];
   7.235 -
   7.236 -    if (context) {
   7.237 -        SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.238 -        NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.239 +    @autoreleasepool {
   7.240 +        if (context) {
   7.241 +            SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.242 +            NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.243  
   7.244 -        if (window->flags & SDL_WINDOW_SHOWN) {
   7.245 -#ifndef FULLSCREEN_TOGGLEABLE
   7.246 -            if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.247 -                [nscontext setFullScreen];
   7.248 -            } else
   7.249 -#endif
   7.250 -            {
   7.251 -                [nscontext setView:[windowdata->nswindow contentView]];
   7.252 -                [nscontext update];
   7.253 +            if (window->flags & SDL_WINDOW_SHOWN) {
   7.254 +    #ifndef FULLSCREEN_TOGGLEABLE
   7.255 +                if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.256 +                    [nscontext setFullScreen];
   7.257 +                } else
   7.258 +    #endif
   7.259 +                {
   7.260 +                    [nscontext setView:[windowdata->nswindow contentView]];
   7.261 +                    [nscontext update];
   7.262 +                }
   7.263              }
   7.264 +            [nscontext makeCurrentContext];
   7.265 +        } else {
   7.266 +            [NSOpenGLContext clearCurrentContext];
   7.267          }
   7.268 -        [nscontext makeCurrentContext];
   7.269 -    } else {
   7.270 -        [NSOpenGLContext clearCurrentContext];
   7.271      }
   7.272  
   7.273 -    [pool release];
   7.274      return 0;
   7.275  }
   7.276  
   7.277  int
   7.278  Cocoa_GL_SetSwapInterval(_THIS, int interval)
   7.279  {
   7.280 -    NSAutoreleasePool *pool;
   7.281      NSOpenGLContext *nscontext;
   7.282      GLint value;
   7.283      int status;
   7.284  
   7.285 -    pool = [[NSAutoreleasePool alloc] init];
   7.286 -
   7.287 -    nscontext = [NSOpenGLContext currentContext];
   7.288 -    if (nscontext != nil) {
   7.289 -        value = interval;
   7.290 -        [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.291 -        status = 0;
   7.292 -    } else {
   7.293 -        SDL_SetError("No current OpenGL context");
   7.294 -        status = -1;
   7.295 +    @autoreleasepool {
   7.296 +        nscontext = [NSOpenGLContext currentContext];
   7.297 +        if (nscontext != nil) {
   7.298 +            value = interval;
   7.299 +            [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.300 +            status = 0;
   7.301 +        } else {
   7.302 +            SDL_SetError("No current OpenGL context");
   7.303 +            status = -1;
   7.304 +        }
   7.305      }
   7.306  
   7.307 -    [pool release];
   7.308      return status;
   7.309  }
   7.310  
   7.311  int
   7.312  Cocoa_GL_GetSwapInterval(_THIS)
   7.313  {
   7.314 -    NSAutoreleasePool *pool;
   7.315      NSOpenGLContext *nscontext;
   7.316      GLint value;
   7.317      int status = 0;
   7.318  
   7.319 -    pool = [[NSAutoreleasePool alloc] init];
   7.320 -
   7.321 -    nscontext = [NSOpenGLContext currentContext];
   7.322 -    if (nscontext != nil) {
   7.323 -        [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.324 -        status = (int)value;
   7.325 +    @autoreleasepool {
   7.326 +        nscontext = [NSOpenGLContext currentContext];
   7.327 +        if (nscontext != nil) {
   7.328 +            [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.329 +            status = (int)value;
   7.330 +        }
   7.331      }
   7.332  
   7.333 -    [pool release];
   7.334      return status;
   7.335  }
   7.336  
   7.337  void
   7.338  Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
   7.339  {
   7.340 -    NSAutoreleasePool *pool;
   7.341      NSOpenGLContext *nscontext;
   7.342  
   7.343 -    pool = [[NSAutoreleasePool alloc] init];
   7.344 -
   7.345 -    /* FIXME: Do we need to get the context for the window? */
   7.346 -    nscontext = [NSOpenGLContext currentContext];
   7.347 -    if (nscontext != nil) {
   7.348 -        [nscontext flushBuffer];
   7.349 +    @autoreleasepool {
   7.350 +        /* FIXME: Do we need to get the context for the window? */
   7.351 +        nscontext = [NSOpenGLContext currentContext];
   7.352 +        if (nscontext != nil) {
   7.353 +            [nscontext flushBuffer];
   7.354 +        }
   7.355      }
   7.356 -
   7.357 -    [pool release];
   7.358  }
   7.359  
   7.360  void
   7.361  Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
   7.362  {
   7.363 -    NSAutoreleasePool *pool;
   7.364      NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.365  
   7.366 -    pool = [[NSAutoreleasePool alloc] init];
   7.367 -
   7.368 -    [nscontext clearDrawable];
   7.369 -    [nscontext release];
   7.370 -
   7.371 -    [pool release];
   7.372 +    @autoreleasepool {
   7.373 +        [nscontext clearDrawable];
   7.374 +        [nscontext release];
   7.375 +    }
   7.376  }
   7.377  
   7.378  #endif /* SDL_VIDEO_OPENGL_CGL */
     8.1 --- a/src/video/cocoa/SDL_cocoashape.m	Fri Feb 01 17:09:01 2013 -0800
     8.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Sun Jan 06 19:04:53 2013 +0300
     8.3 @@ -74,7 +74,7 @@
     8.4      SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
     8.5  	SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
     8.6  	SDL_CocoaClosure closure;
     8.7 -	NSAutoreleasePool *pool = NULL;
     8.8 +
     8.9      if(data->saved == SDL_TRUE) {
    8.10          [data->context restoreGraphicsState];
    8.11          data->saved = SDL_FALSE;
    8.12 @@ -88,12 +88,13 @@
    8.13      NSRectFill([[windata->nswindow contentView] frame]);
    8.14      data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
    8.15  	
    8.16 -	pool = [[NSAutoreleasePool alloc] init];
    8.17 -    closure.view = [windata->nswindow contentView];
    8.18 -    closure.path = [[NSBezierPath bezierPath] autorelease];
    8.19 -	closure.window = shaper->window;
    8.20 -    SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
    8.21 -    [closure.path addClip];
    8.22 +    @autoreleasepool {
    8.23 +        closure.view = [windata->nswindow contentView];
    8.24 +        closure.path = [[NSBezierPath bezierPath] autorelease];
    8.25 +        closure.window = shaper->window;
    8.26 +        SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
    8.27 +        [closure.path addClip];
    8.28 +    }
    8.29  
    8.30      return 0;
    8.31  }
     9.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Fri Feb 01 17:09:01 2013 -0800
     9.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Sun Jan 06 19:04:53 2013 +0300
     9.3 @@ -250,37 +250,36 @@
     9.4          }
     9.5      }
     9.6  
     9.7 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     9.8 +    @autoreleasepool {
     9.9 +        NSString *msg = [NSString stringWithFormat:
    9.10 +                @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
    9.11 +                    data->function, data->filename, data->linenum,
    9.12 +                    data->trigger_count, (data->trigger_count == 1) ? "" : "s",
    9.13 +                    data->condition];
    9.14  
    9.15 -    NSString *msg = [NSString stringWithFormat:
    9.16 -            @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
    9.17 -                data->function, data->filename, data->linenum,
    9.18 -                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
    9.19 -                data->condition];
    9.20 +        NSLog(@"%@", msg);
    9.21  
    9.22 -    NSLog(@"%@", msg);
    9.23 -
    9.24 -    /*
    9.25 -     * !!! FIXME: this code needs to deal with fullscreen modes:
    9.26 -     * !!! FIXME:  reset to default desktop, runModal, reset to current?
    9.27 -     */
    9.28 +        /*
    9.29 +         * !!! FIXME: this code needs to deal with fullscreen modes:
    9.30 +         * !!! FIXME:  reset to default desktop, runModal, reset to current?
    9.31 +         */
    9.32  
    9.33 -    NSAlert* alert = [[NSAlert alloc] init];
    9.34 -    [alert setAlertStyle:NSCriticalAlertStyle];
    9.35 -    [alert setMessageText:msg];
    9.36 -    [alert addButtonWithTitle:@"Retry"];
    9.37 -    [alert addButtonWithTitle:@"Break"];
    9.38 -    [alert addButtonWithTitle:@"Abort"];
    9.39 -    [alert addButtonWithTitle:@"Ignore"];
    9.40 -    [alert addButtonWithTitle:@"Always Ignore"];
    9.41 -    const NSInteger clicked = [alert runModal];
    9.42 -    [pool release];
    9.43 +        NSAlert* alert = [[NSAlert alloc] init];
    9.44 +        [alert setAlertStyle:NSCriticalAlertStyle];
    9.45 +        [alert setMessageText:msg];
    9.46 +        [alert addButtonWithTitle:@"Retry"];
    9.47 +        [alert addButtonWithTitle:@"Break"];
    9.48 +        [alert addButtonWithTitle:@"Abort"];
    9.49 +        [alert addButtonWithTitle:@"Ignore"];
    9.50 +        [alert addButtonWithTitle:@"Always Ignore"];
    9.51 +        const NSInteger clicked = [alert runModal];
    9.52  
    9.53 -    if (!initialized) {
    9.54 -        SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.55 +        if (!initialized) {
    9.56 +            SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.57 +        }
    9.58 +
    9.59 +        return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    9.60      }
    9.61 -
    9.62 -    return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    9.63  }
    9.64  
    9.65  #endif /* SDL_VIDEO_DRIVER_COCOA */
    10.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Fri Feb 01 17:09:01 2013 -0800
    10.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Jan 06 19:04:53 2013 +0300
    10.3 @@ -507,7 +507,6 @@
    10.4  static int
    10.5  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
    10.6  {
    10.7 -    NSAutoreleasePool *pool;
    10.8      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    10.9      SDL_WindowData *data;
   10.10  
   10.11 @@ -522,313 +521,297 @@
   10.12      data->created = created;
   10.13      data->videodata = videodata;
   10.14  
   10.15 -    pool = [[NSAutoreleasePool alloc] init];
   10.16 -
   10.17 -    /* Create an event listener for the window */
   10.18 -    data->listener = [[Cocoa_WindowListener alloc] init];
   10.19 +    @autoreleasepool {
   10.20 +        /* Create an event listener for the window */
   10.21 +        data->listener = [[Cocoa_WindowListener alloc] init];
   10.22  
   10.23 -    /* Fill in the SDL window with the window data */
   10.24 -    {
   10.25 -        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.26 -        ConvertNSRect(&rect);
   10.27 -        window->x = (int)rect.origin.x;
   10.28 -        window->y = (int)rect.origin.y;
   10.29 -        window->w = (int)rect.size.width;
   10.30 -        window->h = (int)rect.size.height;
   10.31 -    }
   10.32 +        /* Fill in the SDL window with the window data */
   10.33 +        {
   10.34 +            NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.35 +            ConvertNSRect(&rect);
   10.36 +            window->x = (int)rect.origin.x;
   10.37 +            window->y = (int)rect.origin.y;
   10.38 +            window->w = (int)rect.size.width;
   10.39 +            window->h = (int)rect.size.height;
   10.40 +        }
   10.41  
   10.42 -    /* Set up the listener after we create the view */
   10.43 -    [data->listener listen:data];
   10.44 +        /* Set up the listener after we create the view */
   10.45 +        [data->listener listen:data];
   10.46  
   10.47 -    if ([nswindow isVisible]) {
   10.48 -        window->flags |= SDL_WINDOW_SHOWN;
   10.49 -    } else {
   10.50 -        window->flags &= ~SDL_WINDOW_SHOWN;
   10.51 -    }
   10.52 -    {
   10.53 -        unsigned int style = [nswindow styleMask];
   10.54 -
   10.55 -        if (style == NSBorderlessWindowMask) {
   10.56 -            window->flags |= SDL_WINDOW_BORDERLESS;
   10.57 +        if ([nswindow isVisible]) {
   10.58 +            window->flags |= SDL_WINDOW_SHOWN;
   10.59          } else {
   10.60 -            window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.61 +            window->flags &= ~SDL_WINDOW_SHOWN;
   10.62          }
   10.63 -        if (style & NSResizableWindowMask) {
   10.64 -            window->flags |= SDL_WINDOW_RESIZABLE;
   10.65 -        } else {
   10.66 -            window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.67 +        {
   10.68 +            unsigned int style = [nswindow styleMask];
   10.69 +
   10.70 +            if (style == NSBorderlessWindowMask) {
   10.71 +                window->flags |= SDL_WINDOW_BORDERLESS;
   10.72 +            } else {
   10.73 +                window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.74 +            }
   10.75 +            if (style & NSResizableWindowMask) {
   10.76 +                window->flags |= SDL_WINDOW_RESIZABLE;
   10.77 +            } else {
   10.78 +                window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.79 +            }
   10.80          }
   10.81 -    }
   10.82 -    /* isZoomed always returns true if the window is not resizable */
   10.83 -    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   10.84 -        window->flags |= SDL_WINDOW_MAXIMIZED;
   10.85 -    } else {
   10.86 -        window->flags &= ~SDL_WINDOW_MAXIMIZED;
   10.87 +        /* isZoomed always returns true if the window is not resizable */
   10.88 +        if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   10.89 +            window->flags |= SDL_WINDOW_MAXIMIZED;
   10.90 +        } else {
   10.91 +            window->flags &= ~SDL_WINDOW_MAXIMIZED;
   10.92 +        }
   10.93 +        if ([nswindow isMiniaturized]) {
   10.94 +            window->flags |= SDL_WINDOW_MINIMIZED;
   10.95 +        } else {
   10.96 +            window->flags &= ~SDL_WINDOW_MINIMIZED;
   10.97 +        }
   10.98 +        if ([nswindow isKeyWindow]) {
   10.99 +            window->flags |= SDL_WINDOW_INPUT_FOCUS;
  10.100 +            SDL_SetKeyboardFocus(data->window);
  10.101 +        }
  10.102 +
  10.103 +        /* All done! */
  10.104 +        window->driverdata = data;
  10.105 +        return 0;
  10.106      }
  10.107 -    if ([nswindow isMiniaturized]) {
  10.108 -        window->flags |= SDL_WINDOW_MINIMIZED;
  10.109 -    } else {
  10.110 -        window->flags &= ~SDL_WINDOW_MINIMIZED;
  10.111 -    }
  10.112 -    if ([nswindow isKeyWindow]) {
  10.113 -        window->flags |= SDL_WINDOW_INPUT_FOCUS;
  10.114 -        SDL_SetKeyboardFocus(data->window);
  10.115 -    }
  10.116 -
  10.117 -    /* All done! */
  10.118 -    [pool release];
  10.119 -    window->driverdata = data;
  10.120 -    return 0;
  10.121  }
  10.122  
  10.123  int
  10.124  Cocoa_CreateWindow(_THIS, SDL_Window * window)
  10.125  {
  10.126 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.127 -    NSWindow *nswindow;
  10.128 -    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.129 -    NSRect rect;
  10.130 -    SDL_Rect bounds;
  10.131 -    unsigned int style;
  10.132 +    @autoreleasepool {
  10.133 +        NSWindow *nswindow;
  10.134 +        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.135 +        NSRect rect;
  10.136 +        SDL_Rect bounds;
  10.137 +        unsigned int style;
  10.138  
  10.139 -    Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.140 -    rect.origin.x = window->x;
  10.141 -    rect.origin.y = window->y;
  10.142 -    rect.size.width = window->w;
  10.143 -    rect.size.height = window->h;
  10.144 -    ConvertNSRect(&rect);
  10.145 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.146 +        rect.origin.x = window->x;
  10.147 +        rect.origin.y = window->y;
  10.148 +        rect.size.width = window->w;
  10.149 +        rect.size.height = window->h;
  10.150 +        ConvertNSRect(&rect);
  10.151  
  10.152 -    style = GetWindowStyle(window);
  10.153 +        style = GetWindowStyle(window);
  10.154  
  10.155 -    /* Figure out which screen to place this window */
  10.156 -    NSArray *screens = [NSScreen screens];
  10.157 -    NSScreen *screen = nil;
  10.158 -    NSScreen *candidate;
  10.159 -    int i, count = [screens count];
  10.160 -    for (i = 0; i < count; ++i) {
  10.161 -        candidate = [screens objectAtIndex:i];
  10.162 -        NSRect screenRect = [candidate frame];
  10.163 -        if (rect.origin.x >= screenRect.origin.x &&
  10.164 -            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.165 -            rect.origin.y >= screenRect.origin.y &&
  10.166 -            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.167 -            screen = candidate;
  10.168 -            rect.origin.x -= screenRect.origin.x;
  10.169 -            rect.origin.y -= screenRect.origin.y;
  10.170 +        /* Figure out which screen to place this window */
  10.171 +        NSArray *screens = [NSScreen screens];
  10.172 +        NSScreen *screen = nil;
  10.173 +        NSScreen *candidate;
  10.174 +        int i, count = [screens count];
  10.175 +        for (i = 0; i < count; ++i) {
  10.176 +            candidate = [screens objectAtIndex:i];
  10.177 +            NSRect screenRect = [candidate frame];
  10.178 +            if (rect.origin.x >= screenRect.origin.x &&
  10.179 +                rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.180 +                rect.origin.y >= screenRect.origin.y &&
  10.181 +                rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.182 +                screen = candidate;
  10.183 +                rect.origin.x -= screenRect.origin.x;
  10.184 +                rect.origin.y -= screenRect.origin.y;
  10.185 +            }
  10.186          }
  10.187 -    }
  10.188 -    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.189 +        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.190  
  10.191 -    // Create a default view for this window
  10.192 -    rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.193 -    NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.194 -    [nswindow setContentView: contentView];
  10.195 -    [contentView release];
  10.196 +        // Create a default view for this window
  10.197 +        rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.198 +        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.199 +        [nswindow setContentView: contentView];
  10.200 +        [contentView release];
  10.201  
  10.202 -    [pool release];
  10.203 -
  10.204 -    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.205 -        [nswindow release];
  10.206 -        return -1;
  10.207 +        if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.208 +            [nswindow release];
  10.209 +            return -1;
  10.210 +        }
  10.211 +        return 0;
  10.212      }
  10.213 -    return 0;
  10.214  }
  10.215  
  10.216  int
  10.217  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  10.218  {
  10.219 -    NSAutoreleasePool *pool;
  10.220      NSWindow *nswindow = (NSWindow *) data;
  10.221      NSString *title;
  10.222  
  10.223 -    pool = [[NSAutoreleasePool alloc] init];
  10.224 -
  10.225 -    /* Query the title from the existing window */
  10.226 -    title = [nswindow title];
  10.227 -    if (title) {
  10.228 -        window->title = SDL_strdup([title UTF8String]);
  10.229 +    @autoreleasepool {
  10.230 +        /* Query the title from the existing window */
  10.231 +        title = [nswindow title];
  10.232 +        if (title) {
  10.233 +            window->title = SDL_strdup([title UTF8String]);
  10.234 +        }
  10.235      }
  10.236  
  10.237 -    [pool release];
  10.238 -
  10.239      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
  10.240  }
  10.241  
  10.242  void
  10.243  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
  10.244  {
  10.245 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.246 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.247 -    NSString *string;
  10.248 +    @autoreleasepool {
  10.249 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.250 +        NSString *string;
  10.251  
  10.252 -    if(window->title) {
  10.253 -        string = [[NSString alloc] initWithUTF8String:window->title];
  10.254 -    } else {
  10.255 -        string = [[NSString alloc] init];
  10.256 +        if(window->title) {
  10.257 +            string = [[NSString alloc] initWithUTF8String:window->title];
  10.258 +        } else {
  10.259 +            string = [[NSString alloc] init];
  10.260 +        }
  10.261 +        [nswindow setTitle:string];
  10.262 +        [string release];
  10.263      }
  10.264 -    [nswindow setTitle:string];
  10.265 -    [string release];
  10.266 -
  10.267 -    [pool release];
  10.268  }
  10.269  
  10.270  void
  10.271  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  10.272  {
  10.273 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.274 -    NSImage *nsimage = Cocoa_CreateImage(icon);
  10.275 +    @autoreleasepool {
  10.276 +        NSImage *nsimage = Cocoa_CreateImage(icon);
  10.277  
  10.278 -    if (nsimage) {
  10.279 -        [NSApp setApplicationIconImage:nsimage];
  10.280 +        if (nsimage) {
  10.281 +            [NSApp setApplicationIconImage:nsimage];
  10.282 +        }
  10.283      }
  10.284 -
  10.285 -    [pool release];
  10.286  }
  10.287  
  10.288  void
  10.289  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
  10.290  {
  10.291 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.292 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.293 -    NSRect rect;
  10.294 -    Uint32 moveHack;
  10.295 -
  10.296 -    rect.origin.x = window->x;
  10.297 -    rect.origin.y = window->y;
  10.298 -    rect.size.width = window->w;
  10.299 -    rect.size.height = window->h;
  10.300 -    ConvertNSRect(&rect);
  10.301 +    @autoreleasepool {
  10.302 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.303 +        NSRect rect;
  10.304 +        Uint32 moveHack;
  10.305  
  10.306 -    moveHack = s_moveHack;
  10.307 -    s_moveHack = 0;
  10.308 -    [nswindow setFrameOrigin:rect.origin];
  10.309 -    s_moveHack = moveHack;
  10.310 +        rect.origin.x = window->x;
  10.311 +        rect.origin.y = window->y;
  10.312 +        rect.size.width = window->w;
  10.313 +        rect.size.height = window->h;
  10.314 +        ConvertNSRect(&rect);
  10.315  
  10.316 -    if (window == _this->current_glwin) {
  10.317 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.318 +        moveHack = s_moveHack;
  10.319 +        s_moveHack = 0;
  10.320 +        [nswindow setFrameOrigin:rect.origin];
  10.321 +        s_moveHack = moveHack;
  10.322 +
  10.323 +        if (window == _this->current_glwin) {
  10.324 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.325 +        }
  10.326      }
  10.327 -
  10.328 -    [pool release];
  10.329  }
  10.330  
  10.331  void
  10.332  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
  10.333  {
  10.334 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.335 -    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.336 -    NSWindow *nswindow = windata->nswindow;
  10.337 -    NSSize size;
  10.338 +    @autoreleasepool {
  10.339 +        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.340 +        NSWindow *nswindow = windata->nswindow;
  10.341 +        NSSize size;
  10.342  
  10.343 -    size.width = window->w;
  10.344 -    size.height = window->h;
  10.345 -    [nswindow setContentSize:size];
  10.346 +        size.width = window->w;
  10.347 +        size.height = window->h;
  10.348 +        [nswindow setContentSize:size];
  10.349  
  10.350 -    if (window == _this->current_glwin) {
  10.351 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.352 +        if (window == _this->current_glwin) {
  10.353 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.354 +        }
  10.355      }
  10.356 -
  10.357 -    [pool release];
  10.358  }
  10.359  
  10.360  void
  10.361  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
  10.362  {
  10.363 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.364 -    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.365 -        
  10.366 -    NSSize minSize;
  10.367 -    minSize.width = window->min_w;
  10.368 -    minSize.height = window->min_h;
  10.369 -        
  10.370 -    [windata->nswindow setContentMinSize:minSize];
  10.371 -    
  10.372 -    [pool release];
  10.373 +    @autoreleasepool {
  10.374 +        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.375 +            
  10.376 +        NSSize minSize;
  10.377 +        minSize.width = window->min_w;
  10.378 +        minSize.height = window->min_h;
  10.379 +            
  10.380 +        [windata->nswindow setContentMinSize:minSize];
  10.381 +    }
  10.382  }
  10.383  
  10.384  void
  10.385  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
  10.386  {
  10.387 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.388 -    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.389 -        
  10.390 -    NSSize maxSize;
  10.391 -    maxSize.width = window->max_w;
  10.392 -    maxSize.height = window->max_h;
  10.393 -        
  10.394 -    [windata->nswindow setContentMaxSize:maxSize];
  10.395 -    
  10.396 -    [pool release];
  10.397 +    @autoreleasepool {
  10.398 +        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.399 +            
  10.400 +        NSSize maxSize;
  10.401 +        maxSize.width = window->max_w;
  10.402 +        maxSize.height = window->max_h;
  10.403 +            
  10.404 +        [windata->nswindow setContentMaxSize:maxSize];
  10.405 +    }
  10.406  }
  10.407  
  10.408  void
  10.409  Cocoa_ShowWindow(_THIS, SDL_Window * window)
  10.410  {
  10.411 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.412 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.413 +    @autoreleasepool {
  10.414 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.415  
  10.416 -    if (![nswindow isMiniaturized]) {
  10.417 -        [nswindow makeKeyAndOrderFront:nil];
  10.418 +        if (![nswindow isMiniaturized]) {
  10.419 +            [nswindow makeKeyAndOrderFront:nil];
  10.420 +        }
  10.421      }
  10.422 -    [pool release];
  10.423  }
  10.424  
  10.425  void
  10.426  Cocoa_HideWindow(_THIS, SDL_Window * window)
  10.427  {
  10.428 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.429 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.430 -
  10.431 -    [nswindow orderOut:nil];
  10.432 -    [pool release];
  10.433 +    @autoreleasepool {
  10.434 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.435 +        [nswindow orderOut:nil];
  10.436 +    }
  10.437  }
  10.438  
  10.439  void
  10.440  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
  10.441  {
  10.442 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.443 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.444 -
  10.445 -    [nswindow makeKeyAndOrderFront:nil];
  10.446 -    [pool release];
  10.447 +    @autoreleasepool {
  10.448 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.449 +        [nswindow makeKeyAndOrderFront:nil];
  10.450 +    }
  10.451  }
  10.452  
  10.453  void
  10.454  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
  10.455  {
  10.456 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.457 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.458 -
  10.459 -    [nswindow zoom:nil];
  10.460 +    @autoreleasepool {
  10.461 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.462 +        [nswindow zoom:nil];
  10.463  
  10.464 -    if (window == _this->current_glwin) {
  10.465 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.466 +        if (window == _this->current_glwin) {
  10.467 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.468 +        }
  10.469      }
  10.470 -
  10.471 -    [pool release];
  10.472  }
  10.473  
  10.474  void
  10.475  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
  10.476  {
  10.477 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.478 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.479 -
  10.480 -    [nswindow miniaturize:nil];
  10.481 -    [pool release];
  10.482 +    @autoreleasepool {
  10.483 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.484 +        [nswindow miniaturize:nil];
  10.485 +    }
  10.486  }
  10.487  
  10.488  void
  10.489  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
  10.490  {
  10.491 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.492 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.493 +    @autoreleasepool {
  10.494 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.495  
  10.496 -    if ([nswindow isMiniaturized]) {
  10.497 -        [nswindow deminiaturize:nil];
  10.498 -    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.499 -        [nswindow zoom:nil];
  10.500 +        if ([nswindow isMiniaturized]) {
  10.501 +            [nswindow deminiaturize:nil];
  10.502 +        } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.503 +            [nswindow zoom:nil];
  10.504 +        }
  10.505      }
  10.506 -    [pool release];
  10.507  }
  10.508  
  10.509  static NSWindow *
  10.510 @@ -854,96 +837,95 @@
  10.511  {
  10.512      /* this message arrived in 10.6. You're out of luck on older OSes. */
  10.513  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
  10.514 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.515 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.516 -    if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.517 -        [nswindow setStyleMask:GetWindowStyle(window)];
  10.518 -        if (bordered) {
  10.519 -            Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.520 +    @autoreleasepool {
  10.521 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.522 +        if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.523 +            [nswindow setStyleMask:GetWindowStyle(window)];
  10.524 +            if (bordered) {
  10.525 +                Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.526 +            }
  10.527          }
  10.528      }
  10.529 -    [pool release];
  10.530  #endif
  10.531  }
  10.532  
  10.533  void
  10.534  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
  10.535  {
  10.536 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.537 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.538 -    NSWindow *nswindow = data->nswindow;
  10.539 -    NSRect rect;
  10.540 -
  10.541 -    /* The view responder chain gets messed with during setStyleMask */
  10.542 -    if ([[nswindow contentView] nextResponder] == data->listener) {
  10.543 -        [[nswindow contentView] setNextResponder:nil];
  10.544 -    }
  10.545 +    @autoreleasepool {
  10.546 +        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.547 +        NSWindow *nswindow = data->nswindow;
  10.548 +        NSRect rect;
  10.549  
  10.550 -    if (fullscreen) {
  10.551 -        SDL_Rect bounds;
  10.552 -
  10.553 -        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.554 -        rect.origin.x = bounds.x;
  10.555 -        rect.origin.y = bounds.y;
  10.556 -        rect.size.width = bounds.w;
  10.557 -        rect.size.height = bounds.h;
  10.558 -        ConvertNSRect(&rect);
  10.559 -
  10.560 -        /* Hack to fix origin on Mac OS X 10.4 */
  10.561 -        NSRect screenRect = [[nswindow screen] frame];
  10.562 -        if (screenRect.size.height >= 1.0f) {
  10.563 -            rect.origin.y += (screenRect.size.height - rect.size.height);
  10.564 +        /* The view responder chain gets messed with during setStyleMask */
  10.565 +        if ([[nswindow contentView] nextResponder] == data->listener) {
  10.566 +            [[nswindow contentView] setNextResponder:nil];
  10.567          }
  10.568  
  10.569 -        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.570 -            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.571 +        if (fullscreen) {
  10.572 +            SDL_Rect bounds;
  10.573 +
  10.574 +            Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.575 +            rect.origin.x = bounds.x;
  10.576 +            rect.origin.y = bounds.y;
  10.577 +            rect.size.width = bounds.w;
  10.578 +            rect.size.height = bounds.h;
  10.579 +            ConvertNSRect(&rect);
  10.580 +
  10.581 +            /* Hack to fix origin on Mac OS X 10.4 */
  10.582 +            NSRect screenRect = [[nswindow screen] frame];
  10.583 +            if (screenRect.size.height >= 1.0f) {
  10.584 +                rect.origin.y += (screenRect.size.height - rect.size.height);
  10.585 +            }
  10.586 +
  10.587 +            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.588 +                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.589 +            } else {
  10.590 +                nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.591 +            }
  10.592          } else {
  10.593 -            nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.594 +            rect.origin.x = window->windowed.x;
  10.595 +            rect.origin.y = window->windowed.y;
  10.596 +            rect.size.width = window->windowed.w;
  10.597 +            rect.size.height = window->windowed.h;
  10.598 +            ConvertNSRect(&rect);
  10.599 +
  10.600 +            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.601 +                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.602 +            } else {
  10.603 +                nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.604 +            }
  10.605          }
  10.606 -    } else {
  10.607 -        rect.origin.x = window->windowed.x;
  10.608 -        rect.origin.y = window->windowed.y;
  10.609 -        rect.size.width = window->windowed.w;
  10.610 -        rect.size.height = window->windowed.h;
  10.611 -        ConvertNSRect(&rect);
  10.612 +
  10.613 +        /* The view responder chain gets messed with during setStyleMask */
  10.614 +        if ([[nswindow contentView] nextResponder] != data->listener) {
  10.615 +            [[nswindow contentView] setNextResponder:data->listener];
  10.616 +        }
  10.617 +
  10.618 +        s_moveHack = 0;
  10.619 +        [nswindow setFrameOrigin:rect.origin];
  10.620 +        [nswindow setContentSize:rect.size];
  10.621 +        s_moveHack = SDL_GetTicks();
  10.622  
  10.623 -        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.624 -            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.625 +        /* When the window style changes the title is cleared */
  10.626 +        if (!fullscreen) {
  10.627 +            Cocoa_SetWindowTitle(_this, window);
  10.628 +        }
  10.629 +
  10.630 +    #ifdef FULLSCREEN_TOGGLEABLE
  10.631 +        if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.632 +            /* OpenGL is rendering to the window, so make it visible! */
  10.633 +            [nswindow setLevel:CGShieldingWindowLevel()];
  10.634          } else {
  10.635 -            nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.636 +            [nswindow setLevel:kCGNormalWindowLevel];
  10.637 +        }
  10.638 +    #endif
  10.639 +        [nswindow makeKeyAndOrderFront:nil];
  10.640 +
  10.641 +        if (window == _this->current_glwin) {
  10.642 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.643          }
  10.644      }
  10.645 -
  10.646 -    /* The view responder chain gets messed with during setStyleMask */
  10.647 -    if ([[nswindow contentView] nextResponder] != data->listener) {
  10.648 -        [[nswindow contentView] setNextResponder:data->listener];
  10.649 -    }
  10.650 -
  10.651 -    s_moveHack = 0;
  10.652 -    [nswindow setFrameOrigin:rect.origin];
  10.653 -    [nswindow setContentSize:rect.size];
  10.654 -    s_moveHack = SDL_GetTicks();
  10.655 -
  10.656 -    /* When the window style changes the title is cleared */
  10.657 -    if (!fullscreen) {
  10.658 -        Cocoa_SetWindowTitle(_this, window);
  10.659 -    }
  10.660 -
  10.661 -#ifdef FULLSCREEN_TOGGLEABLE
  10.662 -    if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.663 -        /* OpenGL is rendering to the window, so make it visible! */
  10.664 -        [nswindow setLevel:CGShieldingWindowLevel()];
  10.665 -    } else {
  10.666 -        [nswindow setLevel:kCGNormalWindowLevel];
  10.667 -    }
  10.668 -#endif
  10.669 -    [nswindow makeKeyAndOrderFront:nil];
  10.670 -
  10.671 -    if (window == _this->current_glwin) {
  10.672 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.673 -    }
  10.674 -
  10.675 -    [pool release];
  10.676  }
  10.677  
  10.678  int
  10.679 @@ -1027,18 +1009,18 @@
  10.680  void
  10.681  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
  10.682  {
  10.683 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.684 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.685 +    @autoreleasepool {
  10.686 +        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.687  
  10.688 -    if (data) {
  10.689 -        [data->listener close];
  10.690 -        [data->listener release];
  10.691 -        if (data->created) {
  10.692 -            [data->nswindow close];
  10.693 +        if (data) {
  10.694 +            [data->listener close];
  10.695 +            [data->listener release];
  10.696 +            if (data->created) {
  10.697 +                [data->nswindow close];
  10.698 +            }
  10.699 +            SDL_free(data);
  10.700          }
  10.701 -        SDL_free(data);
  10.702      }
  10.703 -    [pool release];
  10.704  }
  10.705  
  10.706  SDL_bool
    11.1 --- a/test/automated/rwops/TestSupportRWops_Cocoa.m	Fri Feb 01 17:09:01 2013 -0800
    11.2 +++ b/test/automated/rwops/TestSupportRWops_Cocoa.m	Sun Jan 06 19:04:53 2013 +0300
    11.3 @@ -21,30 +21,23 @@
    11.4      FILE* fp = NULL;
    11.5  
    11.6  	// If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only.
    11.7 -	if(strcmp("r", mode) && strcmp("rb", mode))
    11.8 -	{
    11.9 +	if (strcmp("r", mode) && strcmp("rb", mode)) {
   11.10  		return fopen(file, mode);
   11.11  	}
   11.12  	
   11.13 -	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   11.14 -
   11.15 +	@autoreleasepool {
   11.16 +        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.17 +        NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.18  
   11.19 -	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.20 -	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.21 -
   11.22 -	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.23 +        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.24  
   11.25 -	NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
   11.26 -	if([file_manager fileExistsAtPath:full_path_with_file_to_try])
   11.27 -	{
   11.28 -		fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.29 -	}
   11.30 -	else
   11.31 -	{
   11.32 -		fp = fopen(file, mode);
   11.33 -	}
   11.34 -
   11.35 -	[autorelease_pool drain];
   11.36 +        NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
   11.37 +        if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
   11.38 +            fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.39 +        } else {
   11.40 +            fp = fopen(file, mode);
   11.41 +        }
   11.42 +    }
   11.43  
   11.44  	return fp;
   11.45  }
   11.46 @@ -53,16 +46,14 @@
   11.47  {
   11.48      FILE* fp = NULL;
   11.49  	
   11.50 -	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   11.51 -	
   11.52 -	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.53 -	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.54 -	NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.55 +	@autoreleasepool {
   11.56 +        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.57 +        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.58 +        NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.59  
   11.60 -	fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.61 -	
   11.62 -	[autorelease_pool drain];
   11.63 -	
   11.64 +        fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.65 +    }
   11.66 +    
   11.67  	return fp;
   11.68  }
   11.69  
   11.70 @@ -75,15 +66,14 @@
   11.71  {
   11.72  	SDL_RWops* rw = NULL;
   11.73  
   11.74 -	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   11.75 -	
   11.76 -	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.77 -	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.78 -	NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.79 -	
   11.80 -	rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
   11.81 -
   11.82 -	[autorelease_pool drain];
   11.83 +	@autoreleasepool {
   11.84 +        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.85 +        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.86 +        NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.87 +        
   11.88 +        rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
   11.89 +    }
   11.90 +    
   11.91  	return rw;
   11.92  }
   11.93