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
Tassilo von Parseval
February 10, 2004 05:05
[possible PATCH] (was: Returning a typeglob from FETCH a tied hash - broken as of 5.8.1)
Message ID:
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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About