You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Jim Blandy <ji...@savonarola.red-bean.com> on 2000/08/11 20:04:33 UTC

return value of apr_palloc

Dumb question, Greg:

According to _Writing Apache Modules_, one must check the return value
of ap[r]_palloc.  According to the code, it will always return
non-zero, and APR_ABORT when it runs out of memory.

Is it kosher for me to assume that if apr_palloc returns, it has
succeeded?

Re: return value of apr_palloc

Posted by Ben Collins-Sussman <su...@newton.collab.net>.
Jim Blandy <ji...@savonarola.red-bean.com> writes:

> According to _Writing Apache Modules_, one must check the return value
> of ap[r]_palloc.  According to the code, it will always return
> non-zero, and APR_ABORT when it runs out of memory.
> 
> Is it kosher for me to assume that if apr_palloc returns, it has
> succeeded?

I thought that apr_palloc just calls exit() when it fails... that's
why we never check the return value for this.

Re: return value of apr_palloc

Posted by Branko Čibej <br...@hermes.si>.
Greg Stein wrote:
> In reality, the app must always register an exit/abort function.
> 
> This behavior/design actually makes sense for Subversion, so there aren't
> any plans to attempt any recovery on a memory failure.

I assume Subversion will register a global exit function (e.g., to roll
back pending transactions), so that registering a new exit fn for
every new (sub-)pool isn't necessary. Right?

    Brane

-- 
Branko Čibej                 <br...@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
voice: (+386 1) 586 53 49     fax: (+386 1) 586 52 70

Re: return value of apr_palloc

Posted by Greg Stein <gs...@lyra.org>.
On Sat, Aug 12, 2000 at 02:34:05AM +0100, Joe Orton wrote:
> On Fri, Aug 11, 2000 at 06:27:04PM -0700, Greg Stein wrote:
> > If any of the ap_palloc(), ap_pcalloc(), etc return, then it succeeded. You
> > will never see an "out of memory" error.
> 
> This was true in Apache 1.3 but I don't think it's true in APR... as far
> as I can see, you have to explicitly register an "apr_abort" function
> with the pool, else the *alloc functions will just return NULL if
> malloc() ever returns NULL.

That is the theory. If it isn't done now, then Subversion should be
registering an abort function that does an abort() or exit().

Why "theory"? Because APR makes the same assumption about allocations :-) In
other words, if you attempt to /not/ abort on a malloc() failure, then APR
is going to fall down.

> And you can't seem to register an apr_abort function using
> apr_create_pool, only with make_sub_pool... which seems wrong; maybe I'm
> missing something.

Oh, probably not. The apr_abort thing was (IMO) added in there simply to
satisfy the purists that said APR should never call exit/abort itself, but
should leave it to the app.

In reality, the app must always register an exit/abort function.

This behavior/design actually makes sense for Subversion, so there aren't
any plans to attempt any recovery on a memory failure.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: return value of apr_palloc

Posted by Joe Orton <jo...@orton.demon.co.uk>.
On Fri, Aug 11, 2000 at 06:27:04PM -0700, Greg Stein wrote:
> If any of the ap_palloc(), ap_pcalloc(), etc return, then it succeeded. You
> will never see an "out of memory" error.

This was true in Apache 1.3 but I don't think it's true in APR... as far
as I can see, you have to explicitly register an "apr_abort" function
with the pool, else the *alloc functions will just return NULL if
malloc() ever returns NULL.

And you can't seem to register an apr_abort function using
apr_create_pool, only with make_sub_pool... which seems wrong; maybe I'm
missing something.

joe

Re: return value of apr_palloc

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Aug 11, 2000 at 03:04:33PM -0500, Jim Blandy wrote:
> 
> Dumb question, Greg:
> 
> According to _Writing Apache Modules_, one must check the return value
> of ap[r]_palloc.  According to the code, it will always return
> non-zero, and APR_ABORT when it runs out of memory.
> 
> Is it kosher for me to assume that if apr_palloc returns, it has
> succeeded?

Absolutely. I'd say "by design" :-)

If any of the ap_palloc(), ap_pcalloc(), etc return, then it succeeded. You
will never see an "out of memory" error.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/