[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: [ID 20000118.004] DynaLoader doesn't dlclose XS code on interpreter



Alan Burlison wrote:

> > > DynaLoader maintains a list of opened .so files in dl_librefs - on exit it
> > > should dlunload all the objects in this list.
> >
> > Is not this list dead at the end of global destruction?  1/2 ;-)
> 
> Couldn't it be done in an END block inside DynaLoader?

I've a patch to do this for 5.005_63 (attatched) for at least those
platforms that support dlopen/dlclose - on others it is a no-op (I
hope).

Unfortunately I can't actually get mod_perl + a load of other stuff to
build on 5.005_63, so I can't see if it cures the mod_perl problem.

Could a DynaLoader guru have a quick look at the patch and let me know
if it is complete garbage?

I have backported the patch to 5.005_03, and it appears that mod_perl
doesn't actually destroy the perl interpreter correctly when Apache does
a restart.

Sigh.  What a mess.

Alan Burlison
*** ext/DynaLoader/DynaLoader_pm.PL.orig	Wed Jan 19 13:27:35 2000
--- ext/DynaLoader/DynaLoader_pm.PL	Wed Jan 19 16:02:57 2000
***************
*** 251,256 ****
--- 251,264 ----
  #}
  
  
+ sub END {
+     return if (! defined(&dl_unload_file));
+     while (my $libref = pop(@dl_librefs)) {
+         dl_unload_file($libref);
+     }
+ }
+ 
+ 
  # Let autosplit and the autoloader deal with these functions:
  __END__
  
***************
*** 466,471 ****
--- 474,480 ----
    @symbols = dl_undef_symbols()                        C
    dl_install_xsub($name, $symref [, $filename])        C
    $message = dl_error                                  C
+   dl_unload_file($libref)                              C
  
  =over 4
  
***************
*** 709,714 ****
--- 718,735 ----
  $filename is not defined then "DynaLoader" will be used.
  
  
+ =item dl_unload_file()
+ 
+ Syntax:
+ 
+     dl_unload_file($libref)
+ 
+ Unloads the library referred to by $libref.  Not normally called explicitly,
+ but by an END block in DynaLoader.pm that unloads all the modules whos handles
+ are stored in @dl_librefs.  This function may be absent on platforms that don't
+ require this functionality.
+ 
+ 
  =item bootstrap()
  
  Syntax:
*** ext/DynaLoader/XSLoader_pm.PL.orig	Wed Jan 19 13:56:48 2000
--- ext/DynaLoader/XSLoader_pm.PL	Wed Jan 19 15:48:54 2000
***************
*** 126,131 ****
--- 126,140 ----
      goto &DynaLoader::bootstrap_inherit;
  }
  
+ 
+ sub END {
+     package DynaLoader;
+     return if (! defined(&dl_unload_file));
+     while (my $libref = pop(@dl_librefs)) {
+         dl_unload_file($libref);
+     }
+ }
+ 
  __END__
  
  =head1 NAME
*** ext/DynaLoader/dl_dlopen.xs.orig	Wed Jan 19 13:27:47 2000
--- ext/DynaLoader/dl_dlopen.xs	Wed Jan 19 13:33:38 2000
***************
*** 169,174 ****
--- 169,185 ----
  	sv_setiv( ST(0), PTR2IV(RETVAL));
  
  
+ int
+ dl_unload_file(libhandle)
+     void *	libhandle
+     CODE:
+     DLDEBUG(2, PerlIO_printf(Perl_debug_log, "dl_unload_file(handle=%lx)\n",
+ 			     (unsigned long) libhandle));
+     RETVAL = dlclose(libhandle);
+     if (RETVAL != 0)
+ 	SaveError(aTHX_ "%s",dlerror()) ;
+ 
+ 
  void *
  dl_find_symbol(libhandle, symbolname)
      void *	libhandle

Follow-Ups from:
Ilya Zakharevich <ilya@math.ohio-state.edu>
References to:
Ilya Zakharevich <ilya@math.ohio-state.edu>
Alan Burlison <Alan.Burlison@uk.sun.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]