[vlc-devel] commit: 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 )

git version control git at videolan.org
Tue Mar 4 23:41:35 CET 2008


vlc | branch: master | Faustino Osuna <enrique.osuna at gmail.com> | Tue Mar  4 22:41:30 2008 +0000| [39bd59801c1a0196f564403bd2adfad072801998]

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).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=39bd59801c1a0196f564403bd2adfad072801998
---

 .../macosx/framework/Headers/Public/VLCLibrary.h   |    4 ++++
 projects/macosx/framework/Sources/VLCLibrary.m     |   20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/projects/macosx/framework/Headers/Public/VLCLibrary.h b/projects/macosx/framework/Headers/Public/VLCLibrary.h
index f1ff8c5..a3d6c35 100644
--- a/projects/macosx/framework/Headers/Public/VLCLibrary.h
+++ b/projects/macosx/framework/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;
 
 /**
diff --git a/projects/macosx/framework/Sources/VLCLibrary.m b/projects/macosx/framework/Sources/VLCLibrary.m
index b58e011..2550a48 100644
--- a/projects/macosx/framework/Sources/VLCLibrary.m
+++ b/projects/macosx/framework/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 




More information about the vlc-devel mailing list