| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| MAGIC * |
| 6 |
1 |
| _find_mg(SV* sv) { |
| 7 |
|
| MAGIC *mg; |
| 8 |
1 |
| return mg_find(sv, 'r'); |
| 9 |
|
| } |
| 10 |
|
| |
| 11 |
|
| MODULE = Regexp::Copy PACKAGE = Regexp::Copy |
| 12 |
|
| |
| 13 |
|
| SV* |
| 14 |
|
| re_copy_xs(newre,re) |
| 15 |
|
| SV* newre |
| 16 |
|
| SV* re |
| 17 |
|
| PREINIT: |
| 18 |
|
| SV *sv, *othersv; |
| 19 |
|
| MAGIC *mg; |
| 20 |
1 |
| MGVTBL *vtable = 0; |
| 21 |
|
| CODE: |
| 22 |
1 |
▶ | if (!SvROK(re)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(re)) { |
0 |
1 |
1 |
|
| 23 |
0 |
| croak("re_copy needs a reference"); |
| 24 |
|
| } |
| 25 |
|
| |
| 26 |
1 |
| sv = (SV*) SvRV(re); |
| 27 |
1 |
| othersv = (SV*) SvRV(newre); |
| 28 |
1 |
| mg = _find_mg(othersv); |
| 29 |
|
| |
| 30 |
1 |
▶ | if (mg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg) { |
0 |
1 |
1 |
|
| 31 |
0 |
| mg_free( sv ); |
| 32 |
|
| /* ensure that we are doing the right thing for the |
| 33 |
|
| right version of Perl. 5.8.1 changed behaviour of |
| 34 |
|
| qr// things to have S-magic rather than R-magic. */ |
| 35 |
0 |
▶ | if (SvNV(PL_patchlevel) > 5.008) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvNV(PL_patchlevel) > 5.008) { |
0 |
0 |
0 |
|
| 36 |
0 |
| SvSMAGICAL_on(sv); |
| 37 |
|
| } else { |
| 38 |
0 |
| SvRMAGICAL_on(sv); |
| 39 |
|
| } |
| 40 |
|
| /* copy the magic in mg to sv */ |
| 41 |
0 |
| sv_magicext(sv, mg->mg_obj, 'r', vtable, NULL, 0); |
| 42 |
|
| } else { |
| 43 |
1 |
| croak("no re magic currently set in re"); |
| 44 |
|
| } |
| 45 |
|
| OUTPUT: |
| 46 |
|
| newre |
| 47 |
|
| |