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
exists() on tied hash generates call to FETCH #355
Comments
From @mjdominusIf %h is a tied hash, then exists $h{key} calls the tied EXISTS method and then the tied FETCH method. Sample: ---------------- BEGIN SAMPLE PROGRAM ------------ tie %h => T; package T; sub TIEHASH { sub EXISTS { print "EX\n"; return } sub FETCH { print "FETCH\n"; return } ---------------- END SAMPLE PROGRAM ------------ This program prints out EX even though no fetch should have been done. This problem occurs under at least the following: 5.005_02, _56, and _57. Perl Info
|
From [Unknown Contact. See original ticket]On Sun, 08 Aug 1999 at 13:19:01 -0000, mjd@plover.com wrote:
This appears only to be true if EXISTS returns 'undef', as your example I construe this as a feature; EXISTS returning 'undef' means "don't Ian |
From @mjdominus
Ho! Thank you!
If so, it is a mighty weird feature, because it is the only place in I also don't see it as a very useful feature. Suppose the EXISTS Thanks again for telling me how to fix this. |
From @mjdominusCreated by @mjdominusIf %h is a tied hash, then exists $h{key} calls the tied EXISTS method and then the tied FETCH method. Sample: ---------------- BEGIN SAMPLE PROGRAM ------------ tie %h => T; package T; sub TIEHASH { sub EXISTS { print "EX\n"; return } sub FETCH { print "FETCH\n"; return } ---------------- END SAMPLE PROGRAM ------------ This program prints out EX even though no fetch should have been done. This problem occurs under at least the following: 5.005_02, _56, and Ian Phillipps points out that this occurs only when EXISTS returns Perl Info
|
From @rspierSearching the BugDB for easy ones to close. A quick summary is that http://bugs.perl.org/perlbug.cgi?req=bidmids&bidmids=19990808.001&range=23873&format=H (If you choose to apply this patch, the bug can be easily closed by Inline Patch--- perltie.pod.orig Fri Mar 9 02:03:59 2001
+++ perltie.pod Fri Mar 9 02:09:41 2001
@@ -725,6 +725,10 @@
return exists $self->{LIST}->{$dot};
}
+If your method returns undef (as opposed to a true or false value)
+perl will attempt to satisfy the exists() function by triggering a C<FETCH>.
+If C<FETCH> returns a true value, exists() will be true.
+
=item FIRSTKEY this
This method will be triggered when the user is going |
From @mjdominus
I respectfully disagree. I think this is a bug, not a feature. At least, it is not normal for Perl to treat 'undef' in this special I think the correct approach is to fix it, or at least to leave it as |
From @rspierWhat you're saying makes sense. So, I'll start following it down the other path: A little bit of GDB walking and here's what I see: FETCH is being called inside the SvTRUE is a scary macro which calls sv_2bool and mg_get calls the get entry in the vtable for the magic, which for I think the problem is that the sv passed to I think the patch below may (actually) solve this problem (instead of All tests in the test suite pass for me, (except for op/qu.t, which is Inline Patch--- hv.c.orig Fri Mar 9 03:16:20 2001
+++ hv.c Fri Mar 9 03:20:34 2001
@@ -927,11 +927,12 @@
if (SvRMAGICAL(hv)) {
if (mg_find((SV*)hv,'P')) {
+ SV* svret = sv_newmortal();
sv = sv_newmortal();
keysv = sv_2mortal(newSVsv(keysv));
mg_copy((SV*)hv, sv, (char*)keysv, HEf_SVKEY);
- magic_existspack(sv, mg_find(sv, 'p'));
- return SvTRUE(sv);
+ magic_existspack(svret, mg_find(sv, 'p'));
+ return SvTRUE(svret);
}
#ifdef ENV_IS_CASELESS
else if (mg_find((SV*)hv,'E')) {
-R
MD> I respectfully disagree. I think this is a bug, not a feature. MD> At least, it is not normal for Perl to treat 'undef' in this MD> I think the correct approach is to fix it, or at least to leave it |
From @jhiOn Fri, Mar 09, 2001 at 03:30:20AM -0500, Robert Spier wrote:
Thanks, applied. rm t/op/qu.t |
From The RT System itselfpatch included in change @9090. Waiting a few days for fallout before closing bug. |
From [Unknown Contact. See original ticket]dupe |
Migrated from rt.perl.org#1189 (status was 'resolved')
Searchable as RT1189$
The text was updated successfully, but these errors were encountered: