[ccan] RFC: draft rfc822 module

Rusty Russell rusty at rustcorp.com.au
Thu May 24 21:38:28 EST 2012


On Thu, 24 May 2012 00:21:03 +1000, David Gibson <david at gibson.dropbear.id.au> wrote:
> On Wed, May 23, 2012 at 09:38:30PM +0930, Paul 'Rusty' Russell wrote:
> > On Tue, 22 May 2012 23:37:32 +1000, David Gibson <david at gibson.dropbear.id.au> wrote:
> > > On Tue, May 22, 2012 at 01:35:14PM +0930, Paul 'Rusty' Russell wrote:
> > > > Error handling could be done here:
> > > > 
> > > >         static void *myalloc(struct rfc822 *msg, size_t len)
> > > >         {
> > > >                 void *ret = talloc(msg, len);
> > > >                 if (!ret) {
> > > >                         struct myrfc822 *mymsg = (struct myrfc822 *)msg;
> > > >                         mymsg->alloc_failed++;
> > > >                 }
> > > >                 return ret;
> > > >         }
> > > 
> > > I don't quite see what that does differently from what I already
> > > have.  It already requires talloc, and internal data structures are
> > > allocated using the message structure as a context.
> > 
> > Indeed.  Since ccan/talloc lets you set the alloc functions already,
> > your error handing function is redundant.
> > 
> > However, default talloc doesn't... so might as well leave it as it is,
> > with a global handler.
> 
> Uh... huh?  I'm completely lost.

OK.  You have a global hook for allocation failures:

> +void rfc822_set_allocation_failure_handler(void (*h)(const char *))
> +{

But this isn't strictly necessary, since the caller can use
talloc_set_allocator() and handle any errors there.

OTOH, this hook only exists in the CCAN version of talloc, so keep your
global hook.

Cheers,
Rusty.


More information about the ccan mailing list