[svn:mod_parrot] r534 - in mod_parrot/trunk: lib/ModParrot/APR t/response/TestAPI

[email protected] Mon, 8 Dec 2008 11:20:34 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Mon Dec  8 11:20:33 2008
New Revision: 534

Modified:
   mod_parrot/trunk/lib/ModParrot/APR/Pool.pir
   mod_parrot/trunk/t/response/TestAPI/apr_pool.pir

Log:
add clear() and destroy() methods to APR;Pool


Modified: mod_parrot/trunk/lib/ModParrot/APR/Pool.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/APR/Pool.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/APR/Pool.pir	Mon Dec  8 11:20:33 2008
@@ -49,6 +49,12 @@
 
     dlfunc func, nul, "apr_pool_create_ex", "iVppp"
     set_root_global [ 'APR'; 'NCI' ], "apr_pool_create_ex", func
+
+    dlfunc func, nul, "apr_pool_clear", "vp"
+    set_root_global [ 'APR'; 'NCI' ], "apr_pool_clear", func
+
+    dlfunc func, nul, "apr_pool_destroy", "vp"
+    set_root_global [ 'APR'; 'NCI' ], "apr_pool_destroy", func
 .end
 
 .sub init :vtable :method
@@ -111,6 +117,35 @@
     func(pool, handler_sub, data)
 .end
 
+=item C<clear()>
+
+Clears the memory in a pool and runs cleanup handlers.  Also destroys any
+subpools.
+
+=cut
+
+.sub clear :method
+    .local pmc func, pool
+
+    func = get_root_global [ 'APR'; 'NCI' ], "apr_pool_clear"
+    pool = getattribute self, 'apr_pool'
+    func(pool)
+.end
+
+=item C<destroy()>
+
+Destroys the pool and runs cleanup handlers.  Also destroys any subpools.
+
+=cut
+
+.sub destroy :method
+    .local pmc func, pool
+
+    func = get_root_global [ 'APR'; 'NCI' ], "apr_pool_destroy"
+    pool = getattribute self, 'apr_pool'
+    func(pool)
+.end
+
 =back
 
 =head1 AUTHOR

Modified: mod_parrot/trunk/t/response/TestAPI/apr_pool.pir
==============================================================================
--- mod_parrot/trunk/t/response/TestAPI/apr_pool.pir	(original)
+++ mod_parrot/trunk/t/response/TestAPI/apr_pool.pir	Mon Dec  8 11:20:33 2008
@@ -17,7 +17,7 @@
 
     ap_const = get_root_global [ 'ModParrot'; 'Apache'; 'Constants' ], 'table'
 
-    r.'puts'("1..3\n")
+    r.'puts'("1..5\n")
 
   START_1:
     push_eh NOT_OK_1
@@ -32,30 +32,50 @@
 
   START_2:
     push_eh NOT_OK_2
+    $P0.'clear'()
+    pop_eh
+    goto OK_2
+  NOT_OK_2:
+    r.'puts'("not ")
+  OK_2:
+    r.'puts'("ok 2 - clear pool\n")
+
+  START_3:
+    push_eh NOT_OK_3
+    $P0.'destroy'()
+    pop_eh
+    goto OK_3
+  NOT_OK_3:
+    r.'puts'("not ")
+  OK_3:
+    r.'puts'("ok 3 - destroy pool\n")
+
+  START_4:
+    push_eh NOT_OK_4
     $P1 = r.'pool'()
     $P2 = new 'Hash'
     $P2['parent'] = $P1
     $P0 = new ['ModParrot'; 'APR'; 'Pool'], $P2
     pop_eh
     $S0 = typeof $P0
-    if $S0 == 'ModParrot;APR;Pool' goto OK_2
-  NOT_OK_2:
+    if $S0 == 'ModParrot;APR;Pool' goto OK_4
+  NOT_OK_4:
     r.'puts'("not ")
-  OK_2:
-    r.'puts'("ok 2 - create pool (with request pool parent)\n")
+  OK_4:
+    r.'puts'("ok 4 - create pool (with request pool parent)\n")
 
-  START_3:
+  START_5:
     push_eh NOT_OK_3
     $P0 = r.'pool'()
     $P1 = new 'Undef'
     $P2 = get_global 'test_cleanup_handler'
     $P0.'cleanup_register'($P2, $P1)
     pop_eh
-    goto OK_3
-  NOT_OK_3:
+    goto OK_5
+  NOT_OK_5:
     r.'puts'("not ")
-  OK_3:
-    r.'puts'("ok 3 - cleanup_register\n")
+  OK_5:
+    r.'puts'("ok 5 - cleanup_register\n")
     
     $I0 = ap_const['OK']
     .return($I0)