Skip Menu |

This queue is for tickets about the Tie-DxHash CPAN distribution.

Report information
The Basics
Id: 20171
Status: resolved
Priority: 0/
Queue: Tie-DxHash

People
Owner: KRUSCOE [...] cpan.org
Requestors: cpan [...] mfoxx.myspamkiller.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.93
Fixed in: (no value)



Subject: Tie::DxHash bug... internal pointer not being reset?
* Tie::DxHash v0.93 (i assume, just got it today by doing a Show quoted text
CPAN>install command).
* Perl v5.8.8 * 2.6.9-xenU #2 Wed Nov 10 13:54:13 CST 2004 i686 GNU/Linux (debian 3.0 linux build). I am trying to use Tie::DxHash inside of <Perl> sections in my httpd.conf file (apache 2.0.54 with mod_perl 2.0.2). I put together this simplified sample code (that I've attached) to demonstrate the issue I'm having with the package. **HOWEVER** I also tested the attached code in just a simple .pl perl program, and it also behaves exactly the same way. Basically, you can see the code has 3 sections in it. The first one demonstrates using Tie::IxHash. You can see that ordering is maintained (unlike a regular hash) as expected, but that duplicate indexes are overwritten, rather than duplicated. The second section demonstrates the same code with Tie::DxHash instead. Also, notice I have commented out the call to the "keys" function in this section. The output is as expected, order is preserved, and duplicate keys are not overwritten but added to the end. The third section illustrates the "bug". By simply uncommenting out the call to the keys function, it causes the rest of the assignment calls that add key/value pairs to the hash to "fail" (apparently, though no warning output or errors seem to be given). The result output then only shows the original contents of the hash before the call to "keys". I had some working code doing something similar, with IxHash, but have run across the need for duplicate keys, so I tried to just switch to DxHash, and have run into this issue now. I actually discovered this *not* while using "keys", but using a while loop with "each", but the behavior is exactly the same. I thought from what I read online that "keys" function calls should reset an internal iteration pointer (that "each" is using, for instance), and so I guessed that perhaps DxHash had some issue with not resetting after the last call to "each", so I tried to put in the "keys" call, as a bunch of websites say to do, and still, nothing. This simplified example in the attached code shows that merely obtaining the number of keys (with keys in the scalar context) messes something up with the hash, so that it cannot be added to after that. In fact, to add to the mix, in the perl only version (not in apache), i get some additional warning output when I make a call to the "print Dumper", *then* add some values, *then* "print Dumper" again. The warning output doesn't occur until that second call to the attempted- changed hash, and it says "Use of uninitialized value in string eq at /usr/local/lib/perl5/site_perl/5.8.8/Tie/DxHash.pm line 69." So, my guess from all of this is that there is some bug with how Tie::DxHash is handling and resetting the internal iterator/pointer. Can you confirm such? Fix or workaround?
Subject: tie_dxhash_bug_demo.txt
<Perl> use Data::Dumper; use Tie::DxHash; use Tie::IxHash; ################################################################################# my %ix_temp; tie(%ix_temp, Tie::IxHash); $ix_temp{"a"} = '1'; $ix_temp{"b"} = '2'; $ix_temp{"c"} = '3'; my $ix_keys = scalar keys %ix_temp; $ix_temp{"a"} = 'sss'; $ix_temp{"b"} = 'ttt'; $ix_temp{"f"} = '3'; print Dumper %ix_temp; # prints out: # $VAR1 = 'a'; # $VAR2 = 'sss'; # $VAR3 = 'b'; # $VAR4 = 'ttt'; # $VAR5 = 'c'; # $VAR6 = '3'; # $VAR7 = 'f'; # $VAR8 = '3'; # # correct, expected behavior ################################################################################# my %dx_temp; tie(%dx_temp, Tie::DxHash); $dx_temp{"a"} = '1'; $dx_temp{"b"} = '2'; $dx_temp{"c"} = '3'; #my $dx_keys = scalar keys %dx_temp; $dx_temp{"a"} = 'sss'; $dx_temp{"b"} = 'ttt'; $dx_temp{"f"} = '3'; print Dumper %dx_temp; # prints out: # $VAR1 = 'a'; # $VAR2 = '1'; # $VAR3 = 'b'; # $VAR4 = '2'; # $VAR5 = 'c'; # $VAR6 = '3'; # $VAR7 = 'a'; # $VAR8 = 'sss'; # $VAR9 = 'b'; # $VAR10 = 'ttt'; # $VAR11 = 'f'; # $VAR12 = '3'; # # correct, expected behavior, notice the "keys" function call is commented out ################################################################################# my %dx_temp2; tie(%dx_temp2, Tie::DxHash); $dx_temp2{"a"} = '1'; $dx_temp2{"b"} = '2'; $dx_temp2{"c"} = '3'; my $dx_keys2 = scalar keys %dx_temp2; $dx_temp2{"a"} = 'sss'; $dx_temp2{"b"} = 'ttt'; $dx_temp2{"f"} = '3'; print Dumper %dx_temp2; # prints out: # $VAR1 = 'a'; # $VAR2 = '1'; # $VAR3 = 'b'; # $VAR4 = '2'; # $VAR5 = 'c'; # $VAR6 = '3'; # # unexpected behavior/bug. calling "keys" function apparently causes subsequent assignments to the hash to fail. </Perl>
Hi Show quoted text
> So, my guess from all of this is that there is some bug with how > Tie::DxHash is handling and resetting the internal iterator/pointer. > Can you confirm such? Fix or workaround?
Many thanks for the bug report and sorry for not getting back to you (much) sooner. I have been at sea for the past two years and only arrived in Australia a couple of weeks ago. As you suggest, the bug (actually in the implementation of the NEXTKEY method) is highlighted when using any function which resets the hash's internal iterator. The latest updated version fixes the issue. Please let me know if you have any more problems. Regards Kevin
Subject: Re: [rt.cpan.org #20171] Tie::DxHash bug... internal pointer not being reset?
Date: Wed, 27 Dec 2006 09:32:04 -0600
To: <bug-Tie-DxHash [...] rt.cpan.org>
From: "mfoxx" <mfoxx [...] hotmail.com>
Kevin- Thank you so much for responding. I included your new version, and it works great! Guess it paid to be patient on this one... I just went back to using IxHash when I discovered the issue with DxHash, and just figured since I didn't really have a pressing need for the DxHash functionality quite yet, I'd just wait and be patient to see if a fix ever came, and it finally did! BTW, I am using this in conjunction with some perl code I wrote and embedded in my httpd.conf file, which actually pulls all my virtual host info from a mysql database, instead of being in the conf file itself. I do this so I can manage virtual hosts via web scripts that modify the database tables, and never need to interact with the file, thereby being safer. The need for DxHash comes in that, for instance, I may want to have 2 or 3 entries for a virtual host that are "ServerAlias". This gives rise to the need for duplicate keys. I need the ordering functionality (like IxHash) because there are a few apache vhost directives in which their order inside the entry matters, so I maintain an order-override column in my database to force certain particular configurables (from IxHash) to be the first in the vhost perl hash, but without DxHash, the behavior was unpredictable. Neither of these needs had been a problem actually yet, but it might have been in the future, so I definitely appreciate the updated code. Actually, there was one particular use which necessitated at least IxHash usage in the first place. One peculiarity of Apache is that in a multiple vhost config environment, the very first vhost configuration found is the one used for any default, later unmatched apache requests. So, say one of the vhosts is disabled (for an account being on hold, for instance)... I need for the very first vhost entry, the default one for the server, to take over. Of course, this means I need to control what goes into the first entry, thus the need for an order preserving hash. :) I currently have about 300 records across about 40 virtual host entries, and my apache starts up almost instantaneously, so I don't think speed of the key algorithm as you mentioned in the documentation is any problem for my data set size. Even if I had a much larger data set, and Apache took 5 or 10 seconds to load, since I rarely restart apache, and even then only when apache config data would change, which should be not very often at all, I think even a 30 second or more restart time wouldn't be *that* bad. But, just out of curiosity, at about how many records (loop iterations, hash key inserts, etc) would you think this DxHash code might have speed issues where it was taking say greater than 10 seconds to loop through? 10,000? more? --Kyle Simpson Show quoted text
----- Original Message ----- From: "Kevin Ruscoe via RT" <bug-Tie-DxHash@rt.cpan.org> To: <cpan@mfoxx.myspamkiller.com> Sent: Monday, December 11, 2006 7:33 PM Subject: [rt.cpan.org #20171] Tie::DxHash bug... internal pointer not being reset?
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=20171 > > > Hi >
> > So, my guess from all of this is that there is some bug with how > > Tie::DxHash is handling and resetting the internal iterator/pointer. > > Can you confirm such? Fix or workaround?
> > Many thanks for the bug report and sorry for not getting back to you > (much) sooner. I have been at sea for the past two years and only > arrived in Australia a couple of weeks ago. > > As you suggest, the bug (actually in the implementation of the NEXTKEY > method) is highlighted when using any function which resets the hash's > internal iterator. > > The latest updated version fixes the issue. Please let me know if you > have any more problems. > > Regards > Kevin >
Subject: Re: [rt.cpan.org #20171] Tie::DxHash bug... internal pointer not being reset?
Date: Thu, 28 Dec 2006 09:42:01 +1000
To: bug-Tie-DxHash [...] rt.cpan.org
From: Kevin Ruscoe <kevin [...] sapphireoflondon.org>
Hi Kyle Show quoted text
> I included your new version, and it works great!
Good stuff. Apologies again that it took so long. Show quoted text
> which actually pulls all my virtual host info from a mysql database,
instead of being in the conf file itself That sounds like a good option. I have never had the need myself, since I have never needed more than a handful of vhosts which did not change very often. Show quoted text
> at about how many records (loop iterations, hash key inserts, etc)
would you think this DxHash code Show quoted text
> might have speed issues where it was taking say greater than 10
seconds to loop through? 10,000? Probably at least that many. I only mentioned that in the docs in case somebody found a use for the module - unrelated to Apache cfg - which involved much larger data sets. I should not imagine that any performance problems would arise when used to configure Apache. Regards Kevin
This was resolved several months ago. Think it was reset to open in errorl