This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Glob.xs: PL_opfreehook is an interpreter variable
[perl5.git] / ext / File-Glob / Glob.xs
index 50bb2da..ea8930c 100644 (file)
@@ -11,6 +11,7 @@
 typedef struct {
     int                x_GLOB_ERROR;
     HV *       x_GLOB_ENTRIES;
+    Perl_ophook_t      x_GLOB_OLD_OPHOOK;
 } my_cxt_t;
 
 START_MY_CXT
@@ -312,6 +313,17 @@ doglob_iter_wrapper(pTHX_ AV *entries, SV *patsv)
     return FALSE;
 }
 
+static void
+glob_ophook(pTHX_ OP *o)
+{
+    dMY_CXT;
+    if (MY_CXT.x_GLOB_ENTRIES
+     && (o->op_type == OP_GLOB || o->op_type == OP_ENTERSUB))
+       hv_delete(MY_CXT.x_GLOB_ENTRIES, (char *)&o, sizeof(OP *),
+                 G_DISCARD);
+    if (MY_CXT.x_GLOB_OLD_OPHOOK) MY_CXT.x_GLOB_OLD_OPHOOK(aTHX_ o);
+}
+
 MODULE = File::Glob            PACKAGE = File::Glob
 
 int
@@ -384,6 +396,8 @@ BOOT:
     {
        dMY_CXT;
        MY_CXT.x_GLOB_ENTRIES = NULL;
+       MY_CXT.x_GLOB_OLD_OPHOOK = PL_opfreehook;
+       PL_opfreehook = glob_ophook;
     }  
 }