| 1 |
|
| /* |
| 2 |
|
| * perl_math_int128.c - This file is in the public domain |
| 3 |
|
| * Author: Salvador Fandino <sfandino@yahoo.com> |
| 4 |
|
| * |
| 5 |
|
| * Generated on: 2012-09-10 13:21:21 |
| 6 |
|
| * Math::Int128 version: 0.06_07 |
| 7 |
|
| * Module::CAPIMaker version: 0.02 |
| 8 |
|
| */ |
| 9 |
|
| |
| 10 |
|
| #include "EXTERN.h" |
| 11 |
|
| #include "perl.h" |
| 12 |
|
| #include "ppport.h" |
| 13 |
|
| |
| 14 |
|
| #if ((LONGSIZE >= 8) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))) |
| 15 |
|
| |
| 16 |
|
| #if ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6)) |
| 17 |
|
| |
| 18 |
|
| /* workaroung for gcc 4.4/4.5 - see http://gcc.gnu.org/gcc-4.4/changes.html */ |
| 19 |
|
| typedef int int128_t __attribute__ ((__mode__ (TI))); |
| 20 |
|
| typedef unsigned int uint128_t __attribute__ ((__mode__ (TI))); |
| 21 |
|
| |
| 22 |
|
| #else |
| 23 |
|
| |
| 24 |
|
| typedef __int128 int128_t; |
| 25 |
|
| typedef unsigned __int128 uint128_t; |
| 26 |
|
| |
| 27 |
|
| #endif |
| 28 |
|
| |
| 29 |
|
| |
| 30 |
|
| HV *math_int128_c_api_hash = NULL; |
| 31 |
|
| int math_int128_c_api_min_version = 0; |
| 32 |
|
| int math_int128_c_api_max_version = 0; |
| 33 |
|
| |
| 34 |
|
| int128_t (*math_int128_c_api_SvI128)(pTHX_ SV *sv) = NULL; |
| 35 |
|
| int (*math_int128_c_api_SvI128OK)(pTHX_ SV*) = NULL; |
| 36 |
|
| int128_t (*math_int128_c_api_SvU128)(pTHX_ SV *sv) = NULL; |
| 37 |
|
| int (*math_int128_c_api_SvU128OK)(pTHX_ SV*) = NULL; |
| 38 |
|
| SV * (*math_int128_c_api_newSVi128)(pTHX_ int128_t i128) = NULL; |
| 39 |
|
| SV * (*math_int128_c_api_newSVu128)(pTHX_ uint128_t u128) = NULL; |
| 40 |
|
| |
| 41 |
|
| int |
| 42 |
0 |
| perl_math_int128_load(int required_version) { |
| 43 |
|
| dTHX; |
| 44 |
|
| SV **svp; |
| 45 |
|
| |
| 46 |
0 |
| eval_pv("require Math::Int128", TRUE); |
| 47 |
0 |
▶ | if (SvTRUE(ERRSV)) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) return 0; |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) return 0; |
0 |
0 |
0 |
|
| 48 |
|
| |
| 49 |
0 |
| math_int128_c_api_hash = get_hv("Math::Int128::C_API", 0); |
| 50 |
0 |
▶ | if (!math_int128_c_api_hash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!math_int128_c_api_hash) { |
0 |
0 |
0 |
|
| 51 |
0 |
▶ | sv_setpv(ERRSV, "Unable to load Math::Int128 C API"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to load Math::Int128 C API"); |
0 |
0 |
0 |
|
| 52 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 53 |
0 |
| return 0; |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
0 |
| math_int128_c_api_min_version = SvIV(*hv_fetch(math_int128_c_api_hash, "min_version", 11, 1)); |
| 57 |
0 |
| math_int128_c_api_max_version = SvIV(*hv_fetch(math_int128_c_api_hash, "max_version", 11, 1)); |
| 58 |
0 |
▶ | if ((required_version < math_int128_c_api_min_version) || |
Branch: 1 branch
| Branch | True | False | Total |
| if ((required_version < math_int128_c_api_min_version) || |
0 |
0 |
0 |
|
| 59 |
0 |
▶ | (required_version > math_int128_c_api_max_version)) { |
Branch: 1 branch
| Branch | True | False | Total |
| (required_version > math_int128_c_api_max_version)) { |
0 |
0 |
0 |
|
| 60 |
0 |
▶ | sv_setpvf(ERRSV, |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpvf(ERRSV, |
0 |
0 |
0 |
|
| 61 |
|
| "Math::Int128 C API version mismatch. " |
| 62 |
|
| "The installed module supports versions %d to %d but %d is required", |
| 63 |
|
| math_int128_c_api_min_version, |
| 64 |
|
| math_int128_c_api_max_version, |
| 65 |
|
| required_version); |
| 66 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 67 |
0 |
| return 0; |
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
0 |
| svp = hv_fetch(math_int128_c_api_hash, "SvI128", 6, 0); |
| 71 |
0 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
0 |
0 |
0 |
| if (!svp || !*svp) { |
0 |
0 |
0 |
|
| 72 |
0 |
▶ | sv_setpv(ERRSV, "Unable to fetch pointer 'SvI128' C function from Math::Int128"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to fetch pointer 'SvI128' C function from Math::Int128"); |
0 |
0 |
0 |
|
| 73 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 74 |
0 |
| return 0; |
| 75 |
|
| } |
| 76 |
0 |
| math_int128_c_api_SvI128 = INT2PTR(void *, SvIV(*svp)); |
| 77 |
0 |
| svp = hv_fetch(math_int128_c_api_hash, "SvI128OK", 8, 0); |
| 78 |
0 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
0 |
0 |
0 |
| if (!svp || !*svp) { |
0 |
0 |
0 |
|
| 79 |
0 |
▶ | sv_setpv(ERRSV, "Unable to fetch pointer 'SvI128OK' C function from Math::Int128"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to fetch pointer 'SvI128OK' C function from Math::Int128"); |
0 |
0 |
0 |
|
| 80 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 81 |
0 |
| return 0; |
| 82 |
|
| } |
| 83 |
0 |
| math_int128_c_api_SvI128OK = INT2PTR(void *, SvIV(*svp)); |
| 84 |
0 |
| svp = hv_fetch(math_int128_c_api_hash, "SvU128", 6, 0); |
| 85 |
0 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
0 |
0 |
0 |
| if (!svp || !*svp) { |
0 |
0 |
0 |
|
| 86 |
0 |
▶ | sv_setpv(ERRSV, "Unable to fetch pointer 'SvU128' C function from Math::Int128"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to fetch pointer 'SvU128' C function from Math::Int128"); |
0 |
0 |
0 |
|
| 87 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 88 |
0 |
| return 0; |
| 89 |
|
| } |
| 90 |
0 |
| math_int128_c_api_SvU128 = INT2PTR(void *, SvIV(*svp)); |
| 91 |
0 |
| svp = hv_fetch(math_int128_c_api_hash, "SvU128OK", 8, 0); |
| 92 |
0 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
0 |
0 |
0 |
| if (!svp || !*svp) { |
0 |
0 |
0 |
|
| 93 |
0 |
▶ | sv_setpv(ERRSV, "Unable to fetch pointer 'SvU128OK' C function from Math::Int128"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to fetch pointer 'SvU128OK' C function from Math::Int128"); |
0 |
0 |
0 |
|
| 94 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 95 |
0 |
| return 0; |
| 96 |
|
| } |
| 97 |
0 |
| math_int128_c_api_SvU128OK = INT2PTR(void *, SvIV(*svp)); |
| 98 |
0 |
| svp = hv_fetch(math_int128_c_api_hash, "newSVi128", 9, 0); |
| 99 |
0 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
0 |
0 |
0 |
| if (!svp || !*svp) { |
0 |
0 |
0 |
|
| 100 |
0 |
▶ | sv_setpv(ERRSV, "Unable to fetch pointer 'newSVi128' C function from Math::Int128"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to fetch pointer 'newSVi128' C function from Math::Int128"); |
0 |
0 |
0 |
|
| 101 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 102 |
0 |
| return 0; |
| 103 |
|
| } |
| 104 |
0 |
| math_int128_c_api_newSVi128 = INT2PTR(void *, SvIV(*svp)); |
| 105 |
0 |
| svp = hv_fetch(math_int128_c_api_hash, "newSVu128", 9, 0); |
| 106 |
0 |
▶ | if (!svp || !*svp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!svp || !*svp) { |
0 |
0 |
0 |
| if (!svp || !*svp) { |
0 |
0 |
0 |
|
| 107 |
0 |
▶ | sv_setpv(ERRSV, "Unable to fetch pointer 'newSVu128' C function from Math::Int128"); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setpv(ERRSV, "Unable to fetch pointer 'newSVu128' C function from Math::Int128"); |
0 |
0 |
0 |
|
| 108 |
0 |
▶ | SvSETMAGIC(ERRSV); |
Branch: 2 branches
| Branch | True | False | Total |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
| SvSETMAGIC(ERRSV); |
0 |
0 |
0 |
|
| 109 |
0 |
| return 0; |
| 110 |
|
| } |
| 111 |
0 |
| math_int128_c_api_newSVu128 = INT2PTR(void *, SvIV(*svp)); |
| 112 |
|
| |
| 113 |
0 |
| return 1; |
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
|
| #else |
| 117 |
|
| |
| 118 |
|
| int |
| 119 |
|
| perl_math_int128_load(int required_version) { |
| 120 |
|
| dTHX; |
| 121 |
|
| sv_setpv(ERRSV, "Unable to load Math::Int128 C API: your compiler does not support 128bit integers"); |
| 122 |
|
| SvSETMAGIC(ERRSV); |
| 123 |
|
| return 0; |
| 124 |
|
| } |
| 125 |
|
| |
| 126 |
|
| #endif |
| 127 |
|
| |
| 128 |
|
| |