From 4298c1fb2c41fc92ffe7e125cb1b5798ed98f2c1 Mon Sep 17 00:00:00 2001 From: Marc Schlaich Date: Thu, 11 Dec 2014 09:59:31 +0100 Subject: [PATCH 1/5] gitignore: ignore Visual Studio files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/libuv/libuv/pull/59 Reviewed-By: Bert Belder Reviewed-By: Saúl Ibarra Corretgé --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index afa05394..d9300a21 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,10 @@ vgcore.* /run-benchmarks.dSYM *.sln +*.sln.cache +*.ncb *.vcproj +*.vcproj*.user *.vcxproj *.vcxproj.filters *.vcxproj.user From 6eb2eaa7538155a2aed987930de2e7f2b5377ba1 Mon Sep 17 00:00:00 2001 From: Marc Schlaich Date: Thu, 11 Dec 2014 10:26:15 +0100 Subject: [PATCH 2/5] win: set fallback message if FormatMessage fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FormatMessage can fail, e.g. with ERROR_MUI_FILE_NOT_FOUND. In this case no error message was set and uv_dlerror wrongly returned "no error". With this patch the fallback error message "error: " is generated when FormatMessage fails. PR-URL: https://github.com/libuv/libuv/pull/59 Reviewed-By: Bert Belder Reviewed-By: Saúl Ibarra Corretgé --- src/win/dl.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/win/dl.c b/src/win/dl.c index d5b8f7c7..059cef80 100644 --- a/src/win/dl.c +++ b/src/win/dl.c @@ -69,17 +69,37 @@ const char* uv_dlerror(uv_lib_t* lib) { } +static void uv__format_fallback_error(uv_lib_t* lib, int errorno){ + DWORD_PTR args[1] = { (DWORD_PTR) errorno }; + LPSTR fallback_error = "error: %1!d!"; + + FormatMessageA(FORMAT_MESSAGE_FROM_STRING | + FORMAT_MESSAGE_ARGUMENT_ARRAY | + FORMAT_MESSAGE_ALLOCATE_BUFFER, + fallback_error, 0, 0, + (LPSTR) &lib->errmsg, + 0, (va_list*) args); +} + + + static int uv__dlerror(uv_lib_t* lib, int errorno) { + DWORD res; + if (lib->errmsg) { LocalFree((void*)lib->errmsg); lib->errmsg = NULL; } if (errorno) { - FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, - MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), - (LPSTR)&lib->errmsg, 0, NULL); + res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + (LPSTR) &lib->errmsg, 0, NULL); + if (!res) { + uv__format_fallback_error(lib, errorno); + } } return errorno ? -1 : 0; From 4272e0a61a829c29cd7cde9adfe2c1eeea384cb6 Mon Sep 17 00:00:00 2001 From: Marc Schlaich Date: Thu, 11 Dec 2014 10:41:12 +0100 Subject: [PATCH 3/5] win: fall back to default language in uv_dlerror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/libuv/libuv/pull/59 Reviewed-By: Bert Belder Reviewed-By: Saúl Ibarra Corretgé --- src/win/dl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/win/dl.c b/src/win/dl.c index 059cef80..f7fca81c 100644 --- a/src/win/dl.c +++ b/src/win/dl.c @@ -97,6 +97,13 @@ static int uv__dlerror(uv_lib_t* lib, int errorno) { FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR) &lib->errmsg, 0, NULL); + if (!res && GetLastError() == ERROR_MUI_FILE_NOT_FOUND) { + res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, + 0, (LPSTR) &lib->errmsg, 0, NULL); + } + if (!res) { uv__format_fallback_error(lib, errorno); } From f70b69d055544c212348e6cf1c6e0baa8321a3fa Mon Sep 17 00:00:00 2001 From: Marc Schlaich Date: Thu, 11 Dec 2014 10:25:15 +0100 Subject: [PATCH 4/5] test: improve compatibility for dlerror test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check uv_dlerror() doesn't return "no_error", in order to make the test less dependent on the exact error message the platform produces when loading a dynamic library fails. PR-URL: https://github.com/libuv/libuv/pull/59 Reviewed-By: Bert Belder Reviewed-By: Saúl Ibarra Corretgé --- test/test-dlerror.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/test/test-dlerror.c b/test/test-dlerror.c index 877ebf37..31f1326f 100644 --- a/test/test-dlerror.c +++ b/test/test-dlerror.c @@ -26,31 +26,22 @@ TEST_IMPL(dlerror) { const char* path = "test/fixtures/load_error.node"; + const char* dlerror_no_error = "no error"; const char* msg; uv_lib_t lib; int r; -#ifdef __linux__ - const char* dlerror_desc = "file too short"; -#elif defined (__sun__) - const char* dlerror_desc = "unknown file type"; -#elif defined (_WIN32) - const char* dlerror_desc = "%1 is not a valid Win32 application"; -#else - const char* dlerror_desc = ""; -#endif - r = uv_dlopen(path, &lib); ASSERT(r == -1); msg = uv_dlerror(&lib); ASSERT(msg != NULL); - ASSERT(strstr(msg, dlerror_desc) != NULL); + ASSERT(strstr(msg, dlerror_no_error) == NULL); /* Should return the same error twice in a row. */ msg = uv_dlerror(&lib); ASSERT(msg != NULL); - ASSERT(strstr(msg, dlerror_desc) != NULL); + ASSERT(strstr(msg, dlerror_no_error) == NULL); uv_dlclose(&lib); From 59f875d63868e4c3be326635160e940c6b986c23 Mon Sep 17 00:00:00 2001 From: Marc Schlaich Date: Thu, 11 Dec 2014 12:24:58 +0100 Subject: [PATCH 5/5] test: check dlerror is "no error" in no error case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/libuv/libuv/pull/59 Reviewed-By: Bert Belder Reviewed-By: Saúl Ibarra Corretgé --- test/test-dlerror.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test-dlerror.c b/test/test-dlerror.c index 31f1326f..091200ed 100644 --- a/test/test-dlerror.c +++ b/test/test-dlerror.c @@ -31,6 +31,12 @@ TEST_IMPL(dlerror) { uv_lib_t lib; int r; + lib.errmsg = NULL; + lib.handle = NULL; + msg = uv_dlerror(&lib); + ASSERT(msg != NULL); + ASSERT(strstr(msg, dlerror_no_error) != NULL); + r = uv_dlopen(path, &lib); ASSERT(r == -1);