Skip to content

Commit

Permalink
HG: fix RETURN_VALUES macro to only take single argument (fix #766)
Browse files Browse the repository at this point in the history
Check errnum value in string conversion
  • Loading branch information
soumagne committed Oct 28, 2024
1 parent 79f985d commit 27d7c20
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Documentation/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ the handling of multi-recv buffers and the support of cxi with HPE SHS 11.0.
- Add missing `HG_WARN_UNUSED_RESULT` to HG calls
- Switch to using standard types and align with NA
- Keep some `uint8_t` instances instead of `hg_bool_t` for ABI compatibility
- Add `HG_IO_ERROR` return code and reserve space for additional NA codes
- Add `HG_IO_ERROR` return code
- __[NA]__
- Bump NA version to v5.0.0
- Add `NA_Poll()` and `NA_Poll_wait()` routines
Expand Down
8 changes: 3 additions & 5 deletions src/mercury.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ hg_core_respond_cb(const struct hg_core_cb_info *callback_info);
/*******************/

/* Return code string table */
#define X(a, b) #a,
static const char *const hg_return_name[] = {HG_RETURN_VALUES};
#define X(a) #a,
static const char *const hg_return_name_g[] = {HG_RETURN_VALUES};
#undef X

/* Specific log outlets */
Expand Down Expand Up @@ -1054,9 +1054,7 @@ HG_Version_get(
const char *
HG_Error_to_string(hg_return_t errnum)
{
return hg_return_name[errnum < (hg_return_t) NA_RETURN_MAX
? errnum
: errnum - HG_NA_ERRNO_OFFSET + NA_RETURN_MAX];
return errnum < HG_RETURN_MAX ? hg_return_name_g[errnum] : NULL;
}

/*---------------------------------------------------------------------------*/
Expand Down
64 changes: 29 additions & 35 deletions src/mercury_core_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,38 @@ struct hg_init_info {
unsigned int multi_recv_copy_threshold;
};

/* Keep offset to keep room for additional NA error codes */
#define HG_NA_ERRNO_OFFSET 64

/* Error return codes:
* Functions return 0 for success or corresponding return code */
#define HG_RETURN_VALUES \
X(HG_SUCCESS, NA_SUCCESS) /*!< operation succeeded */ \
X(HG_PERMISSION, NA_PERMISSION) /*!< operation not permitted */ \
X(HG_NOENTRY, NA_NOENTRY) /*!< no such file or directory */ \
X(HG_INTERRUPT, NA_INTERRUPT) /*!< operation interrupted */ \
X(HG_AGAIN, NA_AGAIN) /*!< operation must be retried */ \
X(HG_NOMEM, NA_NOMEM) /*!< out of memory */ \
X(HG_ACCESS, NA_ACCESS) /*!< permission denied */ \
X(HG_FAULT, NA_FAULT) /*!< bad address */ \
X(HG_BUSY, NA_BUSY) /*!< device or resource busy */ \
X(HG_EXIST, NA_EXIST) /*!< entry already exists */ \
X(HG_NODEV, NA_NODEV) /*!< no such device */ \
X(HG_INVALID_ARG, NA_INVALID_ARG) /*!< invalid argument */ \
X(HG_PROTOCOL_ERROR, NA_PROTOCOL_ERROR) /*!< protocol error */ \
X(HG_OVERFLOW, NA_OVERFLOW) /*!< value too large */ \
X(HG_MSGSIZE, NA_MSGSIZE) /*!< message size too long */ \
X(HG_PROTONOSUPPORT, NA_PROTONOSUPPORT) /*!< protocol not supported */ \
X(HG_OPNOTSUPPORTED, \
NA_OPNOTSUPPORTED) /*!< operation not supported on endpoint */ \
X(HG_ADDRINUSE, NA_ADDRINUSE) /*!< address already in use */ \
X(HG_ADDRNOTAVAIL, \
NA_ADDRNOTAVAIL) /*!< cannot assign requested address */ \
X(HG_HOSTUNREACH, \
NA_HOSTUNREACH) /*!< cannot reach host during operation */ \
X(HG_TIMEOUT, NA_TIMEOUT) /*!< operation reached timeout */ \
X(HG_CANCELED, NA_CANCELED) /*!< operation canceled */ \
X(HG_IO_ERROR, NA_IO_ERROR) /*!< I/O error */ \
X(HG_CHECKSUM_ERROR, HG_NA_ERRNO_OFFSET) /*!< checksum error */ \
X(HG_NA_ERROR, HG_NA_ERRNO_OFFSET + 1) /*!< generic NA error */ \
X(HG_OTHER_ERROR, HG_NA_ERRNO_OFFSET + 2) /*!< generic HG error */ \
X(HG_RETURN_MAX, HG_NA_ERRNO_OFFSET + 3)

#define X(a, b) a = b,
X(HG_SUCCESS) /*!< operation succeeded */ \
X(HG_PERMISSION) /*!< operation not permitted */ \
X(HG_NOENTRY) /*!< no such file or directory */ \
X(HG_INTERRUPT) /*!< operation interrupted */ \
X(HG_AGAIN) /*!< operation must be retried */ \
X(HG_NOMEM) /*!< out of memory */ \
X(HG_ACCESS) /*!< permission denied */ \
X(HG_FAULT) /*!< bad address */ \
X(HG_BUSY) /*!< device or resource busy */ \
X(HG_EXIST) /*!< entry already exists */ \
X(HG_NODEV) /*!< no such device */ \
X(HG_INVALID_ARG) /*!< invalid argument */ \
X(HG_PROTOCOL_ERROR) /*!< protocol error */ \
X(HG_OVERFLOW) /*!< value too large */ \
X(HG_MSGSIZE) /*!< message size too long */ \
X(HG_PROTONOSUPPORT) /*!< protocol not supported */ \
X(HG_OPNOTSUPPORTED) /*!< operation not supported on endpoint */ \
X(HG_ADDRINUSE) /*!< address already in use */ \
X(HG_ADDRNOTAVAIL) /*!< cannot assign requested address */ \
X(HG_HOSTUNREACH) /*!< cannot reach host during operation */ \
X(HG_TIMEOUT) /*!< operation reached timeout */ \
X(HG_CANCELED) /*!< operation canceled */ \
X(HG_IO_ERROR) /*!< I/O error */ \
X(HG_CHECKSUM_ERROR) /*!< checksum error */ \
X(HG_NA_ERROR) /*!< generic NA error */ \
X(HG_OTHER_ERROR) /*!< generic HG error */ \
X(HG_RETURN_MAX)

#define X(a) a,
typedef enum hg_return { HG_RETURN_VALUES } hg_return_t;
#undef X

Expand Down
2 changes: 1 addition & 1 deletion src/na/na.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ NA_Cancel(na_class_t *na_class, na_context_t *context, na_op_id_t *op_id)
const char *
NA_Error_to_string(na_return_t errnum)
{
return na_return_name_g[errnum];
return errnum < NA_RETURN_MAX ? na_return_name_g[errnum] : NULL;
}

/*---------------------------------------------------------------------------*/
Expand Down

0 comments on commit 27d7c20

Please sign in to comment.