[svn:mod_parrot] r326 - mod_parrot/trunk/src

[email protected] Sun, 20 Jan 2008 10:10:58 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Sun Jan 20 10:10:58 2008
New Revision: 326

Modified:
   mod_parrot/trunk/src/mod_parrot.c

Log:
register context PMC so GC doesn't destroy it while running HLL handler


Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Sun Jan 20 10:10:58 2008
@@ -137,6 +137,7 @@
     Parrot_PMC ctx_pmc;
     Parrot_PMC namespace;
     Parrot_Int typenum;
+    int res;
 
     typenum = Parrot_PMC_typenum(interp, "ResizableStringArray");
     namespace = (Parrot_PMC)Parrot_PMC_new(interp, typenum);
@@ -144,19 +145,18 @@
     Parrot_PMC_set_intval(interp, namespace, 2);
     Parrot_PMC_set_cstring_intkey(interp, namespace, 0, "ModParrot");
     Parrot_PMC_set_cstring_intkey(interp, namespace, 1, "Context");
-
     ctx_class = Parrot_oo_get_class(interp, namespace);
+    Parrot_unregister_pmc(interp, namespace);
+
     ctx_pmc = (Parrot_PMC)Parrot_Class_instantiate(interp, ctx_class, PMCNULL);
+    Parrot_register_pmc(interp, ctx_pmc);
 
-    Parrot_unregister_pmc(interp, namespace);
 
     if (!hll) hll = MODPARROT_DEFAULT_HLL;
-    if (!modparrot_call_sub_IPS(interp, hll, hll_handler, ret, ctx_pmc,
-        handler)) {
-        return(0);
-    }
-
-    return(1);
+    res = modparrot_call_sub_IPS(interp, hll, hll_handler, ret, ctx_pmc,
+        handler);
+    Parrot_unregister_pmc(interp, ctx_pmc);
+    return res ? 1 : 0;
 }
 
 static char *get_request_hll(request_rec *r, const char *handler,