Fixed bug 3478 - Patch Haiku to use dlopen instead of load_add_on
authorSam Lantinga <slouken@libsdl.org>
Tue, 01 Nov 2016 10:30:46 -0700
changeset 1056515ba7a201f0a
parent 10564 46cfe31e501a
child 10566 0fb14a4fca0b
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.
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
src/dynapi/SDL_dynapi.c
src/loadso/haiku/SDL_sysloadso.c
     1.1 --- a/configure	Sun Oct 30 21:01:46 2016 +0100
     1.2 +++ b/configure	Tue Nov 01 10:30:46 2016 -0700
     1.3 @@ -23490,6 +23490,7 @@
     1.4          CheckDummyVideo
     1.5          CheckDiskAudio
     1.6          CheckDummyAudio
     1.7 +        CheckDLOPEN        
     1.8          CheckHaikuVideo
     1.9          CheckHaikuGL
    1.10          CheckPTHREAD
    1.11 @@ -23518,14 +23519,6 @@
    1.12              SOURCES="$SOURCES $srcdir/src/timer/haiku/*.c"
    1.13              have_timers=yes
    1.14          fi
    1.15 -        # Set up files for the shared object loading library
    1.16 -        if test x$enable_loadso = xyes; then
    1.17 -
    1.18 -$as_echo "#define SDL_LOADSO_HAIKU 1" >>confdefs.h
    1.19 -
    1.20 -            SOURCES="$SOURCES $srcdir/src/loadso/haiku/*.c"
    1.21 -            have_loadso=yes
    1.22 -        fi
    1.23          # Set up files for the system power library
    1.24          if test x$enable_power = xyes; then
    1.25  
     2.1 --- a/configure.in	Sun Oct 30 21:01:46 2016 +0100
     2.2 +++ b/configure.in	Tue Nov 01 10:30:46 2016 -0700
     2.3 @@ -3229,6 +3229,7 @@
     2.4          CheckDummyVideo
     2.5          CheckDiskAudio
     2.6          CheckDummyAudio
     2.7 +        CheckDLOPEN
     2.8          CheckHaikuVideo
     2.9          CheckHaikuGL
    2.10          CheckPTHREAD
    2.11 @@ -3251,12 +3252,6 @@
    2.12              SOURCES="$SOURCES $srcdir/src/timer/haiku/*.c"
    2.13              have_timers=yes
    2.14          fi
    2.15 -        # Set up files for the shared object loading library
    2.16 -        if test x$enable_loadso = xyes; then
    2.17 -            AC_DEFINE(SDL_LOADSO_HAIKU, 1, [ ])
    2.18 -            SOURCES="$SOURCES $srcdir/src/loadso/haiku/*.c"
    2.19 -            have_loadso=yes
    2.20 -        fi
    2.21          # Set up files for the system power library
    2.22          if test x$enable_power = xyes; then
    2.23              AC_DEFINE(SDL_POWER_HAIKU, 1, [ ])
     3.1 --- a/include/SDL_config.h.cmake	Sun Oct 30 21:01:46 2016 +0100
     3.2 +++ b/include/SDL_config.h.cmake	Tue Nov 01 10:30:46 2016 -0700
     3.3 @@ -252,7 +252,6 @@
     3.4  #cmakedefine SDL_HAPTIC_XINPUT @SDL_HAPTIC_XINPUT@
     3.5  
     3.6  /* Enable various shared object loading systems */
     3.7 -#cmakedefine SDL_LOADSO_HAIKU @SDL_LOADSO_HAIKU@
     3.8  #cmakedefine SDL_LOADSO_DLOPEN @SDL_LOADSO_DLOPEN@
     3.9  #cmakedefine SDL_LOADSO_DUMMY @SDL_LOADSO_DUMMY@
    3.10  #cmakedefine SDL_LOADSO_LDG @SDL_LOADSO_LDG@
     4.1 --- a/include/SDL_config.h.in	Sun Oct 30 21:01:46 2016 +0100
     4.2 +++ b/include/SDL_config.h.in	Tue Nov 01 10:30:46 2016 -0700
     4.3 @@ -253,7 +253,6 @@
     4.4  #undef SDL_HAPTIC_XINPUT
     4.5  
     4.6  /* Enable various shared object loading systems */
     4.7 -#undef SDL_LOADSO_HAIKU
     4.8  #undef SDL_LOADSO_DLOPEN
     4.9  #undef SDL_LOADSO_DUMMY
    4.10  #undef SDL_LOADSO_LDG
     5.1 --- a/src/dynapi/SDL_dynapi.c	Sun Oct 30 21:01:46 2016 +0100
     5.2 +++ b/src/dynapi/SDL_dynapi.c	Tue Nov 01 10:30:46 2016 -0700
     5.3 @@ -216,21 +216,7 @@
     5.4      return retval;
     5.5  }
     5.6  
     5.7 -#elif defined(__HAIKU__)
     5.8 -#include <os/kernel/image.h>
     5.9 -static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
    5.10 -{
    5.11 -    image_id lib = load_add_on(fname);
    5.12 -    void *retval = NULL;
    5.13 -    if (lib >= 0) {
    5.14 -        if (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR) {
    5.15 -            unload_add_on(lib);
    5.16 -            retval = NULL;
    5.17 -        }
    5.18 -    }
    5.19 -    return retval;
    5.20 -}
    5.21 -#elif defined(unix) || defined(__unix__) || defined(__APPLE__)
    5.22 +#elif defined(unix) || defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
    5.23  #include <dlfcn.h>
    5.24  static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
    5.25  {
     6.1 --- a/src/loadso/haiku/SDL_sysloadso.c	Sun Oct 30 21:01:46 2016 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,71 +0,0 @@
     6.4 -/*
     6.5 -  Simple DirectMedia Layer
     6.6 -  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     6.7 -
     6.8 -  This software is provided 'as-is', without any express or implied
     6.9 -  warranty.  In no event will the authors be held liable for any damages
    6.10 -  arising from the use of this software.
    6.11 -
    6.12 -  Permission is granted to anyone to use this software for any purpose,
    6.13 -  including commercial applications, and to alter it and redistribute it
    6.14 -  freely, subject to the following restrictions:
    6.15 -
    6.16 -  1. The origin of this software must not be misrepresented; you must not
    6.17 -     claim that you wrote the original software. If you use this software
    6.18 -     in a product, an acknowledgment in the product documentation would be
    6.19 -     appreciated but is not required.
    6.20 -  2. Altered source versions must be plainly marked as such, and must not be
    6.21 -     misrepresented as being the original software.
    6.22 -  3. This notice may not be removed or altered from any source distribution.
    6.23 -*/
    6.24 -#include "../../SDL_internal.h"
    6.25 -
    6.26 -#ifdef SDL_LOADSO_HAIKU
    6.27 -
    6.28 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    6.29 -/* System dependent library loading routines                           */
    6.30 -
    6.31 -#include <stdio.h>
    6.32 -#include <os/kernel/image.h>
    6.33 -
    6.34 -#include "SDL_loadso.h"
    6.35 -
    6.36 -void *
    6.37 -SDL_LoadObject(const char *sofile)
    6.38 -{
    6.39 -    void *handle = NULL;
    6.40 -    image_id library_id = load_add_on(sofile);
    6.41 -    if (library_id < 0) {
    6.42 -        SDL_SetError(strerror((int) library_id));
    6.43 -    } else {
    6.44 -        handle = (void *) (library_id);
    6.45 -    }
    6.46 -    return (handle);
    6.47 -}
    6.48 -
    6.49 -void *
    6.50 -SDL_LoadFunction(void *handle, const char *name)
    6.51 -{
    6.52 -    void *sym = NULL;
    6.53 -    image_id library_id = (image_id) handle;
    6.54 -    status_t rc =
    6.55 -        get_image_symbol(library_id, name, B_SYMBOL_TYPE_TEXT, &sym);
    6.56 -    if (rc != B_NO_ERROR) {
    6.57 -        SDL_SetError(strerror(rc));
    6.58 -    }
    6.59 -    return (sym);
    6.60 -}
    6.61 -
    6.62 -void
    6.63 -SDL_UnloadObject(void *handle)
    6.64 -{
    6.65 -    image_id library_id;
    6.66 -    if (handle != NULL) {
    6.67 -        library_id = (image_id) handle;
    6.68 -        unload_add_on(library_id);
    6.69 -    }
    6.70 -}
    6.71 -
    6.72 -#endif /* SDL_LOADSO_HAIKU */
    6.73 -
    6.74 -/* vi: set ts=4 sw=4 expandtab: */