]> git.ozlabs.org Git - ccan/commit
tcon: Add an alternate way of building type canaries
authorDavid Gibson <david@gibson.dropbear.id.au>
Tue, 20 Oct 2015 03:23:37 +0000 (14:23 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Sun, 25 Oct 2015 12:32:44 +0000 (23:32 +1100)
commit43992de4769085b3aba0fd9c167a85ad14e771d2
treed51ca50c13930ac3694cd64c050ceecd4aa99ce0
parentfced03d35c9fdf132f4405114f8d507716da1842
tcon: Add an alternate way of building type canaries

The tcon module allows you to add "type canaries" to a structures, which
can be used for later typechecks.  The canaries are implemented using
a flexible array member, to avoid them taking any actual space at runtime.
That means the canaries must go at the end of your structure.

That doesn't seem like a big limitation, except that it also means the
structure containing the canaries must be at the end of any structure it
is embedded in in turn, which is a rather more serious limitation.

This patch adds a TCON_WRAP() macro which wraps a given type in a new type
which also contains type canaries, and doesn't suffer the last member
limitation.  The drawback is that if the wrapped type has smaller size than
a pointer, the type canaries will pad the wrapped type out to the size of a
pointer.

By constructing the wrappers carefully, the existing tcon macros will work
on both wrapper types constructed with TCON_WRAP and on structures
explicitly including TCON type canaries.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/tcon/_info
ccan/tcon/tcon.h
ccan/tcon/test/compile_fail-tcon_cast_wrap.c [new file with mode: 0644]
ccan/tcon/test/compile_fail-wrap.c [new file with mode: 0644]
ccan/tcon/test/compile_ok-void.c
ccan/tcon/test/compile_ok.c
ccan/tcon/test/run-wrap.c [new file with mode: 0644]