You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Joe Schaefer <jo...@sunstarsys.com> on 2004/07/12 21:19:55 UTC
APR::Table each() support for multivalued keys
This weekend I finally got around to implementing multivalued
key iterators in apreq2. Here is a backport of the each() code
to APR::Table, with apr-ext/table.t tests included. Rather
than lauching into a longwined explanation of the hows and
whys of this patch (see
http://marc.theaimsgroup.com/?t=105478383300002&r=1&w=2
for the priors), please look over those new apr-ext/table.t
tests to see what behavior this patch provides.
Thanks in advance for looking this over- I'll be happy to
explain it in more detail if anyone is interested.
Index: xs/maps/apr_functions.map
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/maps/apr_functions.map,v
retrieving revision 1.82
diff -u -r1.82 apr_functions.map
--- xs/maps/apr_functions.map 9 Jun 2004 14:46:22 -0000 1.82
+++ xs/maps/apr_functions.map 12 Jul 2004 18:54:26 -0000
@@ -253,7 +253,7 @@
-apr_table_setn
apr_table_unset
-apr_table_vdo
- const char *:DEFINE_FETCH | | apr_table_t *:t, const char *:key
+ const char *:DEFINE_FETCH | MPXS_apr_table_get |
void:DEFINE_STORE | | apr_table_t *:t, const char *:key, const char *:value
void:DEFINE_DELETE | | apr_table_t *:t, const char *:key
void:DEFINE_CLEAR | | apr_table_t *:t
Index: t/apr-ext/table.t
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/apr-ext/table.t,v
retrieving revision 1.1
diff -u -r1.1 table.t
--- t/apr-ext/table.t 16 Jun 2004 03:55:48 -0000 1.1
+++ t/apr-ext/table.t 12 Jul 2004 18:54:24 -0000
@@ -1,15 +1,32 @@
use Apache::Test;
-
+use Apache::TestUtil;
use blib;
use Apache2;
-plan tests => 1;
+plan tests => 13;
require APR;
require APR::Table;
require APR::Pool;
+use APR;
+use APR::Table;
+use APR::Pool;
my $p = APR::Pool->new;
my $table = APR::Table::make($p, 2);
ok ref $table eq 'APR::Table';
+
+$table->add("first" => 1);
+$table->add("second" => 2);
+$table->add("first" => 3);
+
+my $i = 0;
+while (($a,$b) = each %$table) {
+ my $key = ("first", "second")[$i % 2];
+ my $val = ++$i;
+ ok t_cmp $a, $key, "table each: key test";
+ ok t_cmp $b, $val, "table each: value test";
+ ok t_cmp $table->get($a), $val, "table each: get test";
+ ok t_cmp tied(%$table)->get($a), $val, "table each: tied get test";
+}
Index: src/modules/perl/modperl_common_util.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_common_util.h,v
retrieving revision 1.2
diff -u -r1.2 modperl_common_util.h
--- src/modules/perl/modperl_common_util.h 22 Jun 2004 22:34:10 -0000 1.2
+++ src/modules/perl/modperl_common_util.h 12 Jul 2004 18:54:23 -0000
@@ -75,6 +75,9 @@
SV *tsv, void *p);
/* tied %hash */
+MP_INLINE SV *modperl_hash_tied_object_rv(pTHX_
+ const char *classname,
+ SV *tsv);
MP_INLINE void *modperl_hash_tied_object(pTHX_ const char *classname,
SV *tsv);
Index: src/modules/perl/modperl_common_util.c
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_common_util.c,v
retrieving revision 1.2
diff -u -r1.2 modperl_common_util.c
--- src/modules/perl/modperl_common_util.c 22 Jun 2004 22:34:10 -0000 1.2
+++ src/modules/perl/modperl_common_util.c 12 Jul 2004 18:54:23 -0000
@@ -36,9 +36,9 @@
gv_stashpv(classname, TRUE)));
}
-MP_INLINE void *modperl_hash_tied_object(pTHX_
- const char *classname,
- SV *tsv)
+MP_INLINE SV *modperl_hash_tied_object_rv(pTHX_
+ const char *classname,
+ SV *tsv)
{
if (sv_derived_from(tsv, classname)) {
if (SVt_PVHV == SvTYPE(SvRV(tsv))) {
@@ -47,7 +47,7 @@
if (SvMAGICAL(hv)) {
if ((mg = mg_find(hv, PERL_MAGIC_tied))) {
- return (void *)MgObjIV(mg);
+ return mg->mg_obj;
}
else {
Perl_warn(aTHX_ "Not a tied hash: (magic=%c)", mg);
@@ -58,7 +58,7 @@
}
}
else {
- return (void *)SvObjIV(tsv);
+ return tsv;
}
}
else {
@@ -67,7 +67,17 @@
"(expecting an %s derived object)", classname);
}
- return NULL;
+ return &PL_sv_undef;
+}
+MP_INLINE void *modperl_hash_tied_object(pTHX_
+ const char *classname,
+ SV *tsv)
+{
+ SV *rv = modperl_hash_tied_object_rv(aTHX_ classname, tsv);
+ if (SvROK(rv))
+ return (void *)SvIVX(SvRV(rv));
+ else
+ return NULL;
}
/* same as Symbol::gensym() */
Index: xs/APR/Table/APR__Table.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/APR/Table/APR__Table.h,v
retrieving revision 1.11
diff -u -r1.11 APR__Table.h
--- xs/APR/Table/APR__Table.h 4 Mar 2004 06:01:10 -0000 1.11
+++ xs/APR/Table/APR__Table.h 12 Jul 2004 18:54:26 -0000
@@ -13,7 +13,6 @@
* limitations under the License.
*/
-#define mpxs_APR__Table_FETCH apr_table_get
#define mpxs_APR__Table_STORE apr_table_set
#define mpxs_APR__Table_DELETE apr_table_unset
#define mpxs_APR__Table_CLEAR apr_table_clear
@@ -122,54 +121,74 @@
static MP_INLINE const char *mpxs_APR__Table_NEXTKEY(pTHX_ SV *tsv, SV *key)
{
- apr_table_t *t = mp_xs_sv2_APR__Table(tsv);
+ apr_table_t *t;
+ SV *rv = modperl_hash_tied_object_rv(aTHX_ "APR::Table", tsv);
+ if (!SvROK(rv)) {
+ Perl_croak(aTHX_ "Usage: $table->NEXTKEY($key): "
+ "first argument not an APR::Table object");
+ }
+ t = (apr_table_t *)SvIVX(SvRV(rv));
if (apr_is_empty_table(t)) {
return NULL;
}
-
- if (mpxs_apr_table_iterix(tsv) < apr_table_elts(t)->nelts) {
- return mpxs_apr_table_nextkey(t, tsv);
+ if (key == NULL) {
+ mpxs_apr_table_iterix(rv) = 0; /* reset iterator index */
}
-
+ if (mpxs_apr_table_iterix(rv) < apr_table_elts(t)->nelts) {
+ return mpxs_apr_table_nextkey(t, rv);
+ }
+ mpxs_apr_table_iterix(rv) = 0;
return NULL;
}
static MP_INLINE const char *mpxs_APR__Table_FIRSTKEY(pTHX_ SV *tsv)
{
- mpxs_apr_table_iterix(tsv) = 0; /* reset iterator index */
-
return mpxs_APR__Table_NEXTKEY(aTHX_ tsv, Nullsv);
}
static XS(MPXS_apr_table_get)
{
dXSARGS;
+ SV *rv;
if (items != 2) {
Perl_croak(aTHX_ "Usage: $table->get($key)");
}
+ rv = modperl_hash_tied_object_rv(aTHX_ "APR::Table", ST(0));
+ if (!SvROK(rv)) {
+ Perl_croak(aTHX_ "Usage: $table->get($key): "
+ "first argument not an APR::Table object");
+ }
+
mpxs_PPCODE({
- APR__Table t = modperl_hash_tied_object(aTHX_ "APR::Table", ST(0));
+ APR__Table t = (APR__Table) SvIVX(SvRV(rv));
const char *key = (const char *)SvPV_nolen(ST(1));
+ int i = mpxs_apr_table_iterix(rv);
+ const apr_array_header_t *arr;
+ apr_table_entry_t *elts;
if (!t) {
XSRETURN_UNDEF;
}
-
- if (GIMME_V == G_SCALAR) {
- const char *val = apr_table_get(t, key);
+ arr = apr_table_elts(t);
+ elts = (apr_table_entry_t *)arr->elts;
- if (val) {
- XPUSHs(sv_2mortal(newSVpv((char*)val, 0)));
+ if (GIMME_V == G_SCALAR) {
+ if (i > 0 && i <= arr->nelts
+ && !strcasecmp(key, elts[i-1].key))
+ {
+ XPUSHs(sv_2mortal(newSVpv(elts[i-1].val, 0)));
+ }
+ else {
+ const char *val = apr_table_get(t, key);
+ if (val) {
+ XPUSHs(sv_2mortal(newSVpv((char*)val, 0)));
+ }
}
}
else {
- const apr_array_header_t *arr = apr_table_elts(t);
- apr_table_entry_t *elts = (apr_table_entry_t *)arr->elts;
- int i;
-
for (i = 0; i < arr->nelts; i++) {
if (!elts[i].key || strcasecmp(elts[i].key, key)) {
continue;
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
>>>>As mentioned before, I'd love to see apr-ext/ and
>>>>non-apr-ext somehow re-using the same tests, instead of
>>>>duplicating and spreading them all over, making it hard
>>>>to maintain.
>>>>
>>>>If it's too much of a bother, I can do that move.
>>>
>>>
>>>Why not just copy them there instead of moving them?
>>>I don't see the harm in having some redundancy in the
>>>test suite.
>>
>>That's not a redundancy, that's a duplication. If later on
>>you change something in one of the tests you need to do it
>>in two places. Instead, it should be one source invoked
>>from both places.
>
>
> I have a working version of such a source that can
> function either as an external or httpd test, based on
> suggestions Stas had - if you like, I could clean
> things up and send something out.
Randy++
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Mon, 12 Jul 2004, Stas Bekman wrote:
> Joe Schaefer wrote:
> > Stas Bekman wrote:
[ ... ]
> >>As mentioned before, I'd love to see apr-ext/ and
> >>non-apr-ext somehow re-using the same tests, instead of
> >>duplicating and spreading them all over, making it hard
> >>to maintain.
> >>
> >>If it's too much of a bother, I can do that move.
> >
> >
> > Why not just copy them there instead of moving them?
> > I don't see the harm in having some redundancy in the
> > test suite.
>
> That's not a redundancy, that's a duplication. If later on
> you change something in one of the tests you need to do it
> in two places. Instead, it should be one source invoked
> from both places.
I have a working version of such a source that can
function either as an external or httpd test, based on
suggestions Stas had - if you like, I could clean
things up and send something out.
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Thanks Joe, now committed with a few tweaks. Now passes tests with both
5.6 and 5.8 (skipping values sub-tests for 5.6).
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> ? Perhaps
> ? config.nice
> Index: docs/api/APR/Table.pod
Thanks Joe.
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> [ patch snipped ]
>
> Works great for me on i686-linux (perl-5.8.4) with
> Apache/2.0.50 prefork.
>
> I was just about to commit a patch so as a common block of
> code could run tests under t/apr/ and t/apr-ext/. Should I
> hold off on that (as it involves changing t/apr-ext/apr.t,
> and so would break Joe's patch)? Or, should I generate a new
> patch, based on the new t/apr-ext/apr.t?
No, one go ahead and commit it, I'll merge Joe's patch and commit it
afterwards.
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
[ patch snipped ]
Works great for me on i686-linux (perl-5.8.4) with
Apache/2.0.50 prefork.
I was just about to commit a patch so as a common block of
code could run tests under t/apr/ and t/apr-ext/. Should I
hold off on that (as it involves changing t/apr-ext/apr.t,
and so would break Joe's patch)? Or, should I generate a new
patch, based on the new t/apr-ext/apr.t?
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
[...]
>>In which case we first need to find out how to clearly indicate to a
>>user that values() are broken.
>
>
> values() has *never, ever* worked for multivalued keys.
> This is a bugfix for values(), and it requires 5.8.0 or better.
>
> The remainder of the patch fixes each() (which again, has
> *never, ever* worked for multivalued keys) so it returns the
> current value in list context(). The each() bugfix applies to
> both 5.6.x and 5.8.x.
I understand all that, Joe. The problem I'm having with is the situation
when someone writes code with perl 5.8.x which works fine, releases it
on CPAN and then a user using 5.6.x will have obscure failures.
> Beyond this, I have no idea what you are asking for.
So what I'm asking for is how can we make the code croak in that
situation and not silently get broken.
It's great that you've fixed it for 5.8.x, but it's still broken for
5.6.x, I hope you understand what is the problem with that.
>>We don't want obscure bug reports from 5.6 users. Can we arrange
>>for values() to croak, explaining that it won't work
>
>
> That would be silly IMO, since values() works fine for tables
> which are not multivalued. It's only the multivalued case
> which is broken.
right, so can we croak only for the multivalued case on 5.6.x?
>> and requires 5.8.1 (or is it 5.8.0)?
>
> ^^^^^
>
> 5.8.0 - please do not confuse this with the MAGIC KEYS
> experiment going on in apreq2.
got it. thanks.
>> And of course this needs to be documented.
>
> Good luck with that.
Thanks Joe. You know that writing docs is the passion of my life.
> I'm just a lowly user trying to fix
> a bug in mp2 that was reported here, on modperl-dev@ a very
> long time ago. I've done my best to provide additional tests
> and documentation to accompany the patch. If need be I will
> gladly submit another patch that includes the missing
> ifdefs for 5.6, but much beyond that I'm not willing to go.
Sure, I'll add the missing one liner that the multivalues each is not
working for 5.6.x.
And yes, another patch with ifdefs for 5.6 is much appreciated.
Thanks Joe.
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Joe Schaefer wrote:
[...]
> > I didn't notice the 5.6.x issue until after I submitted the patch,
> > however the fix for that is very simple, so I'd prefer to wait until
> > the patch is added before adding the 2-3 neded #ifdef 's to
> > modperl_common_util.c.
>
> If it's knowingly doesn't work with 5.6 it shouldn't be committed then
> until it's resolved. We try hard to keep cvs HEAD buildable at all times.
No, I don't "know" that this breaks the 5.6 build of mp2, since I never
tried it on 5.6. The *only* issue is that the size of MGVTBL pointer
has changed from 5.6 to 5.8, so this assignment
static const MGVTBL modperl_table_magic_prefetch = {0, 0, 0, 0, 0,
modperl_table_magic_copy};
may or may not be tolerable to your favorite compiler. MGVTBL has
only 5 slots in 5.6, so when say gcc encounters this line, it will
generate something like
warning: excess elements in struct initializer
Strictly speaking it is a perfectly legal C expression. However it will
cause compilation to fail when -Werror is set, so the fix is to add an
#if PERL_VERSION >= 8
wrapper here, and do the same thing for its invocation magic in
modperl_hash_tie. That's the entire 4-line fix, and here was
the apreq2 counterpart to it (top portion only- ignore MAGIC
KEYS):
http://marc.theaimsgroup.com/?l=apreq-cvs&m=108970253506645&w=2
> In which case we first need to find out how to clearly indicate to a
> user that values() are broken.
values() has *never, ever* worked for multivalued keys.
This is a bugfix for values(), and it requires 5.8.0 or better.
The remainder of the patch fixes each() (which again, has
*never, ever* worked for multivalued keys) so it returns the
current value in list context(). The each() bugfix applies to
both 5.6.x and 5.8.x.
Beyond this, I have no idea what you are asking for.
> We don't want obscure bug reports from 5.6 users. Can we arrange
> for values() to croak, explaining that it won't work
That would be silly IMO, since values() works fine for tables
which are not multivalued. It's only the multivalued case
which is broken.
> and requires 5.8.1 (or is it 5.8.0)?
^^^^^
5.8.0 - please do not confuse this with the MAGIC KEYS
experiment going on in apreq2.
> And of course this needs to be documented.
Good luck with that. I'm just a lowly user trying to fix
a bug in mp2 that was reported here, on modperl-dev@ a very
long time ago. I've done my best to provide additional tests
and documentation to accompany the patch. If need be I will
gladly submit another patch that includes the missing
ifdefs for 5.6, but much beyond that I'm not willing to go.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
>
>>What about the 5.8.1 requirement? mp2 requires 5.6.1, will it work
>>there?
>
>
> No, the mg_copy slot in MGVTBL wasn't added until 5.8.0, so it
> will not work (probably won't compile?) for 5.6.x. Unfortunately
> I didn't notice the 5.6.x issue until after I submitted the patch,
> however the fix for that is very simple, so I'd prefer to wait
> until the patch is added before adding the 2-3 neded #ifdef 's
> to modperl_common_util.c.
If it's knowingly doesn't work with 5.6 it shouldn't be committed then
until it's resolved. We try hard to keep cvs HEAD buildable at all times.
I'm waiting for Randy's refactoring of apr table tests to be committed
and then integrate your patch. But first we need to resolve the 5.6.x issue.
> The downside is that this means values() won't work right for 5.6, but
> there's only so much we can do about that. The each() fix will still
> apply to 5.6, since it requires no extra magic at all.
In which case we first need to find out how to clearly indicate to a
user that values() are broken. We don't want obscure bug reports from
5.6 users. Can we arrange for values() to croak, explaining that it
won't work and requires 5.8.1 (or is it 5.8.0)? And of course this needs
to be documented.
Thanks.
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> What about the 5.8.1 requirement? mp2 requires 5.6.1, will it work
> there?
No, the mg_copy slot in MGVTBL wasn't added until 5.8.0, so it
will not work (probably won't compile?) for 5.6.x. Unfortunately
I didn't notice the 5.6.x issue until after I submitted the patch,
however the fix for that is very simple, so I'd prefer to wait
until the patch is added before adding the 2-3 neded #ifdef 's
to modperl_common_util.c.
The downside is that this means values() won't work right for 5.6, but
there's only so much we can do about that. The each() fix will still
apply to 5.6, since it requires no extra magic at all.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
> [...]
>
>
>>So, is it good at all if we add this overhead? I understand that the
>>patch that you've sent following this email includes that copying, right?
>
>
> No- the patch avoids this copying overhead by simply invoking SvGETMAGIC
> as soon as the value is created. That means the SvCUR() setting is
> accurate when the value is FETCHed, so there's no need to clone the object.
Cool.
What about the 5.8.1 requirement? mp2 requires 5.6.1, will it work there?
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
[...]
> So, is it good at all if we add this overhead? I understand that the
> patch that you've sent following this email includes that copying, right?
No- the patch avoids this copying overhead by simply invoking SvGETMAGIC
as soon as the value is created. That means the SvCUR() setting is
accurate when the value is FETCHed, so there's no need to clone the object.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
>
>>Joe Schaefer wrote:
>
>
> [...]
>
>
>>>:-) Not for this in mp2. Technically the problem lies with
>>>Perl_sv_setsv_flags, which does not copy magic (except for vstrings in
>>>5.8.1+, which explains the current apreq2 code). Once I better
>>>understand the purpose of the (currently undocumented?) mg_copy slot in
>>>struct mgvtbl, I'll see if I can convince p5p to let Perl_sv_setsv_flags
>>>copy magic whenever that slot is occupied.
>>
>>That may just work, if it doesn't incur a significant delay for the
>>generic case.
>
>
> Heh, I just figured out how to get values to work in apreq2 without
> the MAGIC_KEYS hack. The basic problem is that perl does a lazy
> fetch of tied hash values - paraphrasing perlguts, it creates
> an empty PVLV that has (PERL_MAGIC_tiedelem) get-magic, so it
> doesn't actually FETCH the value until perl demands the value.
> So when you write something like
>
> my @values = values %$table;
>
> perl generates all the magic PVLV's by iterating over the keys,
> and it isn't until the "=" assignment that perl executes the
> FETCH on each value. The problem is that our iterator (SvCUR(obj))
> has already ran through the key list, so it's value is 0 when those
> FETCHES are executed.
>
> However, after taking a closer look at how perl constructs the PVLV,
> I realized that this issue can be solved by freezing the iterator's
> value during the PVLV's construction. I just committed this idea
> to apreq2's cvs by simply cloning the table's SV and copying its
> SvCUR setting, and values() seems to work fine. This cloning seems
> involves a ton of copying overhead, so maybe a better choice of
> iterator could make this be more efficient (after all, it's only
> the iterator that we need to clone to get values() working).
So, is it good at all if we add this overhead? I understand that the
patch that you've sent following this email includes that copying, right?
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Joe Schaefer wrote:
[...]
> > :-) Not for this in mp2. Technically the problem lies with
> > Perl_sv_setsv_flags, which does not copy magic (except for vstrings in
> > 5.8.1+, which explains the current apreq2 code). Once I better
> > understand the purpose of the (currently undocumented?) mg_copy slot in
> > struct mgvtbl, I'll see if I can convince p5p to let Perl_sv_setsv_flags
> > copy magic whenever that slot is occupied.
>
> That may just work, if it doesn't incur a significant delay for the
> generic case.
Heh, I just figured out how to get values to work in apreq2 without
the MAGIC_KEYS hack. The basic problem is that perl does a lazy
fetch of tied hash values - paraphrasing perlguts, it creates
an empty PVLV that has (PERL_MAGIC_tiedelem) get-magic, so it
doesn't actually FETCH the value until perl demands the value.
So when you write something like
my @values = values %$table;
perl generates all the magic PVLV's by iterating over the keys,
and it isn't until the "=" assignment that perl executes the
FETCH on each value. The problem is that our iterator (SvCUR(obj))
has already ran through the key list, so it's value is 0 when those
FETCHES are executed.
However, after taking a closer look at how perl constructs the PVLV,
I realized that this issue can be solved by freezing the iterator's
value during the PVLV's construction. I just committed this idea
to apreq2's cvs by simply cloning the table's SV and copying its
SvCUR setting, and values() seems to work fine. This cloning seems
involves a ton of copying overhead, so maybe a better choice of
iterator could make this be more efficient (after all, it's only
the iterator that we need to clone to get values() working).
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
>>>Keep in mind this only fixes each(), values() remains
>>>fundamentally broken for multivalued keys (the MAGIC_KEYS code in apreq2
>>>circumvents this problem, btw).
>>
>>I'm sure it won't take too long before we will see another patch from
>>the productive Joe-machine house :)
>
>
> :-) Not for this in mp2. Technically the problem lies with
> Perl_sv_setsv_flags, which does not copy magic (except for vstrings in
> 5.8.1+, which explains the current apreq2 code). Once I better
> understand the purpose of the (currently undocumented?) mg_copy slot in
> struct mgvtbl, I'll see if I can convince p5p to let Perl_sv_setsv_flags
> copy magic whenever that slot is occupied.
That may just work, if it doesn't incur a significant delay for the
generic case.
>>>True, but it's MUCH quicker to run the standalone apr-ext tests while
>>>developing: eg. % t/TEST -no-httpd apr-ext # avoids ~30sec httpd
>>>startup delay
>>
>>Shouldn't be the case with the latest Apache::Test, prefork should
>>take just a few secs to start. But once we handle that apr-ext/apr one
>>source two tests solution, you should be able to do either of the two.
>
>
> Not using prefork (I haven't abandoned all hope for mp2+worker yet).
Yes, but for the majority of things it's faster to test with prefork,
that why I use it most of the time, swithing to worker very infrequently
just to check that things are still OK.
>>>>As mentioned before, I'd love to see apr-ext/ and non-apr-ext
>>>>somehow re-using the same tests, instead of duplicating and
>>>>spreading them all over, making it hard to maintain.
>>>>
>>>>If it's too much of a bother, I can do that move.
>>>
>>>Why not just copy them there instead of moving them?
>>>I don't see the harm in having some redundancy in the test suite.
>>
>>That's not a redundancy, that's a duplication. If later on you change
>>something in one of the tests you need to do it in two places.
>
>
> Yes, but it's not like the test suite will be silent about it,
> so it'd be hard to overlook the problem for very long.
that's not what I meant. I meant that it's easy to get those two
locations out of sync, while both will keep working fine.
but we are on the same line here...
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Joe Schaefer wrote:
[...]
> > Gladly, assuming the new FETCH (eg. scalar get()) behavior
> > is desirable: eg within an each() iteration, scalar $t->get("foo")
> > will pick the _current_ "foo" value, not necessarily the first
> > "foo". The old behavior ( $t->get("foo") fetches the first value )
> > still applies everywhere else.
>
> As long as it's documented, I think it's perfectly fine. The only
> question I have is this:
>
> What happens if each() doesn't run exhaustively, does that mean that
> $t->get() will continue to give the last value it gave inside the
> each() block and not the first one?
>
> I suppose that's the case, and if so, this should be documented as well.
+1- final patch will be soon forthcoming.
> > Keep in mind this only fixes each(), values() remains
> > fundamentally broken for multivalued keys (the MAGIC_KEYS code in apreq2
> > circumvents this problem, btw).
>
> I'm sure it won't take too long before we will see another patch from
> the productive Joe-machine house :)
:-) Not for this in mp2. Technically the problem lies with
Perl_sv_setsv_flags, which does not copy magic (except for vstrings in
5.8.1+, which explains the current apreq2 code). Once I better
understand the purpose of the (currently undocumented?) mg_copy slot in
struct mgvtbl, I'll see if I can convince p5p to let Perl_sv_setsv_flags
copy magic whenever that slot is occupied.
[...]
> > True, but it's MUCH quicker to run the standalone apr-ext tests while
> > developing: eg. % t/TEST -no-httpd apr-ext # avoids ~30sec httpd
> > startup delay
>
> Shouldn't be the case with the latest Apache::Test, prefork should
> take just a few secs to start. But once we handle that apr-ext/apr one
> source two tests solution, you should be able to do either of the two.
Not using prefork (I haven't abandoned all hope for mp2+worker yet).
>
> >>As mentioned before, I'd love to see apr-ext/ and non-apr-ext
> >>somehow re-using the same tests, instead of duplicating and
> >>spreading them all over, making it hard to maintain.
> >>
> >>If it's too much of a bother, I can do that move.
> > Why not just copy them there instead of moving them?
> > I don't see the harm in having some redundancy in the test suite.
>
> That's not a redundancy, that's a duplication. If later on you change
> something in one of the tests you need to do it in two places.
Yes, but it's not like the test suite will be silent about it,
so it'd be hard to overlook the problem for very long.
> Instead, it should be one source invoked from both places.
+1.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
> [...]
>
>
>>>Thanks in advance for looking this over- I'll be happy to
>>>explain it in more detail if anyone is interested.
>>
>>I think it'd be beneficial to document the logic in the code that
>>implements it.
>>
>>And also update the APR::Table manpage :)
>
>
> Gladly, assuming the new FETCH (eg. scalar get()) behavior
> is desirable: eg within an each() iteration, scalar
> $t->get("foo") will pick the _current_ "foo" value, not
> necessarily the first "foo". The old behavior (
> $t->get("foo") fetches the first value ) still applies
> everywhere else.
As long as it's documented, I think it's perfectly fine. The only
question I have is this:
What happens if each() doesn't run exhaustively, does that mean that
$t->get() will continue to give the last value it gave inside the each()
block and not the first one?
I suppose that's the case, and if so, this should be documented as well.
> Keep in mind this only fixes each(), values() remains
> fundamentally broken for multivalued keys (the MAGIC_KEYS
> code in apreq2 circumvents this problem, btw).
I'm sure it won't take too long before we will see another patch from
the productive Joe-machine house :)
>>But if you don't mind leave that test alone and instead extend
>>t/response/TestAPR/table.pm, since that's where it all tested.
>
>
> True, but it's MUCH quicker to run the standalone apr-ext tests
> while developing: eg.
>
> % t/TEST -no-httpd apr-ext # avoids ~30sec httpd startup delay
Shouldn't be the case with the latest Apache::Test, prefork should take
just a few secs to start. But once we handle that apr-ext/apr one source
two tests solution, you should be able to do either of the two.
>>As mentioned before, I'd love to see apr-ext/ and non-apr-ext somehow
>>re-using the same tests, instead of duplicating and spreading them all
>>over, making it hard to maintain.
>>
>>If it's too much of a bother, I can do that move.
>
>
> Why not just copy them there instead of moving them?
> I don't see the harm in having some redundancy in the
> test suite.
That's not a redundancy, that's a duplication. If later on you change
something in one of the tests you need to do it in two places. Instead,
it should be one source invoked from both places.
--
__________________________________________________________________
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
Re: APR::Table each() support for multivalued keys
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
[...]
> > Thanks in advance for looking this over- I'll be happy to
> > explain it in more detail if anyone is interested.
>
> I think it'd be beneficial to document the logic in the code that
> implements it.
>
> And also update the APR::Table manpage :)
Gladly, assuming the new FETCH (eg. scalar get()) behavior
is desirable: eg within an each() iteration, scalar
$t->get("foo") will pick the _current_ "foo" value, not
necessarily the first "foo". The old behavior (
$t->get("foo") fetches the first value ) still applies
everywhere else.
Keep in mind this only fixes each(), values() remains
fundamentally broken for multivalued keys (the MAGIC_KEYS
code in apreq2 circumvents this problem, btw).
[...]
> But if you don't mind leave that test alone and instead extend
> t/response/TestAPR/table.pm, since that's where it all tested.
True, but it's MUCH quicker to run the standalone apr-ext tests
while developing: eg.
% t/TEST -no-httpd apr-ext # avoids ~30sec httpd startup delay
> As mentioned before, I'd love to see apr-ext/ and non-apr-ext somehow
> re-using the same tests, instead of duplicating and spreading them all
> over, making it hard to maintain.
>
> If it's too much of a bother, I can do that move.
Why not just copy them there instead of moving them?
I don't see the harm in having some redundancy in the
test suite.
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: APR::Table each() support for multivalued keys
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> This weekend I finally got around to implementing multivalued
> key iterators in apreq2. Here is a backport of the each() code
> to APR::Table, with apr-ext/table.t tests included. Rather
> than lauching into a longwined explanation of the hows and
> whys of this patch (see
> http://marc.theaimsgroup.com/?t=105478383300002&r=1&w=2
>
> for the priors), please look over those new apr-ext/table.t
> tests to see what behavior this patch provides.
Excellent, Joe!
I haven't delved into details but it looks fine to me, sans a few
indentation and style issue, that I pointed out below.
> Thanks in advance for looking this over- I'll be happy to
> explain it in more detail if anyone is interested.
I think it'd be beneficial to document the logic in the code that
implements it.
And also update the APR::Table manpage :)
Thanks.
> Index: t/apr-ext/table.t
> ===================================================================
> RCS file: /home/cvspublic/modperl-2.0/t/apr-ext/table.t,v
> retrieving revision 1.1
> diff -u -r1.1 table.t
> --- t/apr-ext/table.t 16 Jun 2004 03:55:48 -0000 1.1
> +++ t/apr-ext/table.t 12 Jul 2004 18:54:24 -0000
> @@ -1,15 +1,32 @@
> use Apache::Test;
> -
> +use Apache::TestUtil;
please also add:
use strict;
use warnings FATAL => 'all';
(which should have been there in first place) and please fix the test
accordingly :) (missing my declarations)
> +while (($a,$b) = each %$table) {
> + my $key = ("first", "second")[$i % 2];
> + my $val = ++$i;
> + ok t_cmp $a, $key, "table each: key test";
> + ok t_cmp $b, $val, "table each: value test";
> + ok t_cmp $table->get($a), $val, "table each: get test";
> + ok t_cmp tied(%$table)->get($a), $val, "table each: tied get test";
> +}
But if you don't mind leave that test alone and instead extend
t/response/TestAPR/table.pm, since that's where it all tested. As
mentioned before, I'd love to see apr-ext/ and non-apr-ext somehow
re-using the same tests, instead of duplicating and spreading them all
over, making it hard to maintain.
If it's too much of a bother, I can do that move.
> Index: src/modules/perl/modperl_common_util.c
> ===================================================================
> else {
> @@ -67,7 +67,17 @@
> "(expecting an %s derived object)", classname);
> }
>
> - return NULL;
> + return &PL_sv_undef;
> +}
new line here please
> +MP_INLINE void *modperl_hash_tied_object(pTHX_
> + const char *classname,
> + SV *tsv)
> +{
> + SV *rv = modperl_hash_tied_object_rv(aTHX_ classname, tsv);
> + if (SvROK(rv))
> + return (void *)SvIVX(SvRV(rv));
> + else
> + return NULL;
{} are a must everywhere in conditionals, even if there is only one
statement following.
> Index: xs/APR/Table/APR__Table.h
> ===================================================================
> RCS file: /home/cvspublic/modperl-2.0/xs/APR/Table/APR__Table.h,v
> retrieving revision 1.11
> diff -u -r1.11 APR__Table.h
> --- xs/APR/Table/APR__Table.h 4 Mar 2004 06:01:10 -0000 1.11
> +++ xs/APR/Table/APR__Table.h 12 Jul 2004 18:54:26 -0000
> @@ -13,7 +13,6 @@
> * limitations under the License.
> */
>
> -#define mpxs_APR__Table_FETCH apr_table_get
> #define mpxs_APR__Table_STORE apr_table_set
> #define mpxs_APR__Table_DELETE apr_table_unset
> #define mpxs_APR__Table_CLEAR apr_table_clear
> @@ -122,54 +121,74 @@
[...]
> + if (GIMME_V == G_SCALAR) {
> + if (i > 0 && i <= arr->nelts
> + && !strcasecmp(key, elts[i-1].key))
> + {
opening { must be on the same line as the conditional statement.
--
__________________________________________________________________
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