| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| #include "ppport.h" |
| 5 |
|
| #include "ffi_platypus.h" |
| 6 |
|
| #include "ffi_platypus_guts.h" |
| 7 |
|
| |
| 8 |
4 |
| XS(ffi_pl_record_accessor_string_ro) |
| 9 |
|
| { |
| 10 |
|
| ffi_pl_record_member *member; |
| 11 |
|
| SV *self; |
| 12 |
|
| char *ptr1; |
| 13 |
|
| char **ptr2; |
| 14 |
|
| |
| 15 |
4 |
| dVAR; dXSARGS; |
| 16 |
|
| |
| 17 |
4 |
▶ | if(items == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(items == 0) |
0 |
4 |
4 |
|
| 18 |
0 |
| croak("This is a method, you must provide at least the object"); |
| 19 |
|
| |
| 20 |
4 |
| member = (ffi_pl_record_member*) CvXSUBANY(cv).any_ptr; |
| 21 |
|
| |
| 22 |
4 |
| self = ST(0); |
| 23 |
4 |
▶ | if(SvROK(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvROK(self)) |
4 |
0 |
4 |
|
| 24 |
4 |
| self = SvRV(self); |
| 25 |
|
| |
| 26 |
4 |
▶ | if(!SvOK(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvOK(self)) |
0 |
4 |
4 |
|
| 27 |
0 |
| croak("Null record error"); |
| 28 |
|
| |
| 29 |
4 |
| ptr1 = (char*) SvPV_nolen(self); |
| 30 |
4 |
| ptr2 = (char**) &ptr1[member->offset]; |
| 31 |
|
| |
| 32 |
4 |
▶ | if(items > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if(items > 1) |
1 |
3 |
4 |
|
| 33 |
|
| { |
| 34 |
1 |
| croak("member is read only"); |
| 35 |
|
| } |
| 36 |
|
| |
| 37 |
3 |
▶ | if(GIMME_V == G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if(GIMME_V == G_VOID) |
0 |
3 |
3 |
|
| 38 |
0 |
| XSRETURN_EMPTY; |
| 39 |
|
| |
| 40 |
3 |
▶ | if(*ptr2 != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(*ptr2 != NULL) |
1 |
2 |
3 |
|
| 41 |
1 |
| XSRETURN_PV(*ptr2); |
| 42 |
|
| else |
| 43 |
2 |
| XSRETURN_EMPTY; |
| 44 |
|
| } |
| 45 |
|
| |
| 46 |
35 |
| XS(ffi_pl_record_accessor_string_rw) |
| 47 |
|
| { |
| 48 |
|
| ffi_pl_record_member *member; |
| 49 |
|
| SV *self; |
| 50 |
|
| SV *arg; |
| 51 |
|
| char *ptr1; |
| 52 |
|
| char **ptr2; |
| 53 |
|
| char *arg_ptr; |
| 54 |
|
| STRLEN len; |
| 55 |
|
| |
| 56 |
35 |
| dVAR; dXSARGS; |
| 57 |
|
| |
| 58 |
35 |
▶ | if(items == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(items == 0) |
0 |
35 |
35 |
|
| 59 |
0 |
| croak("This is a method, you must provide at least the object"); |
| 60 |
|
| |
| 61 |
35 |
| member = (ffi_pl_record_member*) CvXSUBANY(cv).any_ptr; |
| 62 |
|
| |
| 63 |
35 |
| self = ST(0); |
| 64 |
35 |
▶ | if(SvROK(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvROK(self)) |
35 |
0 |
35 |
|
| 65 |
35 |
| self = SvRV(self); |
| 66 |
|
| |
| 67 |
35 |
▶ | if(!SvOK(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvOK(self)) |
0 |
35 |
35 |
|
| 68 |
0 |
| croak("Null record error"); |
| 69 |
|
| |
| 70 |
35 |
| ptr1 = (char*) SvPV_nolen(self); |
| 71 |
35 |
| ptr2 = (char**) &ptr1[member->offset]; |
| 72 |
|
| |
| 73 |
35 |
▶ | if(items > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if(items > 1) |
22 |
13 |
35 |
|
| 74 |
|
| { |
| 75 |
22 |
▶ | if(SvREADONLY(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvREADONLY(self)) |
2 |
20 |
22 |
|
| 76 |
|
| { |
| 77 |
2 |
| croak("record is read-only"); |
| 78 |
|
| } |
| 79 |
|
| else |
| 80 |
|
| { |
| 81 |
20 |
| arg = ST(1); |
| 82 |
20 |
▶ | if(SvOK(arg)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvOK(arg)) |
10 |
10 |
20 |
|
| 83 |
|
| { |
| 84 |
10 |
| arg_ptr = SvPV(arg, len); |
| 85 |
10 |
| *ptr2 = realloc(*ptr2, len+1); |
| 86 |
10 |
| (*ptr2)[len] = 0; |
| 87 |
10 |
| memcpy(*ptr2, arg_ptr, len); |
| 88 |
|
| } |
| 89 |
10 |
▶ | else if(*ptr2 != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| else if(*ptr2 != NULL) |
10 |
0 |
10 |
|
| 90 |
|
| { |
| 91 |
10 |
| free(*ptr2); |
| 92 |
10 |
| *ptr2 = NULL; |
| 93 |
|
| } |
| 94 |
|
| } |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
33 |
▶ | if(GIMME_V == G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if(GIMME_V == G_VOID) |
20 |
13 |
33 |
|
| 98 |
20 |
| XSRETURN_EMPTY; |
| 99 |
|
| |
| 100 |
13 |
▶ | if(*ptr2 != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(*ptr2 != NULL) |
12 |
1 |
13 |
|
| 101 |
12 |
| XSRETURN_PV(*ptr2); |
| 102 |
|
| else |
| 103 |
1 |
| XSRETURN_EMPTY; |
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
27 |
| XS(ffi_pl_record_accessor_string_fixed) |
| 107 |
|
| { |
| 108 |
|
| ffi_pl_record_member *member; |
| 109 |
|
| SV *self; |
| 110 |
|
| SV *arg; |
| 111 |
|
| SV *value; |
| 112 |
|
| char *ptr1; |
| 113 |
|
| char *ptr2; |
| 114 |
|
| char *arg_ptr; |
| 115 |
|
| STRLEN len; |
| 116 |
|
| |
| 117 |
27 |
| dVAR; dXSARGS; |
| 118 |
|
| |
| 119 |
27 |
▶ | if(items == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(items == 0) |
0 |
27 |
27 |
|
| 120 |
0 |
| croak("This is a method, you must provide at least the object"); |
| 121 |
|
| |
| 122 |
27 |
| member = (ffi_pl_record_member*) CvXSUBANY(cv).any_ptr; |
| 123 |
|
| |
| 124 |
27 |
| self = ST(0); |
| 125 |
27 |
▶ | if(SvROK(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvROK(self)) |
27 |
0 |
27 |
|
| 126 |
27 |
| self = SvRV(self); |
| 127 |
|
| |
| 128 |
27 |
▶ | if(!SvOK(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvOK(self)) |
0 |
27 |
27 |
|
| 129 |
0 |
| croak("Null record error"); |
| 130 |
|
| |
| 131 |
27 |
| ptr1 = (char*) SvPV_nolen(self); |
| 132 |
27 |
| ptr2 = (char*) &ptr1[member->offset]; |
| 133 |
|
| |
| 134 |
27 |
▶ | if(items > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if(items > 1) |
13 |
14 |
27 |
|
| 135 |
|
| { |
| 136 |
13 |
▶ | if(SvREADONLY(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvREADONLY(self)) |
2 |
11 |
13 |
|
| 137 |
|
| { |
| 138 |
2 |
| croak("record is read-only"); |
| 139 |
|
| } |
| 140 |
|
| else |
| 141 |
|
| { |
| 142 |
11 |
| arg = ST(1); |
| 143 |
11 |
▶ | if(SvOK(arg)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvOK(arg)) |
11 |
0 |
11 |
|
| 144 |
|
| { |
| 145 |
11 |
| arg_ptr = SvPV(ST(1), len); |
| 146 |
11 |
▶ | if(len > member->count) |
Branch: 1 branch
| Branch | True | False | Total |
| if(len > member->count) |
1 |
10 |
11 |
|
| 147 |
1 |
| len = member->count; |
| 148 |
11 |
| memcpy(ptr2, arg_ptr, len); |
| 149 |
|
| } |
| 150 |
|
| else |
| 151 |
|
| { |
| 152 |
0 |
| croak("Cannot assign undef to a fixed string field"); |
| 153 |
|
| } |
| 154 |
|
| } |
| 155 |
|
| } |
| 156 |
|
| |
| 157 |
25 |
▶ | if(GIMME_V == G_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if(GIMME_V == G_VOID) |
11 |
14 |
25 |
|
| 158 |
11 |
| XSRETURN_EMPTY; |
| 159 |
|
| |
| 160 |
14 |
| value = sv_newmortal(); |
| 161 |
14 |
| sv_setpvn(value, ptr2, member->count); |
| 162 |
14 |
| ST(0) = value; |
| 163 |
14 |
| XSRETURN(1); |
| 164 |
|
| } |