pike has asked for the wisdom of the Perl Monks concerning the following question:

Recently, when I tried to run a script I had just written, I got no error message, but a segfault. After some searching, I found the code that had caused this problem:

$x = { a => undef b => 'x', };

I noticed that I had forgotten the comma after the 'undef'. Anyway, I would expect an error message in such a case, not a segfault.

It seems to have to do with the "undef". If I replace it with a string or variable, I get the correct error message.

Can anyone explain / fix this?

Thanks,

pike

Replies are listed 'Best First'.
Re: Bug in perl compiler?
by Abigail-II (Bishop) on Dec 11, 2002 at 10:40 UTC
    This will indeed segfault in 5.6.1. But it's already fixed. In 5.8.0, you'll get:
    Can't modify constant item in undef operator at -e line 1, near "b + =>" Execution of -e aborted due to compilation errors.

    Abigail

Re: Bug in perl compiler?
by grantm (Parson) on Dec 11, 2002 at 10:21 UTC

    Hmmm, undef is a function too, so I guess it's parsed as:

    $x = { a => undef('b') => 'x', };

    Which means you're asking Perl to undefine a string literal - still shouldn't segfault.

      The error arises on 5.6.1, and running it through B::Deparse gives further wierdness:

      Can't locate object method "pp_anonhash" via package "B::Deparse" (per +haps you forgot to load "B::Deparse"?) at /usr/local/lib/perl5/5.6.1/ +sun4-solaris/B/Deparse.pm line 410. CHECK failed--call queue aborted. Segmentation Fault

Re: Bug in perl compiler?
by PodMaster (Abbot) on Dec 11, 2002 at 17:34 UTC
    Works fine for me.
    $x = { a => undef b => 'x', }; __END__ Can't modify constant item in undef operator at - line 3, near "b +=>" Execution of - aborted due to compilation errors.
    Even Abigail failed to provide a perl -V dump
    Summary of my perl5 (revision 5 version 6 subversion 1) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef use5005threads=undef useithreads=define usemultip +licity=define useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cl', ccflags ='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DN +O_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_S +Y S -DPERL_MSVCRT_READFIX', optimize='-O1 -MD -DNDEBUG', cppflags='-DWIN32' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=4 alignbytes=8, usemymalloc=n, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -release -libpath:"C:/ +Perl\lib\CORE" -machine:x86' libpth="C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib" "C: +\Program Files\Microsoft Visual Studio\VC98\lib" "C:\Perl\lib\CORE" libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib + comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netap +i 32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib +odbccp32.lib msvcrt.lib perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool +.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib n +e tapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32. +lib odbccp32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -l +ibpath:"C:/Perl\lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEX +T PERL_IMPLICIT_SYS Locally applied patches: ActivePerl Build 633 Built under MSWin32 Compiled at Jun 17 2002 21:33:05 @INC: C:/Perl/lib C:/Perl/site/lib .
    I get the same thing with perl 5.8. I don't see how this is a segfault.


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      You're right - I should have included version information right away. Here it is, just for the sake of completeness (because my question has been answered already): I'm running perl 5.6.1 under RedHat linux.

      And here's the perl -V dump:

      Summary of my perl5 (revision 5.0 version 6 subversion 1) configuratio +n: Platform: osname=linux, osvers=2.4.9, archname=i686-linux uname='linux zeus.sail-labs.at 2.4.9 #5 smp tue aug 28 15:24:44 ce +st 2001 i686 unknown ' config_args='' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultipl +icity=undef useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LA +RGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-81 +)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -lgdbm -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.2.2.so, so=so, useshrplib=false, libperl=libperl. +a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami +c' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: USE_LARGE_FILES Built under linux Compiled at Sep 3 2001 21:32:42 %ENV: PERL5LIB=".:/home/robert/:/rnr/rnr_tools/:/rnr/rnr_train/bin/" PERLLIB="/home/robert/:/rnr/rnr_tools/:/rnr/rnr_train/bin/" PERLTEST_ROOT="/home/robert/start/perltest" PERL_MODLIB="/home/robert/:/home/robert/:/home/robert/:/rnr/rnr_to +ols" @INC: . /home/robert/ /rnr/rnr_tools/ /rnr/rnr_train/bin/ /usr/lib/perl5/5.6.1/i686-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i686-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl

      pike