public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 1/4] Cygwin: introduce constexpr errmap_size and errmap[] consistency checks
@ 2024-02-26 14:21 Christian Franke
  2024-02-26 14:24 ` [PATCH 2/4] Cygwin: errmap[]: reduce value size from 32 to 8 bits Christian Franke
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christian Franke @ 2024-02-26 14:21 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0001-Cygwin-introduce-constexpr-errmap_size-and-errmap-co.patch --]
[-- Type: text/plain, Size: 2130 bytes --]

From 947daa02b0b64131626c2ecedb74ca6893aab6c6 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Mon, 26 Feb 2024 13:37:33 +0100
Subject: [PATCH 1/4] Cygwin: introduce constexpr errmap_size and errmap[]
 consistency checks

Use constexpr instead of const for errmap[] to allow static_assert
checks on its values.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/cygwin/errno.cc                |  2 +-
 winsup/cygwin/local_includes/errmap.h | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
index 1c85e9a04..7d58e62ec 100644
--- a/winsup/cygwin/errno.cc
+++ b/winsup/cygwin/errno.cc
@@ -185,7 +185,7 @@ geterrno_from_win_error (DWORD code, int deferrno)
 {
   /* A 0-value in errmap means, we don't handle this windows error
      explicitely.  Fall back to deferrno in these cases. */
-  if (code < sizeof errmap / sizeof errmap[0] && errmap[code])
+  if (code < errmap_size && errmap[code])
     {
       syscall_printf ("windows error %u == errno %d", code, errmap[code]);
       return errmap[code];
diff --git a/winsup/cygwin/local_includes/errmap.h b/winsup/cygwin/local_includes/errmap.h
index a0b3ff400..737c01c8b 100644
--- a/winsup/cygwin/local_includes/errmap.h
+++ b/winsup/cygwin/local_includes/errmap.h
@@ -3,7 +3,7 @@
    to this new array manually on demand. */
 
 /* FIXME: Some of these choices are arbitrary! */
-static const int errmap[] =
+constexpr int errmap[] =
 {
   0,			/* ERROR_SUCCESS */
   EBADRQC,		/* ERROR_INVALID_FUNCTION */
@@ -9006,3 +9006,12 @@ static const int errmap[] =
   0,			/* 8998 */
   0,			/* 8999 */
 };
+
+constexpr unsigned errmap_size = sizeof (errmap) / sizeof (errmap[0]);
+
+/* Some consistency checks. */
+static_assert (errmap_size == 8999 + 1);
+static_assert (EINTR == errmap[/* 104 */ ERROR_INVALID_AT_INTERRUPT_TIME]);
+static_assert (ENXIO == errmap[/* 1006 */ ERROR_FILE_INVALID]);
+static_assert (EAGAIN == errmap[/* 2404 */ ERROR_DEVICE_IN_USE]);
+static_assert (EIO == errmap[/* 8341 */ ERROR_DS_GENERIC_ERROR]);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-26 15:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26 14:21 [PATCH 1/4] Cygwin: introduce constexpr errmap_size and errmap[] consistency checks Christian Franke
2024-02-26 14:24 ` [PATCH 2/4] Cygwin: errmap[]: reduce value size from 32 to 8 bits Christian Franke
2024-02-26 14:25 ` [PATCH 3/4] Cygwin: errmap[]: add error numbers to /* ERROR_... */ comments Christian Franke
2024-02-26 14:27 ` [PATCH 4/4] Cygwin: errmap[]: update comments using current winerror.h Christian Franke
2024-02-26 15:48 ` [PATCH 1/4] Cygwin: introduce constexpr errmap_size and errmap[] consistency checks Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).