Front page | perl.perl5.porters |
Postings from February 2014
[perl #121348] optimizing Perl_do_kv and Perl_magic_scalarpack, tied HV SCALAR method strangeness
Thread Next
From:
bulk88
Date:
February 28, 2014 02:51
Subject:
[perl #121348] optimizing Perl_do_kv and Perl_magic_scalarpack, tied HV SCALAR method strangeness
Message ID:
rt-4.0.18-32214-1393555851-1818.121348-75-0@perl.org
# New Ticket Created by bulk88
# Please include the string: [perl #121348]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=121348 >
This is a bug report for perl from bulk88@hotmail.com,
generated with the help of perlbug 1.40 running under perl 5.19.9.
-----------------------------------------------------------------
[Please describe your issue here]
I ran across some strange looking code so I investigated. The SPAGAINs
and PUTBACKs can be removed since magic calls now swap stacks. But
removing the X from XPUSH is challenging. There is
" EXTEND(SP, HvUSEDKEYS(keys) * (dokeys + dovalues));"
But it DOESNT extend the stack enough to avoid the X being called in
XPUSHs when executing
"our %Config = %Config::Config;"
in ExtUtils\MakeMaker\Config.pm . I tried doing
------------------------
use Config;
use Data::Dumper;
%h = ('a' => 1, 'b' =>2);
print(Dumper(scalar(%h)));
print(Dumper(scalar(%Config)));
------------------------
which gave
#############5.12
C:\Documents and Settings\Owner\Desktop>perl n11.pl
$VAR1 = "2/8";
$VAR1 = 1;
#############5.19
C:\Documents and Settings\Owner\Desktop>perl n11.pl
$VAR1 = '2/8';
$VAR1 = 1;
But %Config clearly doesn't have 1 key in it. Config_heavy.pl does not
have a SCALAR method, and it seem optional to have one per
Perl_magic_scalarpack(pTHX_ HV *hv, MAGIC *mg) in mg.c. I found
https://rt.perl.org/Ticket/Display.html?id=18186 and
https://rt.perl.org/Ticket/Display.html?id=24798 which seem related to
the fact that SCALAR returns an IMMORTAL SV when there is no SCALAR sub
in the package, not the key and bucket counts. Is this intended behavior
or should it be revisted?
So is there a way to fix " EXTEND(SP, HvUSEDKEYS(keys) * (dokeys +
dovalues));" to remove the X from XPUSHs later in the sub and correctly
EXTEND for tied HVs? Calling SCALAR doesn't work on %Config.
Also Perl_magic_scalarpack seems to do the same stash lookup twice for
no good reason.
-------------------------------------------------------------
SV *
Perl_magic_scalarpack(pTHX_ HV *hv, MAGIC *mg)
{
dVAR;
SV *retval;
SV * const tied = SvTIED_obj(MUTABLE_SV(hv), mg);
HV * const pkg = SvSTASH((const SV *)SvRV(tied));
PERL_ARGS_ASSERT_MAGIC_SCALARPACK;
if (!gv_fetchmethod_autoload(pkg, "SCALAR", FALSE))
{<<<<<<<<<<<<<<<FIRST TIME
SV *key;
if (HvEITER_get(hv))
/* we are in an iteration so the hash cannot be empty */
return &PL_sv_yes;
/* no xhv_eiter so now use FIRSTKEY */
key = sv_newmortal();
magic_nextpack(MUTABLE_SV(hv), mg, key);
HvEITER_set(hv, NULL); /* need to reset iterator */
return SvOK(key) ? &PL_sv_yes : &PL_sv_no;
}
/* there is a SCALAR method that we can call */
retval = Perl_magic_methcall(aTHX_ MUTABLE_SV(hv), mg,
SV_CONST(SCALAR), 0, 0);<<<<<<<<<<<<SECOND TIME
if (!retval)
retval = &PL_sv_undef;
return retval;
}
-------------------------------------------------------------
I did testing with the following patch. That is how I know the SPAGAIN
and PUTBACK can go. The extend check assert were so frequent they were
commented out so the stack realloc asserts can trip without noise.
harness did pass all tests with no crashes from stack realloc assert.
("DebugBreak()" is a C breakpoint function so harness stops because a
child perl proc crashed and I can examine the .t perl process with a C
debugger).
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=wishlist
---
Site configuration information for perl 5.19.9:
Configured by Owner at Wed Feb 12 06:47:30 2014.
Summary of my perl5 (revision 5 version 19 subversion 9) configuration:
Derived from: 633f0fd2ca244ca83cc99b3af3a7d3ac2931850b
Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cl', ccflags ='-nologo -GF -W3 -Od -MD -Zi -DDEBUGGING -DWIN32
-D_CONSOLE -DNO_STRICT -DPERL_TEXTMODE_SCRIPTS
-DPERL_HASH_FUNC_ONE_AT_A_TIME -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T',
optimize='-Od -MD -Zi -DDEBUGGING',
cppflags='-DWIN32'
ccversion='13.10.6030', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
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
-libpath:"c:\perl519\lib\CORE" -machine:x86'
libpth="C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\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 comctl32.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 comctl32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl519.lib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-libpath:"c:\perl519\lib\CORE" -machine:x86'
Locally applied patches:
uncommitted-changes
---
@INC for perl 5.19.9:
C:/perl519/site/lib
C:/perl519/lib
.
---
Environment for perl 5.19.9:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C:\perl519\bin;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\IDE;C:\Program Files\Microsoft Visual Studio .NET
2003\VC7\BIN;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools\bin\prerelease;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;
PERL_BADLANG (unset)
SHELL (unset)
Thread Next
-
[perl #121348] optimizing Perl_do_kv and Perl_magic_scalarpack, tied HV SCALAR method strangeness
by bulk88