perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [mp2 patch] APR::Bucket::alloc_ => APR::BucketAlloc
Date Tue, 28 Dec 2004 00:30:21 GMT
Joe, please take a look. It was actually a trivial fix in tests, since 
it's used only in one place. So it probably shouldn't affect any users.

One problem I have is with:

   APR::Bucket::alloc_destroy moved to APR::BucketAlloc::DESTROY

So now one doesn't need to call destroy explicitly since DESTROY will be 
called automatically. Is that a good thing? I think so. The problem that 
most automatic DESTROY methods in mp2 are not very good. If someone 
explicitly calls DESTROY and then perl calls DESTROY, it's a certain 
segfault. That could be fixed, by a wrapper which eats the heart of the 
object once DESTROY is called replaced with a hole (similar to 
APR::Pool::DESTROY, but simpler). Do you think we should bother?

Of course dropping DESTROY methods and replacing those with plan destroy() 
will avoid this problem, and if a user calls destroy() more than once, is 
it their fault that they get a segfault? it certainly is, but it's nice to 
  not to have perl code segfault no matter what. So I'm in favor of 
keeping DESTROY, but ensuring that those don't segfault if called more 
than once on the same object.

Anyway, here is the patch:

Index: xs/maps/apr_functions.map
===================================================================
--- xs/maps/apr_functions.map	(revision 123453)
+++ xs/maps/apr_functions.map	(working copy)
@@ -123,10 +123,6 @@
   mpxs_APR__Bucket_new  | | classname, list, sv, offset=0, len=0
   void:DEFINE_destroy | | apr_bucket:bucket
   void:DEFINE_delete  | | apr_bucket:bucket
->apr_bucket_alloc
-~ apr_bucket_alloc_create
- mpxs_APR__Bucket_alloc_create
- apr_bucket_alloc_destroy
  ~apr_bucket_setaside
   mpxs_APR__Bucket_setaside
  >apr_bucket_free
@@ -163,6 +159,12 @@
  !apr_bucket_destroy_noop
  !apr_bucket_setaside_noop

+MODULE=APR::BucketAlloc
+>apr_bucket_alloc
+~apr_bucket_alloc_create
+ mpxs_APR__BucketAlloc_new
+ void:DEFINE_DESTROY | | apr_bucket_alloc_t *:ba
+
  MODULE=APR::Pool
  -apr_pool_num_bytes | | p, recurse=0 #only available with -DAPR_POOL_DEBUG
   apr_pool_cleanup_for_exec
Index: xs/APR/BucketAlloc/APR__BucketAlloc.h
===================================================================
--- xs/APR/BucketAlloc/APR__BucketAlloc.h	(revision 0)
+++ xs/APR/BucketAlloc/APR__BucketAlloc.h	(revision 0)
@@ -0,0 +1,29 @@
+/* Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "modperl_bucket.h"
+
+#define mpxs_APR__BucketAlloc_DESTROY apr_bucket_alloc_destroy
+
+static MP_INLINE
+SV *mpxs_APR__BucketAlloc_new(pTHX_ SV *CLASS, SV *p_sv)
+{
+    apr_pool_t *p          = mp_xs_sv2_APR__Pool(p_sv);
+    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+    SV *ba_sv = sv_setref_pv(NEWSV(0, 0), "APR::BucketAlloc", (void*)ba);
+    //mpxs_add_pool_magic(ba_sv, p_sv);
+    return ba_sv;
+}
+

Index: xs/APR/Bucket/APR__Bucket.h
===================================================================
--- xs/APR/Bucket/APR__Bucket.h	(revision 123453)
+++ xs/APR/Bucket/APR__Bucket.h	(working copy)
@@ -117,13 +117,3 @@

      return rc;
  }
-
-static MP_INLINE
-SV *mpxs_APR__Bucket_alloc_create(pTHX_ SV *p_sv)
-{
-    apr_pool_t *p             = mp_xs_sv2_APR__Pool(p_sv);
-    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
-    SV *ba_sv = sv_setref_pv(NEWSV(0, 0), "APR::BucketAlloc", (void*)ba);
-    //mpxs_add_pool_magic(ba_sv, p_sv);
-    return ba_sv;
-}

Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
--- xs/tables/current/ModPerl/FunctionTable.pm	(revision 123453)
+++ xs/tables/current/ModPerl/FunctionTable.pm	(working copy)
@@ -2,7 +2,7 @@

  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # ! WARNING: generated by ModPerl::ParseSource/0.01
-# !          Fri Dec 24 18:59:48 2004
+# !          Mon Dec 27 19:15:23 2004
  # !          do NOT edit, any changes will be lost !
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@@ -5517,7 +5517,7 @@
    },
    {
      'return_type' => 'SV *',
-    'name' => 'mpxs_APR__Bucket_alloc_create',
+    'name' => 'mpxs_APR__BucketAlloc_new',
      'args' => [
        {
          'type' => 'PerlInterpreter *',
@@ -5525,6 +5525,10 @@
        },
        {
          'type' => 'SV *',
+        'name' => 'CLASS'
+      },
+      {
+        'type' => 'SV *',
          'name' => 'p_sv'
        }
      ]
Index: t/lib/TestAPRlib/bucket.pm
===================================================================
--- t/lib/TestAPRlib/bucket.pm	(revision 123453)
+++ t/lib/TestAPRlib/bucket.pm	(working copy)
@@ -11,6 +11,7 @@

  use APR::Pool ();
  use APR::Bucket ();
+use APR::BucketAlloc ();
  use APR::BucketType ();
  use APR::Table ();

@@ -21,7 +22,7 @@
  sub test {

      my $pool = APR::Pool->new();
-    my $ba = APR::Bucket::alloc_create($pool);
+    my $ba   = APR::BucketAlloc->new($pool);

      # new: basic
      {
@@ -171,7 +172,7 @@
          my $data   = "foobartar";
          my $offset = 3;
          my $real = substr $data, $offset;
-        #my $ba = APR::Bucket::alloc_create(APR::Pool->new);
+        #my $ba = APR::BucketAlloc->new(APR::Pool->new);
          my $b = APR::Bucket->new($ba, $data, $offset);

          # try to overwrite the temp pool data
@@ -204,9 +205,6 @@
                   "data inside the setaside bucket is not corrupted");
          $b->destroy;
      }
-
-    APR::Bucket::alloc_destroy($ba);
-
  }

  1;
Index: Changes
===================================================================
--- Changes	(revision 123453)
+++ Changes	(working copy)
@@ -12,6 +12,9 @@

  =item 1.99_20-dev

+APR::Bucket::alloc_create moved  to APR::BucketAlloc::new
+APR::Bucket::alloc_destroy moved to APR::BucketAlloc::DESTROY [Stas]
+
  deal with a situation where an object is used to construct another
  object, but it's then auto-DESTROYed by perl rendering the object that
  used it corrupted. the solution is to make the newly created objects

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message