Преглед на файлове

macosx/VLCKit: Load VLCLibrary when VLCKit is loaded. No longer need atexit( ... ) to unload library, use __attribute__((destructor))__ instead. Also make sure we don't autorelease the VLCLibrary (as the library's destructor will take care of that for us).

Faustino Osuna преди 17 години
родител
ревизия
1c46396c97
променени са 2 файла, в които са добавени 19 реда и са изтрити 5 реда
  1. 4 0
      Headers/Public/VLCLibrary.h
  2. 15 5
      Sources/VLCLibrary.m

+ 4 - 0
Headers/Public/VLCLibrary.h

@@ -27,6 +27,10 @@
 #import "VLCMediaList.h"
 #import "VLCMedia.h"
 
+
+extern void * CreateSharedLibraryOnStartup( void ) __attribute__((constructor));
+extern void * DestroySharedLibraryAtExit( void ) __attribute__((destructor));
+
 @class VLCAudio;
 
 /**

+ 15 - 5
Sources/VLCLibrary.m

@@ -49,7 +49,20 @@ void __catch_exception( void * e, const char * function, const char * file, int
     }
 }
 
-static void * DestroySharedLibraryAtExit( void )
+void * CreateSharedLibraryOnStartup( void ) 
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    
+    /* This library is not loaded for no reason, so let's create
+     * a VLCLibrary instance. */
+    [VLCLibrary sharedLibrary];
+    
+    [pool release];
+    
+    return NULL;
+}
+
+void * DestroySharedLibraryAtExit( void )
 {
     /* Release the global object that may have been alloc-ed
      * in -[VLCLibrary init] */
@@ -66,11 +79,8 @@ static void * DestroySharedLibraryAtExit( void )
     {
         /* Initialize a shared instance */
         sharedLibrary = [[self alloc] init];
-        
-        /* Make sure, this will get released at some point */
-        atexit( (void *)DestroySharedLibraryAtExit );
     }
-    return [[sharedLibrary retain] autorelease];
+    return sharedLibrary;
 }
 
 - (id)init