Replaced manual NSAutoreleasePool handing with @autorelease
authorstopiccot <alexey.petruchik@gmail.com>
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 +	@autoreleasepool {
     1.9 +        NSFileManager* file_manager = [NSFileManager defaultManager];
    1.10 +        NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.11  
    1.12 +        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.13  
    1.14 -	NSFileManager* file_manager = [NSFileManager defaultManager];
    1.15 -	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.16 -
    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 +    @autoreleasepool {
    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  
    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 +        /* We only keep one field editor per process, since only the front most
    4.21 +         * window can receive text input events, so it make no sense to keep more
    4.22 +         * than one copy. When we switched to another window and requesting for
    4.23 +         * text input, simply remove the field editor from its superview then add
    4.24 +         * it to the front most window's content view */
    4.25 +        if (!data->fieldEdit) {
    4.26 +            data->fieldEdit =
    4.27 +                [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
    4.28 +        }
    4.29 +
    4.30 +        if (![[data->fieldEdit superview] isEqual: parentView])
    4.31 +        {
    4.32 +            // DEBUG_IME(@"add fieldEdit to window contentView");
    4.33 +            [data->fieldEdit removeFromSuperview];
    4.34 +            [parentView addSubview: data->fieldEdit];
    4.35 +            [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
    4.36 +        }
    4.37      }
    4.38 -
    4.39 -    if (![[data->fieldEdit superview] isEqual: parentView])
    4.40 -    {
    4.41 -        // DEBUG_IME(@"add fieldEdit to window contentView");
    4.42 -        [data->fieldEdit removeFromSuperview];
    4.43 -        [parentView addSubview: data->fieldEdit];
    4.44 -        [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
    4.45 -    }
    4.46 -
    4.47 -    [pool release];
    4.48  }
    4.49  
    4.50  void
    4.51 @@ -655,11 +654,11 @@
    4.52      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    4.53  
    4.54      if (data && data->fieldEdit) {
    4.55 -        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.56 -        [data->fieldEdit removeFromSuperview];
    4.57 -        [data->fieldEdit release];
    4.58 -        data->fieldEdit = nil;
    4.59 -        [pool release];
    4.60 +        @autoreleasepool {
    4.61 +            [data->fieldEdit removeFromSuperview];
    4.62 +            [data->fieldEdit release];
    4.63 +            data->fieldEdit = nil;
    4.64 +        }
    4.65      }
    4.66  }
    4.67  
     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 +    @autoreleasepool {
     5.9 +        NSAlert* alert = [[NSAlert alloc] init];
    5.10  
    5.11 -    NSAlert* alert = [[NSAlert alloc] init];
    5.12 +        if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.13 +            [alert setAlertStyle:NSCriticalAlertStyle];
    5.14 +        } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.15 +            [alert setAlertStyle:NSWarningAlertStyle];
    5.16 +        } else {
    5.17 +            [alert setAlertStyle:NSInformationalAlertStyle];
    5.18 +        }
    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 +        [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.27 +        [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.28 +
    5.29 +        const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.30 +        int i;
    5.31 +        for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.32 +            NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
    5.33 +            if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.34 +                [button setKeyEquivalent:@"\r"];
    5.35 +            } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.36 +                [button setKeyEquivalent:@"\033"];
    5.37 +            } else {
    5.38 +                [button setKeyEquivalent:@""];
    5.39 +            }
    5.40 +        }
    5.41 +
    5.42 +        NSInteger clicked = [alert runModal];
    5.43 +        clicked -= NSAlertFirstButtonReturn;
    5.44 +        *buttonid = buttons[clicked].buttonid;
    5.45 +        [alert release];
    5.46      }
    5.47  
    5.48 -    [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.49 -    [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.50 -
    5.51 -    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.52 -    int i;
    5.53 -    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.54 -        NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
    5.55 -        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.56 -            [button setKeyEquivalent:@"\r"];
    5.57 -        } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.58 -            [button setKeyEquivalent:@"\033"];
    5.59 -        } else {
    5.60 -            [button setKeyEquivalent:@""];
    5.61 -        }
    5.62 -    }
    5.63 -
    5.64 -    NSInteger clicked = [alert runModal];
    5.65 -    clicked -= NSAlertFirstButtonReturn;
    5.66 -    *buttonid = buttons[clicked].buttonid;
    5.67 -    [alert release];
    5.68 -
    5.69 -    [pool release];
    5.70 -
    5.71      return 0;
    5.72  }
    5.73  
     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 +        nsimage = Cocoa_CreateImage(surface);
    6.54 +        if (nsimage) {
    6.55 +            nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    6.56 +        }
    6.57 +
    6.58 +        if (nscursor) {
    6.59 +            cursor = SDL_calloc(1, sizeof(*cursor));
    6.60 +            if (cursor) {
    6.61 +                cursor->driverdata = nscursor;
    6.62 +            }
    6.63 +        }
    6.64 +        
    6.65 +        return cursor;
    6.66      }
    6.67 -
    6.68 -    if (nscursor) {
    6.69 -        cursor = SDL_calloc(1, sizeof(*cursor));
    6.70 -        if (cursor) {
    6.71 -            cursor->driverdata = nscursor;
    6.72 -        }
    6.73 -    }
    6.74 -
    6.75 -    [pool release];
    6.76 -
    6.77 -    return cursor;
    6.78  }
    6.79  
    6.80  static SDL_Cursor *
    6.81  Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    6.82  {
    6.83 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.84 -    NSCursor *nscursor = NULL;
    6.85 -    SDL_Cursor *cursor = NULL;
    6.86 +    @autoreleasepool {
    6.87 +        NSCursor *nscursor = NULL;
    6.88 +        SDL_Cursor *cursor = NULL;
    6.89  
    6.90 -    switch(id)
    6.91 -    {
    6.92 -    case SDL_SYSTEM_CURSOR_ARROW:
    6.93 -        nscursor = [NSCursor arrowCursor];
    6.94 -        break;
    6.95 -    case SDL_SYSTEM_CURSOR_IBEAM:
    6.96 -        nscursor = [NSCursor IBeamCursor];
    6.97 -        break;
    6.98 -    case SDL_SYSTEM_CURSOR_WAIT:
    6.99 -        nscursor = [NSCursor arrowCursor];
   6.100 -        break;
   6.101 -    case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.102 -        nscursor = [NSCursor crosshairCursor];
   6.103 -        break;
   6.104 -    case SDL_SYSTEM_CURSOR_WAITARROW:
   6.105 -        nscursor = [NSCursor arrowCursor];
   6.106 -        break;
   6.107 -    case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.108 -    case SDL_SYSTEM_CURSOR_SIZENESW:
   6.109 -        nscursor = [NSCursor closedHandCursor];
   6.110 -        break;
   6.111 -    case SDL_SYSTEM_CURSOR_SIZEWE:
   6.112 -        nscursor = [NSCursor resizeLeftRightCursor];
   6.113 -        break;
   6.114 -    case SDL_SYSTEM_CURSOR_SIZENS:
   6.115 -        nscursor = [NSCursor resizeUpDownCursor];
   6.116 -        break;
   6.117 -    case SDL_SYSTEM_CURSOR_SIZEALL:
   6.118 -        nscursor = [NSCursor closedHandCursor];
   6.119 -        break;
   6.120 -    case SDL_SYSTEM_CURSOR_NO:
   6.121 -        nscursor = [NSCursor operationNotAllowedCursor];
   6.122 -        break;
   6.123 -    case SDL_SYSTEM_CURSOR_HAND:
   6.124 -        nscursor = [NSCursor pointingHandCursor];
   6.125 -        break;
   6.126 -    default:
   6.127 -        SDL_assert(!"Unknown system cursor");
   6.128 -        return NULL;
   6.129 +        switch(id)
   6.130 +        {
   6.131 +        case SDL_SYSTEM_CURSOR_ARROW:
   6.132 +            nscursor = [NSCursor arrowCursor];
   6.133 +            break;
   6.134 +        case SDL_SYSTEM_CURSOR_IBEAM:
   6.135 +            nscursor = [NSCursor IBeamCursor];
   6.136 +            break;
   6.137 +        case SDL_SYSTEM_CURSOR_WAIT:
   6.138 +            nscursor = [NSCursor arrowCursor];
   6.139 +            break;
   6.140 +        case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.141 +            nscursor = [NSCursor crosshairCursor];
   6.142 +            break;
   6.143 +        case SDL_SYSTEM_CURSOR_WAITARROW:
   6.144 +            nscursor = [NSCursor arrowCursor];
   6.145 +            break;
   6.146 +        case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.147 +        case SDL_SYSTEM_CURSOR_SIZENESW:
   6.148 +            nscursor = [NSCursor closedHandCursor];
   6.149 +            break;
   6.150 +        case SDL_SYSTEM_CURSOR_SIZEWE:
   6.151 +            nscursor = [NSCursor resizeLeftRightCursor];
   6.152 +            break;
   6.153 +        case SDL_SYSTEM_CURSOR_SIZENS:
   6.154 +            nscursor = [NSCursor resizeUpDownCursor];
   6.155 +            break;
   6.156 +        case SDL_SYSTEM_CURSOR_SIZEALL:
   6.157 +            nscursor = [NSCursor closedHandCursor];
   6.158 +            break;
   6.159 +        case SDL_SYSTEM_CURSOR_NO:
   6.160 +            nscursor = [NSCursor operationNotAllowedCursor];
   6.161 +            break;
   6.162 +        case SDL_SYSTEM_CURSOR_HAND:
   6.163 +            nscursor = [NSCursor pointingHandCursor];
   6.164 +            break;
   6.165 +        default:
   6.166 +            SDL_assert(!"Unknown system cursor");
   6.167 +            return NULL;
   6.168 +        }
   6.169 +
   6.170 +        if (nscursor) {
   6.171 +            cursor = SDL_calloc(1, sizeof(*cursor));
   6.172 +            if (cursor) {
   6.173 +                // We'll free it later, so retain it here
   6.174 +                [nscursor retain];
   6.175 +                cursor->driverdata = nscursor;
   6.176 +            }
   6.177 +        }
   6.178 +            
   6.179 +        return cursor;
   6.180      }
   6.181 -
   6.182 -    if (nscursor) {
   6.183 -        cursor = SDL_calloc(1, sizeof(*cursor));
   6.184 -        if (cursor) {
   6.185 -            // We'll free it later, so retain it here
   6.186 -            [nscursor retain];
   6.187 -            cursor->driverdata = nscursor;
   6.188 -        }
   6.189 -    }
   6.190 -
   6.191 -    [pool release];
   6.192 -
   6.193 -    return cursor;
   6.194  }
   6.195  
   6.196  static void
   6.197  Cocoa_FreeCursor(SDL_Cursor * cursor)
   6.198  {
   6.199 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.200 -    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.201 +    @autoreleasepool {
   6.202 +        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.203  
   6.204 -    [nscursor release];
   6.205 -    SDL_free(cursor);
   6.206 -
   6.207 -    [pool release];
   6.208 +        [nscursor release];
   6.209 +        SDL_free(cursor);
   6.210 +    }
   6.211  }
   6.212  
   6.213  static int
   6.214  Cocoa_ShowCursor(SDL_Cursor * cursor)
   6.215  {
   6.216 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.217 +    @autoreleasepool {
   6.218 +        if (cursor) {
   6.219 +            NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.220  
   6.221 -    if (cursor) {
   6.222 -        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.223 -
   6.224 -        [nscursor set];
   6.225 -        [NSCursor unhide];
   6.226 -    } else {
   6.227 -        [NSCursor hide];
   6.228 +            [nscursor set];
   6.229 +            [NSCursor unhide];
   6.230 +        } else {
   6.231 +            [NSCursor hide];
   6.232 +        }
   6.233      }
   6.234  
   6.235 -    [pool release];
   6.236 -
   6.237      return 0;
   6.238  }
   6.239  
     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 -    /* specify a profile if we're on Lion (10.7) or later. */
    7.30 -    if (data->osversion >= 0x1070) {
    7.31 -        NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
    7.32 -        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
    7.33 -            if (wantver == 0x0302) {
    7.34 -                profile = kCGLOGLPVersion_3_2_Core;
    7.35 +    #ifndef FULLSCREEN_TOGGLEABLE
    7.36 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.37 +            attr[i++] = NSOpenGLPFAFullScreen;
    7.38 +        }
    7.39 +    #endif
    7.40 +
    7.41 +        attr[i++] = NSOpenGLPFAColorSize;
    7.42 +        attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
    7.43 +
    7.44 +        attr[i++] = NSOpenGLPFADepthSize;
    7.45 +        attr[i++] = _this->gl_config.depth_size;
    7.46 +
    7.47 +        if (_this->gl_config.double_buffer) {
    7.48 +            attr[i++] = NSOpenGLPFADoubleBuffer;
    7.49 +        }
    7.50 +
    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 +        fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.103 +        if (fmt == nil) {
   7.104 +            SDL_SetError ("Failed creating OpenGL pixel format");
   7.105 +            return NULL;
   7.106 +        }
   7.107  
   7.108 -    attr[i++] = NSOpenGLPFADepthSize;
   7.109 -    attr[i++] = _this->gl_config.depth_size;
   7.110 +        context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.111  
   7.112 -    if (_this->gl_config.double_buffer) {
   7.113 -        attr[i++] = NSOpenGLPFADoubleBuffer;
   7.114 -    }
   7.115 +        [fmt release];
   7.116  
   7.117 -    if (_this->gl_config.stereo) {
   7.118 -        attr[i++] = NSOpenGLPFAStereo;
   7.119 -    }
   7.120 +        if (context == nil) {
   7.121 +            SDL_SetError ("Failed creating OpenGL context");
   7.122 +            return NULL;
   7.123 +        }
   7.124  
   7.125 -    if (_this->gl_config.stencil_size) {
   7.126 -        attr[i++] = NSOpenGLPFAStencilSize;
   7.127 -        attr[i++] = _this->gl_config.stencil_size;
   7.128 -    }
   7.129 +        /*
   7.130 +         * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.131 +         *  "You are blowing a couple of the internal OpenGL function caches. This
   7.132 +         *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.133 +         *  the cache size by issuing the following calls right after you create
   7.134 +         *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.135 +         */
   7.136  
   7.137 -    if ((_this->gl_config.accum_red_size +
   7.138 -         _this->gl_config.accum_green_size +
   7.139 -         _this->gl_config.accum_blue_size +
   7.140 -         _this->gl_config.accum_alpha_size) > 0) {
   7.141 -        attr[i++] = NSOpenGLPFAAccumSize;
   7.142 -        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.143 -    }
   7.144 +        #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.145 +        #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.146 +        #endif
   7.147  
   7.148 -    if (_this->gl_config.multisamplebuffers) {
   7.149 -        attr[i++] = NSOpenGLPFASampleBuffers;
   7.150 -        attr[i++] = _this->gl_config.multisamplebuffers;
   7.151 -    }
   7.152 +        #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.153 +        #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.154 +        #endif
   7.155  
   7.156 -    if (_this->gl_config.multisamplesamples) {
   7.157 -        attr[i++] = NSOpenGLPFASamples;
   7.158 -        attr[i++] = _this->gl_config.multisamplesamples;
   7.159 -        attr[i++] = NSOpenGLPFANoRecovery;
   7.160 -    }
   7.161 -
   7.162 -    if (_this->gl_config.accelerated >= 0) {
   7.163 -        if (_this->gl_config.accelerated) {
   7.164 -            attr[i++] = NSOpenGLPFAAccelerated;
   7.165 -        } else {
   7.166 -            attr[i++] = NSOpenGLPFARendererID;
   7.167 -            attr[i++] = kCGLRendererGenericFloatID;
   7.168 +        {
   7.169 +            GLint cache_max = 64;
   7.170 +            CGLContextObj ctx = [context CGLContextObj];
   7.171 +            CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.172 +            CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.173          }
   7.174      }
   7.175 -
   7.176 -    attr[i++] = NSOpenGLPFAScreenMask;
   7.177 -    attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
   7.178 -    attr[i] = 0;
   7.179 -
   7.180 -    fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.181 -    if (fmt == nil) {
   7.182 -        SDL_SetError ("Failed creating OpenGL pixel format");
   7.183 -        [pool release];
   7.184 -        return NULL;
   7.185 -    }
   7.186 -
   7.187 -    context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.188 -
   7.189 -    [fmt release];
   7.190 -
   7.191 -    if (context == nil) {
   7.192 -        SDL_SetError ("Failed creating OpenGL context");
   7.193 -        [pool release];
   7.194 -        return NULL;
   7.195 -    }
   7.196 -
   7.197 -    /*
   7.198 -     * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.199 -     *  "You are blowing a couple of the internal OpenGL function caches. This
   7.200 -     *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.201 -     *  the cache size by issuing the following calls right after you create
   7.202 -     *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.203 -     */
   7.204 -
   7.205 -    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.206 -    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.207 -    #endif
   7.208 -
   7.209 -    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.210 -    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.211 -    #endif
   7.212 -
   7.213 -    {
   7.214 -        GLint cache_max = 64;
   7.215 -        CGLContextObj ctx = [context CGLContextObj];
   7.216 -        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.217 -        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.218 -    }
   7.219 -
   7.220      /* End Wisdom from Apple Engineer section. --ryan. */
   7.221  
   7.222 -    [pool release];
   7.223 -
   7.224      if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
   7.225          Cocoa_GL_DeleteContext(_this, context);
   7.226          return NULL;
   7.227 @@ -226,107 +220,94 @@
   7.228  int
   7.229  Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   7.230  {
   7.231 -    NSAutoreleasePool *pool;
   7.232 +    @autoreleasepool {
   7.233 +        if (context) {
   7.234 +            SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.235 +            NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.236  
   7.237 -    pool = [[NSAutoreleasePool alloc] init];
   7.238 -
   7.239 -    if (context) {
   7.240 -        SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.241 -        NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.242 -
   7.243 -        if (window->flags & SDL_WINDOW_SHOWN) {
   7.244 -#ifndef FULLSCREEN_TOGGLEABLE
   7.245 -            if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.246 -                [nscontext setFullScreen];
   7.247 -            } else
   7.248 -#endif
   7.249 -            {
   7.250 -                [nscontext setView:[windowdata->nswindow contentView]];
   7.251 -                [nscontext update];
   7.252 +            if (window->flags & SDL_WINDOW_SHOWN) {
   7.253 +    #ifndef FULLSCREEN_TOGGLEABLE
   7.254 +                if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.255 +                    [nscontext setFullScreen];
   7.256 +                } else
   7.257 +    #endif
   7.258 +                {
   7.259 +                    [nscontext setView:[windowdata->nswindow contentView]];
   7.260 +                    [nscontext update];
   7.261 +                }
   7.262              }
   7.263 +            [nscontext makeCurrentContext];
   7.264 +        } else {
   7.265 +            [NSOpenGLContext clearCurrentContext];
   7.266          }
   7.267 -        [nscontext makeCurrentContext];
   7.268 -    } else {
   7.269 -        [NSOpenGLContext clearCurrentContext];
   7.270      }
   7.271  
   7.272 -    [pool release];
   7.273      return 0;
   7.274  }
   7.275  
   7.276  int
   7.277  Cocoa_GL_SetSwapInterval(_THIS, int interval)
   7.278  {
   7.279 -    NSAutoreleasePool *pool;
   7.280      NSOpenGLContext *nscontext;
   7.281      GLint value;
   7.282      int status;
   7.283  
   7.284 -    pool = [[NSAutoreleasePool alloc] init];
   7.285 -
   7.286 -    nscontext = [NSOpenGLContext currentContext];
   7.287 -    if (nscontext != nil) {
   7.288 -        value = interval;
   7.289 -        [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.290 -        status = 0;
   7.291 -    } else {
   7.292 -        SDL_SetError("No current OpenGL context");
   7.293 -        status = -1;
   7.294 +    @autoreleasepool {
   7.295 +        nscontext = [NSOpenGLContext currentContext];
   7.296 +        if (nscontext != nil) {
   7.297 +            value = interval;
   7.298 +            [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.299 +            status = 0;
   7.300 +        } else {
   7.301 +            SDL_SetError("No current OpenGL context");
   7.302 +            status = -1;
   7.303 +        }
   7.304      }
   7.305  
   7.306 -    [pool release];
   7.307      return status;
   7.308  }
   7.309  
   7.310  int
   7.311  Cocoa_GL_GetSwapInterval(_THIS)
   7.312  {
   7.313 -    NSAutoreleasePool *pool;
   7.314      NSOpenGLContext *nscontext;
   7.315      GLint value;
   7.316      int status = 0;
   7.317  
   7.318 -    pool = [[NSAutoreleasePool alloc] init];
   7.319 -
   7.320 -    nscontext = [NSOpenGLContext currentContext];
   7.321 -    if (nscontext != nil) {
   7.322 -        [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.323 -        status = (int)value;
   7.324 +    @autoreleasepool {
   7.325 +        nscontext = [NSOpenGLContext currentContext];
   7.326 +        if (nscontext != nil) {
   7.327 +            [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.328 +            status = (int)value;
   7.329 +        }
   7.330      }
   7.331  
   7.332 -    [pool release];
   7.333      return status;
   7.334  }
   7.335  
   7.336  void
   7.337  Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
   7.338  {
   7.339 -    NSAutoreleasePool *pool;
   7.340      NSOpenGLContext *nscontext;
   7.341  
   7.342 -    pool = [[NSAutoreleasePool alloc] init];
   7.343 -
   7.344 -    /* FIXME: Do we need to get the context for the window? */
   7.345 -    nscontext = [NSOpenGLContext currentContext];
   7.346 -    if (nscontext != nil) {
   7.347 -        [nscontext flushBuffer];
   7.348 +    @autoreleasepool {
   7.349 +        /* FIXME: Do we need to get the context for the window? */
   7.350 +        nscontext = [NSOpenGLContext currentContext];
   7.351 +        if (nscontext != nil) {
   7.352 +            [nscontext flushBuffer];
   7.353 +        }
   7.354      }
   7.355 -
   7.356 -    [pool release];
   7.357  }
   7.358  
   7.359  void
   7.360  Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
   7.361  {
   7.362 -    NSAutoreleasePool *pool;
   7.363      NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.364  
   7.365 -    pool = [[NSAutoreleasePool alloc] init];
   7.366 -
   7.367 -    [nscontext clearDrawable];
   7.368 -    [nscontext release];
   7.369 -
   7.370 -    [pool release];
   7.371 +    @autoreleasepool {
   7.372 +        [nscontext clearDrawable];
   7.373 +        [nscontext release];
   7.374 +    }
   7.375  }
   7.376  
   7.377  #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 +         * !!! FIXME: this code needs to deal with fullscreen modes:
    9.25 +         * !!! FIXME:  reset to default desktop, runModal, reset to current?
    9.26 +         */
    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 +        NSAlert* alert = [[NSAlert alloc] init];
    9.33 +        [alert setAlertStyle:NSCriticalAlertStyle];
    9.34 +        [alert setMessageText:msg];
    9.35 +        [alert addButtonWithTitle:@"Retry"];
    9.36 +        [alert addButtonWithTitle:@"Break"];
    9.37 +        [alert addButtonWithTitle:@"Abort"];
    9.38 +        [alert addButtonWithTitle:@"Ignore"];
    9.39 +        [alert addButtonWithTitle:@"Always Ignore"];
    9.40 +        const NSInteger clicked = [alert runModal];
    9.41  
    9.42 -    NSAlert* alert = [[NSAlert alloc] init];
    9.43 -    [alert setAlertStyle:NSCriticalAlertStyle];
    9.44 -    [alert setMessageText:msg];
    9.45 -    [alert addButtonWithTitle:@"Retry"];
    9.46 -    [alert addButtonWithTitle:@"Break"];
    9.47 -    [alert addButtonWithTitle:@"Abort"];
    9.48 -    [alert addButtonWithTitle:@"Ignore"];
    9.49 -    [alert addButtonWithTitle:@"Always Ignore"];
    9.50 -    const NSInteger clicked = [alert runModal];
    9.51 -    [pool release];
    9.52 +        if (!initialized) {
    9.53 +            SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.54 +        }
    9.55  
    9.56 -    if (!initialized) {
    9.57 -        SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.58 +        return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    9.59      }
    9.60 -
    9.61 -    return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    9.62  }
    9.63  
    9.64  #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 +    @autoreleasepool {
   10.17 +        /* Create an event listener for the window */
   10.18 +        data->listener = [[Cocoa_WindowListener alloc] init];
   10.19  
   10.20 -    /* Create an event listener for the window */
   10.21 -    data->listener = [[Cocoa_WindowListener alloc] init];
   10.22 +        /* Fill in the SDL window with the window data */
   10.23 +        {
   10.24 +            NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.25 +            ConvertNSRect(&rect);
   10.26 +            window->x = (int)rect.origin.x;
   10.27 +            window->y = (int)rect.origin.y;
   10.28 +            window->w = (int)rect.size.width;
   10.29 +            window->h = (int)rect.size.height;
   10.30 +        }
   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 +        /* Set up the listener after we create the view */
   10.41 +        [data->listener listen:data];
   10.42 +
   10.43 +        if ([nswindow isVisible]) {
   10.44 +            window->flags |= SDL_WINDOW_SHOWN;
   10.45 +        } else {
   10.46 +            window->flags &= ~SDL_WINDOW_SHOWN;
   10.47 +        }
   10.48 +        {
   10.49 +            unsigned int style = [nswindow styleMask];
   10.50 +
   10.51 +            if (style == NSBorderlessWindowMask) {
   10.52 +                window->flags |= SDL_WINDOW_BORDERLESS;
   10.53 +            } else {
   10.54 +                window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.55 +            }
   10.56 +            if (style & NSResizableWindowMask) {
   10.57 +                window->flags |= SDL_WINDOW_RESIZABLE;
   10.58 +            } else {
   10.59 +                window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.60 +            }
   10.61 +        }
   10.62 +        /* isZoomed always returns true if the window is not resizable */
   10.63 +        if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   10.64 +            window->flags |= SDL_WINDOW_MAXIMIZED;
   10.65 +        } else {
   10.66 +            window->flags &= ~SDL_WINDOW_MAXIMIZED;
   10.67 +        }
   10.68 +        if ([nswindow isMiniaturized]) {
   10.69 +            window->flags |= SDL_WINDOW_MINIMIZED;
   10.70 +        } else {
   10.71 +            window->flags &= ~SDL_WINDOW_MINIMIZED;
   10.72 +        }
   10.73 +        if ([nswindow isKeyWindow]) {
   10.74 +            window->flags |= SDL_WINDOW_INPUT_FOCUS;
   10.75 +            SDL_SetKeyboardFocus(data->window);
   10.76 +        }
   10.77 +
   10.78 +        /* All done! */
   10.79 +        window->driverdata = data;
   10.80 +        return 0;
   10.81      }
   10.82 -
   10.83 -    /* Set up the listener after we create the view */
   10.84 -    [data->listener listen:data];
   10.85 -
   10.86 -    if ([nswindow isVisible]) {
   10.87 -        window->flags |= SDL_WINDOW_SHOWN;
   10.88 -    } else {
   10.89 -        window->flags &= ~SDL_WINDOW_SHOWN;
   10.90 -    }
   10.91 -    {
   10.92 -        unsigned int style = [nswindow styleMask];
   10.93 -
   10.94 -        if (style == NSBorderlessWindowMask) {
   10.95 -            window->flags |= SDL_WINDOW_BORDERLESS;
   10.96 -        } else {
   10.97 -            window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.98 -        }
   10.99 -        if (style & NSResizableWindowMask) {
  10.100 -            window->flags |= SDL_WINDOW_RESIZABLE;
  10.101 -        } else {
  10.102 -            window->flags &= ~SDL_WINDOW_RESIZABLE;
  10.103 -        }
  10.104 -    }
  10.105 -    /* isZoomed always returns true if the window is not resizable */
  10.106 -    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.107 -        window->flags |= SDL_WINDOW_MAXIMIZED;
  10.108 -    } else {
  10.109 -        window->flags &= ~SDL_WINDOW_MAXIMIZED;
  10.110 -    }
  10.111 -    if ([nswindow isMiniaturized]) {
  10.112 -        window->flags |= SDL_WINDOW_MINIMIZED;
  10.113 -    } else {
  10.114 -        window->flags &= ~SDL_WINDOW_MINIMIZED;
  10.115 -    }
  10.116 -    if ([nswindow isKeyWindow]) {
  10.117 -        window->flags |= SDL_WINDOW_INPUT_FOCUS;
  10.118 -        SDL_SetKeyboardFocus(data->window);
  10.119 -    }
  10.120 -
  10.121 -    /* All done! */
  10.122 -    [pool release];
  10.123 -    window->driverdata = data;
  10.124 -    return 0;
  10.125  }
  10.126  
  10.127  int
  10.128  Cocoa_CreateWindow(_THIS, SDL_Window * window)
  10.129  {
  10.130 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.131 -    NSWindow *nswindow;
  10.132 -    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.133 -    NSRect rect;
  10.134 -    SDL_Rect bounds;
  10.135 -    unsigned int style;
  10.136 +    @autoreleasepool {
  10.137 +        NSWindow *nswindow;
  10.138 +        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.139 +        NSRect rect;
  10.140 +        SDL_Rect bounds;
  10.141 +        unsigned int style;
  10.142  
  10.143 -    Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.144 -    rect.origin.x = window->x;
  10.145 -    rect.origin.y = window->y;
  10.146 -    rect.size.width = window->w;
  10.147 -    rect.size.height = window->h;
  10.148 -    ConvertNSRect(&rect);
  10.149 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.150 +        rect.origin.x = window->x;
  10.151 +        rect.origin.y = window->y;
  10.152 +        rect.size.width = window->w;
  10.153 +        rect.size.height = window->h;
  10.154 +        ConvertNSRect(&rect);
  10.155  
  10.156 -    style = GetWindowStyle(window);
  10.157 +        style = GetWindowStyle(window);
  10.158  
  10.159 -    /* Figure out which screen to place this window */
  10.160 -    NSArray *screens = [NSScreen screens];
  10.161 -    NSScreen *screen = nil;
  10.162 -    NSScreen *candidate;
  10.163 -    int i, count = [screens count];
  10.164 -    for (i = 0; i < count; ++i) {
  10.165 -        candidate = [screens objectAtIndex:i];
  10.166 -        NSRect screenRect = [candidate frame];
  10.167 -        if (rect.origin.x >= screenRect.origin.x &&
  10.168 -            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.169 -            rect.origin.y >= screenRect.origin.y &&
  10.170 -            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.171 -            screen = candidate;
  10.172 -            rect.origin.x -= screenRect.origin.x;
  10.173 -            rect.origin.y -= screenRect.origin.y;
  10.174 +        /* Figure out which screen to place this window */
  10.175 +        NSArray *screens = [NSScreen screens];
  10.176 +        NSScreen *screen = nil;
  10.177 +        NSScreen *candidate;
  10.178 +        int i, count = [screens count];
  10.179 +        for (i = 0; i < count; ++i) {
  10.180 +            candidate = [screens objectAtIndex:i];
  10.181 +            NSRect screenRect = [candidate frame];
  10.182 +            if (rect.origin.x >= screenRect.origin.x &&
  10.183 +                rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.184 +                rect.origin.y >= screenRect.origin.y &&
  10.185 +                rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.186 +                screen = candidate;
  10.187 +                rect.origin.x -= screenRect.origin.x;
  10.188 +                rect.origin.y -= screenRect.origin.y;
  10.189 +            }
  10.190          }
  10.191 +        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.192 +
  10.193 +        // Create a default view for this window
  10.194 +        rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.195 +        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.196 +        [nswindow setContentView: contentView];
  10.197 +        [contentView release];
  10.198 +
  10.199 +        if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.200 +            [nswindow release];
  10.201 +            return -1;
  10.202 +        }
  10.203 +        return 0;
  10.204      }
  10.205 -    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.206 -
  10.207 -    // Create a default view for this window
  10.208 -    rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.209 -    NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.210 -    [nswindow setContentView: contentView];
  10.211 -    [contentView release];
  10.212 -
  10.213 -    [pool release];
  10.214 -
  10.215 -    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.216 -        [nswindow release];
  10.217 -        return -1;
  10.218 -    }
  10.219 -    return 0;
  10.220  }
  10.221  
  10.222  int
  10.223  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  10.224  {
  10.225 -    NSAutoreleasePool *pool;
  10.226      NSWindow *nswindow = (NSWindow *) data;
  10.227      NSString *title;
  10.228  
  10.229 -    pool = [[NSAutoreleasePool alloc] init];
  10.230 -
  10.231 -    /* Query the title from the existing window */
  10.232 -    title = [nswindow title];
  10.233 -    if (title) {
  10.234 -        window->title = SDL_strdup([title UTF8String]);
  10.235 +    @autoreleasepool {
  10.236 +        /* Query the title from the existing window */
  10.237 +        title = [nswindow title];
  10.238 +        if (title) {
  10.239 +            window->title = SDL_strdup([title UTF8String]);
  10.240 +        }
  10.241      }
  10.242  
  10.243 -    [pool release];
  10.244 -
  10.245      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
  10.246  }
  10.247  
  10.248  void
  10.249  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
  10.250  {
  10.251 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.252 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.253 -    NSString *string;
  10.254 +    @autoreleasepool {
  10.255 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.256 +        NSString *string;
  10.257  
  10.258 -    if(window->title) {
  10.259 -        string = [[NSString alloc] initWithUTF8String:window->title];
  10.260 -    } else {
  10.261 -        string = [[NSString alloc] init];
  10.262 +        if(window->title) {
  10.263 +            string = [[NSString alloc] initWithUTF8String:window->title];
  10.264 +        } else {
  10.265 +            string = [[NSString alloc] init];
  10.266 +        }
  10.267 +        [nswindow setTitle:string];
  10.268 +        [string release];
  10.269      }
  10.270 -    [nswindow setTitle:string];
  10.271 -    [string release];
  10.272 -
  10.273 -    [pool release];
  10.274  }
  10.275  
  10.276  void
  10.277  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  10.278  {
  10.279 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.280 -    NSImage *nsimage = Cocoa_CreateImage(icon);
  10.281 +    @autoreleasepool {
  10.282 +        NSImage *nsimage = Cocoa_CreateImage(icon);
  10.283  
  10.284 -    if (nsimage) {
  10.285 -        [NSApp setApplicationIconImage:nsimage];
  10.286 +        if (nsimage) {
  10.287 +            [NSApp setApplicationIconImage:nsimage];
  10.288 +        }
  10.289      }
  10.290 -
  10.291 -    [pool release];
  10.292  }
  10.293  
  10.294  void
  10.295  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
  10.296  {
  10.297 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.298 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.299 -    NSRect rect;
  10.300 -    Uint32 moveHack;
  10.301 +    @autoreleasepool {
  10.302 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.303 +        NSRect rect;
  10.304 +        Uint32 moveHack;
  10.305  
  10.306 -    rect.origin.x = window->x;
  10.307 -    rect.origin.y = window->y;
  10.308 -    rect.size.width = window->w;
  10.309 -    rect.size.height = window->h;
  10.310 -    ConvertNSRect(&rect);
  10.311 +        rect.origin.x = window->x;
  10.312 +        rect.origin.y = window->y;
  10.313 +        rect.size.width = window->w;
  10.314 +        rect.size.height = window->h;
  10.315 +        ConvertNSRect(&rect);
  10.316  
  10.317 -    moveHack = s_moveHack;
  10.318 -    s_moveHack = 0;
  10.319 -    [nswindow setFrameOrigin:rect.origin];
  10.320 -    s_moveHack = moveHack;
  10.321 +        moveHack = s_moveHack;
  10.322 +        s_moveHack = 0;
  10.323 +        [nswindow setFrameOrigin:rect.origin];
  10.324 +        s_moveHack = moveHack;
  10.325  
  10.326 -    if (window == _this->current_glwin) {
  10.327 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.328 +        if (window == _this->current_glwin) {
  10.329 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.330 +        }
  10.331      }
  10.332 -
  10.333 -    [pool release];
  10.334  }
  10.335  
  10.336  void
  10.337  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
  10.338  {
  10.339 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.340 -    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.341 -    NSWindow *nswindow = windata->nswindow;
  10.342 -    NSSize size;
  10.343 +    @autoreleasepool {
  10.344 +        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.345 +        NSWindow *nswindow = windata->nswindow;
  10.346 +        NSSize size;
  10.347  
  10.348 -    size.width = window->w;
  10.349 -    size.height = window->h;
  10.350 -    [nswindow setContentSize:size];
  10.351 +        size.width = window->w;
  10.352 +        size.height = window->h;
  10.353 +        [nswindow setContentSize:size];
  10.354  
  10.355 -    if (window == _this->current_glwin) {
  10.356 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.357 +        if (window == _this->current_glwin) {
  10.358 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.359 +        }
  10.360      }
  10.361 -
  10.362 -    [pool release];
  10.363  }
  10.364  
  10.365  void
  10.366  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
  10.367  {
  10.368 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.369 -    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.370 -        
  10.371 -    NSSize minSize;
  10.372 -    minSize.width = window->min_w;
  10.373 -    minSize.height = window->min_h;
  10.374 -        
  10.375 -    [windata->nswindow setContentMinSize:minSize];
  10.376 -    
  10.377 -    [pool release];
  10.378 +    @autoreleasepool {
  10.379 +        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.380 +            
  10.381 +        NSSize minSize;
  10.382 +        minSize.width = window->min_w;
  10.383 +        minSize.height = window->min_h;
  10.384 +            
  10.385 +        [windata->nswindow setContentMinSize:minSize];
  10.386 +    }
  10.387  }
  10.388  
  10.389  void
  10.390  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
  10.391  {
  10.392 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.393 -    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.394 -        
  10.395 -    NSSize maxSize;
  10.396 -    maxSize.width = window->max_w;
  10.397 -    maxSize.height = window->max_h;
  10.398 -        
  10.399 -    [windata->nswindow setContentMaxSize:maxSize];
  10.400 -    
  10.401 -    [pool release];
  10.402 +    @autoreleasepool {
  10.403 +        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.404 +            
  10.405 +        NSSize maxSize;
  10.406 +        maxSize.width = window->max_w;
  10.407 +        maxSize.height = window->max_h;
  10.408 +            
  10.409 +        [windata->nswindow setContentMaxSize:maxSize];
  10.410 +    }
  10.411  }
  10.412  
  10.413  void
  10.414  Cocoa_ShowWindow(_THIS, SDL_Window * window)
  10.415  {
  10.416 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.417 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.418 +    @autoreleasepool {
  10.419 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.420  
  10.421 -    if (![nswindow isMiniaturized]) {
  10.422 -        [nswindow makeKeyAndOrderFront:nil];
  10.423 +        if (![nswindow isMiniaturized]) {
  10.424 +            [nswindow makeKeyAndOrderFront:nil];
  10.425 +        }
  10.426      }
  10.427 -    [pool release];
  10.428  }
  10.429  
  10.430  void
  10.431  Cocoa_HideWindow(_THIS, SDL_Window * window)
  10.432  {
  10.433 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.434 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.435 -
  10.436 -    [nswindow orderOut:nil];
  10.437 -    [pool release];
  10.438 +    @autoreleasepool {
  10.439 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.440 +        [nswindow orderOut:nil];
  10.441 +    }
  10.442  }
  10.443  
  10.444  void
  10.445  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
  10.446  {
  10.447 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.448 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.449 -
  10.450 -    [nswindow makeKeyAndOrderFront:nil];
  10.451 -    [pool release];
  10.452 +    @autoreleasepool {
  10.453 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.454 +        [nswindow makeKeyAndOrderFront:nil];
  10.455 +    }
  10.456  }
  10.457  
  10.458  void
  10.459  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
  10.460  {
  10.461 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.462 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.463 +    @autoreleasepool {
  10.464 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.465 +        [nswindow zoom:nil];
  10.466  
  10.467 -    [nswindow zoom:nil];
  10.468 -
  10.469 -    if (window == _this->current_glwin) {
  10.470 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.471 +        if (window == _this->current_glwin) {
  10.472 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.473 +        }
  10.474      }
  10.475 -
  10.476 -    [pool release];
  10.477  }
  10.478  
  10.479  void
  10.480  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
  10.481  {
  10.482 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.483 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.484 -
  10.485 -    [nswindow miniaturize:nil];
  10.486 -    [pool release];
  10.487 +    @autoreleasepool {
  10.488 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.489 +        [nswindow miniaturize:nil];
  10.490 +    }
  10.491  }
  10.492  
  10.493  void
  10.494  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
  10.495  {
  10.496 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.497 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.498 +    @autoreleasepool {
  10.499 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.500  
  10.501 -    if ([nswindow isMiniaturized]) {
  10.502 -        [nswindow deminiaturize:nil];
  10.503 -    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.504 -        [nswindow zoom:nil];
  10.505 +        if ([nswindow isMiniaturized]) {
  10.506 +            [nswindow deminiaturize:nil];
  10.507 +        } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.508 +            [nswindow zoom:nil];
  10.509 +        }
  10.510      }
  10.511 -    [pool release];
  10.512  }
  10.513  
  10.514  static NSWindow *
  10.515 @@ -854,96 +837,95 @@
  10.516  {
  10.517      /* this message arrived in 10.6. You're out of luck on older OSes. */
  10.518  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
  10.519 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.520 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.521 -    if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.522 -        [nswindow setStyleMask:GetWindowStyle(window)];
  10.523 -        if (bordered) {
  10.524 -            Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.525 +    @autoreleasepool {
  10.526 +        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.527 +        if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.528 +            [nswindow setStyleMask:GetWindowStyle(window)];
  10.529 +            if (bordered) {
  10.530 +                Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.531 +            }
  10.532          }
  10.533      }
  10.534 -    [pool release];
  10.535  #endif
  10.536  }
  10.537  
  10.538  void
  10.539  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
  10.540  {
  10.541 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.542 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.543 -    NSWindow *nswindow = data->nswindow;
  10.544 -    NSRect rect;
  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 -    /* The view responder chain gets messed with during setStyleMask */
  10.551 -    if ([[nswindow contentView] nextResponder] == data->listener) {
  10.552 -        [[nswindow contentView] setNextResponder:nil];
  10.553 -    }
  10.554 -
  10.555 -    if (fullscreen) {
  10.556 -        SDL_Rect bounds;
  10.557 -
  10.558 -        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.559 -        rect.origin.x = bounds.x;
  10.560 -        rect.origin.y = bounds.y;
  10.561 -        rect.size.width = bounds.w;
  10.562 -        rect.size.height = bounds.h;
  10.563 -        ConvertNSRect(&rect);
  10.564 -
  10.565 -        /* Hack to fix origin on Mac OS X 10.4 */
  10.566 -        NSRect screenRect = [[nswindow screen] frame];
  10.567 -        if (screenRect.size.height >= 1.0f) {
  10.568 -            rect.origin.y += (screenRect.size.height - rect.size.height);
  10.569 +        /* The view responder chain gets messed with during setStyleMask */
  10.570 +        if ([[nswindow contentView] nextResponder] == data->listener) {
  10.571 +            [[nswindow contentView] setNextResponder:nil];
  10.572          }
  10.573  
  10.574 -        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.575 -            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.576 +        if (fullscreen) {
  10.577 +            SDL_Rect bounds;
  10.578 +
  10.579 +            Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.580 +            rect.origin.x = bounds.x;
  10.581 +            rect.origin.y = bounds.y;
  10.582 +            rect.size.width = bounds.w;
  10.583 +            rect.size.height = bounds.h;
  10.584 +            ConvertNSRect(&rect);
  10.585 +
  10.586 +            /* Hack to fix origin on Mac OS X 10.4 */
  10.587 +            NSRect screenRect = [[nswindow screen] frame];
  10.588 +            if (screenRect.size.height >= 1.0f) {
  10.589 +                rect.origin.y += (screenRect.size.height - rect.size.height);
  10.590 +            }
  10.591 +
  10.592 +            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.593 +                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.594 +            } else {
  10.595 +                nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.596 +            }
  10.597          } else {
  10.598 -            nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.599 +            rect.origin.x = window->windowed.x;
  10.600 +            rect.origin.y = window->windowed.y;
  10.601 +            rect.size.width = window->windowed.w;
  10.602 +            rect.size.height = window->windowed.h;
  10.603 +            ConvertNSRect(&rect);
  10.604 +
  10.605 +            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.606 +                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.607 +            } else {
  10.608 +                nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.609 +            }
  10.610          }
  10.611 -    } else {
  10.612 -        rect.origin.x = window->windowed.x;
  10.613 -        rect.origin.y = window->windowed.y;
  10.614 -        rect.size.width = window->windowed.w;
  10.615 -        rect.size.height = window->windowed.h;
  10.616 -        ConvertNSRect(&rect);
  10.617  
  10.618 -        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.619 -            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.620 +        /* The view responder chain gets messed with during setStyleMask */
  10.621 +        if ([[nswindow contentView] nextResponder] != data->listener) {
  10.622 +            [[nswindow contentView] setNextResponder:data->listener];
  10.623 +        }
  10.624 +
  10.625 +        s_moveHack = 0;
  10.626 +        [nswindow setFrameOrigin:rect.origin];
  10.627 +        [nswindow setContentSize:rect.size];
  10.628 +        s_moveHack = SDL_GetTicks();
  10.629 +
  10.630 +        /* When the window style changes the title is cleared */
  10.631 +        if (!fullscreen) {
  10.632 +            Cocoa_SetWindowTitle(_this, window);
  10.633 +        }
  10.634 +
  10.635 +    #ifdef FULLSCREEN_TOGGLEABLE
  10.636 +        if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.637 +            /* OpenGL is rendering to the window, so make it visible! */
  10.638 +            [nswindow setLevel:CGShieldingWindowLevel()];
  10.639          } else {
  10.640 -            nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.641 +            [nswindow setLevel:kCGNormalWindowLevel];
  10.642 +        }
  10.643 +    #endif
  10.644 +        [nswindow makeKeyAndOrderFront:nil];
  10.645 +
  10.646 +        if (window == _this->current_glwin) {
  10.647 +            [((NSOpenGLContext *) _this->current_glctx) update];
  10.648          }
  10.649      }
  10.650 -
  10.651 -    /* The view responder chain gets messed with during setStyleMask */
  10.652 -    if ([[nswindow contentView] nextResponder] != data->listener) {
  10.653 -        [[nswindow contentView] setNextResponder:data->listener];
  10.654 -    }
  10.655 -
  10.656 -    s_moveHack = 0;
  10.657 -    [nswindow setFrameOrigin:rect.origin];
  10.658 -    [nswindow setContentSize:rect.size];
  10.659 -    s_moveHack = SDL_GetTicks();
  10.660 -
  10.661 -    /* When the window style changes the title is cleared */
  10.662 -    if (!fullscreen) {
  10.663 -        Cocoa_SetWindowTitle(_this, window);
  10.664 -    }
  10.665 -
  10.666 -#ifdef FULLSCREEN_TOGGLEABLE
  10.667 -    if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.668 -        /* OpenGL is rendering to the window, so make it visible! */
  10.669 -        [nswindow setLevel:CGShieldingWindowLevel()];
  10.670 -    } else {
  10.671 -        [nswindow setLevel:kCGNormalWindowLevel];
  10.672 -    }
  10.673 -#endif
  10.674 -    [nswindow makeKeyAndOrderFront:nil];
  10.675 -
  10.676 -    if (window == _this->current_glwin) {
  10.677 -        [((NSOpenGLContext *) _this->current_glctx) update];
  10.678 -    }
  10.679 -
  10.680 -    [pool release];
  10.681  }
  10.682  
  10.683  int
  10.684 @@ -1027,18 +1009,18 @@
  10.685  void
  10.686  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
  10.687  {
  10.688 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.689 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.690 +    @autoreleasepool {
  10.691 +        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.692  
  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 +        if (data) {
  10.699 +            [data->listener close];
  10.700 +            [data->listener release];
  10.701 +            if (data->created) {
  10.702 +                [data->nswindow close];
  10.703 +            }
  10.704 +            SDL_free(data);
  10.705          }
  10.706 -        SDL_free(data);
  10.707      }
  10.708 -    [pool release];
  10.709  }
  10.710  
  10.711  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 +	@autoreleasepool {
   11.15 +        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.16 +        NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.17  
   11.18 +        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.19  
   11.20 -	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.21 -	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.22 -
   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