Commits

Bob Ippolito committed d9368c2

- Importing objc now ensure that Foundation is multi-threaded, previously
it only ensured that Python was.

  • Participants
  • Parent commits aa62097
  • Branches pyobjc-ancient

Comments (0)

Files changed (4)

Modules/objc/module.m

 @interface OC_NSAutoreleasePoolCollector: NSObject
 {}
 +(void)newAutoreleasePool;
++(void)targetForBecomingMultiThreaded:(id)sender;
 @end
 @implementation OC_NSAutoreleasePoolCollector
 +(void)newAutoreleasePool
 	global_release_pool = nil;
 	[super dealloc];
 }
+
++(void)targetForBecomingMultiThreaded:(id)sender
+{
+    [sender self];
+}
+
 @end
 
 PyDoc_STRVAR(pyobjc_id_doc,
 #endif /* MACOSX */
 
 	PyEval_InitThreads();
+	if (![NSThread isMultiThreaded]) {
+		[NSThread detachNewThreadSelector:@selector(targetForBecomingMultiThreaded:) toTarget:[OC_NSAutoreleasePoolCollector class] withObject:nil];
+	}
 	[initReleasePool release];
 	/* Allocate an auto-release pool for our own use, this avoids numerous
 	 * warnings during startup of a python script.
 <p>An overview of the relevant changes in new, and older, releases.</p>
 <h2><a name="version-1-3-5-2005-05">Version 1.3.5 (2005-05-??)</a></h2>
 <ul>
+<li>Importing objc now ensure that Foundation is multi-threaded, previously
+it only ensured that Python was.</li>
 <li>New <code><span>objc.RegisterCFSignature</span></code> used to register <code><span>CFTypeRef</span></code>-like
 signatures with the runtime.</li>
 <li><code><span>PyObjCTools.Conversion</span></code> functions now support all property list
 Version 1.3.5 (2005-05-??)
 --------------------------
 
+- Importing objc now ensure that Foundation is multi-threaded, previously
+  it only ensured that Python was.
+
 - New ``objc.RegisterCFSignature`` used to register ``CFTypeRef``-like
   signatures with the runtime.
 

sandbox/parsing/scanframework.py

 from itertools import imap
 import re
 
+TYPES_HEADER = """
+try:
+    set
+except NameError:
+    from sets import Set as set
+TYPES = """
+
 # From searching Xcode for toll free
 TOLL_FREE = [
     # NSObject
 
 class typedict(object):
     def __init__(self):
-        self.dct = {}
+        self.headers = set()
+        self.dct = {'%% HEADERS %%': self.headers}
         
     def update(self, dct):
         if not isinstance(dct, dict):
     def __contains__(self, key):
         return normalize_type(key) in self.dct
 
+    def addHeader(self, header):
+        if header in self.headers:
+            return False
+        self.headers.add(header)
+
     def __setitem__(self, key, item):
+        # allow updates from a type hint file
+        if key == '%% HEADERS %%':
+            try:
+                self.dct[key].update(item)
+            except KeyError:
+                self.dct[key] = set(item)
+            return
         key = normalize_type(key)
         self.dct[key] = item
         print '[type] %s -> %s' % (key, item)
 
     This function only parses type definitions and updates the type table.
     """
+    if not types.addHeader(framework):
+        return
     print "[extractTypes]", framework
     f = FrameworkScanner()
 
     """ % locals()
 
     if bundle_variables or bundle_functions:
-        print >>out, """\
+        print >>out, """
     b = objc.lookUpClass('NSBundle').bundleWithPath_(p)
 """
 
     if bundle_variables:
-        print >>out, """\
+        print >>out, """
     objc.loadBundleVariables(b, globals(), [%(bundle_variables)s
     ])
 """ % locals()
 
     if bundle_functions:
-        print >>out, """\
+        print >>out, """
     objc.loadBundleFunctions(b, globals(), [%(bundle_functions)s
     ])
 """ % locals()
         pass
     makeInit(fmwk, cleanfile(os.path.join(fmwk, '__init__.py'), 'w'), hinter, types)
     typesfile = file(os.path.join(fmwk, '_types.py'), 'w')
-    typesfile.write('TYPES = ')
+    typesfile.write(TYPES_HEADER)
     pprint.pprint(types.dct, typesfile)
-    print >>typesfile, ''
 
 if __name__ == '__main__':
     types = typedict()