2008-08-06 11:15:24 -07:00
|
|
|
/* EINA - EFL data type library
|
2008-09-01 05:42:16 -07:00
|
|
|
* Copyright (C) 2007-2008 Jorge Luis Zapata Muga, Cedric BAIL
|
2008-08-06 11:15:24 -07:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-08-18 01:18:16 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-12-06 08:57:28 -08:00
|
|
|
#include <stdlib.h>
|
2009-08-23 02:18:14 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
2013-01-10 12:25:48 -08:00
|
|
|
#include <libgen.h>
|
2014-01-08 02:46:23 -08:00
|
|
|
#include <unistd.h>
|
2009-08-23 02:18:14 -07:00
|
|
|
|
2015-12-28 05:22:29 -08:00
|
|
|
#if defined HAVE_DLOPEN && ! defined _WIN32
|
2011-08-09 01:39:39 -07:00
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
2008-08-27 23:49:04 -07:00
|
|
|
|
2017-09-22 03:06:10 -07:00
|
|
|
#ifdef _WIN32
|
2019-05-16 10:48:59 -07:00
|
|
|
# include <evil_private.h>
|
2008-11-01 08:39:53 -07:00
|
|
|
#endif
|
|
|
|
|
2009-08-28 05:03:34 -07:00
|
|
|
#include "eina_config.h"
|
|
|
|
#include "eina_private.h"
|
2013-01-03 07:10:34 -08:00
|
|
|
#include "eina_alloca.h"
|
2008-07-30 06:35:49 -07:00
|
|
|
#include "eina_file.h"
|
2009-09-02 16:06:55 -07:00
|
|
|
#include "eina_log.h"
|
2008-07-30 05:46:55 -07:00
|
|
|
|
2009-09-06 15:21:56 -07:00
|
|
|
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
|
|
|
#include "eina_safety_checks.h"
|
|
|
|
#include "eina_module.h"
|
|
|
|
|
2008-07-30 05:46:55 -07:00
|
|
|
/*============================================================================*
|
2010-07-27 19:37:05 -07:00
|
|
|
* Local *
|
|
|
|
*============================================================================*/
|
2008-08-27 23:49:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @cond LOCAL
|
|
|
|
*/
|
|
|
|
|
2009-09-02 16:06:55 -07:00
|
|
|
static int EINA_MODULE_LOG_DOM = -1;
|
2009-09-06 21:23:05 -07:00
|
|
|
#ifdef ERR
|
|
|
|
#undef ERR
|
|
|
|
#endif
|
2009-09-02 16:06:55 -07:00
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(EINA_MODULE_LOG_DOM, __VA_ARGS__)
|
2009-09-06 21:23:05 -07:00
|
|
|
|
|
|
|
#ifdef WRN
|
|
|
|
#undef WRN
|
|
|
|
#endif
|
2009-09-02 16:06:55 -07:00
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(EINA_MODULE_LOG_DOM, __VA_ARGS__)
|
2009-09-06 21:23:05 -07:00
|
|
|
|
2015-05-22 10:20:56 -07:00
|
|
|
#ifdef INF
|
|
|
|
#undef INF
|
|
|
|
#endif
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(EINA_MODULE_LOG_DOM, __VA_ARGS__)
|
|
|
|
|
2009-09-06 21:23:05 -07:00
|
|
|
#ifdef DBG
|
|
|
|
#undef DBG
|
|
|
|
#endif
|
2009-09-02 16:06:55 -07:00
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(EINA_MODULE_LOG_DOM, __VA_ARGS__)
|
|
|
|
|
2008-09-24 05:55:31 -07:00
|
|
|
#define EINA_MODULE_SYMBOL_INIT "__eina_module_init"
|
|
|
|
#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown"
|
2008-08-18 01:18:16 -07:00
|
|
|
|
2008-07-30 05:46:55 -07:00
|
|
|
struct _Eina_Module
|
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
void *handle;
|
|
|
|
int ref;
|
2014-07-11 03:13:02 -07:00
|
|
|
|
|
|
|
Eina_Bool global;
|
|
|
|
|
2014-07-17 16:05:25 -07:00
|
|
|
const char file[1];
|
2008-08-18 01:18:16 -07:00
|
|
|
};
|
|
|
|
|
2008-09-24 05:55:31 -07:00
|
|
|
typedef struct _Dir_List_Get_Cb_Data
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Module_Cb cb;
|
|
|
|
void *data;
|
|
|
|
Eina_Array *array;
|
2008-09-24 05:55:31 -07:00
|
|
|
} Dir_List_Get_Cb_Data;
|
2008-08-18 01:18:16 -07:00
|
|
|
|
2008-09-24 05:55:31 -07:00
|
|
|
typedef struct _Dir_List_Cb_Data
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Module_Cb cb;
|
|
|
|
void *data;
|
2008-09-24 05:55:31 -07:00
|
|
|
} Dir_List_Cb_Data;
|
2008-07-31 09:54:02 -07:00
|
|
|
|
2008-09-24 05:55:31 -07:00
|
|
|
static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Dir_List_Get_Cb_Data *cb_data = data;
|
|
|
|
Eina_Bool ret = EINA_TRUE;
|
|
|
|
|
|
|
|
if (cb_data->cb)
|
2010-07-27 19:37:05 -07:00
|
|
|
ret = cb_data->cb(m, cb_data->data);
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
if (ret)
|
2010-07-27 19:37:05 -07:00
|
|
|
eina_array_push(cb_data->array, m);
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
return ret;
|
2008-07-30 05:46:55 -07:00
|
|
|
}
|
2008-08-18 01:18:16 -07:00
|
|
|
|
2008-09-24 05:55:31 -07:00
|
|
|
static void _dir_list_cb(const char *name, const char *path, void *data)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Dir_List_Cb_Data *cb_data = data;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
length = strlen(name);
|
2010-01-16 08:46:39 -08:00
|
|
|
if (length < sizeof(SHARED_LIB_SUFFIX)) /* x.so */
|
2010-07-27 19:37:05 -07:00
|
|
|
return;
|
|
|
|
|
2010-01-16 08:46:39 -08:00
|
|
|
if (!strcmp(name + length - sizeof(SHARED_LIB_SUFFIX) + 1,
|
2010-07-27 19:37:05 -07:00
|
|
|
SHARED_LIB_SUFFIX))
|
2009-09-02 15:39:41 -07:00
|
|
|
{
|
2010-07-27 19:37:05 -07:00
|
|
|
char *file;
|
|
|
|
Eina_Module *m;
|
|
|
|
|
|
|
|
length = strlen(path) + strlen(name) + 2;
|
2008-08-18 01:18:16 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
file = alloca(sizeof (char) * length);
|
2009-09-02 15:39:41 -07:00
|
|
|
|
2015-08-12 23:14:32 -07:00
|
|
|
snprintf(file, length, "%s" EINA_PATH_SEP_S "%s", path, name);
|
2010-07-27 19:37:05 -07:00
|
|
|
m = eina_module_new(file);
|
|
|
|
if (!m)
|
2010-07-27 20:03:25 -07:00
|
|
|
{
|
|
|
|
return; /* call the user provided cb on this module */
|
|
|
|
|
|
|
|
}
|
2009-09-02 15:39:41 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
if (!cb_data->cb(m, cb_data->data))
|
|
|
|
eina_module_free(m);
|
2009-09-02 15:39:41 -07:00
|
|
|
}
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-01-20 00:29:41 -08:00
|
|
|
|
2010-08-31 23:45:33 -07:00
|
|
|
static void _dir_arch_list_cb(const char *name, const char *path, void *data)
|
2010-08-31 14:19:54 -07:00
|
|
|
{
|
|
|
|
Dir_List_Get_Cb_Data *cb_data = data;
|
|
|
|
Eina_Module *m;
|
2010-09-20 23:51:07 -07:00
|
|
|
char *file = NULL;
|
2010-08-31 14:19:54 -07:00
|
|
|
size_t length;
|
|
|
|
|
|
|
|
length = strlen(path) + 1 + strlen(name) + 1 +
|
|
|
|
strlen((char *)(cb_data->data)) + 1 + sizeof("module") +
|
|
|
|
sizeof(SHARED_LIB_SUFFIX) + 1;
|
|
|
|
|
|
|
|
file = alloca(length);
|
2015-08-12 23:14:32 -07:00
|
|
|
snprintf(file, length, "%s" EINA_PATH_SEP_S "%s" EINA_PATH_SEP_S "%s" EINA_PATH_SEP_S "module" SHARED_LIB_SUFFIX,
|
2010-08-31 14:19:54 -07:00
|
|
|
path, name, (char *)(cb_data->data));
|
|
|
|
m = eina_module_new(file);
|
|
|
|
if (!m)
|
|
|
|
return;
|
|
|
|
|
|
|
|
eina_array_push(cb_data->array, m);
|
|
|
|
}
|
|
|
|
|
2009-01-20 00:29:41 -08:00
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
2009-06-27 23:29:11 -07:00
|
|
|
|
2009-01-20 00:29:41 -08:00
|
|
|
/*============================================================================*
|
2010-07-27 19:37:05 -07:00
|
|
|
* Global *
|
|
|
|
*============================================================================*/
|
2009-01-20 00:29:41 -08:00
|
|
|
|
2009-08-19 00:54:13 -07:00
|
|
|
/**
|
|
|
|
* @cond LOCAL
|
|
|
|
*/
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Error EINA_ERROR_WRONG_MODULE = 0;
|
|
|
|
EINA_API Eina_Error EINA_ERROR_MODULE_INIT_FAILED = 0;
|
2009-08-19 00:54:13 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
2009-06-27 23:29:11 -07:00
|
|
|
/**
|
2009-09-06 15:21:56 -07:00
|
|
|
* @internal
|
|
|
|
* @brief Initialize the module loader module.
|
|
|
|
*
|
|
|
|
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
|
2009-06-27 23:29:11 -07:00
|
|
|
*
|
2009-09-06 15:21:56 -07:00
|
|
|
* This function sets up the module loader module of Eina. It is
|
|
|
|
* called by eina_init().
|
2009-06-27 23:29:11 -07:00
|
|
|
*
|
2013-10-11 00:49:13 -07:00
|
|
|
* This function sets up the module module of Eina.
|
2009-06-27 23:29:11 -07:00
|
|
|
*
|
|
|
|
* @see eina_init()
|
|
|
|
*/
|
2009-09-06 15:21:56 -07:00
|
|
|
Eina_Bool
|
2008-08-18 01:18:16 -07:00
|
|
|
eina_module_init(void)
|
2008-07-30 05:46:55 -07:00
|
|
|
{
|
2009-09-02 16:06:55 -07:00
|
|
|
EINA_MODULE_LOG_DOM = eina_log_domain_register
|
2010-07-27 19:37:05 -07:00
|
|
|
("eina_module", EINA_LOG_COLOR_DEFAULT);
|
2009-09-02 16:06:55 -07:00
|
|
|
if (EINA_MODULE_LOG_DOM < 0)
|
|
|
|
{
|
2010-07-27 19:37:05 -07:00
|
|
|
EINA_LOG_ERR("Could not register log domain: eina_module");
|
|
|
|
return EINA_FALSE;
|
2009-09-02 15:39:41 -07:00
|
|
|
}
|
2009-09-06 15:21:56 -07:00
|
|
|
return EINA_TRUE;
|
2008-07-30 05:46:55 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
2009-06-27 23:29:11 -07:00
|
|
|
/**
|
2009-09-06 15:21:56 -07:00
|
|
|
* @internal
|
|
|
|
* @brief Shut down the module loader module.
|
2009-06-27 23:29:11 -07:00
|
|
|
*
|
2009-09-06 15:21:56 -07:00
|
|
|
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
|
2009-06-27 23:29:11 -07:00
|
|
|
*
|
2009-09-06 15:21:56 -07:00
|
|
|
* This function shuts down the module loader module set up by
|
|
|
|
* eina_module_init(). It is called by eina_shutdown().
|
2009-06-27 23:29:11 -07:00
|
|
|
*
|
|
|
|
* @see eina_shutdown()
|
|
|
|
*/
|
2009-09-06 15:21:56 -07:00
|
|
|
Eina_Bool
|
2008-08-18 01:18:16 -07:00
|
|
|
eina_module_shutdown(void)
|
2008-07-30 05:46:55 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
/* TODO should we store every module when "new" is called and
|
|
|
|
* delete the list of modules here
|
|
|
|
*/
|
2008-09-24 05:55:31 -07:00
|
|
|
|
2009-09-02 16:06:55 -07:00
|
|
|
eina_log_domain_unregister(EINA_MODULE_LOG_DOM);
|
|
|
|
EINA_MODULE_LOG_DOM = -1;
|
2009-09-06 15:21:56 -07:00
|
|
|
return EINA_TRUE;
|
2008-07-30 05:46:55 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
2009-12-27 00:45:30 -08:00
|
|
|
/*============================================================================*
|
2010-07-27 19:37:05 -07:00
|
|
|
* API *
|
|
|
|
*============================================================================*/
|
2009-12-27 00:45:30 -08:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Module *eina_module_new(const char *file)
|
2009-06-27 23:29:11 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Module *m;
|
2009-09-02 16:11:22 -07:00
|
|
|
size_t len;
|
2014-09-30 07:35:45 -07:00
|
|
|
struct stat st;
|
2009-06-27 23:29:11 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
2014-09-30 07:35:45 -07:00
|
|
|
|
|
|
|
/* check that the file exists */
|
|
|
|
if (file[0] == '/' ||
|
|
|
|
file[0] == '.' ||
|
|
|
|
file[0] == '\\' ||
|
|
|
|
(file[0] != '\0' && file[1] == ':' && file[2] == '\\'))
|
|
|
|
{
|
|
|
|
if (stat(file, &st) == -1) return NULL;
|
|
|
|
if (!S_ISREG(st.st_mode)) return NULL;
|
|
|
|
}
|
2009-06-27 23:29:11 -07:00
|
|
|
|
2009-09-02 16:11:22 -07:00
|
|
|
len = strlen(file);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN_VAL(len > 0, NULL);
|
|
|
|
|
|
|
|
m = malloc(sizeof(Eina_Module) + len + 1);
|
2010-07-27 19:37:05 -07:00
|
|
|
if (!m)
|
|
|
|
{
|
|
|
|
ERR("could not malloc(%lu)",
|
|
|
|
(unsigned long)(sizeof(Eina_Module) + len + 1));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-02 16:11:22 -07:00
|
|
|
memcpy((char *)m->file, file, len + 1);
|
2009-09-02 15:39:41 -07:00
|
|
|
m->ref = 0;
|
|
|
|
m->handle = NULL;
|
2014-07-17 16:05:25 -07:00
|
|
|
m->global = EINA_FALSE;
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("m=%p, file=%s", m, file);
|
2009-06-27 23:29:11 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
return m;
|
2009-06-27 23:29:11 -07:00
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Bool eina_module_free(Eina_Module *m)
|
2009-06-27 23:29:11 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
|
|
|
|
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("m=%p, handle=%p, file=%s, refs=%d", m, m->handle, m->file, m->ref);
|
2009-09-02 16:06:55 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
if (m->handle)
|
2010-07-27 19:37:05 -07:00
|
|
|
if (eina_module_unload(m) == EINA_FALSE)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
free(m);
|
|
|
|
return EINA_TRUE;
|
2009-06-27 23:29:11 -07:00
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Bool eina_module_load(Eina_Module *m)
|
2008-09-24 05:55:31 -07:00
|
|
|
{
|
2011-08-09 01:39:39 -07:00
|
|
|
#ifdef HAVE_DLOPEN
|
2009-09-02 15:39:41 -07:00
|
|
|
void *dl_handle;
|
|
|
|
Eina_Module_Init *initcall;
|
2013-08-08 04:18:08 -07:00
|
|
|
int flag = RTLD_NOW;
|
2008-09-24 05:55:31 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
|
2008-12-26 10:31:14 -08:00
|
|
|
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("m=%p, handle=%p, file=%s, refs=%d", m, m->handle, m->file, m->ref);
|
2009-09-02 16:06:55 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
if (m->handle)
|
|
|
|
goto loaded;
|
2008-09-24 05:55:31 -07:00
|
|
|
|
2013-08-08 04:18:08 -07:00
|
|
|
if (getenv("EINA_MODULE_LAZY_LOAD")) flag = RTLD_LAZY;
|
2014-07-11 03:13:02 -07:00
|
|
|
|
|
|
|
if (m->global) flag |= RTLD_GLOBAL;
|
2013-08-08 04:18:08 -07:00
|
|
|
dl_handle = dlopen(m->file, flag);
|
2014-07-11 03:13:02 -07:00
|
|
|
if (m->global) flag &= ~RTLD_GLOBAL;
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
if (!dl_handle)
|
|
|
|
{
|
2015-07-12 22:08:08 -07:00
|
|
|
struct stat st;
|
|
|
|
if (!stat(m->file, &st))
|
2017-08-02 16:16:33 -07:00
|
|
|
ERR("could not dlopen(\"%s\", %s): %s", m->file, dlerror(),
|
2015-07-12 22:08:08 -07:00
|
|
|
(flag == RTLD_NOW) ? "RTLD_NOW" : "RTLD_LAZY");
|
|
|
|
else
|
|
|
|
DBG("could not dlopen(\"%s\", %s): %s", m->file, dlerror(),
|
|
|
|
(flag == RTLD_NOW) ? "RTLD_NOW" : "RTLD_LAZY");
|
2010-07-27 19:37:05 -07:00
|
|
|
return EINA_FALSE;
|
2009-09-02 15:39:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
|
|
|
|
if ((!initcall) || (!(*initcall)))
|
2010-07-27 19:37:05 -07:00
|
|
|
goto ok;
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
if ((*initcall)() == EINA_TRUE)
|
2010-07-27 19:37:05 -07:00
|
|
|
goto ok;
|
2009-09-02 15:39:41 -07:00
|
|
|
|
2015-05-22 10:20:56 -07:00
|
|
|
INF("init function returned false for %s", m->file);
|
2009-09-02 15:39:41 -07:00
|
|
|
dlclose(dl_handle);
|
|
|
|
return EINA_FALSE;
|
2010-07-27 19:37:05 -07:00
|
|
|
ok:
|
2009-09-02 16:06:55 -07:00
|
|
|
DBG("successfully loaded %s", m->file);
|
2009-09-02 15:39:41 -07:00
|
|
|
m->handle = dl_handle;
|
2010-07-27 19:37:05 -07:00
|
|
|
loaded:
|
2009-09-02 15:39:41 -07:00
|
|
|
m->ref++;
|
2009-09-02 16:06:55 -07:00
|
|
|
DBG("ref %d", m->ref);
|
2009-09-02 15:39:41 -07:00
|
|
|
return EINA_TRUE;
|
2011-08-09 01:39:39 -07:00
|
|
|
#else
|
2011-11-17 03:18:12 -08:00
|
|
|
(void) m;
|
2011-08-09 01:39:39 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
#endif
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Bool eina_module_unload(Eina_Module *m)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2011-08-09 01:39:39 -07:00
|
|
|
#ifdef HAVE_DLOPEN
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Module_Shutdown *shut;
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
|
|
|
|
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("m=%p, handle=%p, file=%s, refs=%d", m, m->handle, m->file, m->ref);
|
2009-09-02 16:06:55 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
m->ref--;
|
|
|
|
if (!m->ref)
|
|
|
|
{
|
2010-07-27 19:37:05 -07:00
|
|
|
shut = dlsym(m->handle, EINA_MODULE_SYMBOL_SHUTDOWN);
|
|
|
|
if ((shut) && (*shut))
|
|
|
|
(*shut)();
|
|
|
|
|
|
|
|
dlclose(m->handle);
|
|
|
|
m->handle = NULL;
|
|
|
|
DBG("unloaded module %s", m->file);
|
|
|
|
return EINA_TRUE;
|
2009-09-02 15:39:41 -07:00
|
|
|
}
|
2010-07-27 19:37:05 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
return EINA_FALSE;
|
2011-08-09 01:39:39 -07:00
|
|
|
#else
|
2011-11-17 03:18:12 -08:00
|
|
|
(void) m;
|
2011-08-09 01:39:39 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
#endif
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void *eina_module_symbol_get(const Eina_Module *m, const char *symbol)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2011-08-09 01:39:39 -07:00
|
|
|
#ifdef HAVE_DLOPEN
|
2010-07-27 19:37:05 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
|
2009-09-02 15:39:41 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(m->handle, NULL);
|
|
|
|
return dlsym(m->handle, symbol);
|
2011-08-09 01:39:39 -07:00
|
|
|
#else
|
2011-11-17 03:18:12 -08:00
|
|
|
(void) m;
|
|
|
|
(void) symbol;
|
2011-08-09 01:39:39 -07:00
|
|
|
return NULL;
|
|
|
|
#endif
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API const char *eina_module_file_get(const Eina_Module *m)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
|
|
|
|
return m->file;
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void eina_module_symbol_global_set(Eina_Module *module, Eina_Bool global)
|
2014-07-11 03:13:02 -07:00
|
|
|
{
|
2016-11-07 14:42:51 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(module);
|
2014-07-11 03:13:02 -07:00
|
|
|
module->global = !!global;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API char *eina_module_symbol_path_get(const void *symbol, const char *sub_dir)
|
2008-11-01 08:39:53 -07:00
|
|
|
{
|
|
|
|
#ifdef HAVE_DLADDR
|
2009-09-02 15:39:41 -07:00
|
|
|
Dl_info eina_dl;
|
|
|
|
|
2010-05-28 12:04:44 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(symbol, NULL);
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
if (dladdr(symbol, &eina_dl))
|
2010-10-03 08:08:18 -07:00
|
|
|
{
|
2015-08-12 23:14:32 -07:00
|
|
|
char *pos = strrchr(eina_dl.dli_fname, EINA_PATH_SEP_C);
|
2010-10-03 08:08:18 -07:00
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
int l0;
|
|
|
|
int l1;
|
|
|
|
int l2 = 0;
|
|
|
|
|
|
|
|
l0 = strlen(eina_dl.dli_fname);
|
|
|
|
l1 = strlen(pos);
|
|
|
|
if (sub_dir && (*sub_dir != '\0'))
|
|
|
|
l2 = strlen(sub_dir);
|
|
|
|
|
|
|
|
path = malloc(l0 - l1 + l2 + 1);
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
memcpy(path, eina_dl.dli_fname, l0 - l1);
|
|
|
|
if (sub_dir && (*sub_dir != '\0'))
|
|
|
|
memcpy(path + l0 - l1, sub_dir, l2);
|
|
|
|
|
|
|
|
path[l0 - l1 + l2] = '\0';
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-17 03:18:12 -08:00
|
|
|
#else
|
|
|
|
(void) symbol;
|
|
|
|
(void) sub_dir;
|
2008-11-01 08:39:53 -07:00
|
|
|
#endif /* ! HAVE_DLADDR */
|
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
return NULL;
|
2008-11-01 08:39:53 -07:00
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API char *eina_module_environment_path_get(const char *env,
|
2010-07-27 19:37:05 -07:00
|
|
|
const char *sub_dir)
|
2008-11-01 08:39:53 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
const char *env_dir;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(env, NULL);
|
2014-01-08 05:06:41 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() != geteuid()) return NULL; // if setuid dont use dangerous env
|
|
|
|
#endif
|
2009-09-02 15:39:41 -07:00
|
|
|
env_dir = getenv(env);
|
|
|
|
if (env_dir)
|
|
|
|
{
|
2010-07-27 19:37:05 -07:00
|
|
|
char *path;
|
|
|
|
size_t l1;
|
|
|
|
size_t l2 = 0;
|
|
|
|
|
|
|
|
l1 = strlen(env_dir);
|
|
|
|
if (sub_dir && (*sub_dir != '\0'))
|
|
|
|
l2 = strlen(sub_dir);
|
|
|
|
|
|
|
|
path = (char *)malloc(l1 + l2 + 1);
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
memcpy(path, env_dir, l1);
|
|
|
|
if (sub_dir && (*sub_dir != '\0'))
|
|
|
|
memcpy(path + l1, sub_dir, l2);
|
|
|
|
|
|
|
|
path[l1 + l2] = '\0';
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2009-09-02 15:39:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2008-11-01 08:39:53 -07:00
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Array *eina_module_arch_list_get(Eina_Array *array,
|
2010-07-27 19:37:05 -07:00
|
|
|
const char *path,
|
|
|
|
const char *arch)
|
2010-01-26 07:54:28 -08:00
|
|
|
{
|
|
|
|
Dir_List_Get_Cb_Data list_get_cb_data;
|
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
if ((!path) || (!arch))
|
|
|
|
return array;
|
2010-01-26 07:54:28 -08:00
|
|
|
|
|
|
|
list_get_cb_data.array = array ? array : eina_array_new(4);
|
|
|
|
list_get_cb_data.cb = NULL;
|
|
|
|
list_get_cb_data.data = (void *)arch;
|
|
|
|
|
2017-10-29 05:38:37 -07:00
|
|
|
eina_file_dir_list(path, EINA_FALSE, &_dir_arch_list_cb, &list_get_cb_data);
|
2010-01-26 07:54:28 -08:00
|
|
|
|
|
|
|
return list_get_cb_data.array;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Array *eina_module_list_get(Eina_Array *array,
|
2010-07-27 19:37:05 -07:00
|
|
|
const char *path,
|
2010-09-01 15:31:43 -07:00
|
|
|
Eina_Bool recursive,
|
2010-07-27 19:37:05 -07:00
|
|
|
Eina_Module_Cb cb,
|
|
|
|
void *data)
|
2008-09-24 05:55:31 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Dir_List_Get_Cb_Data list_get_cb_data;
|
|
|
|
Dir_List_Cb_Data list_cb_data;
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2010-07-27 19:37:05 -07:00
|
|
|
if (!path)
|
|
|
|
return array;
|
2008-09-24 05:55:31 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
list_get_cb_data.array = array ? array : eina_array_new(4);
|
|
|
|
list_get_cb_data.cb = cb;
|
|
|
|
list_get_cb_data.data = data;
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
list_cb_data.cb = &_dir_list_get_cb;
|
|
|
|
list_cb_data.data = &list_get_cb_data;
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
eina_file_dir_list(path, recursive, &_dir_list_cb, &list_cb_data);
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
return list_get_cb_data.array;
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API Eina_Module *
|
2010-08-10 05:05:51 -07:00
|
|
|
eina_module_find(const Eina_Array *array, const char *module)
|
2009-11-20 12:46:24 -08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
Eina_Array_Iterator iterator;
|
|
|
|
Eina_Module *m;
|
|
|
|
|
2010-08-11 07:32:30 -07:00
|
|
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
2010-08-09 20:26:15 -07:00
|
|
|
{
|
|
|
|
char *file_m;
|
|
|
|
char *tmp;
|
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
/* basename() can modify its argument, so we first get a copie */
|
|
|
|
/* do not use strdupa, as opensolaris does not have it */
|
|
|
|
len = strlen(eina_module_file_get(m));
|
|
|
|
tmp = alloca(len + 1);
|
|
|
|
memcpy(tmp, eina_module_file_get(m), len + 1);
|
|
|
|
file_m = basename(tmp);
|
|
|
|
len = strlen(file_m);
|
|
|
|
len -= sizeof(SHARED_LIB_SUFFIX) - 1;
|
|
|
|
if (len <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!strncmp(module, file_m, len))
|
2013-06-20 04:08:36 -07:00
|
|
|
return m;
|
2010-08-09 20:26:15 -07:00
|
|
|
}
|
2009-11-20 12:46:24 -08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void eina_module_list_load(Eina_Array *array)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Array_Iterator iterator;
|
|
|
|
Eina_Module *m;
|
|
|
|
unsigned int i;
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2018-01-26 12:29:03 -08:00
|
|
|
if (!array) return;
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("array %p, count %u", array, array->count);
|
2010-08-11 07:32:30 -07:00
|
|
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
2016-08-08 02:25:32 -07:00
|
|
|
{
|
|
|
|
if (!eina_module_load(m))
|
|
|
|
DBG("Cannot load module %s", m->file);
|
|
|
|
}
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void eina_module_list_unload(Eina_Array *array)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Array_Iterator iterator;
|
|
|
|
Eina_Module *m;
|
|
|
|
unsigned int i;
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2018-01-26 12:29:03 -08:00
|
|
|
if (!array) return;
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("array %p, count %u", array, array->count);
|
2010-08-11 07:32:30 -07:00
|
|
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
2010-08-09 20:26:15 -07:00
|
|
|
eina_module_unload(m);
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|
2009-06-22 13:03:58 -07:00
|
|
|
|
eina: Rename EAPI macro to EINA_API in Eina library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: jptiz, lucas, woohyun, vtorri, raster
Reviewed By: jptiz, lucas, vtorri
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
|
|
|
EINA_API void eina_module_list_free(Eina_Array *array)
|
2008-08-18 01:18:16 -07:00
|
|
|
{
|
2009-09-02 15:39:41 -07:00
|
|
|
Eina_Array_Iterator iterator;
|
|
|
|
Eina_Module *m;
|
|
|
|
unsigned int i;
|
2008-09-29 06:28:42 -07:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(array);
|
2009-09-02 18:39:45 -07:00
|
|
|
DBG("array %p, count %u", array, array->count);
|
2010-08-11 07:32:30 -07:00
|
|
|
EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
|
2010-08-09 20:26:15 -07:00
|
|
|
eina_module_free(m);
|
2009-02-17 04:58:09 -08:00
|
|
|
|
2009-09-02 15:39:41 -07:00
|
|
|
eina_array_flush(array);
|
2008-08-18 01:18:16 -07:00
|
|
|
}
|