Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Sep 2017 17:51:35 +0000 (UTC)
From:      David Chisnall <theraven@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r323277 - head/lib/libc/locale
Message-ID:  <201709071751.v87HpZZS061666@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: theraven
Date: Thu Sep  7 17:51:35 2017
New Revision: 323277
URL: https://svnweb.freebsd.org/changeset/base/323277

Log:
  Document some invariants for the XLC_ enum.
  
  These can't be reordered without breaking other code.  Document that and add
  some static asserts to ensure that anyone who tries gets build failures.

Modified:
  head/lib/libc/locale/xlocale_private.h

Modified: head/lib/libc/locale/xlocale_private.h
==============================================================================
--- head/lib/libc/locale/xlocale_private.h	Thu Sep  7 17:20:47 2017	(r323276)
+++ head/lib/libc/locale/xlocale_private.h	Thu Sep  7 17:51:35 2017	(r323277)
@@ -40,6 +40,14 @@
 #include <machine/atomic.h>
 #include "setlocale.h"
 
+/**
+ * The XLC_ values are indexes into the components array.  They are defined in
+ * the same order as the LC_ values in locale.h, but without the LC_ALL zero
+ * value.  Translating from LC_X to XLC_X is done by subtracting one.
+ *
+ * Any reordering of this enum should ensure that these invariants are not
+ * violated.
+ */
 enum {
 	XLC_COLLATE = 0,
 	XLC_CTYPE,
@@ -50,6 +58,19 @@ enum {
 	XLC_LAST
 };
 
+_Static_assert(XLC_LAST - XLC_COLLATE == 6, "XLC values should be contiguous");
+_Static_assert(XLC_COLLATE == LC_COLLATE - 1,
+               "XLC_COLLATE doesn't match the LC_COLLATE value.");
+_Static_assert(XLC_CTYPE == LC_CTYPE - 1,
+               "XLC_CTYPE doesn't match the LC_CTYPE value.");
+_Static_assert(XLC_MONETARY == LC_MONETARY - 1,
+               "XLC_MONETARY doesn't match the LC_MONETARY value.");
+_Static_assert(XLC_NUMERIC == LC_NUMERIC - 1,
+               "XLC_NUMERIC doesn't match the LC_NUMERIC value.");
+_Static_assert(XLC_TIME == LC_TIME - 1,
+               "XLC_TIME doesn't match the LC_TIME value.");
+_Static_assert(XLC_MESSAGES == LC_MESSAGES - 1,
+               "XLC_MESSAGES doesn't match the LC_MESSAGES value.");
 
 /**
  * Header used for objects that are reference counted.  Objects may optionally



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201709071751.v87HpZZS061666>