Skip to content

Commit

Permalink
Refactor installing op hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashb committed Aug 8, 2009
1 parent 58b253d commit b708682
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions TryCatch.xs
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,46 @@ STATIC OP* check_return (pTHX_ OP *op, void *user_data) {
return op;
}

MODULE = TryCatch PACKAGE = TryCatch::XS

PROTOTYPES: DISABLE

void
install_return_op_check()
CODE:
/* Code stole from Scalar::Util::dualvar */
UV id;
char* file = CopFILE(&PL_compiling);
STRLEN len = strlen(file);
void dualvar_id(SV* sv, UV id) {

ST(0) = newSV(0);
char* file = CopFILE(&PL_compiling);
STRLEN len = strlen(file);

(void)SvUPGRADE(ST(0),SVt_PVNV);
sv_setpvn(ST(0),file,len);
(void)SvUPGRADE(sv,SVt_PVNV);

id = hook_op_check( OP_RETURN, check_return, ST(0) );
sv_setpvn(sv,file,len);
#ifdef SVf_IVisUV
SvUV_set(ST(0), id);
SvIOK_on(ST(0));
SvIsUV_on(ST(0));
SvUV_set(sv, id);
SvIOK_on(sv);
SvIsUV_on(sv);
#else
SvIV_set(ST(0), id);
SvIOK_on(ST(0));
SvIV_set(sv, id);
SvIOK_on(sv);
#endif
}

SV* install_op_check(int op_code, hook_op_ppaddr_cb_t hook_fn) {
SV* ret;
UV id;

ret = newSV(0);

id = hook_op_check( op_code, hook_fn, ret );
dualvar_id(ret, id);

return ret;
}

MODULE = TryCatch PACKAGE = TryCatch::XS

PROTOTYPES: DISABLE

void
install_return_op_check()
CODE:
ST(0) = install_op_check(OP_RETURN, check_return);
XSRETURN(1);

void
Expand Down

0 comments on commit b708682

Please sign in to comment.