develooper Front page | perl.perl5.porters | Postings from March 2000

[ID 20000322.019] passing string reference to subroutine cancause out-of-memory condition

From:
Mike Sheppard
Date:
March 22, 2000 19:36
Subject:
[ID 20000322.019] passing string reference to subroutine cancause out-of-memory condition
Message ID:
Pine.SGI.4.05.10003222029230.4686-200000@waimea.cs.unm.edu
#!/bin/perl -w
#
# Below is a simple perl program designed to demonstrate some odd behavior
# that may in fact be a perl bug.
#
# The bug appears under the following conditions:
# 1) pass a string-reference to a subroutine
# 2) use the same name for both the global variable and the
#    subroutine variable catching the reference.
# 3) place many instances of the following character sequence
#    in the string being passed by reference:  "\'[num][num]."
#
# I have tested and found this to odd behavior (bug?) to be existant on the
# following perl/OS combinations (perl -V output at the end of this file):
#
# -  version 5.004_04 built for i486-pc-sco3.2v5.0
# -  version 5.004_04 built for i686-linux
# -  version 5.004_04 built for sgi-irix
# -  version 5.004_04 built for sun4-sunos
# -  NT4 SP6, ActiveState build 522 built 09:52:28 on Nov 2 1999
#
#  Mike Sheppard <sheppard@cs.unm.edu>

## ------------------------------------------- main ---

  # -- first we use the same variable name ($data) but no instances of the
  #    "\'[num][num]." sequence
  # -- this pass takes less than a second
  $data = "{\leveltext\leveltext\leveltext\leveltext\leveltext\levelte;}" x 2500;
  print STDERR "data len = " . length($data) . "\n";
  &test_pass_by_reference( \$data );
  print STDERR "done first set of data!\n";

  # -- next we use the a different variable name ($diff) and many instances of
  #    the "\'[num][num]." sequence
  # -- this pass takes less than a second...
  $diff = "{\leveltext\'11\'00.\'01.\'02.\'03.\'04.\'05.\'06.\'07.\'08;}" x 2500;
  print STDERR "data len = " . length($diff) . "\n";
  &test_pass_by_reference( \$diff );
  print STDERR "done second set of data!\n";

  # -- lastly we use the a same variable name ($data) and many instances of
  #    the "\'[num][num]" sequence
  # -- at best, this pass takes several minutes
  # -- at worst, the machine may actually run out of memory
  $data = "{\leveltext\'11\'00.\'01.\'02.\'03.\'04.\'05.\'06.\'07.\'08;}" x 2500;
  print STDERR "data len = " . length($data) . "\n";
  &test_pass_by_reference( \$data );
  print STDERR "done third set of data!\n";

  exit(0);

## ------------------------------------------- subroutine ---

sub test_pass_by_reference
{
  print STDERR "  before reference grab -- " . time() . "\n";
  $$data = shift;
  print STDERR "  after reference grab -- " . time() . "\n";

  return;
}

## ------------------------------------------- perl -V output ---
__END__

# -  version 5.004_04 built for i686-linux
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
  Platform:
    osname=linux, osvers=2.0.34, archname=i686-linux
    uname='linux noobie 2.0.34 #2 thu jun 4 22:36:07 pdt 1998 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.7.2.3
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.5.4.44, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Built under linux
  Compiled at Jul 30 1998 13:46:23
  @INC:
    /usr/local/pkg/perl/perl-5.004_04/lib/i686-linux/5.00404
    /usr/local/pkg/perl/perl-5.004_04/lib
    /usr/local/pkg/perl/perl-5.004_04/lib/site_perl/i686-linux
    /usr/local/pkg/perl/perl-5.004_04/lib/site_perl
    .


# -  version 5.004_04 built for sgi-irix
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
  Platform:
    osname=irix, osvers=6.5, archname=sgi-irix
    uname='irix64 waimea 6.5 05190003 ip19 '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio=undef d_sfio=undef
  Compiler:
    cc='cc -n32', optimize='-O3', gccversion=
    cppflags='-D_BSD_TYPES -D_BSD_TIME -OPT:Olimit=0 -I/usr/local/include -I/usr/gnu/include -DLANGUAGE_C'
    ccflags ='-D_BSD_TYPES -D_BSD_TIME -woff 1009,1110,1184 -OPT:Olimit=0 -I/usr/local/include -I/usr/gnu/include -DLANGUAGE_C'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib -L/usr/lib32 -L/lib32 -L/usr/gnu/lib'
    libpth=/usr/local/lib /usr/gnu/lib /usr/lib32 /lib32 /lib /usr/lib
    libs=-ldb -lm -lc
    libc=/usr/lib32/libc.so, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-n32 -shared -L/usr/local/lib -L/usr/lib32 -L/lib32 -L/usr/gnu/lib'


Characteristics of this binary (from libperl): 
  Built under irix
  Compiled at Aug  3 1998 08:15:40
  @INC:
    /usr/local/pkg/perl/perl-5.004.04/lib/sgi-irix/5.00404
    /usr/local/pkg/perl/perl-5.004.04/lib
    /usr/local/pkg/perl/perl-5.004.04/lib/site_perl/sgi-irix
    /usr/local/pkg/perl/perl-5.004.04/lib/site_perl
    .

# -  version 5.004_04 built for sun4-sunos

Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
  Platform:
    osname=sunos, osvers=4.1.4, archname=sun4-sunos
    uname='sunos heron 4.1.4 2 sun4m '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O', gccversion=
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=true
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, prototype=undef
  Linker and Libraries:
    ld='ld', ldflags =''
    libpth=/lib /usr/lib /usr/ucblib
    libs=-lnsl -ldbm -ldl -lm -lc -lposix
    libc=/lib/libc.so.1.9, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-pic', lddlflags='-assert nodefinitions'


Characteristics of this binary (from libperl): 
  Built under sunos
  @INC:
    /usr/local/pkg/perl/perl-5.004.04/lib/sun4-sunos/5.00404
    /usr/local/pkg/perl/perl-5.004.04/lib
    /usr/local/pkg/perl/perl-5.004.04/lib/site_perl/sun4-sunos
    /usr/local/pkg/perl/perl-5.004.04/lib/site_perl
    .



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