Front page | perl.perl5.porters |
Postings from May 2003
[perl #22163] perlio callback functions get their args mangled
Thread Next
From:
Stas Bekman
Date:
May 9, 2003 06:52
Subject:
[perl #22163] perlio callback functions get their args mangled
Message ID:
rt-22163-57019.13.823672351236@bugs6.perl.org
# New Ticket Created by Stas Bekman
# Please include the string: [perl #22163]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=22163 >
I get C function arguments changing their values "at will" with perlio
callback functions.
Something strange happens with APR::PerlIO perlio layer running with
perl-5.8.0 w/o threads. it works fine w/ threads. I can reproduce a
similar problem with a standalone script (using Inline for
convenience) and you should be able to reproduce it as well. More over
this time the problem inhibits itself w/ and w/o thread-enabled
perl-5.8.0.
When I run the code listed next I get:
% perl-5.8.0 perliobug.pl
starting debug
in seek: offset=1, whence=0, check=0
in seek: offset=0, whence=0, check=1
in seek: offset=2, whence=0, check=2
Notice that the automatic var 'check' which is a copy of the argument
'whence' works just fine, however whence itself gets reset to zero
when used. The C function to look at is: PerlIOFoo_seek
At the end you will also find a gdb script, which you can invoke with:
% gdb -command=.debug
to debug this thing interactively. It's already adjusted to make it easy to
get to PerlIOFoo_seek's guts
Here is the script:
-------8<-----------------------------------------
use strict;
use warnings;
BEGIN {
use Inline Config =>
#FORCE_BUILD => 1,
CLEAN_AFTER_BUILD => 0;
use Inline C => Config =>
AUTO_INCLUDE => '#include "perliol.h"',
BOOT => 'PerlIO_define_layer(aTHX_ &PerlIO_Foo);',
OPTIMIZE => '-g';
use Inline C => <<END;
void my_bp() {
dTHX;
Perl_warn(aTHX_ "starting debug\n");
}
typedef struct {
struct _PerlIO base;
} PerlIOFoo;
static IV PerlIOFoo_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
{
int check = whence;
Perl_warn(aTHX_ "in seek: offset=%d, whence=%d, check=%d\n",
offset, whence, check);
return 0;
}
static PerlIO_funcs PerlIO_Foo = {
sizeof(PerlIO_funcs),
"Foo",
sizeof(PerlIOFoo),
PERLIO_K_MULTIARG,
PerlIOBase_pushed,
PerlIOBase_popped,
NULL,
PerlIOBase_binmode, /* binmode() is handled by :crlf */
NULL, /* no getarg needed */
PerlIOBase_fileno,
NULL,
NULL,
NULL,
NULL,
PerlIOFoo_seek,
NULL,
PerlIOBase_noop_ok, /* close */
NULL,
PerlIOBase_noop_fail, /* fill */
PerlIOBase_eof,
PerlIOBase_error,
PerlIOBase_clearerr,
PerlIOBase_setlinebuf,
NULL, /* get_base */
NULL, /* get_bufsiz */
NULL, /* get_ptr */
NULL, /* get_cnt */
NULL, /* set_ptrcnt */
};
END
Inline->init;
}
my $tmp = "/tmp/perliobug";
open my $out, ">", $tmp or die "Can't open $tmp: $!";
print $out "x" x 20;
close $out;
open my $in, "<:Foo", $tmp or die "Can't open $tmp: $!";
my_bp();
seek $in, 1, 0;
seek $in, 0, 1;
seek $in, 2, 2;
close $in;
unlink $tmp;
-------8<-----------------------------------------
Here is a debug script
-------8<-----------------------------------------
# NOTE: Adjust the path to the perl executable
file /usr/bin/perl-5.8.0
tb main
# NOTE: adjust the name of the script that you run
run perliobug.pl
# when Perl_runops_debug breakpoint is hit Inline will already load
# the autogenerated .so, so we can set the bp in it (that's only if
# you have run 'Inline->init' inside the BEGIN {} block
b S_run_body
continue
b Perl_runops_debug
continue
# here you set your breakpoints
b my_bp
b Perl_PerlIO_seek
b PerlIOFoo_seek
continue
continue
continue
-------8<-----------------------------------------
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.18-6mdksmp, archname=i686-linux
uname='linux hope.stason.org 2.4.18-6mdksmp #1 smp fri mar 15 01:24:36
cet 2002 i686 unknown '
config_args='-des -Dprefix=/home/stas/perl/5.8.0 -Doptimize=-g
-Duseshrplib -Dusedevel'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-g',
cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/include/gdbm'
ccversion='', gccversion='3.2 (Mandrake Linux 9.1 3.2-4mdk)', 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='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -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,/home/stas/perl/5.8.0/lib/5.8.0/i686-linux/CORE'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING USE_LARGE_FILES
Built under linux
Compiled at Nov 26 2002 17:32:54
@INC:
/home/stas/perl/5.8.0/lib/5.8.0/i686-linux
/home/stas/perl/5.8.0/lib/5.8.0
/home/stas/perl/5.8.0/lib/site_perl/5.8.0/i686-linux
/home/stas/perl/5.8.0/lib/site_perl/5.8.0
/home/stas/perl/5.8.0/lib/site_perl
.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Thread Next
-
[perl #22163] perlio callback functions get their args mangled
by Stas Bekman