in reply to .XS segfault

mugwumpjism

I'm no XS expert (I prefer Inline::C) but SIGSEGV leads me to believe you're blowing the stack. PUSHs will not automatically expand the stack for you. Try XPUSHs instead. Just out of curiosity, does the dir you're SIGSEGV'ing on have many more entries than the dirs it works okay on?

-derby

update: I couldn't resist a little Inline::C rewrite:

#!/usr/local/bin/perl -w use Inline C; use strict; foreach( @ARGV ) { my( @stuff ) = readdir_inode($_); foreach(@stuff) { foreach( @$_ ) { print $_, " "; } print "\n"; } } __END__ __C__ #include <sys/types.h> #include <dirent.h> #include <stdio.h> void readdir_inode ( char *dirname ) { struct dirent *ent; DIR *dir; SV *record[2]; AV *entry, *ret_val; Inline_Stack_Vars; Inline_Stack_Reset; dir = opendir(dirname); if( dir ) { while( ent=readdir(dir) ) { record[0] = newSVpv(ent->d_name, 0 ); record[1] = newSViv((IV)ent->d_ino); Inline_Stack_Push(newRV_noinc((SV*)av_make(2,r +ecord))); } closedir(dir); } Inline_Stack_Done; }

Replies are listed 'Best First'.
Re: Re: .XS segfault
by mugwumpjism (Hermit) on Mar 08, 2002 at 16:09 UTC

    That was it, fabulous!

    I actually tried Inline first (Ingy did a really good job of selling it at YAPC::2001), but couldn't figure out how to make it compile the .so at "make" time rather than run time. Now I've got this far, I can give it a try again.

    derby++

    (person who has a votebot downvoting me)--

      mugwumpjism,

      That's outlined in Inline (check out the section titled "Writing Modules with Inline"). To sum those instructions up:

      1. run h2xs -PAXn <ModuleName> 2. Edit ModuleName.pm and add your Inline Code 3. Edit Makefile.PL 3a. Change use ExtUtils::MakeMaker to use Inline::MakeMaker 3b. Change WriteMakefile to WriteInlineMakefile 4. perl Makefile.PL 5. make dist

      -derby