Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 42727 invoked by uid 500); 20 May 2001 13:02:28 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 42716 invoked from network); 20 May 2001 13:02:26 -0000 From: "Sander Striker" To: Cc: "David Reid" Subject: [PATCH] APR Stackable Memory System Date: Sun, 20 May 2001 15:09:33 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0004_01C0E13E.E0166580" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal In-Reply-To: X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0004_01C0E13E.E0166580 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, David is gone for a week, but I already wrote some stuff that might be worth reviewing/commiting. Attached are a few patches: sms-bugfix.patch Fixes a bug in apr_sms_free() that snuck in. sms-style.patch.1 More general cleanup so the code is more conformant to the coding style guidelines as found on: http://dev.apache.org:/styleguide.html. sms-abort.patch.2 Adds an abort_fn member to the apr_sms_t. This includes code calling the abort_fn, if present, on APR_ENOMEM. The code to set the abort function is not present yet. I added this to get sms one step closer to apr pools. sms-create.patch.3 Cleans up apr_sms_create() [only to be called by memory system implementors]. It now returns a status code which will be needed when adding lock creation and other things that could fail in this function. Thusfar the patches. I have been thinking about making the code thread safe, but this will need some thought. As someone pointed out earlier, when only one thread is accessing the code locking is useless overhead. Then there is the problem that apr_lock_create() takes a pool (which we don't have). And finally, when do we lock? In case of the sms framework, we only need to lock when modifying/reading the child memory system lists and the cleanup function lists. In case of the tracking sms we need to lock on malloc/free/ etc. I suppose this is specific to every sms and should be implemented using a seperate lock. Sander ------=_NextPart_000_0004_01C0E13E.E0166580 Content-Type: application/octet-stream; name="sms-style.patch.1" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sms-style.patch.1" diff -ru apr/memory/unix/apr_sms.c apr-style/memory/unix/apr_sms.c=0A= --- apr/memory/unix/apr_sms.c Sun May 20 05:21:56 2001=0A= +++ apr-style/memory/unix/apr_sms.c Sun May 20 05:45:48 2001=0A= @@ -113,7 +113,7 @@=0A= if (size =3D=3D 0)=0A= return NULL;=0A= =0A= - if (!mem_sys->calloc_fn){=0A= + if (!mem_sys->calloc_fn) {=0A= /* Assumption - if we don't have calloc we have=0A= * malloc, might be bogus...=0A= */=0A= @@ -193,18 +193,18 @@=0A= mem_sys->accounting_mem_sys =3D mem_sys;=0A= =0A= if (parent_mem_sys !=3D NULL) {=0A= - if ((mem_sys->sibling_mem_sys =3D = parent_mem_sys->child_mem_sys)!=3DNULL) {=0A= + if ((mem_sys->sibling_mem_sys =3D = parent_mem_sys->child_mem_sys) !=3D NULL)=0A= mem_sys->sibling_mem_sys->ref_mem_sys =3D = &mem_sys->sibling_mem_sys;=0A= - }=0A= +=0A= mem_sys->ref_mem_sys =3D &parent_mem_sys->child_mem_sys;=0A= parent_mem_sys->child_mem_sys =3D mem_sys;=0A= }=0A= /* This seems a bit redundant, but we're not taking chances */=0A= else=0A= {=0A= - mem_sys->ref_mem_sys =3D NULL;=0A= + mem_sys->ref_mem_sys =3D NULL;=0A= mem_sys->sibling_mem_sys =3D NULL;=0A= - mem_sys->child_mem_sys =3D NULL;=0A= + mem_sys->child_mem_sys =3D NULL;=0A= }=0A= =0A= return mem_sys;=0A= @@ -238,7 +238,7 @@=0A= * is either the memory system itself or a direct child.=0A= */=0A= assert(mem_sys->accounting_mem_sys =3D=3D mem_sys ||=0A= - mem_sys->accounting_mem_sys->parent_mem_sys =3D=3D mem_sys);=0A= + mem_sys->accounting_mem_sys->parent_mem_sys =3D=3D mem_sys);=0A= =0A= /*=0A= * A non-tracking memory system can be the child of=0A= @@ -250,7 +250,7 @@=0A= return;=0A= =0A= parent =3D mem_sys=0A= - while (parent){=0A= + while (parent) {=0A= if (apr_sms_is_tracking(parent))=0A= return; /* Tracking memory system found, return satisfied = ;-) */=0A= =0A= @@ -277,8 +277,7 @@=0A= struct apr_sms_cleanup *cleanup;=0A= =0A= cleanup =3D mem_sys->cleanups;=0A= - while (cleanup)=0A= - {=0A= + while (cleanup) {=0A= cleanup->cleanup_fn(cleanup->data);=0A= cleanup =3D cleanup->next;=0A= }=0A= @@ -297,7 +296,7 @@=0A= return;=0A= =0A= mem_sys =3D mem_sys->child_mem_sys;=0A= - while (mem_sys){=0A= + while (mem_sys) {=0A= apr_sms_do_child_cleanups(mem_sys);=0A= apr_sms_do_cleanups(mem_sys);=0A= =0A= @@ -351,7 +350,7 @@=0A= if (!mem_sys)=0A= return APR_EMEMSYS;=0A= =0A= - if (apr_sms_is_tracking(mem_sys)){=0A= + if (apr_sms_is_tracking(mem_sys)) {=0A= /* =0A= * Run the cleanups of all child memory systems _including_=0A= * the accounting memory system.=0A= @@ -361,18 +360,16 @@=0A= /* Run all cleanups, the memory will be freed by the destroy */=0A= apr_sms_do_cleanups(mem_sys);=0A= }=0A= - else=0A= - {=0A= - if (mem_sys->accounting_mem_sys !=3D mem_sys)=0A= - {=0A= + else {=0A= + if (mem_sys->accounting_mem_sys !=3D mem_sys) {=0A= child_mem_sys =3D mem_sys->accounting_mem_sys;=0A= - =0A= + =0A= /* =0A= * Remove the accounting memory system from the memory = systems =0A= * child list (we will explicitly destroy it later in this = block).=0A= */=0A= if (child_mem_sys->sibling_mem_sys !=3D NULL)=0A= - child_mem_sys->sibling_mem_sys->ref_mem_sys =3D = child_mem_sys->ref_mem_sys;=0A= + child_mem_sys->sibling_mem_sys->ref_mem_sys =3D = child_mem_sys->ref_mem_sys;=0A= =0A= *child_mem_sys->ref_mem_sys =3D = child_mem_sys->sibling_mem_sys;=0A= =0A= @@ -384,7 +381,7 @@=0A= /* Visit all children and destroy them */=0A= child_mem_sys =3D mem_sys->child_mem_sys;=0A= =0A= - while (child_mem_sys !=3D NULL){=0A= + while (child_mem_sys) {=0A= sibling_mem_sys =3D child_mem_sys->sibling_mem_sys;=0A= apr_sms_destroy(child_mem_sys);=0A= child_mem_sys =3D sibling_mem_sys;=0A= @@ -394,7 +391,7 @@=0A= * If the accounting memory system _is_ tracking, we also know = that it is=0A= * not the memory system itself.=0A= */=0A= - if (apr_sms_is_tracking(mem_sys->accounting_mem_sys)){=0A= + if (apr_sms_is_tracking(mem_sys->accounting_mem_sys)) {=0A= /* =0A= * Run all cleanups, the memory will be freed by the = destroying of the=0A= * accounting memory system.=0A= @@ -410,58 +407,57 @@=0A= */=0A= mem_sys->accounting_mem_sys =3D mem_sys;=0A= }=0A= - else=0A= - {=0A= + else {=0A= /* Run all cleanups, free'ing memory as we go */=0A= cleanup =3D mem_sys->cleanups;=0A= =0A= - while (cleanup){=0A= + while (cleanup) {=0A= cleanup->cleanup_fn(cleanup->data);=0A= next_cleanup =3D cleanup->next;=0A= apr_sms_free(mem_sys->accounting_mem_sys, cleanup);=0A= cleanup =3D next_cleanup;=0A= }=0A= =0A= - if (mem_sys->accounting_mem_sys !=3D mem_sys)=0A= - {=0A= + if (mem_sys->accounting_mem_sys !=3D mem_sys) {=0A= /* Destroy the accounting memory system */=0A= apr_sms_destroy(mem_sys->accounting_mem_sys);=0A= + =0A= /* =0A= * Set the accounting memory system back to the parent = memory system=0A= * just in case...=0A= */=0A= mem_sys->accounting_mem_sys =3D mem_sys;=0A= }=0A= - }=0A= - }=0A= -=0A= - /* Remove the memory system from the parent memory systems child list = */=0A= - if (mem_sys->sibling_mem_sys)=0A= - mem_sys->sibling_mem_sys->ref_mem_sys =3D mem_sys->ref_mem_sys;=0A= -=0A= - if (mem_sys->ref_mem_sys)=0A= - *mem_sys->ref_mem_sys =3D mem_sys->sibling_mem_sys;=0A= -=0A= - /* Call the pre-destroy if present */=0A= - if (mem_sys->pre_destroy_fn)=0A= - mem_sys->pre_destroy_fn(mem_sys);=0A= + }=0A= + }=0A= =0A= - /* 1 - If we have a self destruct, use it */=0A= - if (mem_sys->destroy_fn)=0A= - return mem_sys->destroy_fn(mem_sys);=0A= + /* Remove the memory system from the parent memory systems child = list */=0A= + if (mem_sys->sibling_mem_sys)=0A= + mem_sys->sibling_mem_sys->ref_mem_sys =3D mem_sys->ref_mem_sys;=0A= +=0A= + if (mem_sys->ref_mem_sys)=0A= + *mem_sys->ref_mem_sys =3D mem_sys->sibling_mem_sys;=0A= +=0A= + /* Call the pre-destroy if present */=0A= + if (mem_sys->pre_destroy_fn)=0A= + mem_sys->pre_destroy_fn(mem_sys);=0A= +=0A= + /* 1 - If we have a self destruct, use it */=0A= + if (mem_sys->destroy_fn)=0A= + return mem_sys->destroy_fn(mem_sys);=0A= =0A= - /* 2 - If we don't have a parent, free using ourselves */=0A= - if (!mem_sys->parent_mem_sys)=0A= - return mem_sys->free_fn(mem_sys, mem_sys);=0A= + /* 2 - If we don't have a parent, free using ourselves */=0A= + if (!mem_sys->parent_mem_sys)=0A= + return mem_sys->free_fn(mem_sys, mem_sys);=0A= =0A= - /* 3 - If we do have a parent and it has a free function, use it */=0A= - if (mem_sys->parent_mem_sys->free_fn)=0A= - return apr_sms_free(mem_sys->parent_mem_sys, mem_sys);=0A= + /* 3 - If we do have a parent and it has a free function, use it */=0A= + if (mem_sys->parent_mem_sys->free_fn)=0A= + return apr_sms_free(mem_sys->parent_mem_sys, mem_sys);=0A= =0A= - /* 4 - Assume we are the child of a tracking memory system, and do = nothing */=0A= + /* 4 - Assume we are the child of a tracking memory system, and do = nothing */=0A= #ifdef APR_ASSERT_MEMORY=0A= mem_sys =3D mem_sys->parent_mem_sys;=0A= - while (mem_sys){=0A= + while (mem_sys) {=0A= if (apr_sms_is_tracking(mem_sys))=0A= return APR_SUCCESS;=0A= =0A= @@ -469,6 +465,7 @@=0A= }=0A= assert(0); /* Made the wrong assumption, so we assert */=0A= #endif /* APR_MEMORY_ASSERT */=0A= + =0A= return APR_SUCCESS;=0A= }=0A= =0A= @@ -531,14 +528,14 @@=0A= return APR_EMEMSYS;=0A= =0A= #ifdef APR_ASSERT_MEMORY=0A= - assert(mem_sys->accounting_mem_sys !=3D NULL);=0A= + assert(mem_sys->accounting_mem_sys);=0A= #endif=0A= =0A= if (!cleanup_fn)=0A= return APR_ENOTIMPL;=0A= =0A= cleanup =3D (struct apr_sms_cleanup *)=0A= - apr_sms_malloc(mem_sys->accounting_mem_sys, sizeof(struct = apr_sms_cleanup));=0A= + apr_sms_malloc(mem_sys->accounting_mem_sys, sizeof(struct = apr_sms_cleanup));=0A= =0A= if (!cleanup)=0A= return APR_ENOMEM;=0A= @@ -563,13 +560,12 @@=0A= return APR_EMEMSYS;=0A= =0A= #ifdef APR_ASSERT_MEMORY=0A= - assert(mem_sys->accounting_mem_sys !=3D NULL);=0A= + assert(mem_sys->accounting_mem_sys);=0A= #endif=0A= =0A= cleanup =3D mem_sys->cleanups;=0A= cleanup_ref =3D &mem_sys->cleanups;=0A= - while (cleanup)=0A= - {=0A= + while (cleanup) {=0A= if ((type =3D=3D 0 || cleanup->cleanup_fn =3D=3D cleanup_fn) &&=0A= cleanup->data =3D=3D data && cleanup->cleanup_fn =3D=3D = cleanup_fn) {=0A= *cleanup_ref =3D cleanup->next;=0A= @@ -601,7 +597,7 @@=0A= return APR_EMEMSYS;=0A= =0A= #ifdef APR_ASSERT_MEMORY=0A= - assert(mem_sys->accounting_mem_sys !=3D NULL);=0A= + assert(mem_sys->accounting_mem_sys);=0A= #endif=0A= =0A= cleanup =3D mem_sys->cleanups;=0A= @@ -611,7 +607,7 @@=0A= if (type =3D=3D 0 || cleanup->type =3D=3D type) {=0A= *cleanup_ref =3D cleanup->next;=0A= =0A= - if (mem_sys->free_fn !=3D NULL)=0A= + if (mem_sys->free_fn)=0A= apr_sms_free(mem_sys, cleanup);=0A= =0A= cleanup =3D *cleanup_ref;=0A= @@ -627,9 +623,9 @@=0A= return rv;=0A= }=0A= =0A= -APR_DECLARE(apr_status_t) apr_sms_cleanup_run(apr_sms_t *mem_sys, = apr_int32_t type,=0A= - void *data, =0A= - apr_status_t (*cleanup_fn)(void = *))=0A= +APR_DECLARE(apr_status_t) apr_sms_cleanup_run(apr_sms_t *mem_sys, = apr_int32_t type,=0A= + void *data, =0A= + apr_status_t = (*cleanup_fn)(void *))=0A= {=0A= apr_status_t rv;=0A= =0A= @@ -653,20 +649,19 @@=0A= return APR_EMEMSYS;=0A= =0A= #ifdef APR_ASSERT_MEMORY=0A= - assert(mem_sys->accounting_mem_sys !=3D NULL);=0A= + assert(mem_sys->accounting_mem_sys);=0A= #endif=0A= =0A= cleanup =3D mem_sys->cleanups;=0A= cleanup_ref =3D &mem_sys->cleanups;=0A= mem_sys =3D mem_sys->accounting_mem_sys;=0A= - while (cleanup)=0A= - {=0A= + while (cleanup) {=0A= if (type =3D=3D 0 || cleanup->type =3D=3D type) {=0A= *cleanup_ref =3D cleanup->next;=0A= =0A= cleanup->cleanup_fn(cleanup->data);=0A= =0A= - if (mem_sys->free_fn !=3D NULL)=0A= + if (mem_sys->free_fn)=0A= apr_sms_free(mem_sys, cleanup);=0A= =0A= cleanup =3D *cleanup_ref;=0A= diff -ru apr/memory/unix/apr_sms_std.c = apr-style/memory/unix/apr_sms_std.c=0A= --- apr/memory/unix/apr_sms_std.c Tue May 15 01:19:46 2001=0A= +++ apr-style/memory/unix/apr_sms_std.c Sun May 20 05:54:56 2001=0A= @@ -107,14 +107,14 @@=0A= {=0A= apr_sms_t *new_mem_sys;=0A= =0A= - assert(mem_sys !=3D NULL);=0A= + assert(mem_sys);=0A= =0A= *mem_sys =3D NULL;=0A= /* should we be using apr_sms_calloc now we have it??? */=0A= new_mem_sys =3D apr_sms_create(malloc(sizeof(apr_sms_t)),=0A= NULL);=0A= =0A= - if (new_mem_sys =3D=3D NULL)=0A= + if (!new_mem_sys)=0A= return APR_ENOMEM;=0A= =0A= new_mem_sys->malloc_fn =3D apr_sms_std_malloc;=0A= @@ -125,6 +125,7 @@=0A= * track of our allocations, we don't have apr_sms_reset or=0A= * apr_sms_destroy functions.=0A= */=0A= + =0A= apr_sms_assert(new_mem_sys);=0A= =0A= *mem_sys =3D new_mem_sys;=0A= diff -ru apr/memory/unix/apr_sms_tracking.c = apr-style/memory/unix/apr_sms_tracking.c=0A= --- apr/memory/unix/apr_sms_tracking.c Tue May 15 01:19:47 2001=0A= +++ apr-style/memory/unix/apr_sms_tracking.c Sun May 20 05:52:44 2001=0A= @@ -91,18 +91,18 @@=0A= apr_sms_tracking_t *tms;=0A= apr_track_node_t *node;=0A= =0A= - assert (mem_sys !=3D NULL);=0A= + assert(mem_sys);=0A= =0A= tms =3D (apr_sms_tracking_t *)mem_sys;=0A= node =3D apr_sms_malloc(mem_sys->parent_mem_sys,=0A= size + sizeof(apr_track_node_t));=0A= - if (node =3D=3D NULL)=0A= + if (!node)=0A= return NULL;=0A= =0A= node->next =3D tms->nodes;=0A= tms->nodes =3D node;=0A= node->ref =3D &tms->nodes;=0A= - if (node->next !=3D NULL)=0A= + if (node->next)=0A= node->next->ref =3D &node->next;=0A= =0A= node++;=0A= @@ -110,24 +110,24 @@=0A= return (void *)node;=0A= }=0A= =0A= -static void * apr_sms_tracking_calloc(apr_sms_t *mem_sys, =0A= - apr_size_t size)=0A= +static void * apr_sms_tracking_calloc(apr_sms_t *mem_sys, =0A= + apr_size_t size)=0A= {=0A= apr_sms_tracking_t *tms;=0A= apr_track_node_t *node;=0A= =0A= - assert (mem_sys !=3D NULL);=0A= + assert(mem_sys);=0A= =0A= tms =3D (apr_sms_tracking_t *)mem_sys;=0A= node =3D apr_sms_calloc(mem_sys->parent_mem_sys,=0A= size + sizeof(apr_track_node_t));=0A= - if (node =3D=3D NULL)=0A= + if (!node)=0A= return NULL;=0A= =0A= node->next =3D tms->nodes;=0A= tms->nodes =3D node;=0A= node->ref =3D &tms->nodes;=0A= - if (node->next !=3D NULL)=0A= + if (node->next)=0A= node->next->ref =3D &node->next;=0A= =0A= node++;=0A= @@ -135,18 +135,18 @@=0A= return (void *)node;=0A= }=0A= =0A= -static void * apr_sms_tracking_realloc(apr_sms_t *mem_sys,=0A= - void *mem, apr_size_t size)=0A= +static void * apr_sms_tracking_realloc(apr_sms_t *mem_sys,=0A= + void *mem, apr_size_t size)=0A= {=0A= apr_sms_tracking_t *tms;=0A= apr_track_node_t *node;=0A= =0A= - assert (mem_sys !=3D NULL);=0A= + assert(mem_sys);=0A= =0A= tms =3D (apr_sms_tracking_t *)mem_sys;=0A= node =3D (apr_track_node_t *)mem;=0A= =0A= - if (node !=3D NULL)=0A= + if (node)=0A= {=0A= node--;=0A= *(node->ref) =3D node->next;=0A= @@ -154,13 +154,13 @@=0A= =0A= node =3D apr_sms_realloc(mem_sys->parent_mem_sys,=0A= node, size + sizeof(apr_track_node_t));=0A= - if (node =3D=3D NULL)=0A= + if (!node)=0A= return NULL;=0A= =0A= node->next =3D tms->nodes;=0A= tms->nodes =3D node;=0A= node->ref =3D &tms->nodes;=0A= - if (node->next !=3D NULL)=0A= + if (node->next)=0A= node->next->ref =3D &node->next;=0A= =0A= node++;=0A= @@ -168,19 +168,19 @@=0A= return (void *)node;=0A= }=0A= =0A= -static apr_status_t apr_sms_tracking_free(apr_sms_t *mem_sys,=0A= - void *mem)=0A= +static apr_status_t apr_sms_tracking_free(apr_sms_t *mem_sys,=0A= + void *mem)=0A= {=0A= apr_track_node_t *node;=0A= =0A= - assert (mem_sys !=3D NULL);=0A= - assert (mem !=3D NULL);=0A= + assert(mem_sys);=0A= + assert(mem);=0A= =0A= node =3D (apr_track_node_t *)mem;=0A= node--;=0A= =0A= *(node->ref) =3D node->next;=0A= - if (node->next !=3D NULL)=0A= + if (node->next)=0A= node->next->ref =3D node->ref;=0A= =0A= return apr_sms_free(mem_sys->parent_mem_sys, node);=0A= @@ -192,31 +192,32 @@=0A= apr_track_node_t *node;=0A= apr_status_t rv;=0A= =0A= - assert (mem_sys !=3D NULL);=0A= + assert(mem_sys);=0A= =0A= tms =3D (apr_sms_tracking_t *)mem_sys;=0A= =0A= - while (tms->nodes !=3D NULL)=0A= - {=0A= + while (tms->nodes) {=0A= node =3D tms->nodes;=0A= *(node->ref) =3D node->next;=0A= - if (node->next !=3D NULL)=0A= + if (node->next)=0A= node->next->ref =3D node->ref;=0A= if ((rv =3D apr_sms_free(mem_sys->parent_mem_sys, =0A= node)) !=3D APR_SUCCESS)=0A= return rv;=0A= }=0A= + =0A= return APR_SUCCESS;=0A= }=0A= =0A= static apr_status_t apr_sms_tracking_destroy(apr_sms_t *mem_sys)=0A= {=0A= apr_status_t rv;=0A= + =0A= /* If this is NULL we won't blow up as it should be caught at the=0A= * next level down and then passed back to us...=0A= */=0A= #ifdef APR_ASSERT_MEMORY=0A= - assert (mem_sys->parent_mem_sys !=3D NULL);=0A= + assert(mem_sys->parent_mem_sys);=0A= #endif=0A= =0A= if (!mem_sys)=0A= @@ -224,6 +225,7 @@=0A= =0A= if ((rv =3D apr_sms_tracking_reset(mem_sys)) !=3D APR_SUCCESS)=0A= return rv;=0A= + =0A= return apr_sms_free(mem_sys->parent_mem_sys, mem_sys);=0A= }=0A= =0A= @@ -233,8 +235,9 @@=0A= apr_sms_t *new_mem_sys, *tmpms;=0A= apr_sms_tracking_t *tms;=0A= =0A= - assert (mem_sys !=3D NULL);=0A= - assert (pms !=3D NULL);=0A= + assert(mem_sys);=0A= + assert(pms);=0A= + =0A= *mem_sys =3D NULL;=0A= /* changed this to 2 stages to make easier to follow...=0A= * should we be using apr_sms_calloc now we have it? =0A= @@ -242,7 +245,7 @@=0A= tmpms =3D apr_sms_malloc(pms, sizeof(apr_sms_tracking_t));=0A= new_mem_sys =3D apr_sms_create(tmpms, pms);=0A= =0A= - if (new_mem_sys =3D=3D NULL)=0A= + if (!new_mem_sys)=0A= return APR_ENOMEM;=0A= =0A= new_mem_sys->malloc_fn =3D apr_sms_tracking_malloc;=0A= ------=_NextPart_000_0004_01C0E13E.E0166580 Content-Type: application/octet-stream; name="sms-create.patch.3" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sms-create.patch.3" Only in apr-create/include: .apr_sms.h.swp=0A= diff -ru apr/include/apr_sms.h apr-create/include/apr_sms.h=0A= --- apr/include/apr_sms.h Sun May 20 15:50:16 2001=0A= +++ apr-create/include/apr_sms.h Sun May 20 15:53:10 2001=0A= @@ -167,15 +167,15 @@=0A= * to serve as a memory system structure from your =0A= * apr_xxx_sms_create. Only use this function when you are=0A= * implementing a memory system.=0A= - * @param memory The memory to turn into a memory system=0A= + * @param mem_sys The memory to turn into a memory system=0A= * @warning The memory passed in should be at least of size =0A= * sizeof(apr_sms_t)=0A= * @param parent_mem_sys The parent memory system=0A= * @return The freshly initialized memory system=0A= - * @deffunc apr_sms_t *apr_sms_create(void *memory,=0A= - * apr_sms_t *parent_mem_sys)=0A= + * @deffunc apr_status_t apr_sms_create(apr_sms_t *mem_sys,=0A= + * apr_sms_t *parent_mem_sys)=0A= */=0A= -APR_DECLARE(apr_sms_t *) apr_sms_create(void *memory, apr_sms_t = *parent_mem_sys);=0A= +APR_DECLARE(apr_status_t) apr_sms_create(apr_sms_t *mem_sys, apr_sms_t = *parent_mem_sys);=0A= =0A= /**=0A= * Check if a memory system is obeying all rules. =0A= diff -ru apr/memory/unix/apr_sms.c apr-create/memory/unix/apr_sms.c=0A= --- apr/memory/unix/apr_sms.c Sun May 20 15:50:16 2001=0A= +++ apr-create/memory/unix/apr_sms.c Sun May 20 16:16:46 2001=0A= @@ -197,21 +197,15 @@=0A= return mem_sys->reset_fn !=3D NULL;=0A= }=0A= =0A= -APR_DECLARE(apr_sms_t *) apr_sms_create(void *memory, =0A= - apr_sms_t *parent_mem_sys)=0A= +APR_DECLARE(apr_status_t) apr_sms_create(apr_sms_t *mem_sys, =0A= + apr_sms_t *parent_mem_sys)=0A= {=0A= - apr_sms_t *mem_sys;=0A= + if (!mem_sys)=0A= + return APR_EINVAL;=0A= =0A= - if (!memory)=0A= - return NULL;=0A= -=0A= - /* Just typecast it, and clear it */=0A= - mem_sys =3D (apr_sms_t *)memory;=0A= - memset(mem_sys, '\0', sizeof(apr_sms_t));=0A= -=0A= - /* Initialize the parent and accounting memory system pointers */=0A= mem_sys->parent_mem_sys =3D parent_mem_sys;=0A= mem_sys->accounting_mem_sys =3D mem_sys;=0A= + mem_sys->child_mem_sys =3D NULL;=0A= =0A= if (parent_mem_sys !=3D NULL) {=0A= if ((mem_sys->sibling_mem_sys =3D = parent_mem_sys->child_mem_sys) !=3D NULL)=0A= @@ -220,17 +214,27 @@=0A= mem_sys->ref_mem_sys =3D &parent_mem_sys->child_mem_sys;=0A= parent_mem_sys->child_mem_sys =3D mem_sys;=0A= }=0A= - /* This seems a bit redundant, but we're not taking chances */=0A= - else=0A= - {=0A= + else {=0A= mem_sys->ref_mem_sys =3D NULL;=0A= mem_sys->sibling_mem_sys =3D NULL;=0A= - mem_sys->child_mem_sys =3D NULL;=0A= }=0A= =0A= - mem_sys->abort_fn =3D NULL;=0A= + mem_sys->malloc_fn =3D NULL;=0A= + mem_sys->calloc_fn =3D NULL;=0A= + mem_sys->realloc_fn =3D NULL;=0A= + mem_sys->free_fn =3D NULL;=0A= + =0A= + mem_sys->pre_destroy_fn =3D NULL;=0A= + =0A= + mem_sys->reset_fn =3D NULL;=0A= + mem_sys->destroy_fn =3D NULL;=0A= + =0A= + mem_sys->lock_fn =3D NULL;=0A= + mem_sys->unlock_fn =3D NULL;=0A= + =0A= + mem_sys->abort_fn =3D NULL;=0A= =0A= - return mem_sys;=0A= + return APR_SUCCESS;=0A= }=0A= =0A= #ifdef APR_MEMORY_ASSERT=0A= diff -ru apr/memory/unix/apr_sms_std.c = apr-create/memory/unix/apr_sms_std.c=0A= --- apr/memory/unix/apr_sms_std.c Sun May 20 15:47:14 2001=0A= +++ apr-create/memory/unix/apr_sms_std.c Sun May 20 16:37:03 2001=0A= @@ -106,21 +106,28 @@=0A= APR_DECLARE(apr_status_t) apr_sms_std_create(apr_sms_t **mem_sys)=0A= {=0A= apr_sms_t *new_mem_sys;=0A= + apr_status_t rv;=0A= =0A= assert(mem_sys);=0A= =0A= *mem_sys =3D NULL;=0A= - /* should we be using apr_sms_calloc now we have it??? */=0A= - new_mem_sys =3D apr_sms_create(malloc(sizeof(apr_sms_t)),=0A= - NULL);=0A= =0A= + /* Use ourselves to allocate memory because we are lacking=0A= + * a parent (we are a top level memory system).=0A= + */=0A= + new_mem_sys =3D apr_sms_std_malloc(NULL, sizeof(apr_sms_t));=0A= + =0A= if (!new_mem_sys)=0A= return APR_ENOMEM;=0A= =0A= + if ((rv =3D apr_sms_create(new_mem_sys, NULL)) !=3D APR_SUCCESS)=0A= + return rv;=0A= +=0A= new_mem_sys->malloc_fn =3D apr_sms_std_malloc;=0A= new_mem_sys->calloc_fn =3D apr_sms_std_calloc;=0A= new_mem_sys->realloc_fn =3D apr_sms_std_realloc;=0A= new_mem_sys->free_fn =3D apr_sms_std_free;=0A= + =0A= /* as we're not a tracking memory module, i.e. we don't keep=0A= * track of our allocations, we don't have apr_sms_reset or=0A= * apr_sms_destroy functions.=0A= diff -ru apr/memory/unix/apr_sms_tracking.c = apr-create/memory/unix/apr_sms_tracking.c=0A= --- apr/memory/unix/apr_sms_tracking.c Sun May 20 15:47:14 2001=0A= +++ apr-create/memory/unix/apr_sms_tracking.c Sun May 20 16:28:37 2001=0A= @@ -232,21 +232,21 @@=0A= APR_DECLARE(apr_status_t) apr_sms_tracking_create(apr_sms_t **mem_sys, =0A= apr_sms_t *pms)=0A= {=0A= - apr_sms_t *new_mem_sys, *tmpms;=0A= + apr_sms_t *new_mem_sys;=0A= apr_sms_tracking_t *tms;=0A= + apr_status_t rv;=0A= =0A= assert(mem_sys);=0A= assert(pms);=0A= =0A= *mem_sys =3D NULL;=0A= - /* changed this to 2 stages to make easier to follow...=0A= - * should we be using apr_sms_calloc now we have it? =0A= - */=0A= - tmpms =3D apr_sms_malloc(pms, sizeof(apr_sms_tracking_t));=0A= - new_mem_sys =3D apr_sms_create(tmpms, pms);=0A= + new_mem_sys =3D apr_sms_malloc(pms, sizeof(apr_sms_tracking_t));=0A= =0A= if (!new_mem_sys)=0A= return APR_ENOMEM;=0A= + =0A= + if ((rv =3D apr_sms_create(new_mem_sys, pms)) !=3D APR_SUCCESS)=0A= + return rv;=0A= =0A= new_mem_sys->malloc_fn =3D apr_sms_tracking_malloc;=0A= new_mem_sys->calloc_fn =3D apr_sms_tracking_calloc;=0A= ------=_NextPart_000_0004_01C0E13E.E0166580 Content-Type: application/octet-stream; name="sms-bugfix.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sms-bugfix.patch" diff -ru apr/memory/unix/apr_sms.c apr-bugfix/memory/unix/apr_sms.c=0A= --- apr/memory/unix/apr_sms.c Sun May 20 05:21:56 2001=0A= +++ apr-bugfix/memory/unix/apr_sms.c Sun May 20 14:50:37 2001=0A= @@ -157,7 +157,7 @@=0A= if (!mem)=0A= return APR_EINVAL;=0A= =0A= - if (!mem_sys->free_fn)=0A= + if (mem_sys->free_fn)=0A= return mem_sys->free_fn(mem_sys, mem); =0A= =0A= return APR_ENOTIMPL;=0A= ------=_NextPart_000_0004_01C0E13E.E0166580 Content-Type: application/octet-stream; name="sms-abort.patch.2" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sms-abort.patch.2" diff -ru apr/include/apr_sms.h apr-abort/include/apr_sms.h=0A= --- apr/include/apr_sms.h Sun May 20 05:21:56 2001=0A= +++ apr-abort/include/apr_sms.h Sun May 20 15:32:20 2001=0A= @@ -106,6 +106,8 @@=0A= apr_status_t (*destroy_fn)(apr_sms_t *mem_sys);=0A= apr_status_t (*lock_fn) (apr_sms_t *mem_sys);=0A= apr_status_t (*unlock_fn) (apr_sms_t *mem_sys);=0A= +=0A= + apr_status_t (*abort_fn) (char *sourcefile, int lineno);=0A= };=0A= =0A= /*=0A= diff -ru apr/memory/unix/apr_sms.c apr-abort/memory/unix/apr_sms.c=0A= --- apr/memory/unix/apr_sms.c Sun May 20 15:47:14 2001=0A= +++ apr-abort/memory/unix/apr_sms.c Sun May 20 15:43:36 2001=0A= @@ -88,6 +88,8 @@=0A= APR_DECLARE(void *) apr_sms_malloc(apr_sms_t *mem_sys,=0A= apr_size_t size)=0A= {=0A= + void *mem;=0A= + =0A= #ifdef APR_ASSERT_MEMORY=0A= assert(mem_sys);=0A= assert(mem_sys->malloc_fn);=0A= @@ -99,12 +101,19 @@=0A= if (size =3D=3D 0)=0A= return NULL;=0A= =0A= - return mem_sys->malloc_fn(mem_sys, size);=0A= + mem =3D mem_sys->malloc_fn(mem_sys, size);=0A= + =0A= + if (!mem && mem_sys->abort_fn)=0A= + mem_sys->abort_fn(__FILE__, __LINE__);=0A= +=0A= + return mem;=0A= }=0A= =0A= APR_DECLARE(void *) apr_sms_calloc(apr_sms_t *mem_sys,=0A= apr_size_t size)=0A= {=0A= + void *mem;=0A= + =0A= #ifdef APR_ASSERT_MEMORY=0A= assert(mem_sys);=0A= assert(mem_sys->malloc_fn);=0A= @@ -117,11 +126,18 @@=0A= /* Assumption - if we don't have calloc we have=0A= * malloc, might be bogus...=0A= */=0A= - void *mem =3D mem_sys->malloc_fn(mem_sys, size);=0A= - memset(mem, '\0', size);=0A= - return mem;=0A= + mem =3D mem_sys->malloc_fn(mem_sys, size);=0A= + if (mem) {=0A= + memset(mem, '\0', size);=0A= + return mem;=0A= + }=0A= } else=0A= - return mem_sys->calloc_fn(mem_sys, size);=0A= + mem =3D mem_sys->calloc_fn(mem_sys, size);=0A= +=0A= + if (!mem && mem_sys->abort_fn)=0A= + mem_sys->abort_fn(__FILE__, __LINE__);=0A= +=0A= + return mem;=0A= }=0A= =0A= APR_DECLARE(void *) apr_sms_realloc(apr_sms_t *mem_sys, void *mem,=0A= @@ -141,7 +157,12 @@=0A= return NULL;=0A= }=0A= =0A= - return mem_sys->realloc_fn(mem_sys, mem, size);=0A= + mem =3D mem_sys->realloc_fn(mem_sys, mem, size);=0A= +=0A= + if (!mem && mem_sys->abort_fn)=0A= + mem_sys->abort_fn(__FILE__, __LINE__);=0A= +=0A= + return mem;=0A= }=0A= =0A= APR_DECLARE(apr_status_t) apr_sms_free(apr_sms_t *mem_sys,=0A= @@ -206,6 +227,8 @@=0A= mem_sys->sibling_mem_sys =3D NULL;=0A= mem_sys->child_mem_sys =3D NULL;=0A= }=0A= +=0A= + mem_sys->abort_fn =3D NULL;=0A= =0A= return mem_sys;=0A= }=0A= ------=_NextPart_000_0004_01C0E13E.E0166580--