| 1 |
#ifndef FFI_PLATYPUS_GUTS_H |
| 2 |
#define FFI_PLATYPUS_GUTS_H |
| 3 |
#ifdef __cplusplus |
| 4 |
extern "C" { |
| 5 |
#endif |
| 6 |
|
| 7 |
void ffi_pl_closure_call(ffi_cif *, void *, void **, void *); |
| 8 |
void ffi_pl_closure_add_data(SV *closure, ffi_pl_closure *closure_data); |
| 9 |
ffi_pl_closure *ffi_pl_closure_get_data(SV *closure, ffi_pl_type *type); |
| 10 |
SV* ffi_pl_custom_perl(SV*,SV*,int); |
| 11 |
void ffi_pl_custom_perl_cb(SV *, SV*, int); |
| 12 |
HV *ffi_pl_get_type_meta(ffi_pl_type *); |
| 13 |
size_t ffi_pl_sizeof(ffi_pl_type *); |
| 14 |
void ffi_pl_perl_to_complex_float(SV *sv, float *ptr); |
| 15 |
void ffi_pl_complex_float_to_perl(SV *sv, float *ptr); |
| 16 |
void ffi_pl_perl_to_complex_double(SV *sv, double *ptr); |
| 17 |
void ffi_pl_complex_double_to_perl(SV *sv, double *ptr); |
| 18 |
|
| 19 |
#define ffi_pl_perl_to_long_double(sv, ptr) \ |
| 20 |
if(!SvOK(sv)) \ |
| 21 |
{ \ |
| 22 |
*(ptr) = 0.0L; \ |
| 23 |
} \ |
| 24 |
else if(sv_isobject(sv) && sv_derived_from(sv, "Math::LongDouble")) \ |
| 25 |
{ \ |
| 26 |
*(ptr) = *INT2PTR(long double *, SvIV((SV*) SvRV(sv))); \ |
| 27 |
} \ |
| 28 |
else \ |
| 29 |
{ \ |
| 30 |
*(ptr) = (long double) SvNV(sv); \ |
| 31 |
} |
| 32 |
|
| 33 |
/* |
| 34 |
* CAVEATS: |
| 35 |
* - We are mucking about with the innerds of Math::LongDouble |
| 36 |
* so if the innerds change we may break Math::LongDouble, |
| 37 |
* FFI::Platypus or both! |
| 38 |
* - This makes Math::LongDouble mutable. Note however, that |
| 39 |
* Math::LongDouble overloads ++ and increments the actual |
| 40 |
* longdouble pointed to in memory, so we are at least not |
| 41 |
* introducing the sin of mutability. See LongDouble.xs |
| 42 |
* C function _overload_inc. |
| 43 |
*/ |
| 44 |
|
| 45 |
#define ffi_pl_long_double_to_perl(sv, ptr) \ |
| 46 |
if(sv_isobject(sv) && sv_derived_from(sv, "Math::LongDouble")) \ |
| 47 |
{ \ |
| 48 |
*INT2PTR(long double *, SvIV((SV*) SvRV(sv))) = *(ptr); \ |
| 49 |
} \ |
| 50 |
else if(MY_CXT.loaded_math_longdouble == 1) \ |
| 51 |
{ \ |
| 52 |
long double *tmp; \ |
| 53 |
Newx(tmp, 1, long double); \ |
| 54 |
*tmp = *(ptr); \ |
| 55 |
sv_setref_pv(sv, "Math::LongDouble", (void*)tmp); \ |
| 56 |
} \ |
| 57 |
else \ |
| 58 |
{ \ |
| 59 |
sv_setnv(sv, *(ptr)); \ |
| 60 |
} |
| 61 |
|
| 62 |
#ifdef __cplusplus |
| 63 |
} |
| 64 |
#endif |
| 65 |
#endif |