svn commit: r250624 - in head/sys: amd64/amd64 i386/i386

Ed Schouten ed at FreeBSD.org
Mon May 13 21:47:18 UTC 2013


Author: ed
Date: Mon May 13 21:47:17 2013
New Revision: 250624
URL: http://svnweb.freebsd.org/changeset/base/250624

Log:
  Improve readability of static assertions for OFFSET_* macros.
  
  Instead of doing all sorts of weird casting of constants to
  pointer-pointers, simply use the standard C offsetof() macro to obtain
  the offset of the respective fields in the structures.

Modified:
  head/sys/amd64/amd64/vm_machdep.c
  head/sys/i386/i386/vm_machdep.c

Modified: head/sys/amd64/amd64/vm_machdep.c
==============================================================================
--- head/sys/amd64/amd64/vm_machdep.c	Mon May 13 21:46:07 2013	(r250623)
+++ head/sys/amd64/amd64/vm_machdep.c	Mon May 13 21:47:17 2013	(r250624)
@@ -90,9 +90,10 @@ static u_int	cpu_reset_proxyid;
 static volatile u_int	cpu_reset_proxy_active;
 #endif
 
-CTASSERT((struct thread **)OFFSETOF_CURTHREAD ==
-    &((struct pcpu *)NULL)->pc_curthread);
-CTASSERT((struct pcb **)OFFSETOF_CURPCB == &((struct pcpu *)NULL)->pc_curpcb);
+_Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
+    "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
+_Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
+    "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
 
 struct savefpu *
 get_pcb_user_save_td(struct thread *td)

Modified: head/sys/i386/i386/vm_machdep.c
==============================================================================
--- head/sys/i386/i386/vm_machdep.c	Mon May 13 21:46:07 2013	(r250623)
+++ head/sys/i386/i386/vm_machdep.c	Mon May 13 21:47:17 2013	(r250624)
@@ -106,9 +106,10 @@ __FBSDID("$FreeBSD$");
 #define	NSFBUFS		(512 + maxusers * 16)
 #endif
 
-CTASSERT((struct thread **)OFFSETOF_CURTHREAD ==
-    &((struct pcpu *)NULL)->pc_curthread);
-CTASSERT((struct pcb **)OFFSETOF_CURPCB == &((struct pcpu *)NULL)->pc_curpcb);
+_Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
+    "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
+_Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
+    "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
 
 static void	cpu_reset_real(void);
 #ifdef SMP


More information about the svn-src-all mailing list