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

B::Deparse mangles constant subs which return blessed objects #9925

Open
p5pRT opened this issue Oct 26, 2009 · 7 comments
Open

B::Deparse mangles constant subs which return blessed objects #9925

p5pRT opened this issue Oct 26, 2009 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 26, 2009

Migrated from rt.perl.org#70023 (status was 'open')

Searchable as RT70023$

@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2009

From anteusz@freemail.hu

Created by anteusz@freemail.hu

I used B​::Deparse on a file. The deparsed file does not run. I get a
syntax error.
I use WxPerl in my application...
My guess is wxDefaultPosition is a constant
This is how the line looks originally​:
$parent->{toolbar} = Wx​::ToolBar->new( $parent, -1, wxDefaultPosition,
wxDefaultSize, wxTB_VERTICAL );
Here is the translation....
$$parent{'toolbar'} = 'Wx​::ToolBar'->new($parent, -1, \3733296,
\34872400, wxTB_VERTICAL());

Here is the error I get
variable is not of type Wx​::Point at D​:\m\perlscripts\textedit.deparsed
line 239
wxDefaultPosition is of type Wx​::Point....
somehow this information gets lost..

I have version 5.10.0. Activestate.

I used concise to analyse the given line...
Here it is​:
# 3443​: $parent->{toolbar} = Wx​::ToolBar->new( $parent, -1,
wxDefaultPosition, wxDefaultSize, wxTB_VERTICAL );
2e <;> nextstate(Editor​::GUI 11738 textedit.pl​:3443) v​:*,&,{,$
2f <0> pushmark s
2g <$> const[PV "Wx​::ToolBar"] sM/BARE
2h <0> padsv[$parent​:11736,11745] lM
2i <$> const[IV -1] sM
2j <$> const[RV \1374160] sM
2k <$> const[RV \34872400] sM
2l <0> pushmark s
2m <#> gv[*Editor​::GUI​::wxTB_VERTICAL] s
2n <1> entersub[t29] lKMS/NO(),TARG,INARGS,3
2o <$> method_named[PV "new"] s
2p <1> entersub[t30] sKS/TARG,2
2q <0> padsv[$parent​:11736,11745] sM/DREFHV
2r <1> rv2hv[t26] sKR/3
2s <$> const[PV "toolbar"] s/BARE
2t <2> helem sKRM*/2
2u <2> sassign vKS/2

Perl Info

Flags:
    category=library
    severity=medium

Site configuration information for perl 5.10.0:

Configured by SYSTEM at Wed Sep  3 13:16:08 2008.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=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='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE 
-DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS 
-DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8804', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', 
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf  
-libpath:"C:\Perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib 
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  
version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug 
-opt:ref,icf  -libpath:"C:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY
    33741 avoids segfaults invoking S_raise_signal() (on Linux)
    33763 Win32 process ids can have more than 16 bits
    32809 Load 'loadable object' with non-default file extension
    32728 64-bit fix for Time::Local


@INC for perl 5.10.0:
    C:/Perl/site/lib
    C:/Perl/lib
    .


Environment for perl 5.10.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=C:\DevSuiteHome_2\jdk\jre\bin\classic;C:\DevSuiteHome_2\jdk\jre\bin;C:\DevSuiteHome_2\jdk\jre\bin\client;C:\DevSuiteHome_2\jlib;C:\DevSuiteHome_2\bin;C:\DevSuiteHome_2\jre\1.4.2\bin\client;C:\DevSuiteHome_2\jre\1.4.2\bin;D:\app\Márton\product\11.1.0\db_1\bin;D:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program 
Files\Common Files\GTK\2.0\bin ;C:\Program Files\TortoiseHg;C:\Program 
Files\Perforce;C:\Program 
Files\QuickTime\QTSystem\;d:\standalone\Parrot-1.5.0\bin;c:\Program 
Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft 
SQL Server\100\DTS\Binn\;C:\Program Files\Objective Caml\bin;C:\Program 
Files\Haskell\bin;d:\standalone\ghc\ghc-6.10.4\bin;
    PERL_BADLANG (unset)
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2009

From zefram@fysh.org

equinox wrote​:

$parent->{toolbar} = Wx​::ToolBar->new( $parent, -1, wxDefaultPosition,
wxDefaultSize, wxTB_VERTICAL );
Here is the translation....
$$parent{'toolbar'} = 'Wx​::ToolBar'->new($parent, -1, \3733296,
\34872400, wxTB_VERTICAL());

Evidently wxDefaultPosition is a constant sub which resolves to reference
to a blessed object. (The same for wxDefaultSize.) The blessed object
is a scalar holding a the address of a C-level data structure; this is
a common trick when integrating C libraries into Perl, but gets in the
way of Perl-level manipulability.

Because the constant sub gets replaced by a constant op, B​::Deparse has
no chance to determine the name "wxDefaultPosition". However, using that
name is the *only* way to correctly reference the object. So B​::Deparse
can't win. It could conceivably emit "bless(\3733296,"Wx​::Point")"
instead of "\3733296", which would correctly represent the Perl part
of the data structure and would partially work if evaled in the same
Perl process. But it would screw up reference counting​: the underlying C
structure would be prone to disappear under the wxDefaultPosition object.
It wouldn't work at all if evaled in a different process.

B​::Deparse should probably give up when it sees the blessed object,
and throw an exception. However, the partially-correct output would
be of some use in some situations, so there's a case for B​::Deparse to
behave exactly as it does.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Oct 26, 2009

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2009

From anteusz@freemail.hu

Zefram via RT wrote​:

equinox wrote​:

$parent->{toolbar} = Wx​::ToolBar->new( $parent, -1, wxDefaultPosition,
wxDefaultSize, wxTB_VERTICAL );
Here is the translation....
$$parent{'toolbar'} = 'Wx​::ToolBar'->new($parent, -1, \3733296,
\34872400, wxTB_VERTICAL());

Evidently wxDefaultPosition is a constant sub which resolves to reference
to a blessed object. (The same for wxDefaultSize.) The blessed object
is a scalar holding a the address of a C-level data structure; this is
a common trick when integrating C libraries into Perl, but gets in the
way of Perl-level manipulability.

Because the constant sub gets replaced by a constant op, B​::Deparse has
no chance to determine the name "wxDefaultPosition". However, using that
name is the *only* way to correctly reference the object. So B​::Deparse
can't win. It could conceivably emit "bless(\3733296,"Wx​::Point")"
instead of "\3733296", which would correctly represent the Perl part
of the data structure and would partially work if evaled in the same
Perl process. But it would screw up reference counting​: the underlying C
structure would be prone to disappear under the wxDefaultPosition object.
It wouldn't work at all if evaled in a different process.

B​::Deparse should probably give up when it sees the blessed object,
and throw an exception. However, the partially-correct output would
be of some use in some situations, so there's a case for B​::Deparse to
behave exactly as it does.

-zefram

What about synchronizing the source and the syntax tree? And if this
case can be detected, then call could be copied from the source. The
source is available , is not it?

Marton.

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2009

From zefram@fysh.org

anteusz@​freemail.hu wrote​:

source is available , is not it?

No. The source is generally not available at runtime, and even if
it were it would not necessarily be parsable. In fact, the ops in
question aren't necessarily derived from Perl source code at all.
B​::Deparse needs to handle sourceless code, on the same terms that it
handles code from source.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Oct 28, 2009

From @nwc10

On Wed, Oct 28, 2009 at 10​:44​:33AM +0000, Zefram wrote​:

anteusz@​freemail.hu wrote​:

source is available , is not it?

No. The source is generally not available at runtime, and even if
it were it would not necessarily be parsable. In fact, the ops in
question aren't necessarily derived from Perl source code at all.
B​::Deparse needs to handle sourceless code, on the same terms that it
handles code from source.

The whole intent of B​::Deparse *is* to convert ops back into source code that
generates them (as best it can), without reference to anything outside the
optree and the rest of the interpreter state.

Nicholas Clark

@demerphq
Copy link
Collaborator

demerphq commented Sep 8, 2022

I think we should close this ticket.

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

3 participants