uv: upgrade to a93dc7e
authorBen Noordhuis <info@bnoordhuis.nl>
Mon, 5 Mar 2012 14:38:43 +0000 (15:38 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 5 Mar 2012 14:38:43 +0000 (15:38 +0100)
deps/uv/config-unix.mk
deps/uv/include/uv.h
deps/uv/src/unix/core.c
deps/uv/src/unix/dl.c
deps/uv/src/win/dl.c
deps/uv/src/win/util.c
deps/uv/test/fixtures/load_error.node [new file with mode: 0644]
deps/uv/test/test-dlerror.c [new file with mode: 0644]
deps/uv/test/test-list.h
deps/uv/uv.gyp

index 8eb1c6e1957ce028efe37d9fba22b0bac3d1ca34..97ba52c75a178c53947b719bc0217621d2c41eb8 100644 (file)
@@ -62,7 +62,7 @@ EV_CONFIG=config_linux.h
 EIO_CONFIG=config_linux.h
 CSTDFLAG += -D_GNU_SOURCE
 CPPFLAGS += -Isrc/ares/config_linux
-LINKFLAGS+=-lrt
+LINKFLAGS+=-ldl -lrt
 OBJS += src/unix/linux/core.o src/unix/linux/inotify.o
 endif
 
index 4af154e9d4e2495e2fc0be14bc916043c1e35ce8..19c5e0e5c88bf9b00fc90d1ca96c9cd17cfa06c5 100644 (file)
@@ -1399,6 +1399,12 @@ UV_EXTERN uv_err_t uv_dlclose(uv_lib_t library);
  */
 UV_EXTERN uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr);
 
+/*
+ * Retrieves and frees an error message of dynamic linking loaders.
+ */
+UV_EXTERN const char *uv_dlerror(uv_lib_t library);
+UV_EXTERN void uv_dlerror_free(uv_lib_t library, const char *msg);
+
 /*
  * The mutex functions return 0 on success, -1 on error
  * (unless the return type is void, of course).
index e93a1686a796352ff070f79b526e8cd383e2ae81..728eb0bf90119e8bd94f39f907e46004c8bcf44c 100644 (file)
@@ -541,8 +541,6 @@ static void uv__timer_cb(EV_P_ ev_timer* w, int revents) {
 
   assert(uv__timer_active(timer));
 
-  assert(uv__timer_active(timer));
-
   if (!uv__timer_repeating(timer)) {
     timer->flags &= ~UV_TIMER_ACTIVE;
     ev_ref(EV_A);
index 41c244d79ea4729b22206568523487f0c335de3f..88c9525f76570021ef87ee09d5c97f93c604e21e 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <dlfcn.h>
 #include <errno.h>
+#include <string.h>
+#include <locale.h>
 
 /* The dl family of functions don't set errno. We need a good way to communicate
  * errors to the caller but there is only dlerror() and that returns a string -
@@ -67,3 +69,23 @@ uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr) {
   *ptr = (void*) address;
   return uv_ok_;
 }
+
+
+const char *uv_dlerror(uv_lib_t library) {
+  const char* buf = NULL;
+  /* Make uv_dlerror() be independent of locale */
+  char* loc = setlocale(LC_MESSAGES, NULL);
+  if(strcmp(loc, "C") == 0) {
+    return strdup(dlerror());
+  } else {
+    setlocale(LC_MESSAGES, "C");
+    buf = dlerror();
+    setlocale(LC_MESSAGES, loc);
+    return strdup(buf);
+  }
+}
+
+
+void uv_dlerror_free(uv_lib_t library, const char *msg) {
+  free((void*)msg);
+}
index 37cdc131a1a9269689b981d6a17d305bdaca86d4..a7d4ced46cb5d65eb2a8eb9f0ac0a85da5694519 100644 (file)
@@ -22,6 +22,7 @@
 #include "uv.h"
 #include "internal.h"
 
+__declspec( thread ) DWORD saved_errno = 0;
 
 uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) {
   wchar_t filename_w[32768];
@@ -30,12 +31,14 @@ uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) {
   if (!uv_utf8_to_utf16(filename,
                         filename_w,
                         sizeof(filename_w) / sizeof(wchar_t))) {
-    return uv__new_sys_error(GetLastError());
+    saved_errno = GetLastError();
+    return uv__new_sys_error(saved_errno);
   }
 
   handle = LoadLibraryW(filename_w);
   if (handle == NULL) {
-    return uv__new_sys_error(GetLastError());
+    saved_errno = GetLastError();
+    return uv__new_sys_error(saved_errno);
   }
 
   *library = handle;
@@ -45,7 +48,8 @@ uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) {
 
 uv_err_t uv_dlclose(uv_lib_t library) {
   if (!FreeLibrary(library)) {
-    return uv__new_sys_error(GetLastError());
+    saved_errno = GetLastError();
+    return uv__new_sys_error(saved_errno);
   }
 
   return uv_ok_;
@@ -55,9 +59,24 @@ uv_err_t uv_dlclose(uv_lib_t library) {
 uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr) {
   FARPROC proc = GetProcAddress(library, name);
   if (proc == NULL) {
-    return uv__new_sys_error(GetLastError());
+    saved_errno = GetLastError();
+    return uv__new_sys_error(saved_errno);
   }
 
   *ptr = (void*) proc;
   return uv_ok_;
 }
+
+
+const char *uv_dlerror(uv_lib_t library) {
+  char* buf = NULL;
+  FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+                 FORMAT_MESSAGE_IGNORE_INSERTS, NULL, saved_errno,
+                 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&buf, 0, NULL);
+  return buf;
+}
+
+
+void uv_dlerror_free(uv_lib_t library, const char *msg) {
+  LocalFree((LPVOID)msg);
+}
index 6ded755cef663d4708f535fd0711dfdc41e0b28b..15618e928d92cdec3df42ff90efde27950b8ac64 100644 (file)
@@ -610,7 +610,6 @@ void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time) {
     time.tm_hour = system_time.wHour;
     time.tm_min = system_time.wMinute;
     time.tm_sec = system_time.wSecond;
-    time.tm_isdst = -1;
 
     *stat_time = mktime(&time);
   } else {
diff --git a/deps/uv/test/fixtures/load_error.node b/deps/uv/test/fixtures/load_error.node
new file mode 100644 (file)
index 0000000..323fae0
--- /dev/null
@@ -0,0 +1 @@
+foobar
diff --git a/deps/uv/test/test-dlerror.c b/deps/uv/test/test-dlerror.c
new file mode 100644 (file)
index 0000000..763bfec
--- /dev/null
@@ -0,0 +1,49 @@
+/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "uv.h"
+#include "task.h"
+#include <string.h>
+
+const char* path = "test/fixtures/load_error.node";
+const char* msg;
+
+#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
+
+uv_lib_t lib;
+uv_err_t r;
+
+TEST_IMPL(dlerror) {
+  r = uv_dlopen(path, &lib);
+  msg = uv_dlerror(lib);
+  ASSERT(msg != NULL);
+  ASSERT(strstr(msg, dlerror_desc) != NULL);
+  uv_dlerror_free(lib, msg);
+  return 0;
+}
index 2997b179d2cf595a9955f93ec0ed896bf3491e59..38d39259e9662ab64b1277b8ccd915b201bd4d45 100644 (file)
@@ -142,6 +142,7 @@ TEST_DECLARE   (thread_create)
 TEST_DECLARE   (strlcpy)
 TEST_DECLARE   (strlcat)
 TEST_DECLARE   (counters_init)
+TEST_DECLARE   (dlerror)
 #ifdef _WIN32
 TEST_DECLARE   (spawn_detect_pipe_name_collisions_on_windows)
 TEST_DECLARE   (argument_escaping)
@@ -326,6 +327,7 @@ TASK_LIST_START
   TEST_ENTRY  (strlcpy)
   TEST_ENTRY  (strlcat)
   TEST_ENTRY  (counters_init)
+  TEST_ENTRY  (dlerror)
 #if 0
   /* These are for testing the test runner. */
   TEST_ENTRY  (fail_always)
index 89a9445b300eea14a167eaee650ca71ba2421c68..9a828305aefc9052b8861d36cb07c1c53264a2fe 100644 (file)
       ],
       'direct_dependent_settings': {
         'include_dirs': [ 'include' ],
+        'conditions': [
+          ['OS=="linux"', {
+            'libraries': [ '-ldl' ],
+          }],
+        ],
       },
 
       'defines': [
         'test/test-udp-send-and-recv.c',
         'test/test-udp-multicast-join.c',
         'test/test-counters-init.c',
+        'test/test-dlerror.c',
         'test/test-udp-multicast-ttl.c',
       ],
       'conditions': [