intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH] lib/igt_core: document the caveats of magic code blocks
Date: Fri, 14 Mar 2014 14:49:16 +0000	[thread overview]
Message-ID: <532316EC.3070400@linux.intel.com> (raw)
In-Reply-To: <1394781488-20586-1-git-send-email-daniel.vetter@ffwll.ch>


On 03/14/2014 07:18 AM, Daniel Vetter wrote:
[snip]
> + * # Magic Control Blocks
> + *
> + * i-g-t makes heavy use of C macros which serve as magic control blocks. They
> + * work fairly well and transparently but since C doesn't have full-blown
> + * closures there are caveats:
> + *
> + * - Asynchronous blocks which are used to spawn children internally use fork().
> + *   Which means that impossible control flow like jumping out of the control
> + *   block is possible, but it will horribly badly the i-g-t library code. And

I suggest to add a verb and reorder the "horribly badly" part of the 
sentence a bit. Or perhaps you tried to illustrate the program flow 
after jumping out of the control block? :)

> + * - Code blocks with magic control flow are implemented with setjmp() and
> + *   longjmp(). This applies to #igt_fixture and #igt_subtest blocks and all the
> + *   three variants to finish test: igt_success(), igt_skip() and igt_fail().
> + *   Mostly this is of no concern, except when such a control block changes
> + *   stack variables defined in the same function as the control block resides.
> + *   Any store/load behaviour after a longjmp() is ill-defined for these
> + *   variables. Avoid such code.
> + *
> + *   Quoting the man page for longjmp():
> + *
> + *   "The values of automatic variables are unspecified after a call to
> + *   longjmp() if they meet all the following criteria:"
> + *    - "they are local to the function that made the corresponding setjmp() call;
> + *    - "their values are changed between the calls to setjmp() and longjmp(); and
> + *    - "they are not declared as volatile."
>    */

So all variables which are getting initialised in igt_fixture should be 
moved out to file scope? Gcc does warn about potential clobbering 
although I haven't exactly gotten my head round understanding if and 
when it can really happen with igt_fixture.

Tvrtko

  reply	other threads:[~2014-03-14 14:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-14  7:18 [PATCH] lib/igt_core: document the caveats of magic code blocks Daniel Vetter
2014-03-14 14:49 ` Tvrtko Ursulin [this message]
2014-03-14 15:29   ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=532316EC.3070400@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).