Commit 9a8642bd6a1437e5c1b92a0d0ae7f1ce68a171ba

Sam Lantinga 2016-11-01T10:30:46

Fixed bug 3478 - Patch Haiku to use dlopen instead of load_add_on Kai Sterker SDL2 on Haiku so far uses Haiku-specific APIs for loading dynamic objects as add-ons, instead of using dlopen to load them as libraries. This, for example, leads to SDL_mixer not being able to load its audio backends, when compiled with standard settings. As discussed at https://www.freelists.org/post/haikuports/SDL2-mixer-ogg-music-not-playing-and-other-stuff,2 , the best way to deal with this would be using dlopen instead of load_add_on. The following patch implements this change by dropping the Haiku-specific bits and using dlopen instead.

diff --git a/configure b/configure
index 5070f6e..b018dff 100755
--- a/configure
+++ b/configure
@@ -23490,6 +23490,7 @@ fi
         CheckDummyVideo
         CheckDiskAudio
         CheckDummyAudio
+        CheckDLOPEN        
         CheckHaikuVideo
         CheckHaikuGL
         CheckPTHREAD
@@ -23518,14 +23519,6 @@ $as_echo "#define SDL_TIMER_HAIKU 1" >>confdefs.h
             SOURCES="$SOURCES $srcdir/src/timer/haiku/*.c"
             have_timers=yes
         fi
-        # Set up files for the shared object loading library
-        if test x$enable_loadso = xyes; then
-
-$as_echo "#define SDL_LOADSO_HAIKU 1" >>confdefs.h
-
-            SOURCES="$SOURCES $srcdir/src/loadso/haiku/*.c"
-            have_loadso=yes
-        fi
         # Set up files for the system power library
         if test x$enable_power = xyes; then
 
diff --git a/configure.in b/configure.in
index 37c57e2..7fc95a3 100644
--- a/configure.in
+++ b/configure.in
@@ -3229,6 +3229,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
         CheckDummyVideo
         CheckDiskAudio
         CheckDummyAudio
+        CheckDLOPEN
         CheckHaikuVideo
         CheckHaikuGL
         CheckPTHREAD
@@ -3251,12 +3252,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
             SOURCES="$SOURCES $srcdir/src/timer/haiku/*.c"
             have_timers=yes
         fi
-        # Set up files for the shared object loading library
-        if test x$enable_loadso = xyes; then
-            AC_DEFINE(SDL_LOADSO_HAIKU, 1, [ ])
-            SOURCES="$SOURCES $srcdir/src/loadso/haiku/*.c"
-            have_loadso=yes
-        fi
         # Set up files for the system power library
         if test x$enable_power = xyes; then
             AC_DEFINE(SDL_POWER_HAIKU, 1, [ ])
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 98c62a9..12692f5 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -252,7 +252,6 @@
 #cmakedefine SDL_HAPTIC_XINPUT @SDL_HAPTIC_XINPUT@
 
 /* Enable various shared object loading systems */
-#cmakedefine SDL_LOADSO_HAIKU @SDL_LOADSO_HAIKU@
 #cmakedefine SDL_LOADSO_DLOPEN @SDL_LOADSO_DLOPEN@
 #cmakedefine SDL_LOADSO_DUMMY @SDL_LOADSO_DUMMY@
 #cmakedefine SDL_LOADSO_LDG @SDL_LOADSO_LDG@
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index d610cd6..6b96b4f 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -253,7 +253,6 @@
 #undef SDL_HAPTIC_XINPUT
 
 /* Enable various shared object loading systems */
-#undef SDL_LOADSO_HAIKU
 #undef SDL_LOADSO_DLOPEN
 #undef SDL_LOADSO_DUMMY
 #undef SDL_LOADSO_LDG
diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c
index c26baf3..f3474f1 100644
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -216,21 +216,7 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
     return retval;
 }
 
-#elif defined(__HAIKU__)
-#include <os/kernel/image.h>
-static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
-{
-    image_id lib = load_add_on(fname);
-    void *retval = NULL;
-    if (lib >= 0) {
-        if (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR) {
-            unload_add_on(lib);
-            retval = NULL;
-        }
-    }
-    return retval;
-}
-#elif defined(unix) || defined(__unix__) || defined(__APPLE__)
+#elif defined(unix) || defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
 #include <dlfcn.h>
 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
 {
diff --git a/src/loadso/haiku/SDL_sysloadso.c b/src/loadso/haiku/SDL_sysloadso.c
deleted file mode 100644
index 1336d9e..0000000
--- a/src/loadso/haiku/SDL_sysloadso.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifdef SDL_LOADSO_HAIKU
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/* System dependent library loading routines                           */
-
-#include <stdio.h>
-#include <os/kernel/image.h>
-
-#include "SDL_loadso.h"
-
-void *
-SDL_LoadObject(const char *sofile)
-{
-    void *handle = NULL;
-    image_id library_id = load_add_on(sofile);
-    if (library_id < 0) {
-        SDL_SetError(strerror((int) library_id));
-    } else {
-        handle = (void *) (library_id);
-    }
-    return (handle);
-}
-
-void *
-SDL_LoadFunction(void *handle, const char *name)
-{
-    void *sym = NULL;
-    image_id library_id = (image_id) handle;
-    status_t rc =
-        get_image_symbol(library_id, name, B_SYMBOL_TYPE_TEXT, &sym);
-    if (rc != B_NO_ERROR) {
-        SDL_SetError(strerror(rc));
-    }
-    return (sym);
-}
-
-void
-SDL_UnloadObject(void *handle)
-{
-    image_id library_id;
-    if (handle != NULL) {
-        library_id = (image_id) handle;
-        unload_add_on(library_id);
-    }
-}
-
-#endif /* SDL_LOADSO_HAIKU */
-
-/* vi: set ts=4 sw=4 expandtab: */