| 1 |
MODULE = FFI::Platypus PACKAGE = FFI::Platypus::Record |
| 2 |
|
| 3 |
int |
| 4 |
_ffi_record_ro(self) |
| 5 |
SV* self |
| 6 |
CODE: |
| 7 |
if(SvROK(self)) |
| 8 |
self = SvRV(self); |
| 9 |
if(!SvOK(self)) |
| 10 |
croak("Null record error"); |
| 11 |
RETVAL = SvREADONLY(self) ? 1 : 0; |
| 12 |
OUTPUT: |
| 13 |
RETVAL |
| 14 |
|
| 15 |
void |
| 16 |
_accessor(perl_name, path_name, type, offset) |
| 17 |
const char *perl_name |
| 18 |
ffi_pl_string path_name; |
| 19 |
ffi_pl_type *type |
| 20 |
int offset |
| 21 |
PROTOTYPE: $$$$ |
| 22 |
PREINIT: |
| 23 |
ffi_pl_record_member *member; |
| 24 |
CV *cv; |
| 25 |
void *function=NULL; |
| 26 |
/* not the correct prototype */ |
| 27 |
extern void ffi_pl_record_accessor_uint8(); |
| 28 |
extern void ffi_pl_record_accessor_uint16(); |
| 29 |
extern void ffi_pl_record_accessor_uint32(); |
| 30 |
extern void ffi_pl_record_accessor_uint64(); |
| 31 |
extern void ffi_pl_record_accessor_sint8(); |
| 32 |
extern void ffi_pl_record_accessor_sint16(); |
| 33 |
extern void ffi_pl_record_accessor_sint32(); |
| 34 |
extern void ffi_pl_record_accessor_sint64(); |
| 35 |
extern void ffi_pl_record_accessor_float(); |
| 36 |
extern void ffi_pl_record_accessor_double(); |
| 37 |
extern void ffi_pl_record_accessor_opaque(); |
| 38 |
extern void ffi_pl_record_accessor_uint8_array(); |
| 39 |
extern void ffi_pl_record_accessor_uint16_array(); |
| 40 |
extern void ffi_pl_record_accessor_uint32_array(); |
| 41 |
extern void ffi_pl_record_accessor_uint64_array(); |
| 42 |
extern void ffi_pl_record_accessor_sint8_array(); |
| 43 |
extern void ffi_pl_record_accessor_sint16_array(); |
| 44 |
extern void ffi_pl_record_accessor_sint32_array(); |
| 45 |
extern void ffi_pl_record_accessor_sint64_array(); |
| 46 |
extern void ffi_pl_record_accessor_float_array(); |
| 47 |
extern void ffi_pl_record_accessor_double_array(); |
| 48 |
extern void ffi_pl_record_accessor_opaque_array(); |
| 49 |
extern void ffi_pl_record_accessor_string_ro(); |
| 50 |
extern void ffi_pl_record_accessor_string_rw(); |
| 51 |
extern void ffi_pl_record_accessor_string_fixed(); |
| 52 |
CODE: |
| 53 |
Newx(member, 1, ffi_pl_record_member); |
| 54 |
member->offset = offset; |
| 55 |
|
| 56 |
switch(type->type_code & FFI_PL_SHAPE_MASK) |
| 57 |
{ |
| 58 |
case FFI_PL_SHAPE_ARRAY: |
| 59 |
member->count = type->extra[0].array.element_count; |
| 60 |
break; |
| 61 |
default: |
| 62 |
member->count = 1; |
| 63 |
break; |
| 64 |
} |
| 65 |
|
| 66 |
switch(type->type_code) |
| 67 |
{ |
| 68 |
case FFI_PL_TYPE_UINT8: |
| 69 |
function = ffi_pl_record_accessor_uint8; |
| 70 |
break; |
| 71 |
case FFI_PL_TYPE_SINT8: |
| 72 |
function = ffi_pl_record_accessor_sint8; |
| 73 |
break; |
| 74 |
case FFI_PL_TYPE_UINT16: |
| 75 |
function = ffi_pl_record_accessor_uint16; |
| 76 |
break; |
| 77 |
case FFI_PL_TYPE_SINT16: |
| 78 |
function = ffi_pl_record_accessor_sint16; |
| 79 |
break; |
| 80 |
case FFI_PL_TYPE_UINT32: |
| 81 |
function = ffi_pl_record_accessor_uint32; |
| 82 |
break; |
| 83 |
case FFI_PL_TYPE_SINT32: |
| 84 |
function = ffi_pl_record_accessor_sint32; |
| 85 |
break; |
| 86 |
case FFI_PL_TYPE_UINT64: |
| 87 |
function = ffi_pl_record_accessor_uint64; |
| 88 |
break; |
| 89 |
case FFI_PL_TYPE_SINT64: |
| 90 |
function = ffi_pl_record_accessor_sint64; |
| 91 |
break; |
| 92 |
case FFI_PL_TYPE_FLOAT: |
| 93 |
function = ffi_pl_record_accessor_float; |
| 94 |
break; |
| 95 |
case FFI_PL_TYPE_DOUBLE: |
| 96 |
function = ffi_pl_record_accessor_double; |
| 97 |
break; |
| 98 |
case FFI_PL_TYPE_OPAQUE: |
| 99 |
function = ffi_pl_record_accessor_opaque; |
| 100 |
break; |
| 101 |
case FFI_PL_TYPE_STRING: |
| 102 |
switch(type->sub_type) |
| 103 |
{ |
| 104 |
case FFI_PL_TYPE_STRING_RO: |
| 105 |
member->count = 1; |
| 106 |
function = ffi_pl_record_accessor_string_ro; |
| 107 |
break; |
| 108 |
case FFI_PL_TYPE_STRING_RW: |
| 109 |
member->count = 1; |
| 110 |
function = ffi_pl_record_accessor_string_rw; |
| 111 |
break; |
| 112 |
} |
| 113 |
break; |
| 114 |
case FFI_PL_TYPE_UINT8 | FFI_PL_SHAPE_ARRAY: |
| 115 |
function = ffi_pl_record_accessor_uint8_array; |
| 116 |
break; |
| 117 |
case FFI_PL_TYPE_SINT8 | FFI_PL_SHAPE_ARRAY: |
| 118 |
function = ffi_pl_record_accessor_sint8_array; |
| 119 |
break; |
| 120 |
case FFI_PL_TYPE_UINT16 | FFI_PL_SHAPE_ARRAY: |
| 121 |
function = ffi_pl_record_accessor_uint16_array; |
| 122 |
break; |
| 123 |
case FFI_PL_TYPE_SINT16 | FFI_PL_SHAPE_ARRAY: |
| 124 |
function = ffi_pl_record_accessor_sint16_array; |
| 125 |
break; |
| 126 |
case FFI_PL_TYPE_UINT32 | FFI_PL_SHAPE_ARRAY: |
| 127 |
function = ffi_pl_record_accessor_uint32_array; |
| 128 |
break; |
| 129 |
case FFI_PL_TYPE_SINT32 | FFI_PL_SHAPE_ARRAY: |
| 130 |
function = ffi_pl_record_accessor_sint32_array; |
| 131 |
break; |
| 132 |
case FFI_PL_TYPE_UINT64 | FFI_PL_SHAPE_ARRAY: |
| 133 |
function = ffi_pl_record_accessor_uint64_array; |
| 134 |
break; |
| 135 |
case FFI_PL_TYPE_SINT64 | FFI_PL_SHAPE_ARRAY: |
| 136 |
function = ffi_pl_record_accessor_sint64_array; |
| 137 |
break; |
| 138 |
case FFI_PL_TYPE_FLOAT | FFI_PL_SHAPE_ARRAY: |
| 139 |
function = ffi_pl_record_accessor_float_array; |
| 140 |
break; |
| 141 |
case FFI_PL_TYPE_DOUBLE | FFI_PL_SHAPE_ARRAY: |
| 142 |
function = ffi_pl_record_accessor_double_array; |
| 143 |
break; |
| 144 |
case FFI_PL_TYPE_OPAQUE | FFI_PL_SHAPE_ARRAY: |
| 145 |
function = ffi_pl_record_accessor_opaque_array; |
| 146 |
break; |
| 147 |
case FFI_PL_TYPE_RECORD: |
| 148 |
member->count = type->extra[0].record.size; |
| 149 |
function = ffi_pl_record_accessor_string_fixed; |
| 150 |
break; |
| 151 |
default: |
| 152 |
Safefree(member); |
| 153 |
XSRETURN_PV("type not supported"); |
| 154 |
break; |
| 155 |
} |
| 156 |
|
| 157 |
if(path_name == NULL) |
| 158 |
path_name = "unknown"; |
| 159 |
|
| 160 |
/* |
| 161 |
* this ifdef is needed for Perl 5.8.8 support. |
| 162 |
* once we don't need to support 5.8.8 we can |
| 163 |
* remove this workaround (the ndef'd branch) |
| 164 |
*/ |
| 165 |
#ifdef newXS_flags |
| 166 |
cv = newXSproto(perl_name, function, path_name, "$;$"); |
| 167 |
#else |
| 168 |
newXSproto(perl_name, function, path_name, "$;$"); |
| 169 |
cv = get_cv(perl_name,0); |
| 170 |
#endif |
| 171 |
|
| 172 |
CvXSUBANY(cv).any_ptr = (void*) member; |
| 173 |
XSRETURN_EMPTY; |
| 174 |
|