Jonathan Vanasco wrote:
> On Mar 30, 2006, at 6:42 PM, Perrin Harkins wrote:
> 
>> On Thu, 2006-03-30 at 18:34 -0500, Jonathan Vanasco wrote:
>>> if you subclass a module to override a few methods, and then decide
>>> to remove a subclassed method (to call off the method in the parent
>>> class instead), you will raise an error instead of calling the parent
>>> method.
>>> if you do a restart, everything works as expected.
>> Perl caches method lookups in order to reduce the performance hit  
>> of OO
>> code.  If you'd like to make a patch for the A::Reload docs saying  
>> that
>> it can't handle changes that modify which package a method should be
>> called in, I think that's close enough.

Or, you can try this quick patch (no test for this included);-) Basically,
when causing things that might invalidate Perl's method cache, one is
supposed to increase PL_sub_generation.

This patch adds this behavior to Apache2::Reload and might just make this
problem go away. Feedback on success/failure would be very much appreciated.

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Index: lib/Apache2/Reload.pm
===================================================================
--- lib/Apache2/Reload.pm	(revision 390295)
+++ lib/Apache2/Reload.pm	(working copy)
@@ -167,6 +167,8 @@
         my $package = module_to_package($module);
         ModPerl::Util::unload_package($package);
     }
+
+    ModPerl::Util::invalidate_perl_method_cache();
     
     #Then, let's reload them all, so that module dependencies can satisfy
     #themselves in the correct order.
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
--- xs/tables/current/ModPerl/FunctionTable.pm	(revision 390295)
+++ xs/tables/current/ModPerl/FunctionTable.pm	(working copy)
@@ -4338,6 +4338,16 @@
     ]
   },
   {
+    'return_type' => 'void',
+    'name' => 'modperl_perl_method_cache_invalidate',
+    'args' => [
+      {
+        'type' => 'PerlInterpreter *',
+        'name' => 'my_perl'
+      },
+    ]
+  },
+  {
     'return_type' => 'int',
     'name' => 'modperl_perl_module_loaded',
     'attr' => [
Index: xs/ModPerl/Util/ModPerl__Util.h
===================================================================
--- xs/ModPerl/Util/ModPerl__Util.h	(revision 390295)
+++ xs/ModPerl/Util/ModPerl__Util.h	(working copy)
@@ -38,4 +38,7 @@
 #define mpxs_ModPerl__Util_unload_package_xs(pkg) \
     modperl_package_unload(aTHX_ pkg)
 
+#define mpxs_ModPerl__Util_invalidate_perl_method_cache() \
+    modperl_perl_method_cache_invalidate(aTHX)
+
 /* ModPerl::Util::exit lives in mod_perl.so, see modperl_perl.c */
Index: xs/maps/modperl_functions.map
===================================================================
--- xs/maps/modperl_functions.map	(revision 390295)
+++ xs/maps/modperl_functions.map	(working copy)
@@ -8,6 +8,7 @@
  SV *:DEFINE_current_perl_id
  char *:DEFINE_current_callback 
  DEFINE_unload_package_xs | | const char *:package
+ void:DEFINE_invalidate_perl_method_cache
 
 MODULE=ModPerl::Global
  mpxs_ModPerl__Global_special_list_call
Index: src/modules/perl/modperl_util.h
===================================================================
--- src/modules/perl/modperl_util.h	(revision 390295)
+++ src/modules/perl/modperl_util.h	(working copy)
@@ -100,6 +100,8 @@
 apr_array_header_t *modperl_avrv2apr_array_header(pTHX_ apr_pool_t *p,
                                                   SV *avrv);
 void modperl_package_unload(pTHX_ const char *package);
+void modperl_perl_method_cache_invalidate(pTHX);
+
 #if defined(MP_TRACE) && APR_HAS_THREADS
 #define MP_TRACEf_TID   "/tid 0x%lx"
 #define MP_TRACEv_TID   (unsigned long)apr_os_thread_current()
Index: src/modules/perl/modperl_util.c
===================================================================
--- src/modules/perl/modperl_util.c	(revision 390295)
+++ src/modules/perl/modperl_util.c	(working copy)
@@ -796,6 +796,11 @@
 
 }
 
+void modperl_perl_method_cache_invalidate(pTHX)
+{
+    PL_sub_generation++;
+}
+
 #define MP_RESTART_COUNT_KEY "mod_perl_restart_count"
 
 /* passing the main server object here, just because we don't have the

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to