Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dynload.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2011 Henrik Andersson.
4 Copyright (C) 2011 johannes hanika.
5 Copyright (C) 2011 Ulrich Pegelow.
6 Copyright (C) 2012 Richard Wonka.
7 Copyright (C) 2013-2014, 2016 Tobias Ellinghaus.
8 Copyright (C) 2020 parafin.
9 Copyright (C) 2020 Pascal Obry.
10 Copyright (C) 2022 Martin Baƙinka.
11
12 darktable is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 darktable is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with darktable. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#ifdef HAVE_OPENCL
27
28#include "common/darktable.h"
29#include <stdlib.h>
30#ifndef __APPLE__
31#include <stdio.h>
32#include <string.h>
33#else
34#include <dlfcn.h>
35#include <glib.h>
36#endif
37
38#include "common/dynload.h"
39
40
41#ifndef __APPLE__
42/* check if gmodules is supported on this platform */
44{
45 int success = g_module_supported();
46
47 return success;
48}
49
50
51/* dynamically load library */
52dt_gmodule_t *dt_gmodule_open(const char *library)
53{
54 dt_gmodule_t *module = NULL;
55 GModule *gmodule;
56 char *name;
57
58 if(strchr(library, '/') == NULL)
59 {
60 name = g_module_build_path(NULL, library);
61 }
62 else
63 {
64 name = g_strdup(library);
65 }
66
67 gmodule = g_module_open(name, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
68
69 if(!IS_NULL_PTR(gmodule))
70 {
71 module = (dt_gmodule_t *)malloc(sizeof(dt_gmodule_t));
72 module->gmodule = gmodule;
73 module->library = name;
74 }
75 else
77
78 return module;
79}
80
81
82/* get pointer to symbol */
83int dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void (**pointer)(void))
84{
85 int success = g_module_symbol(module->gmodule, name, (gpointer)pointer);
86
87 return success;
88}
89#else
90/* check if gmodules is supported on this platform */
92{
93 return TRUE;
94}
95
96/* dynamically load library */
97dt_gmodule_t *dt_gmodule_open(const char *library)
98{
99 // logic here is simplified since it's used only specifically for OpenCL
100 dt_gmodule_t *module = NULL;
101 void *gmodule = dlopen(library, RTLD_LAZY | RTLD_LOCAL);
102
103 if(!IS_NULL_PTR(gmodule))
104 {
105 module = (dt_gmodule_t *)malloc(sizeof(dt_gmodule_t));
106 module->gmodule = gmodule;
107 module->library = g_strdup(library);
108 }
109
110 return module;
111}
112
113/* get pointer to symbol */
114int dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void (**pointer)(void))
115{
116 *pointer = dlsym(module->gmodule, name);
117
118 return !IS_NULL_PTR(*pointer) ? TRUE : FALSE;
119}
120#endif
121#endif //HAVE_OPENCL
122
123// clang-format off
124// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
125// vim: shiftwidth=2 expandtab tabstop=2 cindent
126// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
127// clang-format on
128
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
char * name
#define dt_free(ptr)
Definition darktable.h:456
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
int dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void(**pointer)(void))
Definition dynload.c:83
dt_gmodule_t * dt_gmodule_open(const char *library)
Definition dynload.c:52
int dt_gmodule_supported(void)
APPLE
Definition dynload.c:43
APPLE
Definition dynload.h:39
GModule * gmodule
Definition dynload.h:41