What happens if you "my" the $str inside the foreach of the first sub
listing?

Joe Frazier, Jr.
Senior Support Engineer

Peopleclick Service Support
Tel:  +1-800-841-2365
E-Mail: [EMAIL PROTECTED] 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Glenn Linderman
> Sent: Tuesday, July 27, 2004 2:36 AM
> To: GUI
> Subject: [perl-win32-gui-users] exception in Perl's C code... 
> "fixed" by reworking the Perl source. But why?
> 
> So, I find this to be an interesting problem.  Probably my 
> "fix" just hides the problem, rather than fixing it.  It 
> smells of an unitialized variable "somewhere".
> 
> I have this Perl program that works consistently correctly on 
> Win2K.  On WinXP, it fails pretty regularly but not always, 
> on certain operations.
> 
> This Perl program uses Win32::GUI, and contains a combobox 
> widget.  On occasion, and as part of the operation that makes 
> the program fail with an access violation, it needs to read 
> the contents of the combobox.  It uses the following 
> subroutine to do so.
> 
> After figuring out how to install symbols for Perl, using 
> MSVC++6.0's debug IDE traceback, I discovered the failure 
> happens in interpreting this sub, called from DoEvent.  The 
> sub is fairly straightforward, in wanting to copy each entry 
> from the ComboBox into the key of a hash. 
> The data are all unique, as the combobox was populated from a 
> hash initially.  The actual failure was in reading some hash 
> value or property (if I can guess at the Perl internal symbol 
> names reasonably).
> 
> The first subroutine below is how it was, when it worked on 
> Win2K and failed on WinXP.  The second subroutine succeeded 3 
> timse in a row on WinXP.
> 
> Clearly my modified version and the original version do the 
> same job, but the modified version does it "slower" by using 
> an intermediate array.  (A slow algorithm is faster than a 
> broken algorithm.)  However, I see no reason why this should 
> "fix" a crash, nor why the crash should be there in the first place.
> 
> 
> # bad
> #####################################
> sub read_lb  # version 2002/02/23
> { my ( $lb ) = @_;
>    my ( %hash, $count, $ix, $str );
>    $count = $lb->Count () - 1;
>    foreach $ix ( 0 .. $count )
>    { $str = $lb->GetString ( $ix );
>      $hash{ $str } = 1;
>    }
>    return \%hash;
> }
> #####################################
> 
> 
> # good
> #####################################
> sub read_lb  # version 2002/07/26
> { my ( $lb ) = @_;
>    my ( %hash, $count, $ix, @str );
>    $count = $lb->Count () - 1;
>    foreach $ix ( 0 .. $count )
>    { push @str, $lb->GetString ( $ix );
>    }
>    foreach my $str ( @str )
>    { $hash{ $str } = 1;
>    }
>    return \%hash;
> }
> #####################################
> 
> --
> Glenn -- http://nevcal.com/
> ===========================
> The best part about procrastination is that you are never 
> bored, because you have all kinds of things that you should be doing.
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by BEA Weblogic Workshop
> FREE Java Enterprise J2EE developer tools!
> Get your free copy of BEA WebLogic Workshop 8.1 today.
> http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
> 
> 
> 

Reply via email to