Skip to content

Commit

Permalink
macosx/VLCKit: Load VLCLibrary when VLCKit is loaded. No longer need …
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
feosuna1 committed Mar 4, 2008
1 parent a0fd14f commit 39bd598
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions projects/macosx/framework/Headers/Public/VLCLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#import "VLCMediaList.h"
#import "VLCMedia.h"


extern void * CreateSharedLibraryOnStartup( void ) __attribute__((constructor));
extern void * DestroySharedLibraryAtExit( void ) __attribute__((destructor));

@class VLCAudio;

/**
Expand Down
20 changes: 15 additions & 5 deletions projects/macosx/framework/Sources/VLCLibrary.m
Original file line number Diff line number Diff line change
Expand Up @@ -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] */
Expand All @@ -66,11 +79,8 @@ + (VLCLibrary *)sharedLibrary
{
/* 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
Expand Down

0 comments on commit 39bd598

Please sign in to comment.