mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-20 14:40:10 +00:00
lib_common: move dlopen etc compat to separate src
It is a bit needless to compile the dlerror() commat in a huge number of sources including that file. Moreover, the compat functions are not direcly linked to modules' infrastructure in UG, which was piggy-backed to.
This commit is contained in:
@@ -113,6 +113,7 @@ COMMON_OBJS = \
|
||||
src/capture_filter/none.o \
|
||||
src/capture_filter/split.o \
|
||||
src/compat/alarm.o \
|
||||
src/compat/dlfunc.o \
|
||||
src/compat/drand48.o \
|
||||
src/compat/gettimeofday.o \
|
||||
src/compat/platform_pipe.o \
|
||||
|
||||
59
src/compat/dlfunc.c
Normal file
59
src/compat/dlfunc.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file compat/dlfunc.c
|
||||
* @author Martin Pulec <pulec@cesnet.cz>
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2012-2022 CESNET, z. s. p. o.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, is permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of CESNET nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config_unix.h"
|
||||
#include "config_win32.h"
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include "dlfunc.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
char *dlerror() {
|
||||
_Thread_local static char buf[1024] = "(unknown)";
|
||||
FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, // flags
|
||||
NULL, // lpsource
|
||||
GetLastError(), // message id
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // languageid
|
||||
buf, // output buffer
|
||||
sizeof buf, // size of msgbuf, bytes
|
||||
NULL); // va_list of arguments
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
55
src/compat/dlfunc.h
Normal file
55
src/compat/dlfunc.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @file compat/dlfunc.h
|
||||
* @author Martin Pulec <pulec@cesnet.cz>
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2011-2022 CESNET, z. s. p. o.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, is permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of CESNET nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef COMPAT_DLFUNC_H_08AEAEE7_485F_4969_8FDF_FBC2E4A78713
|
||||
#define COMPAT_DLFUNC_H_08AEAEE7_485F_4969_8FDF_FBC2E4A78713
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "config_common.h" // EXTERN_C
|
||||
#include <windows.h>
|
||||
#define LIB_HANDLE HMODULE
|
||||
#define dlopen(name, flags) LoadLibraryA(name)
|
||||
#define dlsym GetProcAddress
|
||||
#define dlclose FreeLibrary
|
||||
EXTERN_C char *dlerror(void);
|
||||
#else // ! defined _WIN32
|
||||
#include <dlfcn.h>
|
||||
#define LIB_HANDLE void *
|
||||
#endif // defined _WIN32
|
||||
|
||||
#endif // ! defined COMPAT_DLFUNC_H_08AEAEE7_485F_4969_8FDF_FBC2E4A78713
|
||||
|
||||
@@ -10,4 +10,12 @@
|
||||
#undef MAX
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
|
||||
#ifndef EXTERN_C
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN_C extern "C"
|
||||
#else
|
||||
#define EXTERN_C
|
||||
#endif
|
||||
#endif // defined EXTERN_C
|
||||
|
||||
#endif // defined CONFIG_COMMON_H_A4B25A33_74EC_435F_95DD_9738A7A23EA9
|
||||
|
||||
@@ -188,12 +188,4 @@ struct NOT_DEFINED_STRUCT_THAT_SWALLOWS_SEMICOLON
|
||||
#define OPTIMIZED_FOR for
|
||||
#endif
|
||||
|
||||
#ifndef EXTERN_C
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN_C extern "C"
|
||||
#else
|
||||
#define EXTERN_C
|
||||
#endif
|
||||
#endif // defined EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,16 +39,12 @@
|
||||
#ifndef JACK_COMMON_H
|
||||
#define JACK_COMMON_H
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#include <jack/jack.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "compat/dlfunc.h"
|
||||
#include "debug.h"
|
||||
#include "lib_common.h"
|
||||
|
||||
#include "types.h"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @author Martin Pulec <pulec@cesnet.cz>
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2012-2019 CESNET, z. s. p. o.
|
||||
* Copyright (c) 2012-2022 CESNET, z. s. p. o.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @author Martin Pulec <pulec@cesnet.cz>
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2011-2021 CESNET, z. s. p. o.
|
||||
* Copyright (c) 2011-2022 CESNET, z. s. p. o.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,31 +43,6 @@
|
||||
|
||||
#include "host.h" // UNIQUE_LABEL
|
||||
|
||||
#ifdef _WIN32
|
||||
#define LIB_HANDLE HMODULE
|
||||
#define dlopen(name, flags) LoadLibraryA(name)
|
||||
#define dlsym GetProcAddress
|
||||
#define dlclose FreeLibrary
|
||||
#if !defined __cplusplus && !defined thread_local
|
||||
#define thread_local _Thread_local
|
||||
#endif
|
||||
static char *dlerror(void) ATTRIBUTE(unused);
|
||||
|
||||
static char *dlerror(void) {
|
||||
thread_local static char buf[1024] = "(unknown)";
|
||||
FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, // flags
|
||||
NULL, // lpsource
|
||||
GetLastError(), // message id
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // languageid
|
||||
buf, // output buffer
|
||||
sizeof buf, // size of msgbuf, bytes
|
||||
NULL); // va_list of arguments
|
||||
return buf;
|
||||
}
|
||||
#else // ! defined _WIN32
|
||||
#define LIB_HANDLE void *
|
||||
#endif // defined _WIN32
|
||||
|
||||
/** @brief This macro causes that this module will be statically linked with UltraGrid. */
|
||||
#define MK_STATIC(A) A, NULL
|
||||
#define MK_STATIC_REF(A) &A, NULL
|
||||
|
||||
@@ -43,18 +43,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#define NDILIB_CPP_DEFAULT_CONSTRUCTORS 0
|
||||
#include <Processing.NDI.Lib.h>
|
||||
|
||||
#include "compat/dlfunc.h"
|
||||
#include "config_common.h" // MAX
|
||||
#include "debug.h"
|
||||
#include "lib_common.h" // LIB_HANDLE, dlclose/dlerror abstraction
|
||||
#include "utils/color_out.h" // MERGE, TOSTRING
|
||||
#include "utils/misc.h" // MERGE, TOSTRING
|
||||
|
||||
|
||||
@@ -47,11 +47,8 @@
|
||||
#include <xiApi.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#include "debug.h"
|
||||
#include "compat/dlfunc.h"
|
||||
#include "lib_common.h"
|
||||
#include "utils/color_out.h"
|
||||
#include "utils/misc.h"
|
||||
|
||||
Reference in New Issue
Block a user