xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 1 | /* ABI compatibility for lgamma functions. |
| 2 | Copyright (C) 2015-2016 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef LGAMMA_COMPAT_H |
| 20 | #define LGAMMA_COMPAT_H 1 |
| 21 | |
| 22 | #include <shlib-compat.h> |
| 23 | |
| 24 | /* XSI POSIX requires lgamma to set signgam, but ISO C does not permit |
| 25 | this. Namespace issues can be avoided if the functions set |
| 26 | __signgam and signgam is a weak alias, but this only works if both |
| 27 | signgam and __signgam were exported from the glibc version the |
| 28 | program was linked against. Before glibc 2.23, lgamma functions |
| 29 | set signgam which was not a weak alias for __signgam, so old |
| 30 | binaries have dynamic symbols for signgam only and the versions of |
| 31 | lgamma used for old binaries must set both signgam and __signgam. |
| 32 | Those versions also do a check of _LIB_VERSION != _ISOC_ to match |
| 33 | old glibc. |
| 34 | |
| 35 | Users of this file define USE_AS_COMPAT to 0 when building the main |
| 36 | version of lgamma, 1 when building the compatibility version. */ |
| 37 | |
| 38 | #define LGAMMA_OLD_VER GLIBC_2_0 |
| 39 | #define LGAMMA_NEW_VER GLIBC_2_23 |
| 40 | #define HAVE_LGAMMA_COMPAT SHLIB_COMPAT (libm, LGAMMA_OLD_VER, LGAMMA_NEW_VER) |
| 41 | |
| 42 | /* Whether to build this version at all. */ |
| 43 | #define BUILD_LGAMMA (HAVE_LGAMMA_COMPAT || !USE_AS_COMPAT) |
| 44 | |
| 45 | /* The name to use for this version. */ |
| 46 | #if USE_AS_COMPAT |
| 47 | # define LGFUNC(FUNC) FUNC ## _compat |
| 48 | #else |
| 49 | # define LGFUNC(FUNC) FUNC |
| 50 | #endif |
| 51 | |
| 52 | /* If there is a compatibility version, gamma (not an ISO C function, |
| 53 | so never a problem for it to set signgam) points directly to it |
| 54 | rather than having separate versions. */ |
| 55 | #define GAMMA_ALIAS (USE_AS_COMPAT ? HAVE_LGAMMA_COMPAT : !HAVE_LGAMMA_COMPAT) |
| 56 | |
| 57 | /* How to call the underlying lgamma_r function. */ |
| 58 | #define CALL_LGAMMA(TYPE, FUNC, ARG) \ |
| 59 | ({ \ |
| 60 | TYPE lgamma_tmp; \ |
| 61 | int local_signgam; \ |
| 62 | if (USE_AS_COMPAT) \ |
| 63 | { \ |
| 64 | lgamma_tmp = FUNC ((ARG), &local_signgam); \ |
| 65 | if (_LIB_VERSION != _ISOC_) \ |
| 66 | signgam = __signgam = local_signgam; \ |
| 67 | } \ |
| 68 | else \ |
| 69 | lgamma_tmp = FUNC ((ARG), &__signgam); \ |
| 70 | lgamma_tmp; \ |
| 71 | }) |
| 72 | |
| 73 | #endif /* lgamma-compat.h. */ |