develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu

From:
Joerg Schumacher
Date:
November 17, 1999 14:59
Subject:
Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu
Message ID:
199911172259.XAA20971@aunt.gaertner.de
Hi!

> Ilya> Without further explanation I hardly think this is a solution.  The
> Ilya> real problem is that putenv() of Term::ReadLine::Gnu is mentioning a
> Ilya> wrong malloc()  [though I have no idea how this might have happened -
> Ilya> but it does, at least on Solaris 2.7].
> 
> I agree with you.  Something wrong around malloc().

Nope.  It's completly related to free()ing memory which hasn't been
malloc()'ed before.  There can't be such a thing like the "wrong
malloc()" since my perl has been build with "usemymalloc=n".  I'll 
append the testcase and perl version info. The test

	if (environ == PL_origenviron)

in util.c:my_setenv() assumes that the char **environ will only be
modified by perl itself.  This assumption doesn't always hold true if 
some Perl XS module calls putenv(3) before the first call to my_setenv().

> But I feel strange by seeing the patch.
>[...]
> >> -    if (environ == PL_origenviron) {	/* need we copy environment? */
> 
> is true, only when my_setenv() is called at the first time only.  And
> Joerg's patch should work as same as original code.  I do not
> understand why the patch works.

The patch works because it makes sure that perl only free()'s memory
that has been allocated before.  The test via a static variable is
stronger than the comparison to the saved environ pointer.

A workaround only for Term::ReadLine::Gnu would be the appended
patch.  It makes sure that LINES and COLUMNS are defined in the
environment before initializing the GNU Readline Library, so that  
putenv() hopefully doesn't need to modify the char **environ.  
Please keep in mind that this patch is only a workaound for the weak 
assumption in my_setenv().


Kind regards,
Joerg 

-- 
 Gaertner Datensysteme                         38114 Braunschweig 
 Joerg Schumacher                              Hamburger Str. 273a
 Tel: 0531-2335555          		       Fax: 0531-2335556


----------------------------------------------------------------------

--- Term-ReadLine-Gnu-1.07/Gnu.pm.orig  Wed Nov 17 23:22:59 1999
+++ Term-ReadLine-Gnu-1.07/Gnu.pm       Wed Nov 17 23:28:26 1999
@@ -159,6 +159,11 @@
     # set rl_readline_name before .inputrc is read in rl_initialize()
     $Attribs{readline_name} = $name;
 
+    # make sure that LINES and COLUMNS are defined in the environment 
+    # before initializing the GNU Readline Library
+    $ENV{LINES} = 25 if !defined($ENV{LINES});
+    $ENV{COLUMNS} = 80 if !defined($ENV{COLUMNS});
+
     # initialize the GNU Readline Library and termcap library
     $self->initialize();
 
----------------------------------------------------------------------
#!/tmp/perl/bin/perl -w
# dumps core if LINES and COLUMNS aren't defined in the env
use Term::ReadLine;
$RL = new Term::ReadLine 'foo';

$ENV{PATH} ="foo";
use vars qw($RL);
----------------------------------------------------------------------
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=solaris, osvers=2.5.1, archname=sun4-solaris
    uname='sunos aunt 5.5.1 generic_103640-24 sun4u sparc '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O', gccversion=2.7.2.1
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldb -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Built under solaris
  Compiled at Nov 17 1999 23:34:56
  @INC:
    /tmp/perl/lib/5.00503/sun4-solaris
    /tmp/perl/lib/5.00503
    /tmp/perl/lib/site_perl/5.005/sun4-solaris
    /tmp/perl/lib/site_perl/5.005
    .




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About