Re: cbdata

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Thu, 12 Jul 2001 23:16:55 +0200

Adrian Chadd wrote:

> It might be this really long meeting, but in all cases isn't cbdata
> potentially *free* data at this stage?

Nope.

> I've been trying to get into the habit of:
>
> if (cbdataValid(cbdata)) {
> callback(cbdata);
> }
> cbdataUnlock(cbdata);

Which is fine, but if the local state is reused, beware of the callback
causing it to be reused before the cbdataUnlock.. (has happened at a few
places).

> .. oh. I see what you're doing in the API now. Yup, it was the meeting. :-)
> However, isn't the callback data still potentially invalid data?

It is known to be valid up to the point where the callback is made.
After that the status is unknown.

cbdataAbandon() returns NULL if the data is not valid, so in

       if (void *cbdata = cbdataAbandon(mystate->calllback_data))
               mystate->callback(..., cbdata);

the callback will only be made if cbdata is valid, and the cbdata
reference is destroyed before the callback, causing the callback_data to
have a correct reference count.

--
Henrik
Received on Thu Jul 12 2001 - 15:49:53 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:07 MST