On Nov 26, 2007 5:07 PM, Xavier <shiningxc@gmail.com> wrote:
On Mon, Nov 26, 2007 at 03:49:14PM -0600, Aaron Griffin wrote:
On Nov 24, 2007 5:02 AM, Xavier <shiningxc@gmail.com> wrote:
That's the first thing I thought about, but I don't know if that is possible. There are two lists that can only be freed after the error happens : *data and deps (asked could be freed before). Or maybe it is possible to do something like : MALLOC(miss, sizeof(pmdepmissing_t), FREELIST(*data); FREELIST(deps); RET_ERR(PM_ERR_MEMORY, -1));
Though, there is also the "goto cleanup;" that would be skipped, and so the "alpm_list_free(list);", so that's yet another call to add there. So that would duplicate the "FREELIST(deps)'" and "alpm_list_free(list);" calls.
While this one has already been merged, you could still use the macro by simply throwing something like (void)0 in the third param. Or even pm_errno = BLAHBLAH. This way we still get the output from the macro, even if we don't get the real failure+return.
I see, but how do we detect if it failed or not? Using 0, it doesn't seem to be possible. Maybe by setting pm_errno as you said, or ret.
So maybe something like this :
MALLOC(miss, sizeof(pmdepmissing_t), ret = -1); if(ret == -1) { /* free the lists */ pm_errno = blabla; goto cleanup; }
?
I don't know how MACRO handle arguments, so I wasn't sure this was possible.
I think it looks OK. Remember that a macro gets handled during preprocessing and isn't a function call at all, so you can do a few things you wouldn't normally be able to. Want to check? Look into using "gcc -E <sourcefile>", which just spits the preprocessed code back at you so you can check things. -Dan