Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates HSYS_GOTO_ERROR to emit GetLastError() values on Win32 #492

Merged
merged 9 commits into from
Mar 23, 2021
28 changes: 27 additions & 1 deletion release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,33 @@ New Features

Library:
--------
- HSYS_GOTO_ERROR now emits the results of GetLastError() on Windows

HSYS_GOTO_ERROR is an internal macro that is used to produce error
messages when system calls fail. These strings include errno and the
the associated strerror() value, which are not particularly useful
when a Win32 API call fails.

On Windows, this macro has been updated to include the result of
GetLastError(). When a system call fails on Windows, usually only
one of errno and GetLastError() will be useful, however we emit both
for the user to parse. The Windows error message is not emitted as
it would be awkward to free the FormatMessage() buffer given the
existing HDF5 error framework. Users will have to look up the error
codes in MSDN.

The format string on Windows has been changed from:

"%s, errno = %d, error message = '%s'"

to:

"%s, errno = %d, error message = '%s', Win32 GetLastError() = %"PRIu32""

for those inclined to parse it for error values.

(DER - 2021/03/21)

- File locking now works on Windows

Since version 1.10.0, the HDF5 library has used a file locking scheme
Expand All @@ -400,7 +427,6 @@ New Features

(DER - 2021/03/19, HDFFV-10191)


- H5Epush_ret() now requires a trailing semicolon

H5Epush_ret() is a function-like macro that has been changed to
Expand Down
30 changes: 30 additions & 0 deletions src/H5Eprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef struct H5E_t H5E_t;
/* Retrieve the error code description string and push it onto the error
* stack.
*/
#ifndef H5_HAVE_WIN32_API
#define HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) \
{ \
int myerrno = errno; \
Expand All @@ -129,6 +130,35 @@ typedef struct H5E_t H5E_t;
HGOTO_ERROR(majorcode, minorcode, retcode, "%s, errno = %d, error message = '%s'", str, myerrno, \
jhendersonHDF marked this conversation as resolved.
Show resolved Hide resolved
HDstrerror(myerrno)); \
}
#else /* H5_HAVE_WIN32_API */
/* On Windows we also emit the result of GetLastError(). This call returns a DWORD, which is always a
* 32-bit unsigned type. Note that on Windows, either errno or GetLastError() (but probably not both) will
* be useful depending on whether a C/POSIX or Win32 call failed. The other value will likely be zero,
* though I wouldn't count on that.
*/
#define HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) \
{ \
int myerrno = errno; \
DWORD win_error = GetLastError(); \
/* Other projects may rely on the description format to get the errno and any changes should be \
* considered as an API change \
*/ \
HDONE_ERROR(majorcode, minorcode, retcode, \
"%s, errno = %d, error message = '%s', Win32 GetLastError() = %" PRIu32 "", str, \
myerrno, HDstrerror(myerrno), win_error); \
}
#define HSYS_GOTO_ERROR(majorcode, minorcode, retcode, str) \
jhendersonHDF marked this conversation as resolved.
Show resolved Hide resolved
{ \
int myerrno = errno; \
DWORD win_error = GetLastError(); \
/* Other projects may rely on the description format to get the errno and any changes should be \
* considered as an API change \
*/ \
HGOTO_ERROR(majorcode, minorcode, retcode, \
"%s, errno = %d, error message = '%s', Win32 GetLastError() = %" PRIu32 "", str, \
myerrno, HDstrerror(myerrno), win_error); \
}
#endif /* H5_HAVE_WIN32_API */

#ifdef H5_HAVE_PARALLEL
/*
Expand Down