Permalink
Browse files

Refactor installing op hooks.

  • Loading branch information...
1 parent 58b253d commit b708682add9fb1e9648acd9c09b05278715c766e @ashb committed Aug 8, 2009
Showing with 31 additions and 18 deletions.
  1. +31 −18 TryCatch.xs
View
49 TryCatch.xs
@@ -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

0 comments on commit b708682

Please sign in to comment.