[Zope-Perl] problem with dynamic loading of perl embedded in python ?

Gisle Aas gisle@ActiveState.com
04 Aug 2000 09:15:15 +0200


Joseph Wayne Norton <norton@alum.mit.edu> writes:

> I'm having trouble getting the following example to work with simply
> perl embedded in python (a similiar perl only script works fine with
> perl):
> 
>         import perl
>         perl.eval("""
>            print "hello world\n";
>            """)
>         perl.eval("""
>            use Data::Dumper;
>            my @c = ('c');
>            my $c = \@c;
>            my $b = {};
>            my $a = [1, $b, $c];
>            $b->{a} = $a;
>            $b->{b} = $a->[1];
>            $b->{c} = $a->[2];
>            print Data::Dumper->Dump([$a,$b,$c], [qw(a b c)]);
>            """)
> 
> I get the following error ...
> 
>         /export/arseed-apps/base/bin/python basic.py
>         hello world
>         Traceback (innermost last):
>           File "basic.py", line 8, in ?
>             perl.eval("""
>         perl.PerlError: Can't load '/export/arseed-apps/base/lib/perl5/5.6.0/i686-linux/auto/Data/Dumper/Dumper.so' for module Data::Dumper: /export/arseed-apps/base/lib/perl5/5.6.0/i686-linux/auto/Data/Dumper/Dumper.so: undefined symbol: PL_sv_undef at /export/arseed-apps/base/lib/perl5/5.6.0/i686-linux/DynaLoader.pm line 200.

This is the problem that is fixed by the python-dynload-global patch.
It make python provide the RTLD_GLOBAL flag when it load extensions.
The effect of this is that symbols found in one .so-file can be used
to resolve names in another .so-file.  This is needed because we need
to make the symbols of perl available to perl extensions.  What fails
here is that Dumper.so can't find the PL_sv_undef symbol that is
actually defined in perl.so loaded by python.

>          at (eval 2) line 2
>         Compilation failed in require at (eval 2) line 2.
>         BEGIN failed--compilation aborted at (eval 2) line 2.
> 
> 
> I'm using perl-5.6.0, python-1.5.2, Distutils, plus the patches
> supplied by Gisle on a linux system.  I'm building perl as follows.
> 
>               mysystem("patch < $patdir/perl5.6.0-perl-method-G_EVAL");
>               mysystem("patch < $patdir/perl5.6.0-perl-vcroak-null");
>               mysystem("rm -f config.sh Policy.sh");
>               mysystem("sh ./Configure -Dprefix=$pfx -des");

This is the Python-1.5.2 version of the python-dynload-global patch.

--- Python-1.5.2/Python/importdl.c.dist	Wed Jan 27 18:53:10 1999
+++ Python-1.5.2/Python/importdl.c	Fri Aug  4 08:48:46 2000
@@ -441,13 +441,13 @@
 #ifdef RTLD_NOW
 		/* RTLD_NOW: resolve externals now
 		   (i.e. core dump now if some are missing) */
-		void *handle = dlopen(pathname, RTLD_NOW);
+		void *handle = dlopen(pathname, RTLD_NOW | RTLD_GLOBAL);
 #else
 		void *handle;
 		if (Py_VerboseFlag)
 			printf("dlopen(\"%s\", %d);\n", pathname,
 			       RTLD_LAZY);
-		handle = dlopen(pathname, RTLD_LAZY);
+		handle = dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL);
 #endif /* RTLD_NOW */
 		if (handle == NULL) {
 			PyErr_SetString(PyExc_ImportError, dlerror());

The next zope-perl release will have this patch included in addition
to the py1.6 version of the patch.

Regards,
Gisle