passenger 5.0.25 → 5.0.26

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +20 -0
  3. data/CONTRIBUTORS +1 -0
  4. data/build/cxx_dependency_map.rb +7338 -7104
  5. data/build/cxx_tests.rb +3 -3
  6. data/build/misc.rb +1 -0
  7. data/dev/index_cxx_dependencies.rb +3 -2
  8. data/resources/templates/standalone/config.erb +1 -1
  9. data/resources/templates/standalone/http.erb +1 -0
  10. data/resources/templates/standalone/server.erb +1 -0
  11. data/src/agent/Core/ApplicationPool/AbstractSession.h +83 -0
  12. data/src/agent/Core/ApplicationPool/Common.h +6 -4
  13. data/src/agent/Core/ApplicationPool/Options.h +4 -1
  14. data/src/agent/Core/ApplicationPool/Pool.h +2 -2
  15. data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +3 -6
  16. data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
  17. data/src/agent/Core/ApplicationPool/Session.h +15 -27
  18. data/src/agent/Core/ApplicationPool/TestSession.h +188 -0
  19. data/src/agent/Core/Controller.h +15 -6
  20. data/src/agent/Core/Controller/CheckoutSession.cpp +13 -5
  21. data/src/agent/Core/Controller/ForwardResponse.cpp +20 -2
  22. data/src/agent/Core/Controller/Hooks.cpp +15 -2
  23. data/src/agent/Core/Controller/InitRequest.cpp +5 -1
  24. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +1 -0
  25. data/src/agent/Core/Controller/Request.h +11 -4
  26. data/src/agent/Core/Controller/SendRequest.cpp +34 -13
  27. data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +2 -2
  28. data/src/agent/Core/CoreMain.cpp +27 -1
  29. data/src/agent/Core/OptionParser.h +11 -1
  30. data/src/agent/Core/SpawningKit/DirectSpawner.h +1 -0
  31. data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -0
  32. data/src/agent/Core/SpawningKit/Spawner.h +21 -1
  33. data/src/agent/SpawnPreparer/SpawnPreparerMain.cpp +1 -1
  34. data/src/agent/UstRouter/OptionParser.h +7 -1
  35. data/src/agent/UstRouter/UstRouterMain.cpp +27 -1
  36. data/src/cxx_supportlib/Algorithms/MovingAverage.h +223 -0
  37. data/src/cxx_supportlib/Constants.h +2 -2
  38. data/src/cxx_supportlib/DataStructures/StringKeyTable.h +96 -40
  39. data/src/cxx_supportlib/ResourceLocator.h +33 -14
  40. data/src/cxx_supportlib/ServerKit/Channel.h +198 -69
  41. data/src/cxx_supportlib/ServerKit/Errors.h +6 -1
  42. data/src/cxx_supportlib/ServerKit/HttpRequest.h +20 -1
  43. data/src/cxx_supportlib/ServerKit/HttpServer.h +124 -32
  44. data/src/cxx_supportlib/ServerKit/Server.h +65 -1
  45. data/src/cxx_supportlib/Utils/IOUtils.cpp +12 -22
  46. data/src/cxx_supportlib/Utils/JsonUtils.h +87 -1
  47. data/src/cxx_supportlib/Utils/StrIntUtils.cpp +16 -1
  48. data/src/cxx_supportlib/Utils/StrIntUtils.h +31 -1
  49. data/src/cxx_supportlib/Utils/VariantMap.h +6 -1
  50. data/src/cxx_supportlib/WatchdogLauncher.h +17 -9
  51. data/src/cxx_supportlib/vendor-copy/libuv/AUTHORS +43 -0
  52. data/src/cxx_supportlib/vendor-copy/libuv/ChangeLog +350 -1
  53. data/src/cxx_supportlib/vendor-copy/libuv/Makefile.am +9 -1
  54. data/src/cxx_supportlib/vendor-copy/libuv/README.md +48 -0
  55. data/src/cxx_supportlib/vendor-copy/libuv/checksparse.sh +1 -0
  56. data/src/cxx_supportlib/vendor-copy/libuv/common.gypi +5 -5
  57. data/src/cxx_supportlib/vendor-copy/libuv/configure.ac +2 -1
  58. data/src/cxx_supportlib/vendor-copy/libuv/gyp_uv.py +0 -3
  59. data/src/cxx_supportlib/vendor-copy/libuv/include/uv-version.h +5 -1
  60. data/src/cxx_supportlib/vendor-copy/libuv/include/uv.h +30 -3
  61. data/src/cxx_supportlib/vendor-copy/libuv/src/fs-poll.c +3 -3
  62. data/src/cxx_supportlib/vendor-copy/libuv/src/inet.c +0 -4
  63. data/src/cxx_supportlib/vendor-copy/libuv/src/queue.h +17 -1
  64. data/src/cxx_supportlib/vendor-copy/libuv/src/threadpool.c +10 -10
  65. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/aix.c +84 -166
  66. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/android-ifaddrs.c +11 -11
  67. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/async.c +7 -1
  68. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/atomic-ops.h +17 -0
  69. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/core.c +140 -21
  70. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/darwin.c +15 -11
  71. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/dl.c +4 -7
  72. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/freebsd.c +52 -37
  73. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/fs.c +181 -60
  74. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/fsevents.c +39 -34
  75. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/getaddrinfo.c +4 -4
  76. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/internal.h +3 -1
  77. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/kqueue.c +12 -4
  78. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/linux-core.c +38 -15
  79. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/linux-inotify.c +36 -8
  80. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/linux-syscalls.c +4 -4
  81. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/linux-syscalls.h +2 -2
  82. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/loop-watcher.c +6 -1
  83. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/loop.c +28 -8
  84. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/netbsd.c +18 -16
  85. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/openbsd.c +18 -16
  86. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/pipe.c +3 -3
  87. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/process.c +18 -6
  88. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/proctitle.c +2 -2
  89. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/pthread-fixes.c +1 -0
  90. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/signal.c +2 -0
  91. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/stream.c +47 -30
  92. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/sunos.c +13 -11
  93. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/tcp.c +43 -8
  94. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/thread.c +21 -15
  95. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/tty.c +16 -2
  96. data/src/cxx_supportlib/vendor-copy/libuv/src/unix/udp.c +54 -14
  97. data/src/cxx_supportlib/vendor-copy/libuv/src/uv-common.c +104 -21
  98. data/src/cxx_supportlib/vendor-copy/libuv/src/uv-common.h +14 -1
  99. data/src/cxx_supportlib/vendor-copy/libuv/src/version.c +1 -5
  100. data/src/cxx_supportlib/vendor-copy/libuv/uv.gyp +22 -1
  101. data/src/nginx_module/CacheLocationConfig.c +52 -0
  102. data/src/nginx_module/CacheLocationConfig.c.erb +13 -1
  103. data/src/nginx_module/Configuration.c +1 -0
  104. data/src/nginx_module/Configuration.h +1 -0
  105. data/src/nginx_module/ConfigurationCommands.c +20 -0
  106. data/src/nginx_module/ConfigurationFields.h +4 -0
  107. data/src/nginx_module/CreateLocationConfig.c +8 -0
  108. data/src/nginx_module/MergeLocationConfig.c +12 -0
  109. data/src/nginx_module/config +31 -13
  110. data/src/nginx_module/ngx_http_passenger_module.c +4 -0
  111. data/src/ruby_supportlib/phusion_passenger.rb +1 -1
  112. data/src/ruby_supportlib/phusion_passenger/constants.rb +1 -1
  113. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +11 -1
  114. data/src/ruby_supportlib/phusion_passenger/platform_info/apache.rb +6 -1
  115. data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +32 -31
  116. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +13 -2
  117. data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +1 -0
  118. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +6 -1
  119. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +6 -0
  120. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +29 -19
  121. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +2 -2
  122. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +2 -3
  123. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +2 -1
  124. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/spec_helper.rb +2 -0
  125. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/time_point.rb +3 -17
  126. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +7 -10
  127. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +11 -9
  128. metadata +5 -2
@@ -51,8 +51,6 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
51
51
  flags = 0;
52
52
  newfd = -1;
53
53
 
54
- uv__stream_init(loop, (uv_stream_t*) tty, UV_TTY);
55
-
56
54
  /* Reopen the file descriptor when it refers to a tty. This lets us put the
57
55
  * tty in non-blocking mode without affecting other processes that share it
58
56
  * with us.
@@ -89,11 +87,18 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
89
87
  }
90
88
 
91
89
  skip:
90
+ uv__stream_init(loop, (uv_stream_t*) tty, UV_TTY);
91
+
92
+ /* If anything fails beyond this point we need to remove the handle from
93
+ * the handle queue, since it was added by uv__handle_init in uv_stream_init.
94
+ */
95
+
92
96
  #if defined(__APPLE__)
93
97
  r = uv__stream_try_select((uv_stream_t*) tty, &fd);
94
98
  if (r) {
95
99
  if (newfd != -1)
96
100
  uv__close(newfd);
101
+ QUEUE_REMOVE(&tty->handle_queue);
97
102
  return r;
98
103
  }
99
104
  #endif
@@ -231,6 +236,15 @@ uv_handle_type uv_guess_handle(uv_file file) {
231
236
  return UV_UDP;
232
237
 
233
238
  if (type == SOCK_STREAM) {
239
+ #if defined(_AIX)
240
+ /* on AIX the getsockname call returns an empty sa structure
241
+ * for sockets of type AF_UNIX. For all other types it will
242
+ * return a properly filled in structure.
243
+ */
244
+ if (len == 0)
245
+ return UV_NAMED_PIPE;
246
+ #endif /* defined(_AIX) */
247
+
234
248
  if (sa.sa_family == AF_INET || sa.sa_family == AF_INET6)
235
249
  return UV_TCP;
236
250
  if (sa.sa_family == AF_UNIX)
@@ -89,6 +89,9 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
89
89
  uv_udp_send_t* req;
90
90
  QUEUE* q;
91
91
 
92
+ assert(!(handle->flags & UV_UDP_PROCESSING));
93
+ handle->flags |= UV_UDP_PROCESSING;
94
+
92
95
  while (!QUEUE_EMPTY(&handle->write_completed_queue)) {
93
96
  q = QUEUE_HEAD(&handle->write_completed_queue);
94
97
  QUEUE_REMOVE(q);
@@ -100,7 +103,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
100
103
  handle->send_queue_count--;
101
104
 
102
105
  if (req->bufs != req->bufsml)
103
- free(req->bufs);
106
+ uv__free(req->bufs);
104
107
  req->bufs = NULL;
105
108
 
106
109
  if (req->send_cb == NULL)
@@ -121,6 +124,8 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
121
124
  if (!uv__io_active(&handle->io_watcher, UV__POLLIN))
122
125
  uv__handle_stop(handle);
123
126
  }
127
+
128
+ handle->flags &= ~UV_UDP_PROCESSING;
124
129
  }
125
130
 
126
131
 
@@ -316,6 +321,10 @@ int uv__udp_bind(uv_udp_t* handle,
316
321
 
317
322
  if (bind(fd, addr, addrlen)) {
318
323
  err = -errno;
324
+ if (errno == EAFNOSUPPORT)
325
+ /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
326
+ * socket created with AF_INET to an AF_INET6 address or vice versa. */
327
+ err = -EINVAL;
319
328
  goto out;
320
329
  }
321
330
 
@@ -399,10 +408,12 @@ int uv__udp_send(uv_udp_send_t* req,
399
408
 
400
409
  req->bufs = req->bufsml;
401
410
  if (nbufs > ARRAY_SIZE(req->bufsml))
402
- req->bufs = malloc(nbufs * sizeof(bufs[0]));
411
+ req->bufs = uv__malloc(nbufs * sizeof(bufs[0]));
403
412
 
404
- if (req->bufs == NULL)
413
+ if (req->bufs == NULL) {
414
+ uv__req_unregister(handle->loop, req);
405
415
  return -ENOMEM;
416
+ }
406
417
 
407
418
  memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0]));
408
419
  handle->send_queue_size += uv__count_bufs(req->bufs, req->nbufs);
@@ -410,10 +421,11 @@ int uv__udp_send(uv_udp_send_t* req,
410
421
  QUEUE_INSERT_TAIL(&handle->write_queue, &req->queue);
411
422
  uv__handle_start(handle);
412
423
 
413
- if (empty_queue)
424
+ if (empty_queue && !(handle->flags & UV_UDP_PROCESSING)) {
414
425
  uv__udp_sendmsg(handle);
415
- else
426
+ } else {
416
427
  uv__io_start(handle->loop, &handle->io_watcher, UV__POLLOUT);
428
+ }
417
429
 
418
430
  return 0;
419
431
  }
@@ -545,25 +557,51 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
545
557
  }
546
558
 
547
559
 
548
- int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) {
560
+ int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags) {
561
+ int domain;
562
+ int err;
563
+ int fd;
564
+
565
+ /* Use the lower 8 bits for the domain */
566
+ domain = flags & 0xFF;
567
+ if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
568
+ return -EINVAL;
569
+
570
+ if (flags & ~0xFF)
571
+ return -EINVAL;
572
+
573
+ if (domain != AF_UNSPEC) {
574
+ err = uv__socket(domain, SOCK_DGRAM, 0);
575
+ if (err < 0)
576
+ return err;
577
+ fd = err;
578
+ } else {
579
+ fd = -1;
580
+ }
581
+
549
582
  uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP);
550
583
  handle->alloc_cb = NULL;
551
584
  handle->recv_cb = NULL;
552
585
  handle->send_queue_size = 0;
553
586
  handle->send_queue_count = 0;
554
- uv__io_init(&handle->io_watcher, uv__udp_io, -1);
587
+ uv__io_init(&handle->io_watcher, uv__udp_io, fd);
555
588
  QUEUE_INIT(&handle->write_queue);
556
589
  QUEUE_INIT(&handle->write_completed_queue);
557
590
  return 0;
558
591
  }
559
592
 
560
593
 
594
+ int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) {
595
+ return uv_udp_init_ex(loop, handle, AF_UNSPEC);
596
+ }
597
+
598
+
561
599
  int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
562
600
  int err;
563
601
 
564
602
  /* Check for already active socket. */
565
603
  if (handle->io_watcher.fd != -1)
566
- return -EALREADY; /* FIXME(bnoordhuis) Should be -EBUSY. */
604
+ return -EBUSY;
567
605
 
568
606
  err = uv__nonblock(sock, 1);
569
607
  if (err)
@@ -632,6 +670,8 @@ static int uv__setsockopt_maybe_char(uv_udp_t* handle,
632
670
  int val) {
633
671
  #if defined(__sun) || defined(_AIX)
634
672
  char arg = val;
673
+ #elif defined(__OpenBSD__)
674
+ unsigned char arg = val;
635
675
  #else
636
676
  int arg = val;
637
677
  #endif
@@ -666,13 +706,13 @@ int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
666
706
  * so hardcode the size of these options on this platform,
667
707
  * and use the general uv__setsockopt_maybe_char call on other platforms.
668
708
  */
669
- #if defined(__sun)
709
+ #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__)
670
710
  return uv__setsockopt(handle,
671
711
  IP_TTL,
672
712
  IPV6_UNICAST_HOPS,
673
713
  &ttl,
674
714
  sizeof(ttl));
675
- #endif /* defined(__sun) */
715
+ #endif /* defined(__sun) || defined(_AIX) || defined (__OpenBSD__) */
676
716
 
677
717
  return uv__setsockopt_maybe_char(handle,
678
718
  IP_TTL,
@@ -688,14 +728,14 @@ int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
688
728
  * IP_MULTICAST_TTL, so hardcode the size of the option in the IPv6 case,
689
729
  * and use the general uv__setsockopt_maybe_char call otherwise.
690
730
  */
691
- #if defined(__sun)
731
+ #if defined(__sun) || defined(_AIX)
692
732
  if (handle->flags & UV_HANDLE_IPV6)
693
733
  return uv__setsockopt(handle,
694
734
  IP_MULTICAST_TTL,
695
735
  IPV6_MULTICAST_HOPS,
696
736
  &ttl,
697
737
  sizeof(ttl));
698
- #endif /* defined(__sun) */
738
+ #endif /* defined(__sun) || defined(_AIX) */
699
739
 
700
740
  return uv__setsockopt_maybe_char(handle,
701
741
  IP_MULTICAST_TTL,
@@ -711,14 +751,14 @@ int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) {
711
751
  * IP_MULTICAST_LOOP, so hardcode the size of the option in the IPv6 case,
712
752
  * and use the general uv__setsockopt_maybe_char call otherwise.
713
753
  */
714
- #if defined(__sun)
754
+ #if defined(__sun) || defined(_AIX)
715
755
  if (handle->flags & UV_HANDLE_IPV6)
716
756
  return uv__setsockopt(handle,
717
757
  IP_MULTICAST_LOOP,
718
758
  IPV6_MULTICAST_LOOP,
719
759
  &on,
720
760
  sizeof(on));
721
- #endif /* defined(__sun) */
761
+ #endif /* defined(__sun) || defined(_AIX) */
722
762
 
723
763
  return uv__setsockopt_maybe_char(handle,
724
764
  IP_MULTICAST_LOOP,
@@ -29,10 +29,80 @@
29
29
  #include <stdlib.h> /* malloc */
30
30
  #include <string.h> /* memset */
31
31
 
32
- #if !defined(_WIN32)
32
+ #if defined(_WIN32)
33
+ # include <malloc.h> /* malloc */
34
+ #else
33
35
  # include <net/if.h> /* if_nametoindex */
34
36
  #endif
35
37
 
38
+
39
+ typedef struct {
40
+ uv_malloc_func local_malloc;
41
+ uv_realloc_func local_realloc;
42
+ uv_calloc_func local_calloc;
43
+ uv_free_func local_free;
44
+ } uv__allocator_t;
45
+
46
+ static uv__allocator_t uv__allocator = {
47
+ malloc,
48
+ realloc,
49
+ calloc,
50
+ free,
51
+ };
52
+
53
+ char* uv__strdup(const char* s) {
54
+ size_t len = strlen(s) + 1;
55
+ char* m = uv__malloc(len);
56
+ if (m == NULL)
57
+ return NULL;
58
+ return memcpy(m, s, len);
59
+ }
60
+
61
+ char* uv__strndup(const char* s, size_t n) {
62
+ char* m;
63
+ size_t len = strlen(s);
64
+ if (n < len)
65
+ len = n;
66
+ m = uv__malloc(len + 1);
67
+ if (m == NULL)
68
+ return NULL;
69
+ m[len] = '\0';
70
+ return memcpy(m, s, len);
71
+ }
72
+
73
+ void* uv__malloc(size_t size) {
74
+ return uv__allocator.local_malloc(size);
75
+ }
76
+
77
+ void uv__free(void* ptr) {
78
+ uv__allocator.local_free(ptr);
79
+ }
80
+
81
+ void* uv__calloc(size_t count, size_t size) {
82
+ return uv__allocator.local_calloc(count, size);
83
+ }
84
+
85
+ void* uv__realloc(void* ptr, size_t size) {
86
+ return uv__allocator.local_realloc(ptr, size);
87
+ }
88
+
89
+ int uv_replace_allocator(uv_malloc_func malloc_func,
90
+ uv_realloc_func realloc_func,
91
+ uv_calloc_func calloc_func,
92
+ uv_free_func free_func) {
93
+ if (malloc_func == NULL || realloc_func == NULL ||
94
+ calloc_func == NULL || free_func == NULL) {
95
+ return UV_EINVAL;
96
+ }
97
+
98
+ uv__allocator.local_malloc = malloc_func;
99
+ uv__allocator.local_realloc = realloc_func;
100
+ uv__allocator.local_calloc = calloc_func;
101
+ uv__allocator.local_free = free_func;
102
+
103
+ return 0;
104
+ }
105
+
36
106
  #define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t);
37
107
 
38
108
  size_t uv_handle_size(uv_handle_type type) {
@@ -67,14 +137,23 @@ uv_buf_t uv_buf_init(char* base, unsigned int len) {
67
137
  }
68
138
 
69
139
 
140
+ static const char* uv__unknown_err_code(int err) {
141
+ char buf[32];
142
+ char* copy;
143
+
144
+ snprintf(buf, sizeof(buf), "Unknown system error %d", err);
145
+ copy = uv__strdup(buf);
146
+
147
+ return copy != NULL ? copy : "Unknown system error";
148
+ }
149
+
150
+
70
151
  #define UV_ERR_NAME_GEN(name, _) case UV_ ## name: return #name;
71
152
  const char* uv_err_name(int err) {
72
153
  switch (err) {
73
154
  UV_ERRNO_MAP(UV_ERR_NAME_GEN)
74
- default:
75
- assert(0);
76
- return NULL;
77
155
  }
156
+ return uv__unknown_err_code(err);
78
157
  }
79
158
  #undef UV_ERR_NAME_GEN
80
159
 
@@ -83,9 +162,8 @@ const char* uv_err_name(int err) {
83
162
  const char* uv_strerror(int err) {
84
163
  switch (err) {
85
164
  UV_ERRNO_MAP(UV_STRERROR_GEN)
86
- default:
87
- return "Unknown system error";
88
165
  }
166
+ return uv__unknown_err_code(err);
89
167
  }
90
168
  #undef UV_STRERROR_GEN
91
169
 
@@ -259,19 +337,25 @@ int uv_udp_recv_stop(uv_udp_t* handle) {
259
337
 
260
338
 
261
339
  void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
340
+ QUEUE queue;
262
341
  QUEUE* q;
263
342
  uv_handle_t* h;
264
343
 
265
- QUEUE_FOREACH(q, &loop->handle_queue) {
344
+ QUEUE_MOVE(&loop->handle_queue, &queue);
345
+ while (!QUEUE_EMPTY(&queue)) {
346
+ q = QUEUE_HEAD(&queue);
266
347
  h = QUEUE_DATA(q, uv_handle_t, handle_queue);
348
+
349
+ QUEUE_REMOVE(q);
350
+ QUEUE_INSERT_TAIL(&loop->handle_queue, q);
351
+
267
352
  if (h->flags & UV__HANDLE_INTERNAL) continue;
268
353
  walk_cb(h, arg);
269
354
  }
270
355
  }
271
356
 
272
357
 
273
- #ifndef NDEBUG
274
- static void uv__print_handles(uv_loop_t* loop, int only_active) {
358
+ static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) {
275
359
  const char* type;
276
360
  QUEUE* q;
277
361
  uv_handle_t* h;
@@ -292,7 +376,7 @@ static void uv__print_handles(uv_loop_t* loop, int only_active) {
292
376
  default: type = "<unknown>";
293
377
  }
294
378
 
295
- fprintf(stderr,
379
+ fprintf(stream,
296
380
  "[%c%c%c] %-8s %p\n",
297
381
  "R-"[!(h->flags & UV__HANDLE_REF)],
298
382
  "A-"[!(h->flags & UV__HANDLE_ACTIVE)],
@@ -303,15 +387,14 @@ static void uv__print_handles(uv_loop_t* loop, int only_active) {
303
387
  }
304
388
 
305
389
 
306
- void uv_print_all_handles(uv_loop_t* loop) {
307
- uv__print_handles(loop, 0);
390
+ void uv_print_all_handles(uv_loop_t* loop, FILE* stream) {
391
+ uv__print_handles(loop, 0, stream);
308
392
  }
309
393
 
310
394
 
311
- void uv_print_active_handles(uv_loop_t* loop) {
312
- uv__print_handles(loop, 1);
395
+ void uv_print_active_handles(uv_loop_t* loop, FILE* stream) {
396
+ uv__print_handles(loop, 1, stream);
313
397
  }
314
- #endif
315
398
 
316
399
 
317
400
  void uv_ref(uv_handle_t* handle) {
@@ -400,7 +483,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req) {
400
483
  if (*nbufs > 0 && *nbufs != (unsigned int) req->result)
401
484
  (*nbufs)--;
402
485
  for (; *nbufs < (unsigned int) req->result; (*nbufs)++)
403
- free(dents[*nbufs]);
486
+ uv__free(dents[*nbufs]);
404
487
  }
405
488
 
406
489
 
@@ -414,11 +497,11 @@ int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) {
414
497
 
415
498
  /* Free previous entity */
416
499
  if (*nbufs > 0)
417
- free(dents[*nbufs - 1]);
500
+ uv__free(dents[*nbufs - 1]);
418
501
 
419
502
  /* End was already reached */
420
503
  if (*nbufs == (unsigned int) req->result) {
421
- free(dents);
504
+ uv__free(dents);
422
505
  req->ptr = NULL;
423
506
  return UV_EOF;
424
507
  }
@@ -492,12 +575,12 @@ uv_loop_t* uv_default_loop(void) {
492
575
  uv_loop_t* uv_loop_new(void) {
493
576
  uv_loop_t* loop;
494
577
 
495
- loop = malloc(sizeof(*loop));
578
+ loop = uv__malloc(sizeof(*loop));
496
579
  if (loop == NULL)
497
580
  return NULL;
498
581
 
499
582
  if (uv_loop_init(loop)) {
500
- free(loop);
583
+ uv__free(loop);
501
584
  return NULL;
502
585
  }
503
586
 
@@ -540,5 +623,5 @@ void uv_loop_delete(uv_loop_t* loop) {
540
623
  (void) err; /* Squelch compiler warnings. */
541
624
  assert(err == 0);
542
625
  if (loop != default_loop)
543
- free(loop);
626
+ uv__free(loop);
544
627
  }
@@ -41,6 +41,10 @@
41
41
  #include "tree.h"
42
42
  #include "queue.h"
43
43
 
44
+ #if !defined(snprintf) && defined(_MSC_VER) && _MSC_VER < 1900
45
+ extern int snprintf(char*, size_t, const char*, ...);
46
+ #endif
47
+
44
48
  #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
45
49
 
46
50
  #define container_of(ptr, type, member) \
@@ -196,7 +200,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req);
196
200
  (((h)->flags & UV__HANDLE_REF) != 0)
197
201
 
198
202
  #if defined(_WIN32)
199
- # define uv__handle_platform_init(h)
203
+ # define uv__handle_platform_init(h) ((h)->u.fd = -1)
200
204
  #else
201
205
  # define uv__handle_platform_init(h) ((h)->next_closing = NULL)
202
206
  #endif
@@ -211,4 +215,13 @@ void uv__fs_scandir_cleanup(uv_fs_t* req);
211
215
  } \
212
216
  while (0)
213
217
 
218
+
219
+ /* Allocator prototypes */
220
+ void *uv__calloc(size_t count, size_t size);
221
+ char *uv__strdup(const char* s);
222
+ char *uv__strndup(const char* s, size_t n);
223
+ void* uv__malloc(size_t size);
224
+ void uv__free(void* ptr);
225
+ void* uv__realloc(void* ptr, size_t size);
226
+
214
227
  #endif /* UV_COMMON_H_ */