diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 73751a0571..dc62e2eecf 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -1806,6 +1806,15 @@ void gui_macvim_get_window_layout(int *count, int *layout) } } +void *gui_macvim_new_autoreleasepool() +{ + return (void *)[[NSAutoreleasePool alloc] init]; +} + +void gui_macvim_release_autoreleasepool(void *pool) +{ + [(id)pool release]; +} // -- Client/Server --------------------------------------------------------- diff --git a/src/main.c b/src/main.c index a294cf031a..965f372006 100644 --- a/src/main.c +++ b/src/main.c @@ -23,10 +23,6 @@ # include #endif -#ifdef FEAT_GUI_MACVIM -#include /* for objc_*() and sel_*() */ -#endif - /* Maximum number of commands from + or -c arguments. */ #define MAX_ARG_CMDS 10 @@ -180,9 +176,7 @@ main // Cocoa needs an NSAutoreleasePool in place or it will leak memory. // This particular pool will hold autorelease objects created during // initialization. - id autoreleasePool = objc_msgSend(objc_msgSend( - objc_getClass("NSAutoreleasePool"),sel_getUid("alloc") - ), sel_getUid("init")); + void *autoreleasePool = gui_macvim_new_autoreleasepool(); #endif /* @@ -1066,13 +1060,11 @@ vim_main2(int argc UNUSED, char **argv UNUSED) #ifdef FEAT_GUI_MACVIM // The autorelease pool might have filled up quite a bit during // initialization, so purge it before entering the main loop. - objc_msgSend(autoreleasePool, sel_getUid("release")); + gui_macvim_release_autoreleasepool(autoreleasePool); // The main loop sets up its own autorelease pool, but to be safe we still // realloc this one here. - autoreleasePool = objc_msgSend(objc_msgSend( - objc_getClass("NSAutoreleasePool"),sel_getUid("alloc") - ), sel_getUid("init")); + autoreleasePool = gui_macvim_new_autoreleasepool(); #endif /* @@ -1081,7 +1073,7 @@ vim_main2(int argc UNUSED, char **argv UNUSED) main_loop(FALSE, FALSE); #ifdef FEAT_GUI_MACVIM - objc_msgSend(autoreleasePool, sel_getUid("release")); + gui_macvim_release_autoreleasepool(autoreleasePool); #endif return 0; @@ -1152,9 +1144,7 @@ main_loop(cmdwin, noexmode) #ifdef FEAT_GUI_MACVIM // Cocoa needs an NSAutoreleasePool in place or it will leak memory. // This particular pool gets released once every loop. - id autoreleasePool = objc_msgSend(objc_msgSend( - objc_getClass("NSAutoreleasePool"),sel_getUid("alloc") - ), sel_getUid("init")); + void *autoreleasePool = gui_macvim_new_autoreleasepool(); #endif if (stuff_empty()) @@ -1404,7 +1394,7 @@ main_loop(cmdwin, noexmode) #ifdef FEAT_GUI_MACVIM // TODO! Make sure there are no continue statements that will cause // this not to be called or MacVim will leak memory! - objc_msgSend(autoreleasePool, sel_getUid("release")); + gui_macvim_release_autoreleasepool(autoreleasePool); #endif } } diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 40b295185f..427205d76f 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -236,3 +236,6 @@ gui_mch_register_sign(char_u *signfile); void gui_mch_destroy_sign(void *sign); + +void *gui_macvim_new_autoreleasepool(); +void gui_macvim_release_autoreleasepool(void *pool);