Skip to content
Permalink
Browse files

Split up src/SDL_loadso.c into platform directories.

  • Loading branch information
icculus committed Nov 17, 2005
1 parent 33aae66 commit 22d1555103aaf306fb4a42e1331703a2dd1eabc1
@@ -304,11 +304,11 @@ CheckALSA()
alsa_lib=`ls $alsa_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
echo "-- $alsa_lib_spec -> $alsa_lib"

if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_alsa_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_alsa_shared = xyes && test x$alsa_lib != x; then
CFLAGS="$CFLAGS -DALSA_SUPPORT -DALSA_DYNAMIC=\$(alsa_lib) $ALSA_CFLAGS"
AC_SUBST(alsa_lib)
@@ -367,11 +367,11 @@ CheckESD()
esd_lib_spec=`echo $ESD_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libesd.so.*/'`
esd_lib=`ls $esd_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
echo "-- $esd_lib_spec -> $esd_lib"
if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_esd_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_esd_shared = xyes && test x$esd_lib != x; then
CFLAGS="$CFLAGS -DESD_SUPPORT -DESD_DYNAMIC=\$(esd_lib) $ESD_CFLAGS"
AC_SUBST(esd_lib)
@@ -418,11 +418,11 @@ CheckARTSC()
arts_lib_spec="$ARTSC_PREFIX/lib/libartsc.so.*"
arts_lib=`ls $arts_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
echo "-- $arts_lib_spec -> $arts_lib"
if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_arts_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi
if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_arts_shared = xyes && test x$arts_lib != x; then
CFLAGS="$CFLAGS -DARTSC_SUPPORT -DARTSC_DYNAMIC=\$(arts_lib) $ARTSC_CFLAGS"
AC_SUBST(arts_lib)
@@ -617,12 +617,12 @@ CheckX11()
x11_lib='libX11.so.6'
x11ext_lib='libXext.so.6'

if test x$use_dlopen != xyes && \
if test x$have_loadso != xyes && \
test x$enable_x11_shared = xyes; then
AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
AC_MSG_ERROR([You must have SDL_LoadObject() support])
fi

if test x$use_dlopen = xyes && \
if test x$have_loadso = xyes && \
test x$enable_x11_shared = xyes && test x$x11_lib != x && test x$x11ext_lib != x; then
CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -DX11_DYNAMIC=\$(x11_lib) -DX11EXT_DYNAMIC=\$(x11ext_lib) -I$srcdir/include -I$srcdir/src/video"
SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS"
@@ -1131,7 +1131,7 @@ CheckOpenGL()
AC_MSG_RESULT($video_opengl)
if test x$video_opengl = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
if test x$use_dlopen != xyes; then
if test x$have_loadso != xyes; then
AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl")
fi
fi
@@ -1154,7 +1154,7 @@ CheckOpenGLQNX()
if test x$video_opengl = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
SYSTEM_LIBS="$SYSTEM_LIBS -lGL"
if test x$use_dlopen != xyes; then
if test x$have_loadso != xyes; then
AC_CHECK_LIB(c, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS", AC_CHECK_LIB(ltdl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -lltdl"))
fi
fi
@@ -1778,16 +1778,16 @@ CheckDLOPEN()
, enable_sdl_dlopen=yes)
if test x$enable_sdl_dlopen = xyes; then
AC_MSG_CHECKING(for dlopen)
use_dlopen=no
have_loadso=no
AC_TRY_COMPILE([
#include <dlfcn.h>
],[
],[
use_dlopen=yes
have_loadso=yes
])
AC_MSG_RESULT($use_dlopen)
AC_MSG_RESULT($have_loadso)

if test x$use_dlopen = xyes; then
if test x$have_loadso = xyes; then
CFLAGS="$CFLAGS -DUSE_DLOPEN"
AC_CHECK_LIB(c, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS",
AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl",
@@ -1806,6 +1806,7 @@ CheckAtariLdg()
AC_CHECK_HEADER(ldg.h, have_ldg_hdr=yes)
AC_CHECK_LIB(ldg, ldg_open, have_ldg_lib=yes, have_ldg_lib=no, -lgem)
if test x$have_ldg_hdr = xyes -a x$have_ldg_lib = xyes; then
have_loadso=yes
CFLAGS="$CFLAGS -DENABLE_LDG"
SYSTEM_LIBS="$SYSTEM_LIBS -lldg -lgem"
fi
@@ -1989,6 +1990,7 @@ CheckRPATH()
, enable_rpath=yes)
}

have_loadso=no
case "$target" in
arm-*-elf*)
ARCH=linux
@@ -2560,6 +2562,7 @@ case "$target" in
;;
*-*-cygwin* | *-*-mingw32*)
ARCH=win32
have_loadso=yes
if test "$build" != "$target"; then # cross-compiling
# Default cross-compile location
ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
@@ -2625,6 +2628,7 @@ case "$target" in
*-*-beos*)
ARCH=beos
ac_default_prefix=/boot/develop/tools/gnupro
have_loadso=yes
CheckDummyVideo
CheckDiskAudio
CheckNASM
@@ -2668,6 +2672,7 @@ case "$target" in
# use it at present, but Apple is working on a X-to-9 compiler
# for which this case would be handy.
ARCH=macos
have_loadso=yes
CheckDummyVideo
CheckDiskAudio
CheckTOOLBOX
@@ -2711,6 +2716,7 @@ case "$target" in
# just the OS X kernel sans upper layers like Carbon and Cocoa.
# Next line is broken, and a few files below require Mac OS X (full)
ARCH=macosx
have_loadso=yes
CheckDummyVideo
CheckDiskAudio
CheckCOCOA
@@ -28,234 +28,23 @@ static char rcsid =
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */

#include <stdio.h>
#if defined(USE_DLOPEN)
# include <dlfcn.h>
/* !!! FIXME: includes so I don't have to update all the project files... */
#define SDL_INTERNAL_BUILDING_LOADSO 1
#if defined(USE_DUMMY_LOADSO)
# include "loadso/dummy/SDL_loadso.c"
#elif defined(MACOSX)
# include "loadso/macosx/SDL_loadso.c"
#elif defined(macintosh)
# include "loadso/macos/SDL_loadso.c"
#elif defined(USE_DLOPEN)
# include "loadso/dlopen/SDL_loadso.c"
#elif defined(WIN32) || defined(_WIN32_WCE)
# include <windows.h>
# include "loadso/windows/SDL_loadso.c"
#elif defined(__BEOS__)
# include <be/kernel/image.h>
#elif defined(macintosh)
# include <string.h>
#define OLDP2C 1
# include <Strings.h>
# include <CodeFragments.h>
# include <Errors.h>
# include "loadso/beos/SDL_loadso.c"
#elif defined(__MINT__) && defined(ENABLE_LDG)
# include <gem.h>
# include <ldg.h>
# include "loadso/mint/SDL_loadso.c"
#else
/*#error Unsupported dynamic link environment*/
# include "loadso/dummy/SDL_loadso.c"
#endif /* system type */

#include "SDL_types.h"
#include "SDL_error.h"
#include "SDL_loadso.h"

void *SDL_LoadObject(const char *sofile)
{
void *handle = NULL;
const char *loaderror = "SDL_LoadObject() not implemented";
#if defined(USE_DLOPEN)
/* * */
handle = dlopen(sofile, RTLD_NOW);
loaderror = (char *)dlerror();
#elif defined(_WIN32_WCE)
/* * */
char errbuf[512];

wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
wchar_t *sofile_t = malloc((MAX_PATH+1) * sizeof(wchar_t));

MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH);
handle = (void *)LoadLibrary(sofile_t);

/* Generate an error message if all loads failed */
if ( handle == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf_t, SDL_TABLESIZE(errbuf), NULL);
WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
loaderror = errbuf;
}

free(sofile_t);
free(errbuf_t);

#elif defined(WIN32)
/* * */
char errbuf[512];

handle = (void *)LoadLibrary(sofile);

/* Generate an error message if all loads failed */
if ( handle == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
loaderror = errbuf;
}
#elif defined(__BEOS__)
/* * */
image_id library_id;

library_id = load_add_on(sofile);
if ( library_id == B_ERROR ) {
loaderror = "BeOS error";
} else {
handle = (void *)(library_id);
}
#elif defined(macintosh)
/* * */
CFragConnectionID library_id;
Ptr mainAddr;
Str255 errName;
OSErr error;
char psofile[512];

strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
psofile[SDL_TABLESIZE(psofile)-1] = '\0';
error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
kLoadCFrag, &library_id, &mainAddr, errName);
switch (error) {
case noErr:
loaderror = NULL;
break;
case cfragNoLibraryErr:
loaderror = "Library not found";
break;
case cfragUnresolvedErr:
loaderror = "Unabled to resolve symbols";
break;
case cfragNoPrivateMemErr:
case cfragNoClientMemErr:
loaderror = "Out of memory";
break;
default:
loaderror = "Unknown Code Fragment Manager error";
break;
}
if ( loaderror == NULL ) {
handle = (void *)(library_id);
}
#elif defined(__MINT__) && defined(ENABLE_LDG)
/* * */
handle = (void *)ldg_open((char *)sofile, ldg_global);
#endif /* system type */

if ( handle == NULL ) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
return(handle);
}

void *SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = NULL;
const char *loaderror = "SDL_LoadFunction not implemented";
#if defined(USE_DLOPEN)
/* * */
symbol = dlsym(handle, name);
if ( symbol == NULL ) {
loaderror = (char *)dlerror();
}
#elif defined(_WIN32_WCE)
/* * */
char errbuf[512];
int length = strlen(name);

wchar_t *name_t = malloc((length + 1) * sizeof(wchar_t));
wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));

MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length);

symbol = (void *)GetProcAddress((HMODULE)handle, name_t);
if ( symbol == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf_t, SDL_TABLESIZE(errbuf), NULL);
WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
loaderror = errbuf;
}

free(name_t);
free(errbuf_t);

#elif defined(WIN32)
/* * */
char errbuf[512];

symbol = (void *)GetProcAddress((HMODULE)handle, name);
if ( symbol == NULL ) {
FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM),
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errbuf, SDL_TABLESIZE(errbuf), NULL);
loaderror = errbuf;
}
#elif defined(__BEOS__)
/* * */
image_id library_id = (image_id)handle;
if ( get_image_symbol(library_id,
name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
loaderror = "Symbol not found";
}
#elif defined(macintosh)
/* * */
CFragSymbolClass class;
CFragConnectionID library_id = (CFragConnectionID)handle;
char pname[512];

strncpy(pname, name, SDL_TABLESIZE(pname));
pname[SDL_TABLESIZE(pname)-1] = '\0';
if ( FindSymbol(library_id, C2PStr(pname),
(char **)&symbol, &class) != noErr ) {
loaderror = "Symbol not found";
}
#elif defined(__MINT__) && defined(ENABLE_LDG)
/* * */
symbol = (void *)ldg_find((char *)name, (LDG *)handle);
#endif /* system type */

if ( symbol == NULL ) {
SDL_SetError("Failed loading %s: %s", name, loaderror);
}
return(symbol);
}

void SDL_UnloadObject(void *handle)
{
#if defined(__BEOS__)
image_id library_id;
#elif defined(macintosh)
CFragConnectionID library_id;
#endif
if ( handle == NULL ) {
return;
}
#if defined(USE_DLOPEN)
/* * */
dlclose(handle);
#elif defined(WIN32)
/* * */
FreeLibrary((HMODULE)handle);
#elif defined(__BEOS__)
/* * */
library_id = (image_id)handle;
unload_add_on(library_id);
#elif defined(macintosh)
/* * */
library_id = (CFragConnectionID)handle;
CloseConnection(&library_id);
#elif defined(__MINT__) && defined(ENABLE_LDG)
/* * */
ldg_close((LDG *)handle, ldg_global);
#endif /* system type */
}

0 comments on commit 22d1555

Please sign in to comment.