[ccan] RFC: draft rfc822 module
David Gibson
david at gibson.dropbear.id.au
Mon May 28 18:13:30 EST 2012
On Thu, May 24, 2012 at 09:08:28PM +0930, Paul 'Rusty' Russell wrote:
> 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.
Hrm. Even so, the talloc hook doesn't seem to acocmplish quite the
same thing. The current global hook is expected usually to not return
- but it doesn't have to - you can supply a hook that will continue.
I don't see that that's possible with the talloc internal hook.
Although, come to that, I'm not sure allowing a hook which returns is
a terribly good idea.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
More information about the ccan
mailing list