2015-05-13 22:40:33 -07:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2015 Vincent Torri
|
|
|
|
*
|
|
|
|
* 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_UTIL_H_
|
|
|
|
#define EINA_UTIL_H_
|
|
|
|
|
2016-12-19 12:03:49 -08:00
|
|
|
#include <float.h>
|
2017-01-06 11:18:49 -08:00
|
|
|
#include <math.h>
|
2016-12-19 12:03:49 -08:00
|
|
|
|
2015-05-13 22:40:33 -07:00
|
|
|
/**
|
|
|
|
* @addtogroup Eina_Tools_Group Tools
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Returns the content of the environment referred by HOME on this system.
|
2018-07-12 00:27:15 -07:00
|
|
|
* @return A temporary string to the content referred by HOME on this system.
|
2015-05-13 22:40:33 -07:00
|
|
|
*
|
|
|
|
* @note The result of this call is highly system dependent and you better use
|
|
|
|
* it instead of the naive getenv("HOME").
|
2015-07-23 03:14:21 -07:00
|
|
|
*
|
|
|
|
* @since 1.15
|
2015-05-13 22:40:33 -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_environment_home_get(void);
|
2015-05-13 22:40:33 -07:00
|
|
|
|
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Returns the content of the environment referred as TMPDIR on this system.
|
2018-07-12 00:27:15 -07:00
|
|
|
* @return A temporary string to the content referred by TMPDIR on this system.
|
2015-05-13 22:40:33 -07:00
|
|
|
*
|
|
|
|
* @note The result of this call is highly system dependent and you better use
|
|
|
|
* it instead of the naive getenv("TMPDIR").
|
2015-07-23 03:14:21 -07:00
|
|
|
*
|
|
|
|
* @since 1.15
|
2015-05-13 22:40:33 -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_environment_tmp_get(void);
|
2015-05-13 22:40:33 -07:00
|
|
|
|
2017-01-06 09:57:46 -08:00
|
|
|
/**
|
|
|
|
* @brief Warningless comparison of doubles using ==
|
2018-09-08 04:19:53 -07:00
|
|
|
* @param[in] a First member to compare
|
|
|
|
* @param[in] b Second member to compare
|
2017-01-06 09:57:46 -08:00
|
|
|
*
|
|
|
|
* @return @c true if two doubles match
|
|
|
|
* @since 1.19
|
|
|
|
*/
|
2017-01-06 11:33:20 -08:00
|
|
|
static inline Eina_Bool eina_dbl_exact(double a, double b);
|
2017-01-06 09:57:46 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Warningless comparison of floats using ==
|
2018-09-08 04:19:53 -07:00
|
|
|
* @param[in] a First member to compare
|
|
|
|
* @param[in] b Second member to compare
|
2017-01-06 09:57:46 -08:00
|
|
|
*
|
|
|
|
* @return @c true if two floats match
|
|
|
|
* @since 1.19
|
|
|
|
*/
|
2017-01-06 11:33:20 -08:00
|
|
|
static inline Eina_Bool eina_flt_exact(float a, float b);
|
2017-01-06 09:57:46 -08:00
|
|
|
|
2016-12-19 12:03:49 -08:00
|
|
|
/**
|
|
|
|
* @brief Safe comparison of float
|
2018-09-08 04:19:53 -07:00
|
|
|
* @param[in] a First member to compare
|
|
|
|
* @param[in] b Second member to compare
|
2017-01-06 09:57:46 -08:00
|
|
|
* @since 1.19
|
2016-12-19 12:03:49 -08:00
|
|
|
*
|
|
|
|
* @return @c true if two floats match
|
|
|
|
*/
|
2019-02-28 01:08:23 -08:00
|
|
|
#define EINA_FLT_EQ(a, b) (!!(fabsf((float)(a) - (float)(b)) <= FLT_EPSILON))
|
2016-12-19 12:03:49 -08:00
|
|
|
|
2017-01-06 09:57:46 -08:00
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Determines if a float is not zero
|
2018-09-08 04:19:53 -07:00
|
|
|
* @param[in] a The float
|
2017-01-06 09:57:46 -08:00
|
|
|
*
|
2017-01-06 11:18:49 -08:00
|
|
|
* @return @c true if float is not zero
|
2017-01-06 09:57:46 -08:00
|
|
|
* @since 1.19
|
|
|
|
*/
|
2017-01-06 11:18:49 -08:00
|
|
|
#define EINA_FLT_NONZERO(a) (!!(fpclassify((float)(a)) != FP_ZERO))
|
2017-01-06 09:57:46 -08:00
|
|
|
|
2016-12-19 12:03:49 -08:00
|
|
|
/**
|
|
|
|
* @brief Safe comparison of double
|
2018-09-08 04:19:53 -07:00
|
|
|
* @param[in] a First member to compare
|
|
|
|
* @param[in] b Second member to compare
|
2017-01-06 09:57:46 -08:00
|
|
|
* @since 1.19
|
2016-12-19 12:03:49 -08:00
|
|
|
*
|
|
|
|
* @return @c true if two double match
|
|
|
|
*/
|
2019-02-28 01:08:23 -08:00
|
|
|
#define EINA_DBL_EQ(a, b) (!!(fabs((double)(a) - (double)(b)) <= DBL_EPSILON))
|
2016-12-19 12:03:49 -08:00
|
|
|
|
2017-01-06 09:57:46 -08:00
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Determines if a double is not zero
|
2018-09-08 04:19:53 -07:00
|
|
|
* @param[in] a The double
|
2017-01-06 09:57:46 -08:00
|
|
|
*
|
2017-01-06 11:18:49 -08:00
|
|
|
* @return @c true if double is not zero
|
2017-01-06 09:57:46 -08:00
|
|
|
* @since 1.19
|
|
|
|
*/
|
2017-01-06 11:18:49 -08:00
|
|
|
#define EINA_DBL_NONZERO(a) (!!(fpclassify((double)(a)) != FP_ZERO))
|
2017-01-06 09:57:46 -08:00
|
|
|
|
2016-11-21 18:47:04 -08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2017-01-06 11:33:20 -08:00
|
|
|
#include "eina_inline_util.x"
|
|
|
|
|
2015-05-13 22:40:33 -07:00
|
|
|
#endif
|