[igt-dev] [PATCH i-g-t 01/74] lib: Introduce typed cleanups
Petri Latvala
petri.latvala at intel.com
Thu Sep 1 11:31:41 UTC 2022
On Thu, Sep 01, 2022 at 12:56:09PM +0200, Mauro Carvalho Chehab wrote:
> On Thu, 1 Sep 2022 12:19:28 +0300
> Petri Latvala <petri.latvala at intel.com> wrote:
>
> > On Thu, Sep 01, 2022 at 08:36:09AM +0200, Mauro Carvalho Chehab wrote:
> > > From: Chris Wilson <chris at chris-wilson.co.uk>
> > >
> > > Start introducing standard types with automatic cleanup courtesy of
> > > gcc's __attribute__((cleanup)). As an example, we start with an fd
> > > that will automatically call close() on going out of scope, and
> > > crucially before atexit where we will want to check for resource leaks.
> > >
> > > Suggested-by: Andrzej Hajda <andrzej.hajda at intel.com>
> > > Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> > > Cc: Andrzej Hajda <andrzej.hajda at intel.com>
> > > Cc: Petri Latvala <petri.latvala at intel.com>
> > > Acked-by: Nirmoy Das <nirmoy.das at linux.intel.com>
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
>
> ...
>
> > > +void igt_cleanup_fd(int *fd);
> > > +#define igt_fd_t(x__) \
> > > + int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
> > > +
> > > +#endif /* IGT_TYPES_H */
>
> ...
>
> >
> > This fails with clang currently, and might fail with gcc in the
> > future. longjmp is funky.
>
> It is unlikely that gcc would change it, but yeah, there's a possibility.
Forgot to mention: Back when we discovered this curiosity we caught it
because there was a difference in behaviour between optimizing and
debug builds. Both on gcc.
--
Petri Latvala
More information about the igt-dev
mailing list