joes 2004/07/13 08:59:35
Modified: glue/perl/t/response/TestApReq request.pm
glue/perl/xsbuilder apreq_xs_tables.h
glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h
glue/perl/xsbuilder/Apache/Request Apache__Request.h
glue/perl/xsbuilder/Apache/Upload Apache__Upload.h
glue/perl/xsbuilder/maps apreq_functions.map
Log:
separate table iterator logic from MAGIC KEYS insanity, so we can decide
which behaviors we want to reasonably support in the future.
Revision Changes Path
1.30 +15 -10 httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm
Index: request.pm
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- request.pm 13 Jul 2004 01:00:07 -0000 1.29
+++ request.pm 13 Jul 2004 15:59:35 -0000 1.30
@@ -146,6 +146,8 @@
$args->add("foo" => "bar2");
my $test_string = "";
+ # TIEHASH ITERATOR TESTS
+
$test_string .= "$a=$b;" while ($a, $b) = each %$args;
die "each test failed: '$test_string'" unless
$test_string eq "test=disable_uploads;foo=bar1;foo=bar2;";
@@ -154,19 +156,22 @@
die "values test failed: '$test_string'" unless
$test_string eq "disable_uploads:bar1:bar2";
-# $test_string = "";
-# $test_string .= "$_=" . $args->get($_) . ";" for $args->get;
-# die "get test failed: '$test_string'" unless
-# $test_string eq "test=disable_uploads;foo=bar1;foo=bar2;";
-
-# $test_string = "";
-# $test_string .= "$_=" . $args->get($_) . ";" for @_ =
$args->get;
-# die "get test2 failed: '$test_string'" unless
-# $test_string eq "test=disable_uploads;foo=bar1;foo=bar2;";
-
$test_string = join ":", %$args;
die "list deref test failed: '$test_string'" unless
$test_string eq "test:disable_uploads:foo:bar1:foo:bar2";
+
+ # MAGIC KEY TESTS
+
+ $test_string = "";
+ $test_string .= "$_=" . $args->get($_) . ";" for $args->get;
+ die "get test failed: '$test_string'" unless
+ $test_string eq "test=disable_uploads;foo=bar1;foo=bar2;";
+
+ $test_string = "";
+ $test_string .= "$_=" . $args->get($_) . ";" for @_ = $args->get;
+ die "get test2 failed: '$test_string'" unless
+ $test_string eq "test=disable_uploads;foo=bar1;foo=bar2;";
+
[EMAIL PROTECTED]>print("ok");
}
1.16 +45 -21 httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_tables.h
Index: apreq_xs_tables.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_tables.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- apreq_xs_tables.h 13 Jul 2004 07:08:46 -0000 1.15
+++ apreq_xs_tables.h 13 Jul 2004 15:59:35 -0000 1.16
@@ -178,7 +178,7 @@
** if perl still chokes on key magic
** Need 5.8.1 or higher for PERL_MAGIC_vstring
*/
-#define APREQ_XS_TABLE_USE_KEY_MAGIC 0
+#define APREQ_XS_TABLE_USE_KEY_MAGIC (PERL_VERSION == 8 && PERL_SUBVERSION >
0)
#if APREQ_XS_TABLE_USE_KEY_MAGIC
@@ -267,6 +267,7 @@
PUTBACK; \
return 1; \
} \
+ \
static XS(apreq_xs_##attr##_get) \
{ \
dXSARGS; \
@@ -290,7 +291,6 @@
XSprePUSH; \
switch (GIMME_V) { \
apreq_##type##_t *RETVAL; \
- IV idx; \
MAGIC *mg; \
case G_ARRAY: \
PUTBACK; \
@@ -305,23 +305,6 @@
PUTBACK; \
break; \
} \
- else if ((idx = SvCUR(obj)) > 0) { \
- const apr_array_header_t *arr = apr_table_elts( \
- apreq_xs_##attr##_sv2table(obj)); \
- apr_table_entry_t *te = (apr_table_entry_t *)arr->elts; \
- \
- if (idx <= arr->nelts && !strcasecmp(key, te[idx-1].key)) \
- { \
- RETVAL = apreq_value_to_##type( \
- apreq_strtoval(te[idx-1].val)); \
- if (COND) { \
- XPUSHs(sv_2mortal(apreq_xs_##type##2sv( \
- RETVAL,subclass,obj))); \
- PUTBACK; \
- break; \
- } \
- } \
- } \
if (SvMAGICAL(ST(1)) \
&& (mg = mg_find(ST(1),PERL_MAGIC_vstring)) \
&& mg->mg_len == -1 /*&& mg->mg_obj == obj*/) \
@@ -339,7 +322,6 @@
} \
} \
\
- \
RETVAL = apreq_xs_##attr##_##type(obj, key); \
\
if (RETVAL && (COND)) \
@@ -352,6 +334,49 @@
apreq_xs_##attr##_error_check; \
}
+#define APREQ_XS_DEFINE_TABLE_FETCH(attr,type,subclass) \
+static XS(apreq_xs_##attr##_FETCH) \
+{ \
+ dXSARGS; \
+ SV *sv, *obj; \
+ IV idx; \
+ const char *key; \
+ const char *val; \
+ apr_table_t *t; \
+ const apr_array_header_t *arr; \
+ apr_table_entry_t *te; \
+ void *env; \
+ \
+ if (items != 2 || !SvROK(ST(0)) || !SvPOK(ST(1))) \
+ Perl_croak(aTHX_ "Usage: $table->get($key)"); \
+ \
+ sv = ST(0); \
+ obj = apreq_xs_find_obj(aTHX_ sv, #attr); \
+ key = SvPV_nolen(ST(1)); \
+ idx = SvCUR(obj); \
+ t = apreq_xs_##attr##_sv2table(obj); \
+ arr = apr_table_elts(t); \
+ te = (apr_table_entry_t *)arr->elts; \
+ env = apreq_xs_##attr##_sv2env(obj); \
+ \
+ if (idx > 0 && idx <= arr->nelts \
+ && !strcasecmp(key, te[idx-1].key)) \
+ val = te[idx-1].val; \
+ else \
+ val = apr_table_get(t, key); \
+ \
+ if (val != NULL) { \
+ apreq_##type##_t *RETVAL = apreq_value_to_##type( \
+ apreq_strtoval(val)); \
+ sv = apreq_xs_##type##2sv(RETVAL, subclass, obj); \
+ ST(0) = sv_2mortal(sv); \
+ XSRETURN(1); \
+ } \
+ else \
+ XSRETURN_UNDEF; \
+}
+
+
#define APREQ_XS_DEFINE_TABLE_NEXTKEY(attr) \
static XS(apreq_xs_##attr##_NEXTKEY) \
{ \
@@ -376,7 +401,6 @@
} \
idx = SvCUR(obj)++; \
sv = newSVpv(te[idx].key, 0); \
- APREQ_XS_TABLE_ADD_KEY_MAGIC(arr->pool,sv,obj,te[idx].val); \
ST(0) = sv_2mortal(sv); \
XSRETURN(1); \
}
1.28 +2 -0
httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h
Index: Apache__Cookie.h
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Apache__Cookie.h 11 Jul 2004 06:31:44 -0000 1.27
+++ Apache__Cookie.h 13 Jul 2004 15:59:35 -0000 1.28
@@ -70,6 +70,8 @@
APREQ_XS_DEFINE_TABLE_GET(jar, TABLE_PKG, cookie, COOKIE_PKG, 1);
APREQ_XS_DEFINE_TABLE_GET(table, TABLE_PKG, cookie, COOKIE_PKG, 1);
+APREQ_XS_DEFINE_TABLE_FETCH(table, cookie, COOKIE_PKG);
+
APREQ_XS_DEFINE_POOL(jar);
APREQ_XS_DEFINE_POOL(table);
1.45 +1 -0
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
Index: Apache__Request.h
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- Apache__Request.h 11 Jul 2004 06:31:44 -0000 1.44
+++ Apache__Request.h 13 Jul 2004 15:59:35 -0000 1.45
@@ -136,6 +136,7 @@
APREQ_XS_DEFINE_TABLE_GET(request_args, PARAM_TABLE, param, NULL, 1);
APREQ_XS_DEFINE_TABLE_GET(request_body, PARAM_TABLE, param, NULL, 1);
APREQ_XS_DEFINE_TABLE_GET(table, PARAM_TABLE, param, NULL, 1);
+APREQ_XS_DEFINE_TABLE_FETCH(table, param, NULL);
APREQ_XS_DEFINE_TABLE_NEXTKEY(table);
1.25 +2 -0
httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
Index: Apache__Upload.h
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Apache__Upload.h 11 Jul 2004 20:28:47 -0000 1.24
+++ Apache__Upload.h 13 Jul 2004 15:59:35 -0000 1.25
@@ -105,6 +105,8 @@
APREQ_XS_DEFINE_TABLE_GET(request_upload, UPLOAD_TABLE, param, UPLOAD_PKG,
RETVAL->bb);
APREQ_XS_DEFINE_TABLE_GET(upload_table, UPLOAD_TABLE, param, UPLOAD_PKG, 1);
+APREQ_XS_DEFINE_TABLE_FETCH(upload_table, param, UPLOAD_PKG);
+
APREQ_XS_DEFINE_ENV(upload);
APREQ_XS_DEFINE_POOL(upload_table);
1.31 +3 -3
httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map
Index: apreq_functions.map
===================================================================
RCS file:
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- apreq_functions.map 11 Jul 2004 06:31:44 -0000 1.30
+++ apreq_functions.map 13 Jul 2004 15:59:35 -0000 1.31
@@ -15,7 +15,7 @@
MODULE=Apache::Request PACKAGE=Apache::Request::Table
PREFIX=Apache__Request__Table_
DEFINE_get | apreq_xs_table_get |
- DEFINE_FETCH | apreq_xs_table_get |
+ DEFINE_FETCH | apreq_xs_table_FETCH |
DEFINE_pool | apreq_xs_table_pool |
DEFINE_set | apreq_xs_table_param_set |
DEFINE_STORE | apreq_xs_table_param_set |
@@ -39,7 +39,7 @@
MODULE=Apache::Upload PACKAGE=Apache::Upload::Table
PREFIX=Apache__Upload__Table_
DEFINE_get | apreq_xs_upload_table_get |
- DEFINE_FETCH | apreq_xs_upload_table_get |
+ DEFINE_FETCH | apreq_xs_upload_table_FETCH |
DEFINE_pool | apreq_xs_upload_table_pool |
DEFINE_set | apreq_xs_table_param_set |
DEFINE_STORE | apreq_xs_table_param_set |
@@ -82,7 +82,7 @@
MODULE=Apache::Cookie PACKAGE=Apache::Cookie::Table
PREFIX=Apache__Cookie__Table_
DEFINE_get | apreq_xs_table_get |
- DEFINE_FETCH | apreq_xs_table_get |
+ DEFINE_FETCH | apreq_xs_table_FETCH |
DEFINE_pool | apreq_xs_table_pool |
DEFINE_set | apreq_xs_table_cookie_set |
DEFINE_STORE | apreq_xs_table_cookie_set |