plastimatch
Loading...
Searching...
No Matches
delayload_legacy.h
Go to the documentation of this file.
1/* -----------------------------------------------------------------------
2 See COPYRIGHT.TXT and LICENSE.TXT for copyright and license information
3 ----------------------------------------------------------------------- */
4#ifndef _delayload_legacy_h_
5#define _delayload_legacy_h_
6
7#include "plmsys_config.h"
8#ifndef _WIN32
9#include <dlfcn.h>
10#endif
11#include <stdlib.h>
12
13// Needed for delay loading windows DLLs
14#if _MSC_VER
15 #pragma comment(lib, "delayimp")
16 #pragma comment(lib, "user32")
17#endif
18
19// JAS 2010.11.23
20// ------------------------------------------------------------
21// Because these macros contain declarations, their
22// usage is restricted under C89. C89-GNU, C99, and
23// C++ are all cool with using these macros pretty
24// much anywhere... be careful inside switch statements.
25// Still, their usage will determine the portability of
26// plastimatch.
27
28// Note: if you attempt to load a library that
29// does not exist or cannot be found, this
30// returns a null pointer.
31#if !defined(_WIN32) && defined(PLM_USE_GPU_PLUGINS)
32 #define LOAD_LIBRARY(lib) \
33 void* lib = dlopen_ex (#lib".so");
34#else
35 #define LOAD_LIBRARY(lib) \
36 ;
37#endif
38
39// Note: if lib contains a null pointer here
40// (see above note), this will return a
41// null function pointer. Be careful pls.
42#if !defined(_WIN32) && defined(PLM_USE_GPU_PLUGINS)
43 #define LOAD_SYMBOL(sym, lib) \
44 sym##_##t* sym = (sym##_##t*) dlsym (lib, #sym);
45#else
46 #define LOAD_SYMBOL(sym, lib) \
47 ;
48#endif
49
50// ------------------------------------------------------------
51
52
53// JAS 2012.03.29
54// ------------------------------------------------------------
55// Now that plastimatch is officially C++, we can now safely
56// define this macro, which reduces programmer error. This
57// should be used instead of LOAD_LIBRARY
58#if !defined(_WIN32) && defined(PLM_USE_GPU_PLUGINS)
59 #define LOAD_LIBRARY_SAFE(lib) \
60 if (!delayload_##lib()) { exit (0); } \
61 void* lib = dlopen_ex (#lib".so");
62#else
63 #define LOAD_LIBRARY_SAFE(lib) \
64 if (!delayload_##lib()) { exit (0); } \
65 ;
66#endif
67
68// JAS 2010.12.09
69// Despite what the man pages say, dlclose()ing NULL
70// was resulting in segfaults! So, now we check 1st.
71#if !defined(_WIN32) && defined(PLM_USE_GPU_PLUGINS)
72 #define UNLOAD_LIBRARY(lib) \
73 if (lib != NULL) { \
74 dlclose (lib); \
75 }
76#else
77 #define UNLOAD_LIBRARY(lib) \
78 ;
79#endif
80
81#define DELAYLOAD_WRAP(f, ...) \
82 f (__VA_ARGS__); typedef f##_t(__VA_ARGS__);
83
88PLMSYS_C_API void* dlopen_ex (const char* lib);
89
90#endif
EXTERNC int delayload_libplmcuda(void)
Definition: cuda_delayload.cxx:194
EXTERNC int delayload_libplmreconstructcuda(void)
Definition: cuda_delayload.cxx:200
EXTERNC int delayload_libplmregistercuda(void)
Definition: cuda_delayload.cxx:207
EXTERNC int delayload_libplmopencl(void)
Definition: cuda_delayload.cxx:215
EXTERNC void * dlopen_ex(const char *lib)
Definition: cuda_delayload.cxx:64
#define PLMSYS_C_API
Definition: plmsys_config.h:18