Added SDL_GetLoadedModule to do the equivalent of GetModuleHandle/dlload(NOLOAD)
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Feb 2014 11:05:24 -0800
changeset 8210581caa876b2e
parent 8209 56e9c709db7e
child 8211 089bc02a5e4b
Added SDL_GetLoadedModule to do the equivalent of GetModuleHandle/dlload(NOLOAD)

CR: Jorgen
include/SDL_loadso.h
src/loadso/dlopen/SDL_sysloadso.c
src/loadso/windows/SDL_sysloadso.c
     1.1 --- a/include/SDL_loadso.h	Wed Feb 12 18:12:14 2014 -0300
     1.2 +++ b/include/SDL_loadso.h	Thu Feb 13 11:05:24 2014 -0800
     1.3 @@ -58,6 +58,16 @@
     1.4  extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
     1.5  
     1.6  /**
     1.7 + *  This function returns a handle to an already-loaded shared object and 
     1.8 + *  returns a pointer to the object handle. If the object file was not loaded
     1.9 + *  the function returns NULL. This function adds a reference to the shared
    1.10 + *  object, so the caller should call SDL_UnloadObject when they are finished
    1.11 + *  with this reference to ensure that the object can be unloaded.
    1.12 + *  The 'sofile' parameter is a system dependent name of the object file.
    1.13 + */
    1.14 +extern DECLSPEC void *SDLCALL SDL_GetLoadedObject(const char *sofile);
    1.15 +
    1.16 +/**
    1.17   *  Given an object handle, this function looks up the address of the
    1.18   *  named function in the shared object and returns it.  This address
    1.19   *  is no longer valid after calling SDL_UnloadObject().
     2.1 --- a/src/loadso/dlopen/SDL_sysloadso.c	Wed Feb 12 18:12:14 2014 -0300
     2.2 +++ b/src/loadso/dlopen/SDL_sysloadso.c	Thu Feb 13 11:05:24 2014 -0800
     2.3 @@ -42,6 +42,13 @@
     2.4  }
     2.5  
     2.6  void *
     2.7 +SDL_GetLoadedObject(const char *sofile)
     2.8 +{
     2.9 +	void *handle = dlopen(sofile, RTLD_NOLOAD);
    2.10 +	return (handle);
    2.11 +}
    2.12 +
    2.13 +void *
    2.14  SDL_LoadFunction(void *handle, const char *name)
    2.15  {
    2.16      void *symbol = dlsym(handle, name);
     3.1 --- a/src/loadso/windows/SDL_sysloadso.c	Wed Feb 12 18:12:14 2014 -0300
     3.2 +++ b/src/loadso/windows/SDL_sysloadso.c	Thu Feb 13 11:05:24 2014 -0800
     3.3 @@ -47,6 +47,22 @@
     3.4  }
     3.5  
     3.6  void *
     3.7 +SDL_GetLoadedObject(const char *sofile)
     3.8 +{
     3.9 +    LPTSTR tstr = WIN_UTF8ToString(sofile);
    3.10 +    void *handle = (void *) GetModuleHandle(tstr);
    3.11 +
    3.12 +	/* if we got a handle, call LoadLibrary to get
    3.13 +	*  it again with the ref count incremented.
    3.14 +	* We do this to match the dlopen version of this function */
    3.15 +	handle = (void *)LoadLibrary( tstr );
    3.16 +
    3.17 +    SDL_free(tstr);
    3.18 +
    3.19 +    return handle;
    3.20 +}
    3.21 +
    3.22 +void *
    3.23  SDL_LoadFunction(void *handle, const char *name)
    3.24  {
    3.25      void *symbol = (void *) GetProcAddress((HMODULE) handle, name);