efl/src/lib/eina/eina_inline_modinfo.x

66 lines
2.1 KiB
Plaintext
Raw Normal View History

/* EINA - EFL data type library
* Copyright (C) 2016 Amitesh Singh
*
* 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/>.
*/
#ifndef EINA_INLINE_MODINFO_X_
#define EINA_INLINE_MODINFO_X_
#define __EINA_MODINFO_CONCAT(a, b) a##b
#define _EINA_MODINFO_CONCAT(a, b) __EINA_MODINFO_CONCAT(a, b)
#define __EINA_MODULE_UNIQUE_ID(id) _EINA_MODINFO_CONCAT(__EINA_MODULE_UNIQUE_ID_, id)
#define _EINA_MODINFO(name, info) \
eina: Use EXPORTAPI for macro EINA_MODINFO The EINA_MODINFO must export the symbols in the current module, and it is not used for importing symbols so we can use EXPORTAPI to export without needing to know what is being built. Patch from a series of patches to rename EAPI symbols to specific library DSOs. = The Rationale = This patch is 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 LIBAPI is the only solution that works for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
2020-12-14 08:09:36 -08:00
EXPORTAPI const char __EINA_MODULE_UNIQUE_ID(name)[] \
__attribute__((__used__)) __attribute__((unused, aligned(1))) = info;
#define EINA_MODINFO(tag, info) _EINA_MODINFO(tag, info)
/**
* @ingroup Eina_Module_Group
*
* This macro is used for defining license.
*
*/
#define EINA_MODULE_LICENSE(_license) EINA_MODINFO(license, _license)
/**
* @ingroup Eina_Module_Group
*
* This macro is used for defining author
* Use "name <email>" or just "name"
* for multiple authors, use multiple lines like below
@code{.c}
EINA_MODULE_AUTHOR("Author 1 <author1.email>\n"
"Author 2 <author2.email>");
@endcode
*/
#define EINA_MODULE_AUTHOR(_author) EINA_MODINFO(author, _author)
/**
* @ingroup Eina_Module_Group
*
* This macro is used for defining version.
*/
#define EINA_MODULE_VERSION(_ver) EINA_MODINFO(ver, _ver)
/**
* @ingroup Eina_Module_Group
*
* This macro is used for defining description.
* Explain what your module does.
*/
#define EINA_MODULE_DESCRIPTION(_desc) EINA_MODINFO(desc, _desc)
#endif