perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: [Fwd: Re: [rfc] APR::Table & polymorphic values]
Date Fri, 06 Jun 2003 04:34:54 GMT
Joe Schaefer wrote:
> Stas Bekman <stas@stason.org> writes:
> 
> 
>>I'd hate to take the joy of adding these wonderful features away from
>>Philippe,  who's now busy wrestling with mod_perl 1.28 release, but
>>once done will certainly love to do those. Right Philippe?
> 
> 
> Curiosity got the better of me.  Here's a patch that seems to 
> work (all tests pass), but it sure ain't pretty.  Hopefully
> it'll help once Philippe gets some free tuits.

;)

> +    my $c = 0;
> +    while (my($a, $b) = each %$table) {
> +        ok $a eq 'foo';
> +        ok $b eq $array[$c];
> +        ok not defined $table->{'bar'};
> +        $c++;
> +    }

that reads much better to my idiomatic brain than the scary:

for (1..X) {
    my($a, $b) = each %$table;
    ...
}

as it was in your original patch ;)

> +        /* XXX: really nasty hack: set the numeric value of the key
> +         * to represent a pointer to the corresponding val.
> +         * We mark SvEND with another copy of the val's address
> +         * as a means of confirming SvIVX really repesents a 
> +         * pointer.
> +         */
> +        SvUPGRADE(sv, SVt_PVIV);
> +        SvGROW(sv, len + 3*sizeof(IV) + 1);
> +        memcpy(SvPVX(sv), e->key, len);
> +        SvCUR_set(sv, len);
> +        SvEND(sv)[0] = 0;
> +        SvIVX(sv) = (IV) e->val;
> +        ((IV *)SvEND(sv))[1] = SvIVX(sv) = (IV) e->val;
> +        SvPOK_on(sv);
> +        SvIOK_on(sv);

what happens if the key is used in a numeric context? won't this scheme blow? 
Probably the only safe way to do that is to attach magic :(

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message