[waffle] [PATCH 0/3] Add the waffle_teardown API

Chad Versace chad.versace at intel.com
Tue Jan 20 10:46:38 PST 2015


On 01/15/2015 05:31 AM, Emil Velikov wrote:
> On 15 January 2015 at 15:21, Emil Velikov <emil.l.velikov at gmail.com> wrote:
>> Hello all,
>>
>> As mentioned a while back, here is the function waffle_teardown. Its purpose
>> is to cleanup the global state (the api_platform variable and the respective
>> platform private data).
>>
>> This makes valgrind a bit happier (-20k of still reachable) and will allow
>> the user to use multiple platforms within a single application. For example
>>
>> static const int32_t init_attribs_list[][] = {
>>  { WAFFLE_PLATFORM, WAFFLE_PLATFORM_GLX, 0 },
>>  { WAFFLE_PLATFORM, WAFFLE_PLATFORM_X11_EGL, 0 },
>> };
>>
>> for (i = 0, i < ARRAYSIZE(init_attribs_list[]), i++) {
>>    waffle_init(WAFFLE_PLATFORM_GLX);
>>    ...
>>    waffle_teardown()
>> }
>>
>>
>>
>> I'm not 100% happy with the function name - waffle_teardown, so if you have
>> any suggestions please put them forward.
>>
>> This work has pointed out a bug (leak) in mesa's libGL/dri2 implementation,
>> which I'll send a patch for shortly.
>>
>> The series can be found in my repo in the wip/waffle-teardown branch.
>>
> Forgot to mention - I would like to make use of this in gl_basic_test,
> yet the level of macros is getting the best of me.
> If anyone has any tips that would be appreciated.

The gl_basic_draw() macro simulates a function having named parameters
with default values. It relies on the C99 behavior that, in a designated
struct initializer, members may be initialized multiple times and the
last initialization wins.

#define gl_basic_draw(...) \
    \
    gl_basic_draw__((struct gl_basic_draw_args__) { \
        .api = 0, \
        .version = WAFFLE_DONT_CARE, \
        .profile = WAFFLE_DONT_CARE, \
        .forward_compatible = false, \
        .debug = false, \
        .alpha = false, \
        .expect_error = WAFFLE_NO_ERROR, \
        __VA_ARGS__ \
        })

For example, here are some syntactically valid uses of the macro:

    gl_basic_draw(.version = 79, .debug = true);
    gl_basic_draw(.version = 63, .debug = false, .expect_error = WAFFLE_ERROR_BAD_ATTRIBUTE);

If you want to ensure that waffle_teardown is called at the end of each successful call to
gl_basic_draw(), I think you need the below diff. But, I don't exactly know your plans, so
I'm just guessing.

    // Teardown.
    ABORT_IF(!waffle_make_current(dpy, NULL, NULL));                                                                                                                      
    ASSERT_TRUE(waffle_window_destroy(window));
    ASSERT_TRUE(waffle_context_destroy(ctx));
    ASSERT_TRUE(waffle_config_destroy(config));
    ASSERT_TRUE(waffle_display_disconnect(dpy));
+   ASSERT_TRUE(waffle_teardown());
}

On the other hand, if you want to call waffle_teardown() after each call to gl_basic_draw(),
even when the test fails and ends early, then you need to carefully call waffle_teardown in
gl_basic_test.c:testgroup_gl_basic_teardown()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 884 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/waffle/attachments/20150120/0c016074/attachment-0001.sig>


More information about the waffle mailing list