| 1 |
|
| #define ERRORED (SvTRUE(ERRSV) || !SvPOK(ERRSV)) |
| 2 |
|
| |
| 3 |
|
| /* |
| 4 |
|
| * Instead of creating new stacks, we reuse a given one. So that's why no |
| 5 |
|
| * ENTER/LEAVE |
| 6 |
|
| * |
| 7 |
|
| * We create 2 variable |
| 8 |
|
| * a) if errored and catch exists, before catch and free it after invocation |
| 9 |
|
| * b) if errored(settled by catch or catch doesn't exists), before fin. Make |
| 10 |
|
| * immortal this time because we're going to die either in fin or by croak |
| 11 |
|
| * |
| 12 |
|
| * We set new SP in return it. Why not do it in XS? - Because XS syntax sucks |
| 13 |
|
| */ |
| 14 |
|
| |
| 15 |
0 |
| static inline SV **evo_lib_try(int ax, int items, SV **SP) { |
| 16 |
|
| dTHX; |
| 17 |
|
| |
| 18 |
0 |
▶ | if (items < 2) croak("Bad usage: got %d args", items); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items < 2) croak("Bad usage: got %d args", items); |
0 |
0 |
0 |
|
| 19 |
0 |
| SV *try_sv = ST(0); |
| 20 |
0 |
| SV *catch = ST(1); |
| 21 |
0 |
▶ | SV *fin = items > 2 && SvTRUE(ST(2)) ? ST(2) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *fin = items > 2 && SvTRUE(ST(2)) ? ST(2) : NULL; |
0 |
0 |
0 |
| SV *fin = items > 2 && SvTRUE(ST(2)) ? ST(2) : NULL; |
0 |
0 |
0 |
|
| 22 |
|
| |
| 23 |
|
| // try |
| 24 |
0 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
0 |
0 |
|
| 25 |
0 |
| int count = call_sv(try_sv, GIMME_V | G_EVAL); |
| 26 |
|
| |
| 27 |
0 |
▶ | bool errored = ERRORED; |
Branch: 4 branches
| Branch | True | False | Total |
| bool errored = ERRORED; |
0 |
0 |
0 |
| bool errored = ERRORED; |
0 |
0 |
0 |
| bool errored = ERRORED; |
0 |
0 |
0 |
| bool errored = ERRORED; |
0 |
0 |
0 |
|
| 28 |
|
| |
| 29 |
|
| // catch |
| 30 |
0 |
▶ | if (errored && SvTRUE(catch)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (errored && SvTRUE(catch)) { |
0 |
0 |
0 |
| if (errored && SvTRUE(catch)) { |
0 |
0 |
0 |
|
| 31 |
0 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
0 |
0 |
|
| 32 |
0 |
▶ | SV *tmp_err = newSVsv(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *tmp_err = newSVsv(ERRSV); |
0 |
0 |
0 |
|
| 33 |
0 |
| PUSHs(tmp_err); |
| 34 |
0 |
| PUTBACK; |
| 35 |
0 |
| count = call_sv(catch, GIMME_V | G_EVAL); |
| 36 |
0 |
| SvREFCNT_dec(tmp_err); // because we don't use ENTER..LEAVE |
| 37 |
|
| |
| 38 |
0 |
▶ | errored = ERRORED; |
Branch: 4 branches
| Branch | True | False | Total |
| errored = ERRORED; |
0 |
0 |
0 |
| errored = ERRORED; |
0 |
0 |
0 |
| errored = ERRORED; |
0 |
0 |
0 |
| errored = ERRORED; |
0 |
0 |
0 |
|
| 39 |
|
| } |
| 40 |
|
| // before fin because it can reset ERRSV |
| 41 |
0 |
▶ | SV *err_mcopy = errored ? sv_mortalcopy(ERRSV) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *err_mcopy = errored ? sv_mortalcopy(ERRSV) : NULL; |
0 |
0 |
0 |
| SV *err_mcopy = errored ? sv_mortalcopy(ERRSV) : NULL; |
0 |
0 |
0 |
|
| 42 |
|
| |
| 43 |
0 |
| SPAGAIN; // don't call it until now |
| 44 |
0 |
▶ | if (fin) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fin) { |
0 |
0 |
0 |
|
| 45 |
0 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
0 |
0 |
|
| 46 |
0 |
| call_sv(fin, G_DISCARD | G_NOARGS); |
| 47 |
|
| } |
| 48 |
0 |
▶ | if (err_mcopy) croak_sv(err_mcopy); |
Branch: 1 branch
| Branch | True | False | Total |
| if (err_mcopy) croak_sv(err_mcopy); |
0 |
0 |
0 |
|
| 49 |
|
| |
| 50 |
0 |
| int sp_index = count - 1; |
| 51 |
0 |
| SP = &ST(sp_index); |
| 52 |
|
| |
| 53 |
0 |
| return SP; |
| 54 |
|
| } |