develooper Front page | perl.perl5.porters | Postings from May 2003

Seg fault in dying from XS

Thread Next
From:
Ken Williams
Date:
May 26, 2003 12:42
Subject:
Seg fault in dying from XS
Message ID:
16CC9AEA-8FB2-11D7-A682-003065F6D85A@mathforum.org
Hi,

Below is a short test case in which I'm calling some callback perl code 
from XS and using the G_EVAL flag to trap exceptions.  I then call 
croak(Nullch) to propagate the exception, and I get a segmentation 
fault.  Does anyone see something wrong with it?  The code is below.  
I'm running it under perl 5.6.1 on Mac OS X 10.2.6.

---------------------- bug.pl script ------------------------
#!/usr/bin/perl

use strict;
use blib;
use Params::Validate;

warn "Checking...\n";
throw( sub { die bless {}, $_[1] } );
print "Done\n";
---------------------- Params/Validate.pm ------------------------
package Params::Validate;
use strict;

use Exporter;
use DynaLoader;
use vars qw( $VERSION @ISA @EXPORT);

@ISA = qw(Exporter DynaLoader);
$VERSION = '0.59';
@EXPORT = qw( throw );

bootstrap Params::Validate $Params::Validate::VERSION;

1;
---------------------- Params/Validate.xs ------------------------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#define NEED_newCONSTSUB
#include "ppport.h"

MODULE = Params::Validate               PACKAGE = Params::Validate

void
throw(on_fail)
	SV* on_fail
     PPCODE:
	{
	    warn("Will fail");
	    SV* buffer = sv_2mortal(newSVpv("Odd number of parameters in 
call", 0));
	
	    dSP;
	
	    ENTER;
	    SAVETMPS;
	    PUSHMARK(SP);
	    XPUSHs(buffer);
	    PUTBACK;
	    perl_call_sv(on_fail, G_DISCARD|G_VOID|G_EVAL);
	    warn("Checking eval");
	    if (SvROK(ERRSV)) {
		warn("Ref looks okay");
		croak(Nullch);
	    }
	}
--------------------------------------------------------------------

As you can see, this code is whittled down from Params::Validate, where 
this segfaulting was first observed.  Dave Rolsky and I have been 
scratching our heads about this one for a while.

The output on my machine is:

% perl bug.pl
Using /Users/ken/Downloads/perl/Params-Validate-0.59/blib
Checking...
Will fail at bug.pl line 8.
Checking eval at bug.pl line 8.
Ref looks okay at bug.pl line 8.
%

Notice how it never gets to the final "Done\n".

  -Ken

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
   Platform:
     osname=darwin, osvers=6.6, archname=darwin
     uname='darwin junior.local. 6.6 darwin kernel version 6.6: thu may 
1 21:48:54 pdt 2003; root:xnuxnu-344.34.obj~1release_ppc power 
macintosh powerpc '
     config_args='-des -Dfirstmakefile=GNUmakefile 
-Dldflags=-flat_namespace -Dprefix=/sw -Dinstallprefix=/sw 
-Uinstallusrbinperl -Dman3ext=3perl'
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=undef
     useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=undef use64bitall=undef uselongdouble=undef
   Compiler:
     cc='cc', ccflags ='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE 
-fno-strict-aliasing',
     optimize='-O3',
     cppflags='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE 
-fno-strict-aliasing'
     ccversion='', gccversion='Apple cpp-precomp 6.14', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, usemymalloc=n, prototype=define
   Linker and Libraries:
     ld='cc', ldflags ='-flat_namespace -L/usr/local/lib'
     libpth=/usr/local/lib /usr/lib
     libs=-lm -lc
     perllibs=-lm -lc
     libc=/System/Library/Frameworks/System.framework/System, so=dylib, 
useshrplib=true, libperl=libperl.dylib
   Dynamic Linking:
     dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags='-flat_namespace -bundle -undefined 
suppress -L/usr/local/lib'


Characteristics of this binary (from libperl):
   Compile-time options: USE_LARGE_FILES
   Built under darwin
   Compiled at 05/25/03 21:17:33
   %ENV:
     PERL5LIB="/sw/lib/perl5"
   @INC:
     /sw/lib/perl5/5.6.1/darwin
     /sw/lib/perl5/5.6.1
     /sw/lib/perl5/darwin
     /sw/lib/perl5
     /sw/lib/perl5/5.6.1/darwin
     /sw/lib/perl5/5.6.1
     /Library/Perl/darwin
     /Library/Perl
     /Library/Perl
     .


Thread Next


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