efl/src/lib/eina/eina_convert.h

361 lines
11 KiB
C
Raw Normal View History

/* EINA - EFL data type library
* Copyright (C) 2008 Cedric BAIL, 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_CONVERT_H_
#define EINA_CONVERT_H_
#include "eina_types.h"
#include "eina_error.h"
#include "eina_fp.h"
2011-04-07 04:39:20 -07:00
/**
* @addtogroup Eina_Convert_Group Convert
*
* These functions allow you to convert integer or real numbers to
* string or conversely.
*
* To use these functions, you have to call eina_init()
* first, and eina_shutdown() when eina is not used anymore.
*
* @section Eina_Convert_From_Integer_To_String Conversion from integer to string
2011-04-07 04:39:20 -07:00
*
* To convert an integer to a string in the decimal base,
* eina_convert_itoa() should be used. If the hexadecimal base is
* wanted, eina_convert_xtoa() should be used. They all need a buffer
2011-04-07 04:39:20 -07:00
* sufficiently large to store all the cyphers.
*
* Here is an example of use:
*
* @code
* #include <stdlib.h>
* #include <stdio.h>
*
* #include <Eina.h>
*
* int main(void)
* {
* char tmp[128];
*
* if (!eina_init())
* {
* printf ("Error during the initialization of eina.\n");
* return EXIT_FAILURE;
* }
*
* eina_convert_itoa(45, tmp);
* printf("value: %s\n", tmp);
* eina_convert_xtoa(0xA1, tmp);
* printf("value: %s\n", tmp);
*
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
* @endcode
*
* Compile this code with the following command:
*
* @code
* gcc -Wall -o test_eina_convert test_eina.c `pkg-config --cflags --libs eina`
* @endcode
*
* @note
* The alphabetical cyphers are in lower case.
*
* @section Eina_Convert_Double Conversion double / string
*
* To convert a double to a string, eina_convert_dtoa() should be
* used. Like with the integer functions, a buffer must be used. The
* resulting string has the following format (which is the result
2011-04-07 04:39:20 -07:00
* obtained with snprintf() and the @%a modifier):
*
* @code
* [-]0xh.hhhhhp[+-]e
* @endcode
*
* To convert a string to a double, eina_convert_atod() should be
* used. The format of the string must be as above. Then, the double
* has the following mantissas and exponent:
2011-04-07 04:39:20 -07:00
*
* @code
* mantissa : [-]hhhhhh
2011-04-07 04:39:20 -07:00
* exponent : 2^([+-]e - 4 * n)
* @endcode
*
* with n being number of cyphers after the point in the string
* format. To obtain the double number from the mantissas and exponent,
2011-04-07 04:39:20 -07:00
* use ldexp().
*
* Here is an example of use:
*
* @code
* #include <stdlib.h>
* #include <stdio.h>
* #include <math.h>
*
* #include <Eina.h>
*
* int main(void)
* {
* char tmp[128];
* long long int m = 0;
* long int e = 0;
* double r;
*
* if (!eina_init())
* {
* printf ("Error during the initialization of eina.\n");
* return EXIT_FAILURE;
* }
*
* printf("initial value : 40.56\n");
* eina_convert_dtoa(40.56, tmp);
* printf("result dtoa : %s\n", tmp);
* eina_convert_atod(tmp, 128, &m, &e);
* r = ldexp((double)m, e);
* printf("result atod : %f\n", r);
*
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
* @endcode
*
* Compile this code with the following command:
*
* @code
* gcc -Wall -o test_eina_convert test_eina.c `pkg-config --cflags --libs eina` -lm
* @endcode
*/
/**
* @addtogroup Eina_Tools_Group Tools
*
* @{
*/
/**
* @defgroup Eina_Convert_Group Convert
*
* @{
*/
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 extern Eina_Error EINA_ERROR_CONVERT_P_NOT_FOUND; /**< Not used, perhaps a placeholder? Defined as 0 in eina_convert.c*/
EINA_API extern Eina_Error EINA_ERROR_CONVERT_0X_NOT_FOUND; /**< Not used, perhaps a placeholder? Defined as 0 in eina_convert.c*/
EINA_API extern Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH; /**< Not used, perhaps a placeholder? Defined as 0 in eina_convert.c*/
2011-04-07 04:39:20 -07:00
/**
* @brief Converts an integer number to a string in decimal base.
2011-04-07 04:39:20 -07:00
*
* @param[in] n The integer to convert.
* @param[out] s The buffer to store the converted integer.
* @return The length of the string, including the null terminated
2011-04-07 04:39:20 -07:00
* character.
*
* This function converts @p n to a null terminated string. The
2011-04-07 04:39:20 -07:00
* converted string is in decimal base. As no check is done, @p s must
* be a buffer that is sufficiently large to store the integer.
*
* The returned value is the length of the string, including the null
2011-04-07 04:39:20 -07:00
* terminated character.
*/
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 int eina_convert_itoa(int n, char *s) EINA_ARG_NONNULL(2);
2011-04-07 04:39:20 -07:00
/**
* @brief Converts an integer number to a string in hexadecimal base.
2011-04-07 04:39:20 -07:00
*
* @param[in] n The integer to convert.
* @param[out] s The buffer to store the converted integer.
* @return The length of the string, including the null terminated
2011-04-07 04:39:20 -07:00
* character.
*
* This function converts @p n to a null terminated string. The
2011-04-07 04:39:20 -07:00
* converted string is in hexadecimal base and the alphabetical
* cyphers are in lower case. As no check is done, @p s must be a
* buffer that is sufficiently large to store the integer.
*
* The returned value is the length of the string, including the nul
* terminated character.
*/
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 int eina_convert_xtoa(unsigned int n, char *s) EINA_ARG_NONNULL(2);
2011-04-07 04:39:20 -07:00
/**
* @brief Converts a double to a string.
2011-04-07 04:39:20 -07:00
*
* @param[in] d The double to convert.
* @param[out] des The destination buffer to store the converted double.
2011-04-07 04:39:20 -07:00
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
*
* This function converts the double @p d to a string. The string is
* stored in the buffer pointed by @p des and must be sufficiently
* large to contain the converted double. The returned string is null
2011-04-07 04:39:20 -07:00
* terminated and has the following format:
*
* @code
* [-]0xh.hhhhhp[+-]e
* @endcode
*
* where the h are the hexadecimal cyphers of the mantissas and e the
2011-04-07 04:39:20 -07:00
* exponent (a decimal number).
*
* The returned value is the length of the string, including the null
2011-04-07 04:39:20 -07:00
* character.
*/
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 int eina_convert_dtoa(double d, char *des) EINA_ARG_NONNULL(2);
2011-04-07 04:39:20 -07:00
/**
* @brief Converts a string to a double.
2011-04-07 04:39:20 -07:00
*
* @param[in] src The string to convert.
* @param[in] length The length of the string.
* @param[out] m The mantissa.
* @param[out] e The exponent.
2011-04-07 04:39:20 -07:00
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
*
* This function converts the string @p s of length @p length that
* represent a double in hexadecimal base to a double. It is used to
* replace the use of snprintf() with the \%a modifier, which is
* missing on some platform (like Windows (tm) or OpenBSD).
*
* The string must have the following format:
*
* @code
* [-]0xh.hhhhhp[+-]e
* @endcode
*
* where the h are the hexadecimal cyphers of the mantissas and e the
* exponent (a decimal number). If n is the number of cyphers after the
* point, the returned mantissas and exponents are:
2011-04-07 04:39:20 -07:00
*
* @code
* mantissa : [-]hhhhhh
2011-04-07 04:39:20 -07:00
* exponent : 2^([+-]e - 4 * n)
* @endcode
*
* The mantissas and exponent are stored in the buffers pointed
2011-04-07 04:39:20 -07:00
* respectively by @p m and @p e.
*
* If the string is invalid #EINA_FALSE is returned, otherwise #EINA_TRUE is
2011-04-07 04:39:20 -07:00
* returned.
*/
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_convert_atod(const char *src,
int length,
long long *m,
long *e) EINA_ARG_NONNULL(1, 3, 4);
2011-04-07 04:39:20 -07:00
/**
* @brief Converts a 32.32 fixed point number to a string.
2011-04-07 04:39:20 -07:00
*
* @param[in] fp The fixed point number to convert.
* @param[out] des The destination buffer to store the converted fixed point number.
2011-04-07 04:39:20 -07:00
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
*
* This function converts the 32.32 fixed point number @p fp to a
* string. The string is stored in the buffer pointed by @p des and
* must be sufficiently large to contain the converted fixed point
* number. The returned string is terminated and has the following
* format:
*
* @code
* [-]0xh.hhhhhp[+-]e
* @endcode
*
* where the h are the hexadecimal cyphers of the mantissas and e the
2011-04-07 04:39:20 -07:00
* exponent (a decimal number).
*
* The returned value is the length of the string, including the null
2011-04-07 04:39:20 -07:00
* character.
*
* @note The code is the same than eina_convert_dtoa() except that it
* implements the frexp() function for fixed point numbers and does
* some optimization.
2011-04-07 04:39:20 -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 int eina_convert_fptoa(Eina_F32p32 fp,
char *des) EINA_ARG_NONNULL(2);
2011-04-07 04:39:20 -07:00
/**
* @brief Converts a string to a 32.32 fixed point number.
2011-04-07 04:39:20 -07:00
*
* @param[in] src The string to convert.
* @param[in] length The length of the string.
* @param[out] fp The fixed point number.
2011-04-07 04:39:20 -07:00
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
*
* This function converts the string @p src of length @p length that
* represent a double in hexadecimal base to a 32.32 fixed point
* number stored in @p fp. The function always tries to convert the
* string with eina_convert_atod().
*
* The string must have the following format:
*
* @code
* [-]0xh.hhhhhp[+-]e
* @endcode
*
* where the h's are the hexadecimal cyphers of the mantissas and e the
* exponent (a decimal number). If n is the number of cyphers after the
* point, the returned mantissas and exponents are:
2011-04-07 04:39:20 -07:00
*
* @code
* mantissa : [-]hhhhhh
2011-04-07 04:39:20 -07:00
* exponent : 2^([+-]e - 4 * n)
* @endcode
*
* The mantissas and exponent are stored in the buffers pointed
2011-04-07 04:39:20 -07:00
* respectively by @p m and @p e.
*
* If the string is invalid, #EINA_FALSE is returned,
2011-04-07 04:39:20 -07:00
* otherwise @p fp is computed and #EINA_TRUE is returned.
*
* @note The code uses eina_convert_atod() and do the correct bit
* shift to compute the fixed point number.
*/
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_convert_atofp(const char *src,
int length,
Eina_F32p32 *fp) EINA_ARG_NONNULL(1, 3);
/**
* @brief Converts a string to a floating point number.
*
* @param[in] nptr a string to convert. It shouldn't be NULL.
* @param[out] endptr If @p endptr is not NULL, a pointer to the character after the last
* character used in the conversion is stored in the location referenced
* by endptr. If @p nptr is NULL, this will also be set to NULL.
* @return a double type floating point number.
*
* This function returns converted floating point number with locale-independency.
* Actually, it use "C" locale for strtod_l function internally. If you need strtod
* without locale-dependency, this function can replace strtod.
* For more information, please refer documents of strtod, strtod_l.
*/
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 double eina_convert_strtod_c(const char *nptr, char **endptr);
/**
* @}
*/
/**
* @}
*/
#endif /* EINA_CONVERT_H_ */