[svn:modperl-modules] rev 220 - Apache-Scoreboard-2.0/trunk

[email protected] 2 Jun 2005 16:17:43 -0000
Newsgroups perl.modperl.modules.svn
Message-ID <[email protected]>
Author: MJH
Date: Thu Jun  2 09:17:43 2005
New Revision: 220

Modified:
   Apache-Scoreboard-2.0/trunk/Changes
   Apache-Scoreboard-2.0/trunk/Scoreboard.xs
Log:
Patch from Stas to do magic-fu so that the pool passed to image() is held on to even if the caller does not keep a reference.


Modified: Apache-Scoreboard-2.0/trunk/Changes
==============================================================================
--- Apache-Scoreboard-2.0/trunk/Changes	(original)
+++ Apache-Scoreboard-2.0/trunk/Changes	Thu Jun  2 09:17:43 2005
@@ -1,5 +1,9 @@
 2.07 - dev
 
+Apache::Scoreboard::image() now does magic so that image(new APR::Pool) doesn't segfault    - Stas
+
+ported to modperl 2.0 API changes   - MJH
+
 2.06 - Fri Mar 18 13:50:49 EST 2005
 
 fix the buggy reconstruction of the fetched binary image in thaw()

Modified: Apache-Scoreboard-2.0/trunk/Scoreboard.xs
==============================================================================
--- Apache-Scoreboard-2.0/trunk/Scoreboard.xs	(original)
+++ Apache-Scoreboard-2.0/trunk/Scoreboard.xs	Thu Jun  2 09:17:43 2005
@@ -2,6 +2,7 @@
 #include "mod_perl.h"
 #include "modperl_xs_sv_convert.h"
 #include "modperl_xs_typedefs.h"
+#include "modperl_xs_util.h"
 
 #include "scoreboard.h"
 
@@ -323,26 +324,33 @@ thaw(CLASS, pool, packet)
     OUTPUT:
     RETVAL
 
-Apache::Scoreboard
-image(CLASS, pool)
+
+SV *
+image(CLASS, pool_sv)
     SV *CLASS
-    APR::Pool pool
-    
+    SV *pool_sv
     
+    INIT:
+    modperl_scoreboard_t *image;
+    apr_pool_t *pool = mp_xs_sv2_APR__Pool(pool_sv);
+
     CODE:
     image_sanity_check(aTHX);
 
-    RETVAL = (modperl_scoreboard_t *)apr_palloc(pool, sizeof(*RETVAL));
-    
+    image = (modperl_scoreboard_t *)apr_palloc(pool, sizeof(*image));
+
     if (ap_exists_scoreboard_image()) {
-        RETVAL->sb   = ap_scoreboard_image;
-        RETVAL->pool = pool;
-        ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &(RETVAL->server_limit));
-        ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &(RETVAL->thread_limit));
+        image->sb   = ap_scoreboard_image;
+        image->pool = pool;
+        ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &(image->server_limit));
+        ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &(image->thread_limit));
     }
     else {
         Perl_croak(aTHX_ "ap_scoreboard_image doesn't exist");
     }
+    RETVAL = sv_setref_pv(NEWSV(0, 0), "Apache::Scoreboard", (void*)image);
+    /* make sure the pool sticks around as long as this object is alive */
+    mpxs_add_pool_magic(RETVAL, pool_sv);
 
     CLASS = CLASS; /* avoid warnings */