Subject: bug#75755: feature/igc: Missing IGC_CHECK_RES?

From: Stefan Kangas <[email-masked]>
Date: Thu, 23 Jan 2025 11:51:50 -0600

Pip Cet <[email-masked]> writes:

> "Eli Zaretskii" <[email-masked]> writes:
>
>>> Date: Thu, 23 Jan 2025 14:34:56 +0000
>>> From: Pip Cet <[email-masked]>
>>> Cc: Stefan Kangas <[email-masked]>, [email-masked], [email-masked], [email-masked], [email-masked], [email-masked]
>>>
>>> "Eli Zaretskii" <[email-masked]> writes:
>>>
>>> > IMO, the single use of this macro is not worth of the complications
>>> > due to relying on an internal enumeration macro.  The single function
>>> > which uses this is a testing tool, which on top of that warns in its
>>> > doc string not to use it.  Introducing significant complexity and
>>> > breakage potential into Emacs due to this is IMO a tail wagging the
>>> > dog.
>>>
>>> I agree with this paragraph; it's not worth it, let's drop the code.
>>>
>>> > So I suggest that we define our own enumeration.  We could copy some
>>>
>>> Why?
>>
>> Because it's easy, and will still give us human-readable error
>> messages.
>
> How does defining an enum give us that?  Did you mean "our own switch
> statement"?  If so, what's wrong with the one on the current branch?

FWIW, I'd keep it simple here and just install this.  At the end of the
day, while suboptimal, it's also not the end of the world if a new error
returns the "unknown error" string.  We do get the numerical error code,
so we can always decipher it.

diff --git a/src/igc.c b/src/igc.c
index 57c13614f73..b02d29ca4da 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -252,18 +252,6 @@
 static enum igc_state igc_state = IGC_STATE_INITIAL;
 static void set_state (enum igc_state state);

-/* Define a named enumeration containing all cases that the integer type
-   mps_res_t is known to cover.  */
-
-#define RES_CASE(prefix, id, doc)                                            \
-  id,
-
-enum mps_res_enum
-{
-  _mps_RES_ENUM (RES_CASE, MPS_RES_)
-};
-#undef RES_CASE
-
 /* Convert an mps result code into a result string.  This shouldn't
    allocate memory because it's called when a fatal memory management
    error occurs. */
@@ -271,9 +259,7 @@ #define RES_CASE(prefix, id, doc)
                          \
 static const char *
 mps_res_to_string (mps_res_t res)
 {
-  /* mps_res_t is typedef'd to int, we want an enum so GCC warns about
-     new cases.  */
-  switch ((enum mps_res_enum) res)
+  switch (res)
     {
     case MPS_RES_OK:
       return "operation succeeded";