Bob Ippolito avatar Bob Ippolito committed 167c011

Added objc.removeAutoreleasePool(), and use it from plug-ins

Comments (0)

Files changed (9)

Examples/Inject/IDNSnitch/IDNSnitchPlugin.py

 
 idnSnitch = IDNSnitch.alloc().init()
 idnSnitch.performSelectorOnMainThread_withObject_waitUntilDone_('startIDNSnitch:', None, True)
+
+objc.removeAutoreleasePool()

Examples/Inject/InjectBrowser/InjectBrowserPlugin.py

 """
 
 from PyObjCTools import NibClassBuilder, AppHelper
+import objc
 from objc import getClassList, objc_object
 from Foundation import *
 from AppKit import *
     myBundle,
     False,
 )
+
+objc.removeAutoreleasePool()

Examples/Inject/InjectInterpreter/InjectInterpreterPlugin.py

 import time
 from code import InteractiveConsole, softspace
 from StringIO import StringIO
+import objc
 from objc import YES, NO, selector
 from Foundation import *
 from AppKit import *
     myBundle,
     False,
 )
+
+objc.removeAutoreleasePool()

Examples/Plugins/EnvironmentPrefs/ShellEnv.py

             None,
             0,
             message)
+
+objc.removeAutoreleasePool()

Examples/Plugins/ProgressViewPalette/ProgressViewPalette.py

 def ibMatchPrototype_(self, prototype):
     super(ProgressCell, self).ibMatchPrototype_(prototype)
     self.setPercentageIncrement_(prototype.percentageIncrement())
+
+objc.removeAutoreleasePool()

Examples/Plugins/SillyBallsSaver/SillyBalls.py

 
         # draw a new ball.
         path.fill()
+
+objc.removeAutoreleasePool()

Modules/objc/module.m

 }
 
 
+PyDoc_STRVAR(remove_autorelease_pool_doc,
+  "removeAutoreleasePool()\n"
+  "\n"
+  "This removes the global NSAutoreleasePool.  You should do this\n"
+  "at the end of a plugin's initialization script.\n");
+static PyObject*
+remove_autorelease_pool(PyObject* self __attribute__((__unused__)),
+	PyObject* args, PyObject* kwds)
+{
+	static char* keywords[] = { NULL };
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "", keywords)) {
+		return NULL;
+	}
+
+	PyObjC_DURING
+		[global_release_pool release];
+		global_release_pool = nil;
+	PyObjC_HANDLER
+		PyObjCErr_FromObjC(localException);
+	PyObjC_ENDHANDLER
+
+	if (PyErr_Occurred()) return NULL;
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 PyDoc_STRVAR(recycle_autorelease_pool_doc,
   "recycleAutoreleasePool()\n"
   "\n"
 	{ "setClassExtender", (PyCFunction)set_class_extender, METH_VARARGS|METH_KEYWORDS, set_class_extender_doc  },
 	{ "setSignatureForSelector", (PyCFunction)set_signature_for_selector, METH_VARARGS|METH_KEYWORDS, set_signature_for_selector_doc },
 	{ "recycleAutoreleasePool", (PyCFunction)recycle_autorelease_pool, METH_VARARGS|METH_KEYWORDS, recycle_autorelease_pool_doc },
+	{ "removeAutoreleasePool", (PyCFunction)remove_autorelease_pool, METH_VARARGS|METH_KEYWORDS, remove_autorelease_pool_doc },
 	{ "setNSNumberWrapper", (PyCFunction)setNSNumberWrapper, METH_VARARGS|METH_KEYWORDS, setNSNumberWrapper_doc },
 	{ "getNSNumberWrapper", (PyCFunction)getNSNumberWrapper, METH_VARARGS|METH_KEYWORDS, getNSNumberWrapper_doc },
 	{ "setVerbose", (PyCFunction)setVerbose, METH_VARARGS|METH_KEYWORDS, setVerbose_doc },
 {
 	PyObject *m, *d;
 
-	/* Allocate an auto-release pool for our own use, this avoids numerous
-	 * warnings during startup of a python script.
-	 */
-	global_release_pool = [[NSAutoreleasePool alloc] init];
+	NSAutoreleasePool *initReleasePool = [[NSAutoreleasePool alloc] init];
 	[OC_NSBundleHack installBundleHack];
 
 	PyObjCClass_DefaultModule = PyString_FromString("objc");
 #endif /* MACOSX */
 
 	PyEval_InitThreads();
+	[initReleasePool release];
+	/* Allocate an auto-release pool for our own use, this avoids numerous
+	 * warnings during startup of a python script.
+	 */
+	global_release_pool = [[NSAutoreleasePool alloc] init];
 }
 <p>An overview of the relevant changes in new, and older, releases.</p>
 <h2><a name="version-1-3-1-2005-04">Version 1.3.1 (2005-04-??)</a></h2>
 <ul>
+<li>New <code><span>objc.removeAutoreleasePool</span></code> function that will remove
+PyObjC's global NSAutoreleasePool, which is particularly useful
+for plugins.</li>
 <li>Synchronize implementation of <code><span>objc.inject</span></code> with mach_* 1.1.
 Now injects on main thread by default, takes third useMainThread
 argument to change this behavior.</li>
 Version 1.3.1 (2005-04-??)
 --------------------------
 
+- New ``objc.removeAutoreleasePool`` function that will remove
+  PyObjC's global NSAutoreleasePool, which is particularly useful
+  for plugins.
+
 - Synchronize implementation of ``objc.inject`` with mach_* 1.1.
   Now injects on main thread by default, takes third useMainThread
   argument to change this behavior.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.