FAQ
Below is some test XS code that uses readdir().
Everything works fine when building with perl 5.8.0
and threads are not enabled, but with -Dusethreads,
readdir is #defined to PerlDir_read, and the build
fails. Eventually PerlDir_read is replaced with
readdir_r, but with the wrong number of arguments.

I didn't submit a bug for this because it's not clear
to me if this really is a bug. Can this be fixed
with a some kind of build-time option?

I gather it's probably not safe to simply insert this
into the module's header file:

#define readdir readdir

Thanks for any info.


Here are the details:




This is the original XS code:

while ((de = readdir(dp)) != NULL) {

printf("%s\n", de->d_name);
}

If threads are not enabled, the resulting C code
looks like this:

while ((de = readdir(dp)) != ((void *)0) ) {

PerlIO_stdoutf( "%s\n" ,de->d_name ) ;
}


With threads enabled, the resulting C code
looks like this:

while ((de = ((((*(___errno())) = readdir_r( dp , (*Perl_Ir
eentrant_buffer_ptr(((PerlInterpreter *)pthread_getspecific( (*Perl_
Gthr_key_ptr(((void *)0) ))) ) )) ->_readdir_struct, & (*Perl_Iree
ntrant_buffer_ptr(((PerlInterpreter *)pthread_getspecific( (*Perl_Gt
hr_key_ptr(((void *)0) )) ) ) )) ->_readdir_ptr))) == 0 ? (*Perl_
Ireentrant_buffer_ptr(((PerlInterpreter *)pthread_getspecific( (*Per
l_Gthr_key_ptr(((void *)0) )) ) ) )) ->_readdir_ptr : 0) ) != ((v
oid *)0) ) {
PerlIO_stdoutf( "%s\n" ,de->d_name ) ;
}


....and the build fails with this error message:

RDtest.xs:30: too many arguments to function `readdir_r'

Here are the version numbers:

perl 5.8.0
Solaris 2.6
gcc 2.8.1 (similar errors with the Sun compiler, too)

This same code builds just fine on perl 5.6.1 with -Dusethreads,
even though exactly the same replacement is made on readdir().




##=====================================================
output of perl -V


Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=solaris, osvers=2.6, archname=sun4-solaris-thread-multi
uname='sunos apollo 5.6 generic_105181-28 sun4u sparc sunw,ultra-250 '
config_args='-Dprefix=/u0/perl/perl580-th -Dcc=gcc -Dusethreads -des'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
optimize='-O',
cppflags='-D_REENTRANT -I/usr/local/include'
ccversion='', gccversion='2.8.1', gccosandvers='solaris2.6'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8, alignbytes=8, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib '
libpth=/usr/local/lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc
perllibs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
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):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
Built under solaris
Compiled at Oct 17 2002 14:13:24
@INC:
/u0/perl/perl580-th/lib/5.8.0/sun4-solaris-thread-multi
/u0/perl/perl580-th/lib/5.8.0
/u0/perl/perl580-th/lib/site_perl/5.8.0/sun4-solaris-thread-multi
/u0/perl/perl580-th/lib/site_perl/5.8.0
/u0/perl/perl580-th/lib/site_perl
.


##=====================================================
test XS code:


MODULE = RDtest PACKAGE = RDtest
PROTOTYPES: ENABLE


int
_list_temp_files()

PREINIT:
DIR *dp;
struct dirent *de;

CODE:
if ((dp = opendir("/tmp")) == NULL) {
XSRETURN_UNDEF;
}

while ((de = readdir(dp)) != NULL) {

printf("%s\n", de->d_name);
}
closedir(dp);

RETVAL = 1;

OUTPUT:
RETVAL




##=====================================================

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupperl5-porters @
categoriesperl
postedOct 19, '02 at 11:07p
activeOct 19, '02 at 11:07p
posts1
users1
websiteperl.org

1 user in discussion

Jpnolan: 1 post

People

Translate

site design / logo © 2021 Grokbase