Repository for eudev development
Go to file
David Herrmann 820c792432 shared: make container_of() use unique variable names
If you stack container_of() macros, you will get warnings due to shadowing
variables of the parent context. To avoid this, use unique names for
variables.

Two new helpers are added:
  UNIQ: This evaluates to a truly unique value never returned by any
        evaluation of this macro. It's a shortcut for __COUNTER__.
  UNIQ_T: Takes two arguments and concatenates them. It is a shortcut for
          CONCATENATE, but meant to defined typed local variables.

As you usually want to use variables that you just defined, you need to
reference the same unique value at least two times. However, UNIQ returns
a new value on each evaluation, therefore, you have to pass the unique
values into the macro like this:

    #define my_macro(a, b) __max_macro(UNIQ, UNIQ, (a), (b))
    #define __my_macro(uniqa, uniqb, a, b) ({
                typeof(a) UNIQ_T(A, uniqa) = (a);
                typeof(b) UNIQ_T(B, uniqb) = (b);
                MY_UNSAFE_MACRO(UNIQ_T(A, uniqa), UNIQ_T(B, uniqb));
        })

This way, MY_UNSAFE_MACRO() can safely evaluate it's arguments multiple
times as they are local variables. But you can also stack invocations to
the macro my_macro() without clashing names.

This is the same as if you did:

    #define my_macro(a, b) __max_macro(__COUNTER__, __COUNTER__, (a), (b))
    #define __my_macro(prefixa, prefixb, a, b) ({
                typeof(a) CONCATENATE(A, prefixa) = (a);
                typeof(b) CONCATENATE(B, prefixb) = (b);
                MY_UNSAFE_MACRO(CONCATENATE(A, prefixa), CONCATENATE(B, prefixb));
        })

...but in my opinion, the first macro is easier to write and read.

This patch starts by converting container_of() to use this new helper.
Other macros may follow (like MIN, MAX, CLAMP, ...).

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-27 22:13:34 -04:00
docs docs/gudev/gudev-sections.txt: add two missing functions 2014-08-05 10:14:50 -04:00
hwdb keymap: Adjust for more Samsung 900X4 series 2014-08-27 21:42:26 -04:00
m4 m4/gtk-doc.m4: update to serial 2 2014-08-05 10:23:10 -04:00
man Document "...|..." udev match syntax 2014-08-27 21:41:14 -04:00
rule_generator rule-generator: make sure /etc/udev/rules.d/ exists prior to trying to write to it 2013-07-10 10:52:13 -04:00
rules rules: bring up to date 2014-08-05 10:14:50 -04:00
src shared: make container_of() use unique variable names 2014-08-27 22:13:34 -04:00
test src/scsi_id/Makefile.am,test/Makefile.am: fix build on debian jessie, issue #97 2014-08-18 16:05:43 -04:00
.gitignore src/shared: refactor shared code 2014-08-05 19:22:24 -04:00
autogen.sh Allow autogen on systems without gtk-doc or introspection installed 2012-11-26 18:40:20 -05:00
configure.ac configure.ac and src/libudev/Makefile.am: bump to 1.10 = upstream 216 2014-08-22 08:03:24 -04:00
CONTRIBUTING CONTRIBUTING: documentation on how to contribute 2012-12-04 17:50:37 -05:00
COPYING Final step of revamping the build system 2012-11-15 21:47:20 -05:00
Makefile.am Switch from external keymaps to internal (hwdb) keymaps 2013-07-24 16:27:01 -04:00
README README: Document the project home page 2013-09-27 17:49:45 -04:00

This git repo is a fork of git://anongit.freedesktop.org/systemd/systemd
with the aim of isolating udev from any particular flavor of system
initialization.  In this case, the isolation is from systemd.

This is a project started by Gentoo developers and testing is currently being
done mostly on OpenRC.  We welcome contribution from others using a variety of
system initializations to ensure eudev remains system initialization and
distribution neutral.

Homepage: http://www.gentoo.org/proj/en/eudev/

Tarballs of releases: http://dev.gentoo.org/~blueness/eudev/

Contact: You can email us as a group below.

IRC: Freenode/#gentoo-udev

Committers (alphabetical order by last name):

    Luca Barbato        (lu_zero)           <lu_zero@gentoo.org>
    Anthony G. Basile   (blueness)          <blueness@gentoo.org>
    Francisco Izquierdo (klondike)          <klondike@gentoo.org>
    Ian Stakenvicius    (axs)               <axs@gentoo.org>
    Matthew Thode       (prometheanfire)    <prometheanfire@gentoo.org>
    Tony Vroon          (chainsaw)          <tony@linx.net>
    Richard Yao         (ryao)              <ryao@gentoo.org>