| 1 |
#include "ffi_platypus_config.h" |
| 2 |
#ifndef HAVE_IV_IS_64 |
| 3 |
/* imported from Math::Int64 0.34 6 December 2014 by PLICEASE */ |
| 4 |
/* |
| 5 |
* perl_math_int64.c - This file is in the public domain |
| 6 |
* Author: Salvador Fandino <[email protected]> |
| 7 |
* |
| 8 |
* Generated on: 2014-10-30 11:43:56 |
| 9 |
* Math::Int64 version: 0.33 |
| 10 |
* Module::CAPIMaker version: 0.02 |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "EXTERN.h" |
| 14 |
#include "perl.h" |
| 15 |
#include "ppport.h" |
| 16 |
|
| 17 |
#ifdef __MINGW32__ |
| 18 |
#include <stdint.h> |
| 19 |
#endif |
| 20 |
|
| 21 |
#ifdef _MSC_VER |
| 22 |
#include <stdlib.h> |
| 23 |
typedef __int64 int64_t; |
| 24 |
typedef unsigned __int64 uint64_t; |
| 25 |
#endif |
| 26 |
|
| 27 |
/* you may need to add a typemap for int64_t here if it is not defined |
| 28 |
by default in your C header files */ |
| 29 |
|
| 30 |
HV *math_int64_c_api_hash; |
| 31 |
int math_int64_c_api_min_version; |
| 32 |
int math_int64_c_api_max_version; |
| 33 |
|
| 34 |
int64_t (*math_int64_c_api_SvI64)(pTHX_ SV*); |
| 35 |
int (*math_int64_c_api_SvI64OK)(pTHX_ SV*); |
| 36 |
uint64_t (*math_int64_c_api_SvU64)(pTHX_ SV*); |
| 37 |
int (*math_int64_c_api_SvU64OK)(pTHX_ SV*); |
| 38 |
SV * (*math_int64_c_api_newSVi64)(pTHX_ int64_t); |
| 39 |
SV * (*math_int64_c_api_newSVu64)(pTHX_ uint64_t); |
| 40 |
uint64_t (*math_int64_c_api_randU64)(pTHX); |
| 41 |
|
| 42 |
int |
| 43 |
perl_math_int64_load(int required_version) { |
| 44 |
dTHX; |
| 45 |
SV **svp; |
| 46 |
eval_pv("require Math::Int64", TRUE); |
| 47 |
if (SvTRUE(ERRSV)) return 0; |
| 48 |
|
| 49 |
math_int64_c_api_hash = get_hv("Math::Int64::C_API", 0); |
| 50 |
if (!math_int64_c_api_hash) { |
| 51 |
sv_setpv(ERRSV, "Unable to load Math::Int64 C API"); |
| 52 |
SvSETMAGIC(ERRSV); |
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
svp = hv_fetch(math_int64_c_api_hash, "min_version", 11, 0); |
| 57 |
if (!svp) svp = hv_fetch(math_int64_c_api_hash, "version", 7, 1); |
| 58 |
if (!svp || !*svp) { |
| 59 |
sv_setpv(ERRSV, "Unable to retrieve C API version for Math::Int64"); |
| 60 |
SvSETMAGIC(ERRSV); |
| 61 |
return 0; |
| 62 |
} |
| 63 |
math_int64_c_api_min_version = SvIV(*svp); |
| 64 |
|
| 65 |
svp = hv_fetch(math_int64_c_api_hash, "max_version", 11, 0); |
| 66 |
if (!svp) svp = hv_fetch(math_int64_c_api_hash, "version", 7, 1); |
| 67 |
if (!svp || !*svp) { |
| 68 |
sv_setpv(ERRSV, "Unable to retrieve C API version for Math::Int64"); |
| 69 |
SvSETMAGIC(ERRSV); |
| 70 |
return 0; |
| 71 |
} |
| 72 |
math_int64_c_api_max_version = SvIV(*svp); |
| 73 |
|
| 74 |
if ((required_version < math_int64_c_api_min_version) || |
| 75 |
(required_version > math_int64_c_api_max_version)) { |
| 76 |
sv_setpvf(ERRSV, |
| 77 |
"Math::Int64 C API version mismatch. " |
| 78 |
"The installed module supports versions %d to %d but %d is required", |
| 79 |
math_int64_c_api_min_version, |
| 80 |
math_int64_c_api_max_version, |
| 81 |
required_version); |
| 82 |
SvSETMAGIC(ERRSV); |
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
svp = hv_fetch(math_int64_c_api_hash, "SvI64", 5, 0); |
| 87 |
if (!svp || !*svp) { |
| 88 |
sv_setpv(ERRSV, "Unable to fetch pointer 'SvI64' C function from Math::Int64"); |
| 89 |
SvSETMAGIC(ERRSV); |
| 90 |
return 0; |
| 91 |
} |
| 92 |
math_int64_c_api_SvI64 = INT2PTR(void *, SvIV(*svp)); |
| 93 |
svp = hv_fetch(math_int64_c_api_hash, "SvI64OK", 7, 0); |
| 94 |
if (!svp || !*svp) { |
| 95 |
sv_setpv(ERRSV, "Unable to fetch pointer 'SvI64OK' C function from Math::Int64"); |
| 96 |
SvSETMAGIC(ERRSV); |
| 97 |
return 0; |
| 98 |
} |
| 99 |
math_int64_c_api_SvI64OK = INT2PTR(void *, SvIV(*svp)); |
| 100 |
svp = hv_fetch(math_int64_c_api_hash, "SvU64", 5, 0); |
| 101 |
if (!svp || !*svp) { |
| 102 |
sv_setpv(ERRSV, "Unable to fetch pointer 'SvU64' C function from Math::Int64"); |
| 103 |
SvSETMAGIC(ERRSV); |
| 104 |
return 0; |
| 105 |
} |
| 106 |
math_int64_c_api_SvU64 = INT2PTR(void *, SvIV(*svp)); |
| 107 |
svp = hv_fetch(math_int64_c_api_hash, "SvU64OK", 7, 0); |
| 108 |
if (!svp || !*svp) { |
| 109 |
sv_setpv(ERRSV, "Unable to fetch pointer 'SvU64OK' C function from Math::Int64"); |
| 110 |
SvSETMAGIC(ERRSV); |
| 111 |
return 0; |
| 112 |
} |
| 113 |
math_int64_c_api_SvU64OK = INT2PTR(void *, SvIV(*svp)); |
| 114 |
svp = hv_fetch(math_int64_c_api_hash, "newSVi64", 8, 0); |
| 115 |
if (!svp || !*svp) { |
| 116 |
sv_setpv(ERRSV, "Unable to fetch pointer 'newSVi64' C function from Math::Int64"); |
| 117 |
SvSETMAGIC(ERRSV); |
| 118 |
return 0; |
| 119 |
} |
| 120 |
math_int64_c_api_newSVi64 = INT2PTR(void *, SvIV(*svp)); |
| 121 |
svp = hv_fetch(math_int64_c_api_hash, "newSVu64", 8, 0); |
| 122 |
if (!svp || !*svp) { |
| 123 |
sv_setpv(ERRSV, "Unable to fetch pointer 'newSVu64' C function from Math::Int64"); |
| 124 |
SvSETMAGIC(ERRSV); |
| 125 |
return 0; |
| 126 |
} |
| 127 |
math_int64_c_api_newSVu64 = INT2PTR(void *, SvIV(*svp)); |
| 128 |
svp = hv_fetch(math_int64_c_api_hash, "randU64", 7, 0); |
| 129 |
if (!svp || !*svp) { |
| 130 |
sv_setpv(ERRSV, "Unable to fetch pointer 'randU64' C function from Math::Int64"); |
| 131 |
SvSETMAGIC(ERRSV); |
| 132 |
return 0; |
| 133 |
} |
| 134 |
math_int64_c_api_randU64 = INT2PTR(void *, SvIV(*svp)); |
| 135 |
|
| 136 |
return 1; |
| 137 |
} |
| 138 |
#endif |