Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blessed object lost in anon sub from 'C' call #3129

Closed
p5pRT opened this issue Jan 16, 2001 · 5 comments
Closed

blessed object lost in anon sub from 'C' call #3129

p5pRT opened this issue Jan 16, 2001 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 16, 2001

Migrated from rt.perl.org#5198 (status was 'resolved')

Searchable as RT5198$

@p5pRT
Copy link
Author

p5pRT commented Jan 16, 2001

From madison@transmeta.com

I have a bug that I managed to isolate to these conditions​:

1) C code starts a perl interpretor that blesses an object
2) C code calls a perl function that creates an anon sub that
  refers to the blessed object.
3) C code calls a perl function that calls the anon sub.

Depending on where and how the blessed object was referred to in
the code *around* the anon sub, it can become undefined in the anon sub.

For example, if the blessed variable isn't mentioned except in
the sub, it will get "lost" (and have an undef value in the sub).

If you just refer to it, then it won't get lost, and sometimes this
fixes other creation of anon subs. It has weird behavior, but it
is reproducible. Calling a subroutine (other than a builtin like
print) inside the anon sub fixes the problem as well.

I tried to run it on perl 5.6.0, but my 5.6 is threaded, and
that's another problem..

Here's the tar of my makefile, the C code and the perl code

begin 640 foo.tz.uu
M'XL(`"3&9#H``^U7;6_B.!#F​:_,K1BFZAI​:7$$J18'LZ#M(6'7T14.FDMJ(A
M,6W​:$$>)T^V*Y7[[C6U2J'​:KO​:N.[H?S\R&)QS/C\4S\V)Y2​:E5RFX5I[IN-
MNHEOTZI9=?XVJ_ORO43.;%BU​:G6_AJHYLVH>-.HYJ&\X+H$T84X,D)LYGI_0
M\$T]$MY]1#@​?C2FO_ZGS2*9^0#8T!M;3/-A_L_[5​:MU​:U;^&\JI5JQWDP-Q0
M/*_P/Z]_USYJ7_9'<`CX)VA​:YZC7MX>'>>.S'WBN$WNP6W;=@​G​:^E,^E0A.%
MAV6ZX`;]]O$0S4LNY(W>6​:=_V;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X3Q5?6&ZXD@​&*[[EL9\(C^+L,-7\4X1+,M​:
MQNG2%-?T(9@​MX9JO+4%D_A2,O;VL&P.6_`;2$Y^!Q=?<`DB0<-V5II5IXN6$
MSF8$I>("$I)G!OP.`OPPS$D_)#[R?0P\5\!'_TSCQV0U2FMK&P9DBAJ,BIU!
MI`IO$,N-PYCZSR21N1​:1%Z2M​:!\*C_/L\G)"OC2E5WZ-`;$C+9;S7,5>RV+_
M92Z\+"2S?*NX_Y*.]P]6?VLP?"Q+V[!^"ILI*"@​H*"@​H*"@​H*"@​H*"@​H*"@​H
-*"AD^!LFL2<\`"@​`````
`
end

Perl Info


Site configuration information for perl 5.00503:

Configured by root at Mon Aug 30 23:08:56 EDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.5-22smp, archname=i386-linux
    uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/lib/perl5/5.00503/i386-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i386-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/madison
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/madison/bin/i386-linux-libc6:/home/madison/bin:/usr/local/bin/i386-linux-libc6:/usr/local/bin:/usr/local/contrib/bin:/bin:/usr/bin:/usr/X11R6/bin:.:/proj/validation/bin/i386-linux-libc6:/proj/validation/bin:/proj/hw/bin/i386-linux-libc6:/proj/hw/bin:/proj/sw/r5/fred/i386-linux-libc6/bin:/cad/polaris/current/exe:/cad/innologic/current/scripts:/cad/scripts:/cad/ssi/current/bin/:/usr/local/lsf/bin:/usr/local/contrib/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented May 22, 2012

From @Hugmeir

On Tue Jan 16 06​:25​:59 2001, madison@​transmeta.com wrote​:

-----------------------------------------------------------------
[Please enter your report here]

I have a bug that I managed to isolate to these conditions​:

1) C code starts a perl interpretor that blesses an object
2) C code calls a perl function that creates an anon sub that
refers to the blessed object.
3) C code calls a perl function that calls the anon sub.

Depending on where and how the blessed object was referred to in
the code *around* the anon sub, it can become undefined in the anon
sub.

For example, if the blessed variable isn't mentioned except in
the sub, it will get "lost" (and have an undef value in the sub).

If you just refer to it, then it won't get lost, and sometimes this
fixes other creation of anon subs. It has weird behavior, but it
is reproducible. Calling a subroutine (other than a builtin like
print) inside the anon sub fixes the problem as well.

I tried to run it on perl 5.6.0, but my 5.6 is threaded, and
that's another problem..

Here's the tar of my makefile, the C code and the perl code

begin 640 foo.tz.uu
M'XL(`"3&9#H``^U7;6_B.!#F​:_,K1BFZAI​:7$$J18'LZ#M(6'7T14.FDMJ(A
M,6W​:$$>)T^V*Y7[[C6U2J'​:KO​:N.[H?S\R&)QS/C\4S\V)Y2​:E5RFX5I[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/R<W@​
M'YA,M[BL-2_VTTN#A$\13P/.​:^T_T9$;RU&@​BPR^9.L_​::RJ)EK//C.J,E4?
MO?X%_\N);FR,'Y[_D>PS_J\=U#C_HZ+B_X\`/X`C6_@​NPV4]^P)Y)Z1ABY\/
M)S#"LVFGW6\/8`Z\​:X*<5C5;R'DLC4.8!'@​JA^O\I`4+H7]DCSHGJ+OL+Y7R
M\_SXRKQ99`K#T?G`7BEDW;"'UX3Q5?6&ZXD@​&*[[EL9\(C^+L,-7\4X1+,M​:
MQNG2%-?T(9@​MX9JO+4%D_A2,O;VL&P.6_`;2$Y^!Q=?<`DB0<-V5II5IXN6$
MSF8$I>("$I)G!OP.`OPPS$D_)#[R?0P\5\!'_TSCQV0U2FMK&P9DBAJ,BIU!
MI`IO$,N-PYCZSR21N1​:1%Z2M​:!\*C_/L\G)"OC2E5WZ-`;$C+9;S7,5>RV+_
M92Z\+"2S?*NX_Y*.]P]6?VLP?"Q+V[!^"ILI*"@​H*"@​H*"@​H*"@​H*"@​H*"@​H
-*"AD^!LFL2<\`"@​`````
`
end

[Please do not change anything below this line]
-----------------------------------------------------------------

---
Site configuration information for perl 5.00503​:

Configured by root at Mon Aug 30 23​:08​:56 EDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
Platform​:
osname=linux, osvers=2.2.5-22smp, archname=i386-linux
uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2
09​:11​:51 edt 1999 i686 unknown '
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef useperlio=undef d_sfio=undef
Compiler​:
cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux
(egcs-1.1.2 release)
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
stdchar='char', d_stdstdio=undef, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries​:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lposix -lcrypt
libc=, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-
rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:

---
@​INC for perl 5.00503​:
/usr/lib/perl5/5.00503/i386-linux
/usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005
.

---
Environment for perl 5.00503​:
HOME=/home/madison
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/madison/bin/i386-linux-
libc6​:/home/madison/bin​:/usr/local/bin/i386-linux-

libc6​:/usr/local/bin​:/usr/local/contrib/bin​:/bin​:/usr/bin​:/usr/X11R6/bin
:.​:/proj/validation/bin/i386-

linux-libc6​:/proj/validation/bin​:/proj/hw/bin/i386-linux-
libc6​:/proj/hw/bin​:/proj/sw/r5/fred/i386-linux-

libc6/bin​:/cad/polaris/current/exe​:/cad/innologic/current/scripts​:/cad/s
cripts​:/cad/ssi/current/bin/​:/usr/local/lsf/bin​:/usr/local/contrib/bin

PERL\_BADLANG \(unset\)
SHELL=/bin/tcsh

I think that this was solved somewhere along the road​:
hugmeir@​naw​:~/foo2$ ./main
Hey​: 21
Hey​: 20

I get the same thing when commenting the line indicated in foo.pl. But I
had to change the .cc a bit to make it compile, so maybe I screwed
something up along the way; If someone can confirm, this ticket could be
closed.

@p5pRT
Copy link
Author

p5pRT commented Jan 30, 2013

From @bulk88

On Mon May 21 18​:52​:35 2012, Hugmeir wrote​:

I think that this was solved somewhere along the road​:
hugmeir@​naw​:~/foo2$ ./main
Hey​: 21
Hey​: 20

I get the same thing when commenting the line indicated in foo.pl. But I
had to change the .cc a bit to make it compile, so maybe I screwed
something up along the way; If someone can confirm, this ticket could be
closed.

Ditto. Close it. Attaching my fixes of main.cc to work on a modern perl.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Jan 30, 2013

From @bulk88

#include <EXTERN.h>
#include <perl.h>
#include <stdio.h>

// --------------------------------------------------
// Perl setup
// --------------------------------------------------
static PerlInterpreter *PERL;
start_perl(char *script) {
  char *args[] = {"",script};
  // setup the perl object and read in the script
  PERL = perl_alloc();
  perl_construct(PERL);
  perl_parse(PERL, NULL, 3, args, NULL);
  perl_run(PERL);
}

end_perl() {
  perl_destruct(PERL);
  perl_free(PERL);
}

do_call() {
    dTHX;
  // Perl juju magick:
  dSP;

  PUSHMARK(sp);

  perl_call_pv("call", G_DISCARD|G_NOARGS);
}

// --------------------------------------------------
// Test code
// --------------------------------------------------
int main(int argc, char **argv, char **envp) {
    PERL_SYS_INIT3(&argc,&argv,NULL);
  start_perl("foo.pl");
  do_call();
  do_call();
  do_call();
  do_call();
  do_call();
  do_call();
  end_perl();
  PERL_SYS_TERM();
  exit(1);
}

@p5pRT
Copy link
Author

p5pRT commented Jan 30, 2013

@iabyn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant