You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jw...@apache.org on 2001/05/21 00:34:56 UTC
cvs commit: apr/memory/unix apr_sms.c apr_sms_std.c apr_sms_tracking.c
jwoolley 01/05/20 15:34:56
Modified: memory/unix apr_sms.c apr_sms_std.c apr_sms_tracking.c
Log:
Bring SMS code into line with the Apache styleguide. No functional change.
Submitted by: Sander Striker <st...@samba-tng.org>
Reviewed by: Cliff Woolley
Revision Changes Path
1.8 +85 -81 apr/memory/unix/apr_sms.c
Index: apr_sms.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -u -r1.7 -r1.8
--- apr_sms.c 2001/05/20 21:47:52 1.7
+++ apr_sms.c 2001/05/20 22:34:53 1.8
@@ -113,15 +113,17 @@
if (size == 0)
return NULL;
- if (!mem_sys->calloc_fn){
+ if (!mem_sys->calloc_fn) {
/* Assumption - if we don't have calloc we have
* malloc, might be bogus...
*/
void *mem = mem_sys->malloc_fn(mem_sys, size);
memset(mem, '\0', size);
return mem;
- } else
- return mem_sys->calloc_fn(mem_sys, size);
+ }
+
+ return mem_sys->calloc_fn(mem_sys, size);
+
}
APR_DECLARE(void *) apr_sms_realloc(apr_sms_t *mem_sys, void *mem,
@@ -135,8 +137,7 @@
if (!mem)
return apr_sms_malloc(mem_sys, size);
- if (size == 0)
- {
+ if (size == 0) {
apr_sms_free(mem_sys, mem);
return NULL;
}
@@ -193,18 +194,17 @@
mem_sys->accounting_mem_sys = mem_sys;
if (parent_mem_sys != NULL) {
- if ((mem_sys->sibling_mem_sys = parent_mem_sys->child_mem_sys)!=NULL) {
+ if ((mem_sys->sibling_mem_sys = parent_mem_sys->child_mem_sys) != NULL)
mem_sys->sibling_mem_sys->ref_mem_sys = &mem_sys->sibling_mem_sys;
- }
+
mem_sys->ref_mem_sys = &parent_mem_sys->child_mem_sys;
parent_mem_sys->child_mem_sys = mem_sys;
}
/* This seems a bit redundant, but we're not taking chances */
- else
- {
- mem_sys->ref_mem_sys = NULL;
+ else {
+ mem_sys->ref_mem_sys = NULL;
mem_sys->sibling_mem_sys = NULL;
- mem_sys->child_mem_sys = NULL;
+ mem_sys->child_mem_sys = NULL;
}
return mem_sys;
@@ -238,7 +238,7 @@
* is either the memory system itself or a direct child.
*/
assert(mem_sys->accounting_mem_sys == mem_sys ||
- mem_sys->accounting_mem_sys->parent_mem_sys == mem_sys);
+ mem_sys->accounting_mem_sys->parent_mem_sys == mem_sys);
/*
* A non-tracking memory system can be the child of
@@ -250,7 +250,7 @@
return;
parent = mem_sys
- while (parent){
+ while (parent) {
if (apr_sms_is_tracking(parent))
return; /* Tracking memory system found, return satisfied ;-) */
@@ -277,8 +277,7 @@
struct apr_sms_cleanup *cleanup;
cleanup = mem_sys->cleanups;
- while (cleanup)
- {
+ while (cleanup) {
cleanup->cleanup_fn(cleanup->data);
cleanup = cleanup->next;
}
@@ -297,7 +296,7 @@
return;
mem_sys = mem_sys->child_mem_sys;
- while (mem_sys){
+ while (mem_sys) {
apr_sms_do_child_cleanups(mem_sys);
apr_sms_do_cleanups(mem_sys);
@@ -351,7 +350,7 @@
if (!mem_sys)
return APR_EMEMSYS;
- if (apr_sms_is_tracking(mem_sys)){
+ if (apr_sms_is_tracking(mem_sys)) {
/*
* Run the cleanups of all child memory systems _including_
* the accounting memory system.
@@ -361,18 +360,17 @@
/* Run all cleanups, the memory will be freed by the destroy */
apr_sms_do_cleanups(mem_sys);
}
- else
- {
- if (mem_sys->accounting_mem_sys != mem_sys)
- {
+ else {
+ if (mem_sys->accounting_mem_sys != mem_sys) {
child_mem_sys = mem_sys->accounting_mem_sys;
-
+
/*
* Remove the accounting memory system from the memory systems
* child list (we will explicitly destroy it later in this block).
*/
if (child_mem_sys->sibling_mem_sys != NULL)
- child_mem_sys->sibling_mem_sys->ref_mem_sys = child_mem_sys->ref_mem_sys;
+ child_mem_sys->sibling_mem_sys->ref_mem_sys =
+ child_mem_sys->ref_mem_sys;
*child_mem_sys->ref_mem_sys = child_mem_sys->sibling_mem_sys;
@@ -384,20 +382,20 @@
/* Visit all children and destroy them */
child_mem_sys = mem_sys->child_mem_sys;
- while (child_mem_sys != NULL){
+ while (child_mem_sys) {
sibling_mem_sys = child_mem_sys->sibling_mem_sys;
apr_sms_destroy(child_mem_sys);
child_mem_sys = sibling_mem_sys;
}
/*
- * If the accounting memory system _is_ tracking, we also know that it is
- * not the memory system itself.
+ * If the accounting memory system _is_ tracking, we also know that
+ * it is not the memory system itself.
*/
- if (apr_sms_is_tracking(mem_sys->accounting_mem_sys)){
+ if (apr_sms_is_tracking(mem_sys->accounting_mem_sys)) {
/*
- * Run all cleanups, the memory will be freed by the destroying of the
- * accounting memory system.
+ * Run all cleanups, the memory will be freed by the destroying
+ * of the accounting memory system.
*/
apr_sms_do_cleanups(mem_sys);
@@ -405,63 +403,62 @@
apr_sms_destroy(mem_sys->accounting_mem_sys);
/*
- * Set the accounting memory system back to the parent memory system
- * just in case...
+ * Set the accounting memory system back to the parent memory
+ * system just in case...
*/
mem_sys->accounting_mem_sys = mem_sys;
}
- else
- {
+ else {
/* Run all cleanups, free'ing memory as we go */
cleanup = mem_sys->cleanups;
- while (cleanup){
+ while (cleanup) {
cleanup->cleanup_fn(cleanup->data);
next_cleanup = cleanup->next;
apr_sms_free(mem_sys->accounting_mem_sys, cleanup);
cleanup = next_cleanup;
}
- if (mem_sys->accounting_mem_sys != mem_sys)
- {
+ if (mem_sys->accounting_mem_sys != mem_sys) {
/* Destroy the accounting memory system */
apr_sms_destroy(mem_sys->accounting_mem_sys);
+
/*
- * Set the accounting memory system back to the parent memory system
- * just in case...
+ * Set the accounting memory system back to the parent memory
+ * system just in case...
*/
mem_sys->accounting_mem_sys = mem_sys;
}
- }
- }
+ }
+ }
- /* Remove the memory system from the parent memory systems child list */
- if (mem_sys->sibling_mem_sys)
- mem_sys->sibling_mem_sys->ref_mem_sys = mem_sys->ref_mem_sys;
+ /* Remove the memory system from the parent memory systems child list */
+ if (mem_sys->sibling_mem_sys)
+ mem_sys->sibling_mem_sys->ref_mem_sys = mem_sys->ref_mem_sys;
- if (mem_sys->ref_mem_sys)
- *mem_sys->ref_mem_sys = mem_sys->sibling_mem_sys;
+ if (mem_sys->ref_mem_sys)
+ *mem_sys->ref_mem_sys = mem_sys->sibling_mem_sys;
- /* Call the pre-destroy if present */
- if (mem_sys->pre_destroy_fn)
- mem_sys->pre_destroy_fn(mem_sys);
+ /* Call the pre-destroy if present */
+ if (mem_sys->pre_destroy_fn)
+ mem_sys->pre_destroy_fn(mem_sys);
- /* 1 - If we have a self destruct, use it */
- if (mem_sys->destroy_fn)
- return mem_sys->destroy_fn(mem_sys);
+ /* 1 - If we have a self destruct, use it */
+ if (mem_sys->destroy_fn)
+ return mem_sys->destroy_fn(mem_sys);
- /* 2 - If we don't have a parent, free using ourselves */
- if (!mem_sys->parent_mem_sys)
- return mem_sys->free_fn(mem_sys, mem_sys);
+ /* 2 - If we don't have a parent, free using ourselves */
+ if (!mem_sys->parent_mem_sys)
+ return mem_sys->free_fn(mem_sys, mem_sys);
- /* 3 - If we do have a parent and it has a free function, use it */
- if (mem_sys->parent_mem_sys->free_fn)
- return apr_sms_free(mem_sys->parent_mem_sys, mem_sys);
+ /* 3 - If we do have a parent and it has a free function, use it */
+ if (mem_sys->parent_mem_sys->free_fn)
+ return apr_sms_free(mem_sys->parent_mem_sys, mem_sys);
- /* 4 - Assume we are the child of a tracking memory system, and do nothing */
+ /* 4 - Assume we are the child of a tracking memory system, do nothing */
#ifdef APR_ASSERT_MEMORY
mem_sys = mem_sys->parent_mem_sys;
- while (mem_sys){
+ while (mem_sys) {
if (apr_sms_is_tracking(mem_sys))
return APR_SUCCESS;
@@ -469,6 +466,7 @@
}
assert(0); /* Made the wrong assumption, so we assert */
#endif /* APR_MEMORY_ASSERT */
+
return APR_SUCCESS;
}
@@ -522,8 +520,10 @@
*/
APR_DECLARE(apr_status_t) apr_sms_cleanup_register(apr_sms_t *mem_sys,
- apr_int32_t type, void *data,
- apr_status_t (*cleanup_fn)(void *))
+ apr_int32_t type,
+ void *data,
+ apr_status_t
+ (*cleanup_fn)(void *))
{
struct apr_sms_cleanup *cleanup;
@@ -531,14 +531,15 @@
return APR_EMEMSYS;
#ifdef APR_ASSERT_MEMORY
- assert(mem_sys->accounting_mem_sys != NULL);
+ assert(mem_sys->accounting_mem_sys);
#endif
if (!cleanup_fn)
return APR_ENOTIMPL;
cleanup = (struct apr_sms_cleanup *)
- apr_sms_malloc(mem_sys->accounting_mem_sys, sizeof(struct apr_sms_cleanup));
+ apr_sms_malloc(mem_sys->accounting_mem_sys,
+ sizeof(struct apr_sms_cleanup));
if (!cleanup)
return APR_ENOMEM;
@@ -552,9 +553,11 @@
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_sms_cleanup_unregister(apr_sms_t *mem_sys, apr_int32_t type,
+APR_DECLARE(apr_status_t) apr_sms_cleanup_unregister(apr_sms_t *mem_sys,
+ apr_int32_t type,
void *data,
- apr_status_t (*cleanup_fn)(void *))
+ apr_status_t
+ (*cleanup_fn)(void *))
{
struct apr_sms_cleanup *cleanup;
struct apr_sms_cleanup **cleanup_ref;
@@ -563,13 +566,12 @@
return APR_EMEMSYS;
#ifdef APR_ASSERT_MEMORY
- assert(mem_sys->accounting_mem_sys != NULL);
+ assert(mem_sys->accounting_mem_sys);
#endif
cleanup = mem_sys->cleanups;
cleanup_ref = &mem_sys->cleanups;
- while (cleanup)
- {
+ while (cleanup) {
if ((type == 0 || cleanup->cleanup_fn == cleanup_fn) &&
cleanup->data == data && cleanup->cleanup_fn == cleanup_fn) {
*cleanup_ref = cleanup->next;
@@ -601,7 +603,7 @@
return APR_EMEMSYS;
#ifdef APR_ASSERT_MEMORY
- assert(mem_sys->accounting_mem_sys != NULL);
+ assert(mem_sys->accounting_mem_sys);
#endif
cleanup = mem_sys->cleanups;
@@ -611,7 +613,7 @@
if (type == 0 || cleanup->type == type) {
*cleanup_ref = cleanup->next;
- if (mem_sys->free_fn != NULL)
+ if (mem_sys->free_fn)
apr_sms_free(mem_sys, cleanup);
cleanup = *cleanup_ref;
@@ -627,16 +629,19 @@
return rv;
}
-APR_DECLARE(apr_status_t) apr_sms_cleanup_run(apr_sms_t *mem_sys, apr_int32_t type,
- void *data,
- apr_status_t (*cleanup_fn)(void *))
+APR_DECLARE(apr_status_t) apr_sms_cleanup_run(apr_sms_t *mem_sys,
+ apr_int32_t type,
+ void *data,
+ apr_status_t
+ (*cleanup_fn)(void *))
{
apr_status_t rv;
if (!mem_sys)
return APR_EMEMSYS;
- if ((rv = apr_sms_cleanup_unregister(mem_sys, type, data, cleanup_fn)) != APR_SUCCESS)
+ if ((rv = apr_sms_cleanup_unregister(mem_sys, type,
+ data, cleanup_fn)) != APR_SUCCESS)
return rv;
return cleanup_fn(data);
@@ -653,20 +658,19 @@
return APR_EMEMSYS;
#ifdef APR_ASSERT_MEMORY
- assert(mem_sys->accounting_mem_sys != NULL);
+ assert(mem_sys->accounting_mem_sys);
#endif
cleanup = mem_sys->cleanups;
cleanup_ref = &mem_sys->cleanups;
mem_sys = mem_sys->accounting_mem_sys;
- while (cleanup)
- {
+ while (cleanup) {
if (type == 0 || cleanup->type == type) {
*cleanup_ref = cleanup->next;
cleanup->cleanup_fn(cleanup->data);
- if (mem_sys->free_fn != NULL)
+ if (mem_sys->free_fn)
apr_sms_free(mem_sys, cleanup);
cleanup = *cleanup_ref;
1.3 +9 -8 apr/memory/unix/apr_sms_std.c
Index: apr_sms_std.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_sms_std.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -u -r1.2 -r1.3
--- apr_sms_std.c 2001/05/14 23:19:46 1.2
+++ apr_sms_std.c 2001/05/20 22:34:53 1.3
@@ -70,14 +70,14 @@
* standard memory system
*/
-static void * apr_sms_std_malloc(apr_sms_t *mem_sys,
- apr_size_t size)
+static void *apr_sms_std_malloc(apr_sms_t *mem_sys,
+ apr_size_t size)
{
return malloc(size);
}
-static void * apr_sms_std_calloc(apr_sms_t *mem_sys,
- apr_size_t size)
+static void *apr_sms_std_calloc(apr_sms_t *mem_sys,
+ apr_size_t size)
{
#if HAVE_CALLOC
return calloc(1, size);
@@ -90,8 +90,8 @@
}
-static void * apr_sms_std_realloc(apr_sms_t *mem_sys,
- void *mem, apr_size_t size)
+static void *apr_sms_std_realloc(apr_sms_t *mem_sys,
+ void *mem, apr_size_t size)
{
return realloc(mem, size);
}
@@ -107,14 +107,14 @@
{
apr_sms_t *new_mem_sys;
- assert(mem_sys != NULL);
+ assert(mem_sys);
*mem_sys = NULL;
/* should we be using apr_sms_calloc now we have it??? */
new_mem_sys = apr_sms_create(malloc(sizeof(apr_sms_t)),
NULL);
- if (new_mem_sys == NULL)
+ if (!new_mem_sys)
return APR_ENOMEM;
new_mem_sys->malloc_fn = apr_sms_std_malloc;
@@ -125,6 +125,7 @@
* track of our allocations, we don't have apr_sms_reset or
* apr_sms_destroy functions.
*/
+
apr_sms_assert(new_mem_sys);
*mem_sys = new_mem_sys;
1.3 +32 -30 apr/memory/unix/apr_sms_tracking.c
Index: apr_sms_tracking.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_sms_tracking.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -u -r1.2 -r1.3
--- apr_sms_tracking.c 2001/05/14 23:19:47 1.2
+++ apr_sms_tracking.c 2001/05/20 22:34:54 1.3
@@ -85,24 +85,24 @@
apr_track_node_t *nodes;
} apr_sms_tracking_t;
-static void * apr_sms_tracking_malloc(apr_sms_t *mem_sys,
- apr_size_t size)
+static void *apr_sms_tracking_malloc(apr_sms_t *mem_sys,
+ apr_size_t size)
{
apr_sms_tracking_t *tms;
apr_track_node_t *node;
- assert (mem_sys != NULL);
+ assert(mem_sys);
tms = (apr_sms_tracking_t *)mem_sys;
node = apr_sms_malloc(mem_sys->parent_mem_sys,
size + sizeof(apr_track_node_t));
- if (node == NULL)
+ if (!node)
return NULL;
node->next = tms->nodes;
tms->nodes = node;
node->ref = &tms->nodes;
- if (node->next != NULL)
+ if (node->next)
node->next->ref = &node->next;
node++;
@@ -110,24 +110,24 @@
return (void *)node;
}
-static void * apr_sms_tracking_calloc(apr_sms_t *mem_sys,
- apr_size_t size)
+static void *apr_sms_tracking_calloc(apr_sms_t *mem_sys,
+ apr_size_t size)
{
apr_sms_tracking_t *tms;
apr_track_node_t *node;
- assert (mem_sys != NULL);
+ assert(mem_sys);
tms = (apr_sms_tracking_t *)mem_sys;
node = apr_sms_calloc(mem_sys->parent_mem_sys,
size + sizeof(apr_track_node_t));
- if (node == NULL)
+ if (!node)
return NULL;
node->next = tms->nodes;
tms->nodes = node;
node->ref = &tms->nodes;
- if (node->next != NULL)
+ if (node->next)
node->next->ref = &node->next;
node++;
@@ -135,32 +135,31 @@
return (void *)node;
}
-static void * apr_sms_tracking_realloc(apr_sms_t *mem_sys,
- void *mem, apr_size_t size)
+static void *apr_sms_tracking_realloc(apr_sms_t *mem_sys,
+ void *mem, apr_size_t size)
{
apr_sms_tracking_t *tms;
apr_track_node_t *node;
- assert (mem_sys != NULL);
+ assert(mem_sys);
tms = (apr_sms_tracking_t *)mem_sys;
node = (apr_track_node_t *)mem;
- if (node != NULL)
- {
+ if (node) {
node--;
*(node->ref) = node->next;
}
node = apr_sms_realloc(mem_sys->parent_mem_sys,
node, size + sizeof(apr_track_node_t));
- if (node == NULL)
+ if (!node)
return NULL;
node->next = tms->nodes;
tms->nodes = node;
node->ref = &tms->nodes;
- if (node->next != NULL)
+ if (node->next)
node->next->ref = &node->next;
node++;
@@ -168,19 +167,19 @@
return (void *)node;
}
-static apr_status_t apr_sms_tracking_free(apr_sms_t *mem_sys,
- void *mem)
+static apr_status_t apr_sms_tracking_free(apr_sms_t *mem_sys,
+ void *mem)
{
apr_track_node_t *node;
- assert (mem_sys != NULL);
- assert (mem != NULL);
+ assert(mem_sys);
+ assert(mem);
node = (apr_track_node_t *)mem;
node--;
*(node->ref) = node->next;
- if (node->next != NULL)
+ if (node->next)
node->next->ref = node->ref;
return apr_sms_free(mem_sys->parent_mem_sys, node);
@@ -192,31 +191,32 @@
apr_track_node_t *node;
apr_status_t rv;
- assert (mem_sys != NULL);
+ assert(mem_sys);
tms = (apr_sms_tracking_t *)mem_sys;
- while (tms->nodes != NULL)
- {
+ while (tms->nodes) {
node = tms->nodes;
*(node->ref) = node->next;
- if (node->next != NULL)
+ if (node->next)
node->next->ref = node->ref;
if ((rv = apr_sms_free(mem_sys->parent_mem_sys,
node)) != APR_SUCCESS)
return rv;
}
+
return APR_SUCCESS;
}
static apr_status_t apr_sms_tracking_destroy(apr_sms_t *mem_sys)
{
apr_status_t rv;
+
/* If this is NULL we won't blow up as it should be caught at the
* next level down and then passed back to us...
*/
#ifdef APR_ASSERT_MEMORY
- assert (mem_sys->parent_mem_sys != NULL);
+ assert(mem_sys->parent_mem_sys);
#endif
if (!mem_sys)
@@ -224,6 +224,7 @@
if ((rv = apr_sms_tracking_reset(mem_sys)) != APR_SUCCESS)
return rv;
+
return apr_sms_free(mem_sys->parent_mem_sys, mem_sys);
}
@@ -233,8 +234,9 @@
apr_sms_t *new_mem_sys, *tmpms;
apr_sms_tracking_t *tms;
- assert (mem_sys != NULL);
- assert (pms != NULL);
+ assert(mem_sys);
+ assert(pms);
+
*mem_sys = NULL;
/* changed this to 2 stages to make easier to follow...
* should we be using apr_sms_calloc now we have it?
@@ -242,7 +244,7 @@
tmpms = apr_sms_malloc(pms, sizeof(apr_sms_tracking_t));
new_mem_sys = apr_sms_create(tmpms, pms);
- if (new_mem_sys == NULL)
+ if (!new_mem_sys)
return APR_ENOMEM;
new_mem_sys->malloc_fn = apr_sms_tracking_malloc;