From 39bd59801c1a0196f564403bd2adfad072801998 Mon Sep 17 00:00:00 2001 From: Faustino Osuna Date: Tue, 4 Mar 2008 22:41:30 +0000 Subject: [PATCH] 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). --- .../framework/Headers/Public/VLCLibrary.h | 4 ++++ .../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 f1ff8c5b6b..a3d6c35909 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 b58e011241..2550a4896b 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 -- 2.39.2