Skip to content

Commit 27d7c20

Browse files
committed
HG: fix RETURN_VALUES macro to only take single argument (fix #766)
Check errnum value in string conversion
1 parent 79f985d commit 27d7c20

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

Documentation/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ the handling of multi-recv buffers and the support of cxi with HPE SHS 11.0.
2828
- Add missing `HG_WARN_UNUSED_RESULT` to HG calls
2929
- Switch to using standard types and align with NA
3030
- Keep some `uint8_t` instances instead of `hg_bool_t` for ABI compatibility
31-
- Add `HG_IO_ERROR` return code and reserve space for additional NA codes
31+
- Add `HG_IO_ERROR` return code
3232
- __[NA]__
3333
- Bump NA version to v5.0.0
3434
- Add `NA_Poll()` and `NA_Poll_wait()` routines

src/mercury.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ hg_core_respond_cb(const struct hg_core_cb_info *callback_info);
207207
/*******************/
208208

209209
/* Return code string table */
210-
#define X(a, b) #a,
211-
static const char *const hg_return_name[] = {HG_RETURN_VALUES};
210+
#define X(a) #a,
211+
static const char *const hg_return_name_g[] = {HG_RETURN_VALUES};
212212
#undef X
213213

214214
/* Specific log outlets */
@@ -1054,9 +1054,7 @@ HG_Version_get(
10541054
const char *
10551055
HG_Error_to_string(hg_return_t errnum)
10561056
{
1057-
return hg_return_name[errnum < (hg_return_t) NA_RETURN_MAX
1058-
? errnum
1059-
: errnum - HG_NA_ERRNO_OFFSET + NA_RETURN_MAX];
1057+
return errnum < HG_RETURN_MAX ? hg_return_name_g[errnum] : NULL;
10601058
}
10611059

10621060
/*---------------------------------------------------------------------------*/

src/mercury_core_types.h

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -119,44 +119,38 @@ struct hg_init_info {
119119
unsigned int multi_recv_copy_threshold;
120120
};
121121

122-
/* Keep offset to keep room for additional NA error codes */
123-
#define HG_NA_ERRNO_OFFSET 64
124-
125122
/* Error return codes:
126123
* Functions return 0 for success or corresponding return code */
127124
#define HG_RETURN_VALUES \
128-
X(HG_SUCCESS, NA_SUCCESS) /*!< operation succeeded */ \
129-
X(HG_PERMISSION, NA_PERMISSION) /*!< operation not permitted */ \
130-
X(HG_NOENTRY, NA_NOENTRY) /*!< no such file or directory */ \
131-
X(HG_INTERRUPT, NA_INTERRUPT) /*!< operation interrupted */ \
132-
X(HG_AGAIN, NA_AGAIN) /*!< operation must be retried */ \
133-
X(HG_NOMEM, NA_NOMEM) /*!< out of memory */ \
134-
X(HG_ACCESS, NA_ACCESS) /*!< permission denied */ \
135-
X(HG_FAULT, NA_FAULT) /*!< bad address */ \
136-
X(HG_BUSY, NA_BUSY) /*!< device or resource busy */ \
137-
X(HG_EXIST, NA_EXIST) /*!< entry already exists */ \
138-
X(HG_NODEV, NA_NODEV) /*!< no such device */ \
139-
X(HG_INVALID_ARG, NA_INVALID_ARG) /*!< invalid argument */ \
140-
X(HG_PROTOCOL_ERROR, NA_PROTOCOL_ERROR) /*!< protocol error */ \
141-
X(HG_OVERFLOW, NA_OVERFLOW) /*!< value too large */ \
142-
X(HG_MSGSIZE, NA_MSGSIZE) /*!< message size too long */ \
143-
X(HG_PROTONOSUPPORT, NA_PROTONOSUPPORT) /*!< protocol not supported */ \
144-
X(HG_OPNOTSUPPORTED, \
145-
NA_OPNOTSUPPORTED) /*!< operation not supported on endpoint */ \
146-
X(HG_ADDRINUSE, NA_ADDRINUSE) /*!< address already in use */ \
147-
X(HG_ADDRNOTAVAIL, \
148-
NA_ADDRNOTAVAIL) /*!< cannot assign requested address */ \
149-
X(HG_HOSTUNREACH, \
150-
NA_HOSTUNREACH) /*!< cannot reach host during operation */ \
151-
X(HG_TIMEOUT, NA_TIMEOUT) /*!< operation reached timeout */ \
152-
X(HG_CANCELED, NA_CANCELED) /*!< operation canceled */ \
153-
X(HG_IO_ERROR, NA_IO_ERROR) /*!< I/O error */ \
154-
X(HG_CHECKSUM_ERROR, HG_NA_ERRNO_OFFSET) /*!< checksum error */ \
155-
X(HG_NA_ERROR, HG_NA_ERRNO_OFFSET + 1) /*!< generic NA error */ \
156-
X(HG_OTHER_ERROR, HG_NA_ERRNO_OFFSET + 2) /*!< generic HG error */ \
157-
X(HG_RETURN_MAX, HG_NA_ERRNO_OFFSET + 3)
158-
159-
#define X(a, b) a = b,
125+
X(HG_SUCCESS) /*!< operation succeeded */ \
126+
X(HG_PERMISSION) /*!< operation not permitted */ \
127+
X(HG_NOENTRY) /*!< no such file or directory */ \
128+
X(HG_INTERRUPT) /*!< operation interrupted */ \
129+
X(HG_AGAIN) /*!< operation must be retried */ \
130+
X(HG_NOMEM) /*!< out of memory */ \
131+
X(HG_ACCESS) /*!< permission denied */ \
132+
X(HG_FAULT) /*!< bad address */ \
133+
X(HG_BUSY) /*!< device or resource busy */ \
134+
X(HG_EXIST) /*!< entry already exists */ \
135+
X(HG_NODEV) /*!< no such device */ \
136+
X(HG_INVALID_ARG) /*!< invalid argument */ \
137+
X(HG_PROTOCOL_ERROR) /*!< protocol error */ \
138+
X(HG_OVERFLOW) /*!< value too large */ \
139+
X(HG_MSGSIZE) /*!< message size too long */ \
140+
X(HG_PROTONOSUPPORT) /*!< protocol not supported */ \
141+
X(HG_OPNOTSUPPORTED) /*!< operation not supported on endpoint */ \
142+
X(HG_ADDRINUSE) /*!< address already in use */ \
143+
X(HG_ADDRNOTAVAIL) /*!< cannot assign requested address */ \
144+
X(HG_HOSTUNREACH) /*!< cannot reach host during operation */ \
145+
X(HG_TIMEOUT) /*!< operation reached timeout */ \
146+
X(HG_CANCELED) /*!< operation canceled */ \
147+
X(HG_IO_ERROR) /*!< I/O error */ \
148+
X(HG_CHECKSUM_ERROR) /*!< checksum error */ \
149+
X(HG_NA_ERROR) /*!< generic NA error */ \
150+
X(HG_OTHER_ERROR) /*!< generic HG error */ \
151+
X(HG_RETURN_MAX)
152+
153+
#define X(a) a,
160154
typedef enum hg_return { HG_RETURN_VALUES } hg_return_t;
161155
#undef X
162156

src/na/na.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ NA_Cancel(na_class_t *na_class, na_context_t *context, na_op_id_t *op_id)
20062006
const char *
20072007
NA_Error_to_string(na_return_t errnum)
20082008
{
2009-
return na_return_name_g[errnum];
2009+
return errnum < NA_RETURN_MAX ? na_return_name_g[errnum] : NULL;
20102010
}
20112011

20122012
/*---------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)