From 87d9834d063466bf1aed407f62d59a3e644b3696 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 8 May 2015 09:49:49 +0200 Subject: [PATCH] Move dylib.c to libretro-common --- Makefile.common | 2 +- dylib.c | 94 ---------------------- dylib.h | 66 ---------------- dynamic.h | 2 +- frontend/drivers/platform_win32.c | 2 +- gfx/d3d/d3d.cpp | 2 +- griffin/griffin.c | 2 +- input/drivers_hid/btstack_hid.c | 2 +- input/drivers_joypad/xinput_joypad.c | 2 +- libretro-common/dynamic/dylib.c | 100 ++++++++++++++++++++++++ libretro-common/include/dynamic/dylib.h | 72 +++++++++++++++++ tools/retroarch-joyconfig-griffin.c | 2 +- 12 files changed, 180 insertions(+), 168 deletions(-) delete mode 100644 dylib.c delete mode 100644 dylib.h create mode 100644 libretro-common/dynamic/dylib.c create mode 100644 libretro-common/include/dynamic/dylib.h diff --git a/Makefile.common b/Makefile.common index e12f861fc9..d8fa9de101 100644 --- a/Makefile.common +++ b/Makefile.common @@ -124,7 +124,7 @@ OBJ += frontend/frontend.o \ configuration.o \ settings_list.o \ settings.o \ - dylib.o \ + libretro-common/dynamic/dylib.o \ dynamic.o \ dynamic_dummy.o \ libretro-common/queues/message_queue.o \ diff --git a/dylib.c b/dylib.c deleted file mode 100644 index 7fafa584d0..0000000000 --- a/dylib.c +++ /dev/null @@ -1,94 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2015 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include -#include "dylib.h" - -#ifdef NEED_DYNAMIC - -#ifdef _WIN32 -#include -#else -#include -#endif - -/** - * dylib_load: - * @path : Path to libretro core library. - * - * Platform independent dylib loading. - * - * Returns: library handle on success, otherwise NULL. - **/ -dylib_t dylib_load(const char *path) -{ -#ifdef _WIN32 - dylib_t lib = LoadLibrary(path); -#else - dylib_t lib = dlopen(path, RTLD_LAZY); -#endif - return lib; -} - -function_t dylib_proc(dylib_t lib, const char *proc) -{ - function_t sym; - void *ptr_sym = NULL; - - (void)ptr_sym; - -#ifdef _WIN32 - sym = (function_t)GetProcAddress(lib ? - (HMODULE)lib : GetModuleHandle(NULL), proc); -#else - if (lib) - ptr_sym = dlsym(lib, proc); - else - { - void *handle = dlopen(NULL, RTLD_LAZY); - if (handle) - { - ptr_sym = dlsym(handle, proc); - dlclose(handle); - } - } - - /* Dirty hack to workaround the non-legality of - * (void*) -> fn-pointer casts. */ - memcpy(&sym, &ptr_sym, sizeof(void*)); -#endif - - return sym; -} - -/** - * dylib_close: - * @lib : Library handle. - * - * Frees library handle. - **/ -void dylib_close(dylib_t lib) -{ -#ifdef _WIN32 - FreeLibrary((HMODULE)lib); -#else -#ifndef NO_DLCLOSE - dlclose(lib); -#endif -#endif -} - -#endif diff --git a/dylib.h b/dylib.h deleted file mode 100644 index b0219a14a0..0000000000 --- a/dylib.h +++ /dev/null @@ -1,66 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2015 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#ifndef __DYLIB_H -#define __DYLIB_H - -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB) -#define NEED_DYNAMIC -#else -#undef NEED_DYNAMIC -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *dylib_t; -typedef void (*function_t)(void); - -#ifdef NEED_DYNAMIC -/** - * dylib_load: - * @path : Path to libretro core library. - * - * Platform independent dylib loading. - * - * Returns: library handle on success, otherwise NULL. - **/ -dylib_t dylib_load(const char *path); - -/** - * dylib_close: - * @lib : Library handle. - * - * Frees library handle. - **/ -void dylib_close(dylib_t lib); - -function_t dylib_proc(dylib_t lib, const char *proc); -#endif - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/dynamic.h b/dynamic.h index dfd53fd5fe..0b9ac7a138 100644 --- a/dynamic.h +++ b/dynamic.h @@ -24,7 +24,7 @@ #include "config.h" #endif -#include "dylib.h" +#include #ifdef __cplusplus extern "C" { diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c index 641cb779c8..c143d0cb48 100644 --- a/frontend/drivers/platform_win32.c +++ b/frontend/drivers/platform_win32.c @@ -19,7 +19,7 @@ #endif #include #include "../frontend_driver.h" -#include "../../dylib.h" +#include #include "../../general.h" #include diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 26d1943840..805d1f5f63 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -51,7 +51,7 @@ #endif #endif -#include "../../dylib.h" +#include /* forward declarations */ static void d3d_calculate_rect(d3d_video_t *d3d, diff --git a/griffin/griffin.c b/griffin/griffin.c index 4a68920f73..465a666d7e 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -548,7 +548,7 @@ FILTERS /*============================================================ DYNAMIC ============================================================ */ -#include "../dylib.c" +#include "../libretro-common/dynamic/dylib.c" #include "../dynamic.c" #include "../dynamic_dummy.c" #include "../gfx/video_filter.c" diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index 72e7f5a0f5..b6a25c1da6 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -29,7 +29,7 @@ #define BUILDING_BTDYNAMIC #include "btstack_hid.h" -#include "../../dylib.h" +#include #include "../connect/joypad_connection.h" typedef struct btstack_hid diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index df96f582f1..cf0697eb6f 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -24,7 +24,7 @@ #include "../input_autodetect.h" #include "../input_common.h" -#include "../../dylib.h" +#include #include "../../general.h" #include diff --git a/libretro-common/dynamic/dylib.c b/libretro-common/dynamic/dylib.c new file mode 100644 index 0000000000..02d2fbecd5 --- /dev/null +++ b/libretro-common/dynamic/dylib.c @@ -0,0 +1,100 @@ +/* Copyright (C) 2010-2015 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (dylib.c). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#ifdef NEED_DYNAMIC + +#ifdef _WIN32 +#include +#else +#include +#endif + +/** + * dylib_load: + * @path : Path to libretro core library. + * + * Platform independent dylib loading. + * + * Returns: library handle on success, otherwise NULL. + **/ +dylib_t dylib_load(const char *path) +{ +#ifdef _WIN32 + dylib_t lib = LoadLibrary(path); +#else + dylib_t lib = dlopen(path, RTLD_LAZY); +#endif + return lib; +} + +function_t dylib_proc(dylib_t lib, const char *proc) +{ + function_t sym; + void *ptr_sym = NULL; + + (void)ptr_sym; + +#ifdef _WIN32 + sym = (function_t)GetProcAddress(lib ? + (HMODULE)lib : GetModuleHandle(NULL), proc); +#else + if (lib) + ptr_sym = dlsym(lib, proc); + else + { + void *handle = dlopen(NULL, RTLD_LAZY); + if (handle) + { + ptr_sym = dlsym(handle, proc); + dlclose(handle); + } + } + + /* Dirty hack to workaround the non-legality of + * (void*) -> fn-pointer casts. */ + memcpy(&sym, &ptr_sym, sizeof(void*)); +#endif + + return sym; +} + +/** + * dylib_close: + * @lib : Library handle. + * + * Frees library handle. + **/ +void dylib_close(dylib_t lib) +{ +#ifdef _WIN32 + FreeLibrary((HMODULE)lib); +#else +#ifndef NO_DLCLOSE + dlclose(lib); +#endif +#endif +} + +#endif diff --git a/libretro-common/include/dynamic/dylib.h b/libretro-common/include/dynamic/dylib.h new file mode 100644 index 0000000000..bdfeee4988 --- /dev/null +++ b/libretro-common/include/dynamic/dylib.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2010-2015 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (dylib.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __DYLIB_H +#define __DYLIB_H + +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB) +#define NEED_DYNAMIC +#else +#undef NEED_DYNAMIC +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *dylib_t; +typedef void (*function_t)(void); + +#ifdef NEED_DYNAMIC +/** + * dylib_load: + * @path : Path to libretro core library. + * + * Platform independent dylib loading. + * + * Returns: library handle on success, otherwise NULL. + **/ +dylib_t dylib_load(const char *path); + +/** + * dylib_close: + * @lib : Library handle. + * + * Frees library handle. + **/ +void dylib_close(dylib_t lib); + +function_t dylib_proc(dylib_t lib, const char *proc); +#endif + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/tools/retroarch-joyconfig-griffin.c b/tools/retroarch-joyconfig-griffin.c index 0d30a36699..89a13fd033 100644 --- a/tools/retroarch-joyconfig-griffin.c +++ b/tools/retroarch-joyconfig-griffin.c @@ -16,7 +16,7 @@ #include "retroarch-joyconfig.c" -#include "../dylib.c" +#include "../libretro-common/dynamic/dylib.c" #if defined(__linux) && !defined(ANDROID) #include "../input/drivers/linuxraw_input.c"