[Mesa-dev] [PATCH] list: add some iterator debug
Erik Faye-Lund
erik.faye-lund at collabora.com
Mon May 27 11:37:30 UTC 2019
On Mon, 2019-05-27 at 04:23 -0700, Rob Clark wrote:
> On Mon, May 27, 2019 at 2:50 AM Erik Faye-Lund
> <erik.faye-lund at collabora.com> wrote:
> > On Sat, 2019-05-25 at 15:44 -0700, Rob Clark wrote:
> > > This ends up embedded in a for loop expression, ie. the C part in
> > > an
> > > for (A;B;C)
> > >
> > > iirc, that means it needs to be a C expr rather than statement..
> > > or
> > > something roughly like that, I'm too lazy to dig out my C grammar
> > >
> >
> > Can't you just call a static helper function to do the validation?
> > Function calls are valid expressions...
>
> I do like the fact that with the current patch I get the correct line
> # in the assert msg.. but perhaps #ifdef MSVC we can make it a static
> inline instead? I'm not sure how many people do active feature dev
> of
> mesa on windows (as opposed to doing dev on linux and then
> compiling/shipping non-debug builds on windows), so maybe just
> disabling the list debug on MSVC is fine.
>
> BR,
> -R
You can just pass __FILE__ and __LINE__ as arguments to the helper, and
not use assert directy but rather fprintf(stderr, ...) and abort. This
is in fact how most custom assert-macros are implemented.
Something like this:
static void
list_assert_helper(bool cond, const char *expr, const char *msg,
const char *file, int line)
{
if (cond) {
fprintf(stderr, "list_assert failed: %s:%d: %s",
file, line, expr);
abort();
}
}
#define list_assert(cond, msg) \
list_assert_helper(LIST_DEBUG && cond, #cond, msg, \
__FILE__, __LINE__)
More information about the mesa-dev
mailing list