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 "system/macros.h"
29#include "system/mem_alloc.h"
30#include <stdlib.h>
31#ifndef __APPLE__
32#include <stdio.h>
33#include <string.h>
34#else
35#include <dlfcn.h>
36#include <glib.h>
37#endif
38
39#include "system/dynload.h"
40
41
42#ifndef __APPLE__
43/* check if gmodules is supported on this platform */
45{
46 int success = g_module_supported();
47
48 return success;
49}
50
51
52/* dynamically load library */
53dt_gmodule_t *dt_gmodule_open(const char *library)
54{
55 dt_gmodule_t *module = NULL;
56 GModule *gmodule;
57 char *name;
58
59 if(strchr(library, '/') == NULL)
60 {
61 name = g_module_build_path(NULL, library);
62 }
63 else
64 {
65 name = g_strdup(library);
66 }
67
68 gmodule = g_module_open(name, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
69
70 if(!IS_NULL_PTR(gmodule))
71 {
72 module = (dt_gmodule_t *)malloc(sizeof(dt_gmodule_t));
73 module->gmodule = gmodule;
74 module->library = name;
75 }
76 else
78
79 return module;
80}
81
82
83/* get pointer to symbol */
84int dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void (**pointer)(void))
85{
86 int success = g_module_symbol(module->gmodule, name, (gpointer)pointer);
87
88 return success;
89}
90#else
91/* check if gmodules is supported on this platform */
93{
94 return TRUE;
95}
96
97/* dynamically load library */
98dt_gmodule_t *dt_gmodule_open(const char *library)
99{
100 // logic here is simplified since it's used only specifically for OpenCL
101 dt_gmodule_t *module = NULL;
102 void *gmodule = dlopen(library, RTLD_LAZY | RTLD_LOCAL);
103
104 if(!IS_NULL_PTR(gmodule))
105 {
106 module = (dt_gmodule_t *)malloc(sizeof(dt_gmodule_t));
107 module->gmodule = gmodule;
108 module->library = g_strdup(library);
109 }
110
111 return module;
112}
113
114/* get pointer to symbol */
115int dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void (**pointer)(void))
116{
117 *pointer = dlsym(module->gmodule, name);
118
119 return !IS_NULL_PTR(*pointer) ? TRUE : FALSE;
120}
121#endif
122#endif //HAVE_OPENCL
123
124// clang-format off
125// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
126// vim: shiftwidth=2 expandtab tabstop=2 cindent
127// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
128// clang-format on
129
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
int dt_gmodule_symbol(dt_gmodule_t *module, const char *name, void(**pointer)(void))
Definition dynload.c:115
dt_gmodule_t * dt_gmodule_open(const char *library)
Definition dynload.c:98
int dt_gmodule_supported(void)
APPLE
Definition dynload.c:92
#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 macros.h:96
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
const char * name
Definition pdf.h:90
APPLE
Definition dynload.h:40
void * gmodule
Definition dynload.h:44