develooper Front page | perl.perl5.porters | Postings from February 2004

[possible PATCH] (was: Returning a typeglob from FETCH a tied hash - broken as of 5.8.1)

Thread Previous | Thread Next
From:
Tassilo von Parseval
Date:
February 10, 2004 05:05
Subject:
[possible PATCH] (was: Returning a typeglob from FETCH a tied hash - broken as of 5.8.1)
Message ID:
20040210130231.GA13539@ethan
On Sun, Jan 25, 2004 at 09:17:42AM +0100 Tassilo von Parseval wrote:
> On Sat, Jan 24, 2004 at 09:29:22PM -0500 Kee Hinckley wrote:
> > Prior to 5.8.1 it was possible to return a typeglob from FETCH in a 
> > tied hash.  DBIx::Recordset relies upon this behavior.  I've tested 
> > 5.6.0 on MacOS X 10.2, 5.6.1 on MacOS X 10.3 and 5.8.0 on Linux.  It 
> > works in all of those.  In 5.8.1 and .3 on MacOS X 10.3, and in 5.8.1 
> > on Linux, it does not work.  I believe the problem was introduced by 
> > the addition of calls to sv_upgrade in hv.c.  One is in 
> > Perl_hv_fetch_ent, the other (which may or may not be involved) is in 
> > S_hv_fetch_flags.
> 
> The problem is indeed the call to sv_upgrade() on a FETCH operation.
> When doing a fetch, all relevant data ($self, $key, $val) along with the
> magic is stuffed into one scalar (triggering of FETCH is deferred so all
> this has to be returned from hv_fetch_common in one variable).
> Unfortunately, the type which is currently used (SVt_PVLV) turned out to
> be too small for storing a glob. 
> 
> This is somewhat a known issue but there hasn't yet been an agreement on
> what the right fix would be.

The attached patch against blead (actually against @22297) should again
allow to assign a GLOB to a an element of a tied hash or array. There
are several ways of fixing it and I am not sure mine is the best.

Since a SVt_PVLV thing cannot be upgraded to hold a GV, there had to be
another way to squeeze the glob into the tied thingy. My patch abuses
the PV slot for that. Later, in Perl_magic_setpack where the STORE is
triggered, it checks whether the PV slot is non-NULL and whether it
contains a GV. The test for a proper GV had to be added since there
appear to be cases in which the PV slot holds an HV (and possibly other
things; I couldn't find out where these assignments happen). In this
case, there was no glob-assignment and the whole scalar can be passed as
is to S_magic_methcall.

This is not a very clean way of doing it. A more thorough approach
would be introducing a new type that is large enough to hold the magic
plus anything that was assigned. This would have required some
significant changes to the core so I took the other route.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About