Dear Ladies and Gentlemen,
I have a _horrible_ small embedded application that 'works' on
unthreaded 5.8.0 (FreeBSD) but not on a threaded 5.8.0.
perl -MExtUtils::Embed -e xsinit
gcc -g -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm
-I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE -DHAVE_CONFIG_H -c
perlxsi.c `perl -MExtUtils::Embed -e ccopts`
gcc -g -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm
-I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE -DHAVE_CONFIG_H -c
mini_epn.c `perl -MExtUtils::Embed -e ccopts`
gcc -g -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm
-I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE -DHAVE_CONFIG_H
mini_epn.o perlxsi.o `perl -MExtUtils::Embed -e ldopts` -o mini_epn
[EMAIL PROTECTED] new2_mini_epn]$
[EMAIL PROTECTED] new2_mini_epn]$ gdb mini_epn
GNU gdb 5.2.1-2mdk (Mandrake Linux)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i586-mandrake-linux-gnu"...
(gdb) l 74
69 /* generate a temporary filename to
which stdout can be redirected. */
70
sprintf(tmpfname,"/tmp/embedded%d",getpid());
71 args[2] = tmpfname;
72
73 /* call our perl interpreter to compile
and optionally cache the command */
74
call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args);
75
76
call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL, args);
77
78 /* check return status */
(gdb) b 74
Breakpoint 1 at 0x804953d: file mini_epn.c, line 74.
(gdb) r
Starting program: /home/stanley/hack-nag/contrib/new2_mini_epn/mini_epn
Enter file name: ap
Breakpoint 1, main (argc=1, argv=0xbffff8f4, env=0xbffff8fc) at
mini_epn.c:74
74
call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args);
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
0x40034ddc in Perl_call_argv () from
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE/libperl.so
(gdb) q
The program is running. Exit anyway? (y or n) y
[EMAIL PROTECTED] new2_mini_epn]$ perl ap
In the beginning was the word and the word was with God.
[EMAIL PROTECTED] new2_mini_epn]$
The intent of this program is merely to feed a script to an application
that embeds a persistent interpreter - closely copied from the perlembed
man pages.
Here is most of the rubbish ..
char command_line[MAX_COMMANDLINE_LENGTH];
char *ap ;
int exitstatus;
int pclose_result;
dTHX;
dSP;
if((perl=perl_alloc())==NULL){
snprintf(buffer,sizeof(buffer),"Error: Could not allocate memory
for embedded Perl interpreter!\n");
buffer[sizeof(buffer)-1]='\x0';
printf("%s\n", buffer);
exit(1);
}
perl_construct(perl);
exitstatus=perl_parse(perl,xs_init,2,embedding,NULL);
if(!exitstatus){
exitstatus=perl_run(perl);
while(printf("Enter file name: ") &&
fgets(command_line,sizeof(command_line),stdin)){
/* call the subroutine, passing it the filename as an argument
*/
command_line[strlen(command_line) -1] = '\0';
strncpy(fname,command_line,strcspn(command_line," "));
fname[strcspn(command_line," ")] = '\x0';
args[0] = fname ;
args[3] = command_line + strlen(fname) + 1 ;
/* generate a temporary filename to which stdout can be
redirected. */
sprintf(tmpfname,"/tmp/embedded%d",getpid());
args[2] = tmpfname;
/* call our perl interpreter to compile and optionally cache the
command
*/
call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL,
args);
call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL,
args);
/* check return status */
if(SvTRUE(ERRSV)){
pclose_result=-2;
printf("embedded perl ran %s with error
%s\n",fname,SvPV(ERRSV,PL_na));
}
/* read back stdout from script */
fp=fopen(tmpfname, "r");
/* default return string in case nothing was returned */
strcpy(plugin_output,"(No output!)");
fgets(plugin_output,sizeof(plugin_output)-1,fp);
plugin_output[sizeof(plugin_output)-1]='\x0';
fclose(fp);
unlink(tmpfname);
printf("embedded perl plugin output was %d,%s\n", pclose_result,
plugin_output);
}
}
All comments gratefully received.
[EMAIL PROTECTED] new2_mini_epn]$ perl -V
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.19-2mdkenterprise,
archname=i386-linux-thread-multi
uname='linux no.mandrakesoft.com 2.4.19-2mdkenterprise #1 smp tue
aug 13 00:17:42 cest 2002 i686 unknown unknown gnulinux '
config_args='-des -Darchname=i386-linux -Dcc=gcc -Doptimize=-O3
-fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math
-fno-strength-reduce -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr
-Dman3ext=3pm -Dcf_by=MandrakeSoft -Dmyhostname=localhost
[EMAIL PROTECTED] -Dd_dosuid -Ud_csh -Duseshrplib -Dusethreads'
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 -D_GNU_SOURCE -fno-strict-aliasing
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O3 -fomit-frame-pointer -pipe -mcpu=pentiumpro
-march=i586 -ffast-math -fno-strength-reduce',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
-I/usr/include/gdbm'
ccversion='', gccversion='3.2 (Mandrake Linux 9.0 3.2-1mdk)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldl -lm -lpthread -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
libc=/lib/libc-2.2.5.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic
-Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
Built under linux
Compiled at Sep 6 2002 23:24:44
@INC:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0
/usr/lib/perl5/vendor_perl
.
[EMAIL PROTECTED] new2_mini_epn]$
Yours sincerely.
--
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------
'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'
from Meditation 17, J Donne.