Skip to content

Commit 69f3cde

Browse files
Updates HSYS_GOTO_ERROR to emit GetLastError() values on Win32 (#492)
* Committing clang-format changes * Updates H5SYS_GOTO_ERROR to emit Win32's GetLastError() * Committing clang-format changes * Format source changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 99c0f50 commit 69f3cde

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

release_docs/RELEASE.txt

+27-1
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,33 @@ New Features
384384

385385
Library:
386386
--------
387+
- HSYS_GOTO_ERROR now emits the results of GetLastError() on Windows
388+
389+
HSYS_GOTO_ERROR is an internal macro that is used to produce error
390+
messages when system calls fail. These strings include errno and the
391+
the associated strerror() value, which are not particularly useful
392+
when a Win32 API call fails.
393+
394+
On Windows, this macro has been updated to include the result of
395+
GetLastError(). When a system call fails on Windows, usually only
396+
one of errno and GetLastError() will be useful, however we emit both
397+
for the user to parse. The Windows error message is not emitted as
398+
it would be awkward to free the FormatMessage() buffer given the
399+
existing HDF5 error framework. Users will have to look up the error
400+
codes in MSDN.
401+
402+
The format string on Windows has been changed from:
403+
404+
"%s, errno = %d, error message = '%s'"
405+
406+
to:
407+
408+
"%s, errno = %d, error message = '%s', Win32 GetLastError() = %"PRIu32""
409+
410+
for those inclined to parse it for error values.
411+
412+
(DER - 2021/03/21)
413+
387414
- File locking now works on Windows
388415

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

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

403-
404430
- H5Epush_ret() now requires a trailing semicolon
405431

406432
H5Epush_ret() is a function-like macro that has been changed to

src/H5Eprivate.h

+30
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ typedef struct H5E_t H5E_t;
111111
/* Retrieve the error code description string and push it onto the error
112112
* stack.
113113
*/
114+
#ifndef H5_HAVE_WIN32_API
114115
#define HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) \
115116
{ \
116117
int myerrno = errno; \
@@ -129,6 +130,35 @@ typedef struct H5E_t H5E_t;
129130
HGOTO_ERROR(majorcode, minorcode, retcode, "%s, errno = %d, error message = '%s'", str, myerrno, \
130131
HDstrerror(myerrno)); \
131132
}
133+
#else /* H5_HAVE_WIN32_API */
134+
/* On Windows we also emit the result of GetLastError(). This call returns a DWORD, which is always a
135+
* 32-bit unsigned type. Note that on Windows, either errno or GetLastError() (but probably not both) will
136+
* be useful depending on whether a C/POSIX or Win32 call failed. The other value will likely be zero,
137+
* though I wouldn't count on that.
138+
*/
139+
#define HSYS_DONE_ERROR(majorcode, minorcode, retcode, str) \
140+
{ \
141+
int myerrno = errno; \
142+
DWORD win_error = GetLastError(); \
143+
/* Other projects may rely on the description format to get the errno and any changes should be \
144+
* considered as an API change \
145+
*/ \
146+
HDONE_ERROR(majorcode, minorcode, retcode, \
147+
"%s, errno = %d, error message = '%s', Win32 GetLastError() = %" PRIu32 "", str, \
148+
myerrno, HDstrerror(myerrno), win_error); \
149+
}
150+
#define HSYS_GOTO_ERROR(majorcode, minorcode, retcode, str) \
151+
{ \
152+
int myerrno = errno; \
153+
DWORD win_error = GetLastError(); \
154+
/* Other projects may rely on the description format to get the errno and any changes should be \
155+
* considered as an API change \
156+
*/ \
157+
HGOTO_ERROR(majorcode, minorcode, retcode, \
158+
"%s, errno = %d, error message = '%s', Win32 GetLastError() = %" PRIu32 "", str, \
159+
myerrno, HDstrerror(myerrno), win_error); \
160+
}
161+
#endif /* H5_HAVE_WIN32_API */
132162

133163
#ifdef H5_HAVE_PARALLEL
134164
/*

0 commit comments

Comments
 (0)