mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Avoid directly calling objc runtime functions in C
By managing autorelease pools in objc code we avoid warnings on OS X 10.9 and it is also safer than calling objc runtime functions from C.
This commit is contained in:
@@ -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 ---------------------------------------------------------
|
||||
|
||||
|
||||
+6
-16
@@ -23,10 +23,6 @@
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifdef FEAT_GUI_MACVIM
|
||||
#include <objc/objc-runtime.h> /* 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user