Skip to content

Commit

Permalink
apr_table: Use APR_TABLE_POOL_DEBUG rather than general APR_POOL_DEBUG
Browse files Browse the repository at this point in the history
Entries need not necessarily be allocated on the table's pool or an ancestor
to have the correct lifetime, the pool they are allocated on just shouldn't
be destroyed before the table.

Don't prevent users that know what they are doing with apr_tables to enable
APR_POOL_DEBUG for the rest of their code, while APR_TABLE_POOL_DEBUG can
be used to enable the apr_tables specific lifetime/ancestor checks now.



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1918670 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ylavic committed Jun 26, 2024
1 parent b0a08c7 commit b24317b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tables/apr_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
#include <strings.h>
#endif

#if (APR_POOL_DEBUG || defined(MAKE_TABLE_PROFILE)) && APR_HAVE_STDIO_H
#ifndef APR_TABLE_POOL_DEBUG
#define APR_TABLE_POOL_DEBUG 0
#endif

#if (APR_TABLE_POOL_DEBUG || defined(MAKE_TABLE_PROFILE)) && APR_HAVE_STDIO_H
#include <stdio.h>
#endif

Expand Down Expand Up @@ -413,7 +417,7 @@ APR_DECLARE(apr_table_t *) apr_table_copy(apr_pool_t *p, const apr_table_t *t)
{
apr_table_t *new = apr_palloc(p, sizeof(apr_table_t));

#if APR_POOL_DEBUG
#if APR_TABLE_POOL_DEBUG
/* we don't copy keys and values, so it's necessary that t->a.pool
* have a life span at least as long as p
*/
Expand Down Expand Up @@ -740,7 +744,7 @@ APR_DECLARE(void) apr_table_mergen(apr_table_t *t, const char *key,
apr_uint32_t checksum;
int hash;

#if APR_POOL_DEBUG
#if APR_TABLE_POOL_DEBUG
{
apr_pool_t *pool;
pool = apr_pool_find(key);
Expand Down Expand Up @@ -814,7 +818,7 @@ APR_DECLARE(void) apr_table_addn(apr_table_t *t, const char *key,
apr_uint32_t checksum;
int hash;

#if APR_POOL_DEBUG
#if APR_TABLE_POOL_DEBUG
{
if (!apr_pool_is_ancestor(apr_pool_find(key), t->a.pool)) {
fprintf(stderr, "apr_table_addn: key not in ancestor pool of t\n");
Expand Down Expand Up @@ -846,7 +850,7 @@ APR_DECLARE(apr_table_t *) apr_table_overlay(apr_pool_t *p,
{
apr_table_t *res;

#if APR_POOL_DEBUG
#if APR_TABLE_POOL_DEBUG
/* we don't copy keys and values, so it's necessary that
* overlay->a.pool and base->a.pool have a life span at least
* as long as p
Expand Down Expand Up @@ -1237,7 +1241,7 @@ APR_DECLARE(void) apr_table_overlap(apr_table_t *a, const apr_table_t *b,
return;
}

#if APR_POOL_DEBUG
#if APR_TABLE_POOL_DEBUG
/* Since the keys and values are not copied, it's required that
* b->a.pool has a lifetime at least as long as a->a.pool. */
if (!apr_pool_is_ancestor(b->a.pool, a->a.pool)) {
Expand Down

0 comments on commit b24317b

Please sign in to comment.