On 11/10/01 4:46 PM, "Brian Pane" <[EMAIL PROTECTED]> wrote:
> This patch changes the apr_table_elts macro so that it provides > access to the internals of an apr_table_t via a const pointer > instead of the current non-const pointer. > > My main motivation for this is to make it possible to speed up > the table internals in the future (e.g., by adding an index > for fast lookups) without breaking backward compatibility. > > In addition, allowing non-const access to the array is dangerous > even with the current code base. For example, an application > can break assumptions in the table code by setting keys in the > array to null. > > All the current uses of apr_table_elts in Apache 2.0 are for > const iterators, so the only change required to the httpd code > is the replacement of "apr_array_header_t*" declarations with > "const apr_array_header_t*" (the patch includes the diffs for > all the affected files). > +1 for the concept If no one objects I'll integrate this. The reason I'm posting is that I remember Will Rowe had some issues With tables in the past, and I'm wanting to make sure he is OK with this .. Will..??? > --Brian > > > > Index: modules/filters/mod_include.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/modules/filters/mod_include.c,v > retrieving revision 1.150 > diff -u -r1.150 mod_include.c > --- modules/filters/mod_include.c 2001/09/19 06:25:07 1.150 > +++ modules/filters/mod_include.c 2001/11/10 23:49:39 > @@ -2601,8 +2601,8 @@ > if (ctx->flags & FLAG_PRINTING) { > ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1); > if ((tag == NULL) && (tag_val == NULL)) { > - apr_array_header_t *arr = apr_table_elts(r->subprocess_env); > - apr_table_entry_t *elts = (apr_table_entry_t *)arr->elts; > + const apr_array_header_t *arr = > apr_table_elts(r->subprocess_env); > + const apr_table_entry_t *elts = (const apr_table_entry_t > *)arr->elts; > int i; > const char *key_text, *val_text; > apr_size_t k_len, v_len, t_wrt; > Index: modules/generators/mod_cgi.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/modules/generators/mod_cgi.c,v > retrieving revision 1.106 > diff -u -r1.106 mod_cgi.c > --- modules/generators/mod_cgi.c 2001/09/18 03:33:30 1.106 > +++ modules/generators/mod_cgi.c 2001/11/10 23:49:39 > @@ -257,8 +257,8 @@ > char *dbuf, const char *sbuf, apr_file_t *script_in, > apr_file_t *script_err) > { > - apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in); > - apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts; > + const apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in); > + const apr_table_entry_t *hdrs = (const apr_table_entry_t *) > hdrs_arr->elts; > char argsbuffer[HUGE_STRING_LEN]; > apr_file_t *f = NULL; > int i; > Index: modules/http/http_request.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/modules/http/http_request.c,v > retrieving revision 1.117 > diff -u -r1.117 http_request.c > --- modules/http/http_request.c 2001/10/30 19:21:41 1.117 > +++ modules/http/http_request.c 2001/11/10 23:49:40 > @@ -310,8 +310,8 @@ > > static apr_table_t *rename_original_env(apr_pool_t *p, apr_table_t *t) > { > - apr_array_header_t *env_arr = apr_table_elts(t); > - apr_table_entry_t *elts = (apr_table_entry_t *) env_arr->elts; > + const apr_array_header_t *env_arr = apr_table_elts(t); > + const apr_table_entry_t *elts = (const apr_table_entry_t *) > env_arr->elts; > apr_table_t *new = apr_table_make(p, env_arr->nalloc); > int i; > > Index: modules/mappers/mod_rewrite.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/modules/mappers/mod_rewrite.c,v > retrieving revision 1.85 > diff -u -r1.85 mod_rewrite.c > --- modules/mappers/mod_rewrite.c 2001/10/21 17:56:36 1.85 > +++ modules/mappers/mod_rewrite.c 2001/11/10 23:49:42 > @@ -3627,12 +3627,12 @@ > > static char *lookup_header(request_rec *r, const char *name) > { > - apr_array_header_t *hdrs_arr; > - apr_table_entry_t *hdrs; > + const apr_array_header_t *hdrs_arr; > + const apr_table_entry_t *hdrs; > int i; > > hdrs_arr = apr_table_elts(r->headers_in); > - hdrs = (apr_table_entry_t *)hdrs_arr->elts; > + hdrs = (const apr_table_entry_t *)hdrs_arr->elts; > for (i = 0; i < hdrs_arr->nelts; ++i) { > if (hdrs[i].key == NULL) { > continue; > Index: modules/metadata/mod_env.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/modules/metadata/mod_env.c,v > retrieving revision 1.25 > diff -u -r1.25 mod_env.c > --- modules/metadata/mod_env.c 2001/10/21 01:17:11 1.25 > +++ modules/metadata/mod_env.c 2001/11/10 23:49:43 > @@ -92,8 +92,8 @@ > env_dir_config_rec *add = addv; > env_dir_config_rec *res = apr_palloc(p, sizeof(*res)); > > - apr_table_entry_t *elts; > - apr_array_header_t *arr; > + const apr_table_entry_t *elts; > + const apr_array_header_t *arr; > > int i; > > Index: modules/metadata/mod_setenvif.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/modules/metadata/mod_setenvif.c,v > retrieving revision 1.30 > diff -u -r1.30 mod_setenvif.c > --- modules/metadata/mod_setenvif.c 2001/06/12 17:06:01 1.30 > +++ modules/metadata/mod_setenvif.c 2001/11/10 23:49:43 > @@ -406,7 +406,7 @@ > { > sei_cfg_rec *sconf; > sei_entry *entries; > - apr_table_entry_t *elts; > + const apr_table_entry_t *elts; > const char *val; > int i, j; > char *last_name; > @@ -459,8 +459,8 @@ > * the headers_in until we find a match or run out of > * headers. > */ > - apr_array_header_t *arr = apr_table_elts(r->headers_in); > - elts = (apr_table_entry_t *) arr->elts; > + const apr_array_header_t *arr = > apr_table_elts(r->headers_in); > + elts = (const apr_table_entry_t *) arr->elts; > val = NULL; > for (j = 0; j < arr->nelts; ++j) { > if (!ap_regexec(b->pnamereg, elts[j].key, 0, NULL, 0)) > { > @@ -489,8 +489,8 @@ > } > > if (!ap_regexec(b->preg, val, 0, NULL, 0)) { > - apr_array_header_t *arr = apr_table_elts(b->features); > - elts = (apr_table_entry_t *) arr->elts; > + const apr_array_header_t *arr = apr_table_elts(b->features); > + elts = (const apr_table_entry_t *) arr->elts; > > for (j = 0; j < arr->nelts; ++j) { > if (!strcmp(elts[j].val, "!")) { > Index: server/util_script.c > =================================================================== > RCS file: /home/cvspublic/httpd-2.0/server/util_script.c,v > retrieving revision 1.65 > diff -u -r1.65 util_script.c > --- server/util_script.c 2001/11/10 18:38:02 1.65 > +++ server/util_script.c 2001/11/10 23:49:44 > @@ -122,8 +122,8 @@ > > AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t) > { > - apr_array_header_t *env_arr = apr_table_elts(t); > - apr_table_entry_t *elts = (apr_table_entry_t *) env_arr->elts; > + const apr_array_header_t *env_arr = apr_table_elts(t); > + const apr_table_entry_t *elts = (const apr_table_entry_t *) > env_arr->elts; > char **env = (char **) apr_palloc(p, (env_arr->nelts + 2) * sizeof(char > *)); > int i, j; > char *tz; > @@ -169,8 +169,8 @@ > char *env_temp; > #endif > const char *host; > - apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in); > - apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts; > + const apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in); > + const apr_table_entry_t *hdrs = (const apr_table_entry_t *) > hdrs_arr->elts; > int i; > apr_port_t rport; > apr_sockaddr_t *remotesa; > Index: srclib/apr/include/apr_tables.h > =================================================================== > RCS file: /home/cvspublic/apr/include/apr_tables.h,v > retrieving revision 1.23 > diff -u -r1.23 apr_tables.h > --- srclib/apr/include/apr_tables.h 2001/08/24 17:55:45 1.23 > +++ srclib/apr/include/apr_tables.h 2001/11/10 23:49:44 > @@ -137,7 +137,7 @@ > * @param t The table > * @return An array containing the contents of the table > */ > -#define apr_table_elts(t) ((apr_array_header_t *)(t)) > +#define apr_table_elts(t) ((const apr_array_header_t *)(t)) > > /** > * Determine if the table is empty >