Re: svn commit: r286168 - head/sys/net

2015-08-02 Thread Bjoern A. Zeeb

 On 02 Aug 2015, at 00:15 , John-Mark Gurney j...@freebsd.org wrote:
 -CTASSERT(sizeof(struct sadb_x_policy) == 16);
 +_Static_assert(sizeof(struct sadb_x_policy) == 16, struct size mismatch);


If this fires, how does it look like?  I am assuming the string at the end is 
the error message?  If so and if the assertion is not printed that string 
should be improved rather than being the same for all checks.

/bz
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


Re: svn commit: r286168 - head/sys/net

2015-08-02 Thread David Chisnall
On 2 Aug 2015, at 17:34, Ian Lepore i...@freebsd.org wrote:
 
 It generates a compiler error, so the output is going to contain
 file-and-line like any other compiler error, as well as the message from
 the source code.

It will, of course, vary between compilers, but this is what clang generates:

$ cat static.c 
_Static_assert(0, example assert failed);
$ cc static.c 
static.c:1:1: error: static_assert failed example assert failed
_Static_assert(0, example assert failed);
^  ~
1 error generated.

GCC 4.8 and later produce very similar output:

$ gcc-4.8 static.c 
static.c:1:1: error: static assertion failed: example assert failed
 _Static_assert(0, example assert failed);
 ^

gcc 4.7 only provides the first line:

$ gcc-4.7 static.c 
static.c:1:1: error: static assertion failed: example assert failed

David
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


Re: svn commit: r286168 - head/sys/net

2015-08-02 Thread Ian Lepore
On Sun, 2015-08-02 at 11:42 +, Bjoern A. Zeeb wrote:
  On 02 Aug 2015, at 00:15 , John-Mark Gurney j...@freebsd.org wrote:
  -CTASSERT(sizeof(struct sadb_x_policy) == 16);
  +_Static_assert(sizeof(struct sadb_x_policy) == 16, struct size mismatch);
 
 
 If this fires, how does it look like?  I am assuming the string at the end is 
 the error message?  If so and if the assertion is not printed that string 
 should be improved rather than being the same for all checks.
 
 /bz
 

It generates a compiler error, so the output is going to contain
file-and-line like any other compiler error, as well as the message from
the source code.

-- Ian


___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


Re: svn commit: r286168 - head/sys/net

2015-08-01 Thread John-Mark Gurney
Bruce Evans wrote this message on Sun, Aug 02, 2015 at 14:10 +1000:
 On Sun, 2 Aug 2015, John-Mark Gurney wrote:
 
  Log:
   convert to C11's _Static_assert, and pull in sys/cdefs.h for
   compatibility w/ older non-C11 compilers...
 
 This include is bogus.  net/pfkeyv2.h already depends on the includer
 including other headers that include sys/cdefs.h.  Mainly sys/types.h.
 sys/types.h defined massive namespace pollution that includes everything
 in sys/cdefs.h.  It includes sys/cdefs.h an infinite number of times
 via recursion, except the recursion is stopped by anti-reinclude guards.
 Th recursion makes the static number of nested includes of sys/cdefs.h
 hard to count.

I'll test w/o sys/cdefs.h and if it compiles, I'll remove it...

 Also, this is a kernel header.  All kernel headers depend on the includer

Except it isn't just a kernel header as we found out, otherwise
CTASSERT would have been perfectly fine...  It defines an API between
kernel and userland for adding and changing the kernel SA/SP
database...  See sbin/setkey and lib/libipsec...

[comments about kernel only headers deleted]

 If an application wants to abuse a kernel header, then it must fake
 the kernel environment for it.  I don't know much about this header,
 but it is not documented in any man page so it can do anything.

-- 
  John-Mark Gurney  Voice: +1 415 225 5579

 All that I will do, has been done, All that I have, has not.
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


Re: svn commit: r286168 - head/sys/net

2015-08-01 Thread Bruce Evans

On Sun, 2 Aug 2015, John-Mark Gurney wrote:


Log:
 convert to C11's _Static_assert, and pull in sys/cdefs.h for
 compatibility w/ older non-C11 compilers...


This include is bogus.  net/pfkeyv2.h already depends on the includer
including other headers that include sys/cdefs.h.  Mainly sys/types.h.
sys/types.h defined massive namespace pollution that includes everything
in sys/cdefs.h.  It includes sys/cdefs.h an infinite number of times
via recursion, except the recursion is stopped by anti-reinclude guards.
Th recursion makes the static number of nested includes of sys/cdefs.h
hard to count.

Also, this is a kernel header.  All kernel headers depend on the includer
including sys/param.h and sys/systm.h.  Some work accidentally
without this, and broken includers depend on this.  For example, this
file didn't depend on sys/systm.h for the definition of CTASSERT()
and wasn't broken when CTASSERT() was added, but if any includers of
it that didn't include sys/systm.h had there brokenness exposed.
sys/param.h and sys/systm.h defined much more massive namespace
pollution than sys/types.h, together with some names that that are
not pollution.  Almost everything in sys/cdef.h is now part of the
API.

As a result, most kernel headers should not include sys/cdefs.h.
Some leaf headers like the x86 _types.h check that it is included
before them.  Some headers that are intentionally shared between
the kernel and userland have a sloppy but non-polluting _KERNEL
section that depends on many includes (mainly all the ones in
sys/param.h and doesn't include anything explicitly, followed
by a non-sloppy  userland section that begins with an include of
sys/cdefs.h.  This include used to be used for __BEGIN/__END_DECLS
and __P(()) but is now just used for the former.  Macros like
__BEGIN/__END_DECLS and _Static_assert are just as ugly as __P(())
and should go away, but they have proliferated faster than __P(())
went away.  The non-sloppyness includes not including sys/types.h
but using basic types and declaring the few ufoo_t types that are
part of the documented API of the header.

If an application wants to abuse a kernel header, then it must fake
the kernel environment for it.  I don't know much about this header,
but it is not documented in any man page so it can do anything.

Bruce
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org


svn commit: r286168 - head/sys/net

2015-08-01 Thread John-Mark Gurney
Author: jmg
Date: Sun Aug  2 00:15:52 2015
New Revision: 286168
URL: https://svnweb.freebsd.org/changeset/base/286168

Log:
  convert to C11's _Static_assert, and pull in sys/cdefs.h for
  compatibility w/ older non-C11 compilers...
  
  passed make tinerdbox..
  
  Suggested by: imp

Modified:
  head/sys/net/pfkeyv2.h

Modified: head/sys/net/pfkeyv2.h
==
--- head/sys/net/pfkeyv2.h  Sun Aug  2 00:11:56 2015(r286167)
+++ head/sys/net/pfkeyv2.h  Sun Aug  2 00:15:52 2015(r286168)
@@ -39,9 +39,7 @@
 #ifndef _NET_PFKEYV2_H_
 #define _NET_PFKEYV2_H_
 
-#ifndef _KERNEL
-#define CTASSERT(x)struct __thisisjustnothing;
-#endif
+#include sys/cdefs.h
 
 /*
 This file defines structures and symbols for the PF_KEY Version 2
@@ -231,7 +229,7 @@ struct sadb_x_policy {
   u_int32_t sadb_x_policy_id;
   u_int32_t sadb_x_policy_reserved2;
 };
-CTASSERT(sizeof(struct sadb_x_policy) == 16);
+_Static_assert(sizeof(struct sadb_x_policy) == 16, struct size mismatch);
 
 /*
  * When policy_type == IPSEC, it is followed by some of
@@ -267,7 +265,7 @@ struct sadb_x_nat_t_type {
   u_int8_t sadb_x_nat_t_type_type;
   u_int8_t sadb_x_nat_t_type_reserved[3];
 };
-CTASSERT(sizeof(struct sadb_x_nat_t_type) == 8);
+_Static_assert(sizeof(struct sadb_x_nat_t_type) == 8, struct size mismatch);
 
 /* NAT-Traversal source or destination port. */
 struct sadb_x_nat_t_port { 
@@ -276,7 +274,7 @@ struct sadb_x_nat_t_port { 
   u_int16_t sadb_x_nat_t_port_port;
   u_int16_t sadb_x_nat_t_port_reserved;
 };
-CTASSERT(sizeof(struct sadb_x_nat_t_port) == 8);
+_Static_assert(sizeof(struct sadb_x_nat_t_port) == 8, struct size mismatch);
 
 /* ESP fragmentation size. */
 struct sadb_x_nat_t_frag {
@@ -285,7 +283,7 @@ struct sadb_x_nat_t_frag {
   u_int16_t sadb_x_nat_t_frag_fraglen;
   u_int16_t sadb_x_nat_t_frag_reserved;
 };
-CTASSERT(sizeof(struct sadb_x_nat_t_frag) == 8);
+_Static_assert(sizeof(struct sadb_x_nat_t_frag) == 8, struct size mismatch);
 
 
 #define SADB_EXT_RESERVED 0
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org