[MacPorts] #55415: cmake @3.10.0 does not build on PPC Tiger, Mac OS X 10.4.11, due to various issues building libuv
MacPorts
noreply at macports.org
Sat Dec 2 21:10:00 UTC 2017
#55415: cmake @3.10.0 does not build on PPC Tiger, Mac OS X 10.4.11, due to various
issues building libuv
------------------------+-----------------------
Reporter: ballapete | Owner: michaelld
Type: defect | Status: assigned
Priority: Normal | Milestone:
Component: ports | Version: 2.4.2
Resolution: | Keywords: tiger
Port: cmake |
------------------------+-----------------------
Comment (by ballapete):
Replying to [comment:11 kencu]:
> That's a good start.
>
> One thing to ponder is how did cmlibuv build on Tiger in cmake 3.9.6,
and could we use that to figure out how to make it build in 3.10.0; or
maybe just steal the whole cmlibuv from 3.9.6 and use that in 3.10.0 on
Tiger?
>
> Maybe we could just diff the two folders (cmlibuv) and see what has
changed to break it in 3.10.0.
These are the changes (cmake-3.10.0/Utilities/cmlibuv/src/unix/cmake-
bootstrap.c ist a new file, possible related to the macro
CMAKE_BOOTSTRAP):
{{{
-rw-r--r-- kitware/staff 16305 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/include/uv-unix.h
-rw-r--r-- kitware/staff 16008 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/include/uv-unix.h
@@ -44,9 +44,7 @@
#include "uv-threadpool.h"
-#ifdef CMAKE_BOOTSTRAP
-# include "uv-posix.h"
-#elif defined(__linux__)
+#if defined(__linux__)
# include "uv-linux.h"
#elif defined (__MVS__)
# include "uv-os390.h"
@@ -126,17 +124,6 @@
typedef int uv_os_sock_t;
typedef int uv_os_fd_t;
-#ifdef CMAKE_BOOTSTRAP
-#define UV_ONCE_INIT 0
-typedef int uv_once_t;
-typedef int uv_thread_t;
-typedef int uv_mutex_t;
-typedef int uv_rwlock_t;
-typedef int uv_sem_t;
-typedef int uv_cond_t;
-typedef int uv_key_t;
-typedef int uv_barrier_t;
-#else
#define UV_ONCE_INIT PTHREAD_ONCE_INIT
typedef pthread_once_t uv_once_t;
@@ -147,7 +134,6 @@
typedef pthread_cond_t uv_cond_t;
typedef pthread_key_t uv_key_t;
typedef pthread_barrier_t uv_barrier_t;
-#endif
/* Platform-specific definitions for uv_spawn support. */
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 2570 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/unix/cmake-bootstrap.c
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 35961 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/unix/fs.c
-rw-r--r-- kitware/staff 35931 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/src/unix/fs.c
@@ -244,7 +244,7 @@
#endif
}
-#if defined(__sun) && (_XOPEN_SOURCE < 600 || defined(CMAKE_BOOTSTRAP))
+#if defined(__sun) && _XOPEN_SOURCE < 600
static char* uv__mkdtemp(char *template)
{
if (!mktemp(template) || mkdir(template, 0700))
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 12011 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/unix/internal.h
-rw-r--r-- kitware/staff 11534 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/src/unix/internal.h
@@ -59,17 +59,7 @@
# include <AvailabilityMacros.h>
#endif
-#if defined(CMAKE_BOOTSTRAP)
-# undef pthread_atfork
-# define pthread_atfork(prepare, parent, child) \
- uv__pthread_atfork(prepare, parent, child)
-int uv__pthread_atfork(void (*prepare)(void), void (*parent)(void),
- void (*child)(void));
-# undef pthread_sigmask
-# define pthread_sigmask(how, set, oldset) \
- uv__pthread_sigmask(how, set, oldset)
-int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
-#elif defined(__ANDROID__)
+#if defined(__ANDROID__)
int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
# ifdef pthread_sigmask
# undef pthread_sigmask
@@ -271,7 +261,7 @@
int uv__getpwuid_r(uv_passwd_t* pwd);
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
int uv___stream_fd(const uv_stream_t* handle);
#define uv__stream_fd(handle) (uv___stream_fd((const uv_stream_t*)
(handle)))
#else
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 7822 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/src/unix/pipe.c
-rw-r--r-- kitware/staff 7851 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/unix/pipe.c
@@ -136,7 +136,7 @@
if (err)
return err;
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
err = uv__stream_try_select((uv_stream_t*) handle, &fd);
if (err)
return err;
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 2004 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/unix/posix-hrtime.c
-rw-r--r-- kitware/staff 1433 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/src/unix/posix-hrtime.c
@@ -22,29 +22,6 @@
#include "uv.h"
#include "internal.h"
-#if defined(__APPLE__)
-/* Special case for CMake bootstrap: no clock_gettime on macOS < 10.12 */
-
-#ifndef CMAKE_BOOTSTRAP
-#error "This code path meant only for use during CMake bootstrap."
-#endif
-
-#include <mach/mach.h>
-#include <mach/mach_time.h>
-
-uint64_t uv__hrtime(uv_clocktype_t type) {
- static mach_timebase_info_data_t info;
-
- if ((ACCESS_ONCE(uint32_t, info.numer) == 0 ||
- ACCESS_ONCE(uint32_t, info.denom) == 0) &&
- mach_timebase_info(&info) != KERN_SUCCESS)
- abort();
-
- return mach_absolute_time() * info.numer / info.denom;
-}
-
-#else
-
#include <stdint.h>
#include <time.h>
@@ -56,5 +33,3 @@
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}
-
-#endif
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 43748 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/src/unix/stream.c
-rw-r--r-- kitware/staff 43893 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/unix/stream.c
@@ -98,7 +98,7 @@
loop->emfile_fd = err;
}
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
stream->select = NULL;
#endif /* defined(__APPLE_) */
@@ -107,7 +107,7 @@
static void uv__stream_osx_interrupt_select(uv_stream_t* stream) {
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
/* Notify select() thread about state change */
uv__stream_select_t* s;
int r;
@@ -131,7 +131,7 @@
}
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
static void uv__stream_osx_select(void* arg) {
uv_stream_t* stream;
uv__stream_select_t* s;
@@ -1598,7 +1598,7 @@
}
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
int uv___stream_fd(const uv_stream_t* handle) {
const uv__stream_select_t* s;
@@ -1619,7 +1619,7 @@
unsigned int i;
uv__stream_queued_fds_t* queued_fds;
-#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
+#if defined(__APPLE__)
/* Terminate select loop first */
if (handle->select != NULL) {
uv__stream_select_t* s;
-----------------------------------------------------------------------------
-rw-r--r-- kitware/staff 15117 Nov 10 13:28 2017
cmake-3.9.6/Utilities/cmlibuv/src/uv-common.c
-rw-r--r-- kitware/staff 15173 Nov 20 16:19 2017
cmake-3.10.0/Utilities/cmlibuv/src/uv-common.c
@@ -19,236 +19,646 @@
* IN THE SOFTWARE.
*/
-/*
- * This file is private to libuv. It provides common functionality to
both
- * Windows and Unix backends.
- */
-
-#ifndef UV_COMMON_H_
-#define UV_COMMON_H_
+#include "uv.h"
+#include "uv-common.h"
#include <assert.h>
+#include <errno.h>
#include <stdarg.h>
-#include <stddef.h>
+#include <stddef.h> /* NULL */
+#include <stdio.h>
+#include <stdlib.h> /* malloc */
+#include <string.h> /* memset */
-#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "stdint-msvc2008.h"
+#if defined(_WIN32)
+# include <malloc.h> /* malloc */
#else
-# include <stdint.h>
+# include <net/if.h> /* if_nametoindex */
#endif
-#include "uv.h"
-#include "tree.h"
-#include "queue.h"
-#if !defined(snprintf) && defined(_MSC_VER) && _MSC_VER < 1900
-extern int snprintf(char*, size_t, const char*, ...);
+typedef struct {
+ uv_malloc_func local_malloc;
+ uv_realloc_func local_realloc;
+ uv_calloc_func local_calloc;
+ uv_free_func local_free;
+} uv__allocator_t;
+
+static uv__allocator_t uv__allocator = {
+ malloc,
+ realloc,
+ calloc,
+ free,
+};
+
+char* uv__strdup(const char* s) {
+ size_t len = strlen(s) + 1;
+ char* m = uv__malloc(len);
+ if (m == NULL)
+ return NULL;
+ return memcpy(m, s, len);
+}
+
+char* uv__strndup(const char* s, size_t n) {
+ char* m;
+ size_t len = strlen(s);
+ if (n < len)
+ len = n;
+ m = uv__malloc(len + 1);
+ if (m == NULL)
+ return NULL;
+ m[len] = '\0';
+ return memcpy(m, s, len);
+}
+
+void* uv__malloc(size_t size) {
+ return uv__allocator.local_malloc(size);
+}
+
+void uv__free(void* ptr) {
+ int saved_errno;
+
+ /* Libuv expects that free() does not clobber errno. The system
allocator
+ * honors that assumption but custom allocators may not be so careful.
+ */
+ saved_errno = errno;
+ uv__allocator.local_free(ptr);
+ errno = saved_errno;
+}
+
+void* uv__calloc(size_t count, size_t size) {
+ return uv__allocator.local_calloc(count, size);
+}
+
+void* uv__realloc(void* ptr, size_t size) {
+ return uv__allocator.local_realloc(ptr, size);
+}
+
+int uv_replace_allocator(uv_malloc_func malloc_func,
+ uv_realloc_func realloc_func,
+ uv_calloc_func calloc_func,
+ uv_free_func free_func) {
+ if (malloc_func == NULL || realloc_func == NULL ||
+ calloc_func == NULL || free_func == NULL) {
+ return UV_EINVAL;
+ }
+
+ uv__allocator.local_malloc = malloc_func;
+ uv__allocator.local_realloc = realloc_func;
+ uv__allocator.local_calloc = calloc_func;
+ uv__allocator.local_free = free_func;
+
+ return 0;
+}
+
+#define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t);
+
+size_t uv_handle_size(uv_handle_type type) {
+ switch (type) {
+ UV_HANDLE_TYPE_MAP(XX)
+ default:
+ return -1;
+ }
+}
+
+size_t uv_req_size(uv_req_type type) {
+ switch(type) {
+ UV_REQ_TYPE_MAP(XX)
+ default:
+ return -1;
+ }
+}
+
+#undef XX
+
+
+size_t uv_loop_size(void) {
+ return sizeof(uv_loop_t);
+}
+
+
+uv_buf_t uv_buf_init(char* base, unsigned int len) {
+ uv_buf_t buf;
+ buf.base = base;
+ buf.len = len;
+ return buf;
+}
+
+
+static const char* uv__unknown_err_code(int err) {
+ char buf[32];
+ char* copy;
+
+ snprintf(buf, sizeof(buf), "Unknown system error %d", err);
+ copy = uv__strdup(buf);
+
+ return copy != NULL ? copy : "Unknown system error";
+}
+
+
+#define UV_ERR_NAME_GEN(name, _) case UV_ ## name: return #name;
+const char* uv_err_name(int err) {
+ switch (err) {
+ UV_ERRNO_MAP(UV_ERR_NAME_GEN)
+ }
+ return uv__unknown_err_code(err);
+}
+#undef UV_ERR_NAME_GEN
+
+
+#define UV_STRERROR_GEN(name, msg) case UV_ ## name: return msg;
+const char* uv_strerror(int err) {
+ switch (err) {
+ UV_ERRNO_MAP(UV_STRERROR_GEN)
+ }
+ return uv__unknown_err_code(err);
+}
+#undef UV_STRERROR_GEN
+
+
+int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr) {
+ memset(addr, 0, sizeof(*addr));
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons(port);
+ return uv_inet_pton(AF_INET, ip, &(addr->sin_addr.s_addr));
+}
+
+
+int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr) {
+ char address_part[40];
+ size_t address_part_size;
+ const char* zone_index;
+
+ memset(addr, 0, sizeof(*addr));
+ addr->sin6_family = AF_INET6;
+ addr->sin6_port = htons(port);
+
+ zone_index = strchr(ip, '%');
+ if (zone_index != NULL) {
+ address_part_size = zone_index - ip;
+ if (address_part_size >= sizeof(address_part))
+ address_part_size = sizeof(address_part) - 1;
+
+ memcpy(address_part, ip, address_part_size);
+ address_part[address_part_size] = '\0';
+ ip = address_part;
+
+ zone_index++; /* skip '%' */
+ /* NOTE: unknown interface (id=0) is silently ignored */
+#ifdef _WIN32
+ addr->sin6_scope_id = atoi(zone_index);
+#else
+ addr->sin6_scope_id = if_nametoindex(zone_index);
#endif
+ }
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+ return uv_inet_pton(AF_INET6, ip, &addr->sin6_addr);
+}
-#define container_of(ptr, type, member) \
- ((type *) ((char *) (ptr) - offsetof(type, member)))
-#define STATIC_ASSERT(expr)
\
- void uv__static_assert(int static_assert_failed[1 - 2 * !(expr)])
+int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size) {
+ return uv_inet_ntop(AF_INET, &src->sin_addr, dst, size);
+}
-#ifndef _WIN32
-enum {
- UV__SIGNAL_ONE_SHOT = 0x80000, /* On signal reception remove
sighandler */
- UV__HANDLE_INTERNAL = 0x8000,
- UV__HANDLE_ACTIVE = 0x4000,
- UV__HANDLE_REF = 0x2000,
- UV__HANDLE_CLOSING = 0 /* no-op on unix */
-};
-#else
-# define UV__SIGNAL_ONE_SHOT_DISPATCHED 0x200
-# define UV__SIGNAL_ONE_SHOT 0x100
-# define UV__HANDLE_INTERNAL 0x80
-# define UV__HANDLE_ACTIVE 0x40
-# define UV__HANDLE_REF 0x20
-# define UV__HANDLE_CLOSING 0x01
-#endif
-int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list
ap);
+int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size) {
+ return uv_inet_ntop(AF_INET6, &src->sin6_addr, dst, size);
+}
+
+
+int uv_tcp_bind(uv_tcp_t* handle,
+ const struct sockaddr* addr,
+ unsigned int flags) {
+ unsigned int addrlen;
+
+ if (handle->type != UV_TCP)
+ return UV_EINVAL;
-void uv__loop_close(uv_loop_t* loop);
+ if (addr->sa_family == AF_INET)
+ addrlen = sizeof(struct sockaddr_in);
+ else if (addr->sa_family == AF_INET6)
+ addrlen = sizeof(struct sockaddr_in6);
+ else
+ return UV_EINVAL;
-int uv__tcp_bind(uv_tcp_t* tcp,
- const struct sockaddr* addr,
- unsigned int addrlen,
- unsigned int flags);
+ return uv__tcp_bind(handle, addr, addrlen, flags);
+}
-int uv__tcp_connect(uv_connect_t* req,
+
+int uv_udp_bind(uv_udp_t* handle,
+ const struct sockaddr* addr,
+ unsigned int flags) {
+ unsigned int addrlen;
+
+ if (handle->type != UV_UDP)
+ return UV_EINVAL;
+
+ if (addr->sa_family == AF_INET)
+ addrlen = sizeof(struct sockaddr_in);
+ else if (addr->sa_family == AF_INET6)
+ addrlen = sizeof(struct sockaddr_in6);
+ else
+ return UV_EINVAL;
+
+ return uv__udp_bind(handle, addr, addrlen, flags);
+}
+
+
+int uv_tcp_connect(uv_connect_t* req,
uv_tcp_t* handle,
const struct sockaddr* addr,
- unsigned int addrlen,
- uv_connect_cb cb);
+ uv_connect_cb cb) {
+ unsigned int addrlen;
-int uv__udp_bind(uv_udp_t* handle,
- const struct sockaddr* addr,
- unsigned int addrlen,
- unsigned int flags);
-
-int uv__udp_send(uv_udp_send_t* req,
- uv_udp_t* handle,
- const uv_buf_t bufs[],
- unsigned int nbufs,
- const struct sockaddr* addr,
- unsigned int addrlen,
- uv_udp_send_cb send_cb);
-
-int uv__udp_try_send(uv_udp_t* handle,
- const uv_buf_t bufs[],
- unsigned int nbufs,
- const struct sockaddr* addr,
- unsigned int addrlen);
-
-int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloccb,
- uv_udp_recv_cb recv_cb);
-
-int uv__udp_recv_stop(uv_udp_t* handle);
-
-void uv__fs_poll_close(uv_fs_poll_t* handle);
-
-int uv__getaddrinfo_translate_error(int sys_err); /* EAI_* error. */
-
-void uv__work_submit(uv_loop_t* loop,
- struct uv__work *w,
- void (*work)(struct uv__work *w),
- void (*done)(struct uv__work *w, int status));
-
-void uv__work_done(uv_async_t* handle);
-
-size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs);
-
-int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value);
-
-void uv__fs_scandir_cleanup(uv_fs_t* req);
-
-#define uv__has_active_reqs(loop)
\
- (QUEUE_EMPTY(&(loop)->active_reqs) == 0)
-
-#define uv__req_register(loop, req)
\
- do {
\
- QUEUE_INSERT_TAIL(&(loop)->active_reqs, &(req)->active_queue);
\
- }
\
- while (0)
-
-#define uv__req_unregister(loop, req)
\
- do {
\
- assert(uv__has_active_reqs(loop));
\
- QUEUE_REMOVE(&(req)->active_queue);
\
- }
\
- while (0)
-
-#define uv__has_active_handles(loop)
\
- ((loop)->active_handles > 0)
-
-#define uv__active_handle_add(h)
\
- do {
\
- (h)->loop->active_handles++;
\
- }
\
- while (0)
-
-#define uv__active_handle_rm(h)
\
- do {
\
- (h)->loop->active_handles--;
\
- }
\
- while (0)
-
-#define uv__is_active(h)
\
- (((h)->flags & UV__HANDLE_ACTIVE) != 0)
-
-#define uv__is_closing(h)
\
- (((h)->flags & (UV_CLOSING | UV_CLOSED)) != 0)
-
-#define uv__handle_start(h)
\
- do {
\
- assert(((h)->flags & UV__HANDLE_CLOSING) == 0);
\
- if (((h)->flags & UV__HANDLE_ACTIVE) != 0) break;
\
- (h)->flags |= UV__HANDLE_ACTIVE;
\
- if (((h)->flags & UV__HANDLE_REF) != 0) uv__active_handle_add(h);
\
- }
\
- while (0)
-
-#define uv__handle_stop(h)
\
- do {
\
- assert(((h)->flags & UV__HANDLE_CLOSING) == 0);
\
- if (((h)->flags & UV__HANDLE_ACTIVE) == 0) break;
\
- (h)->flags &= ~UV__HANDLE_ACTIVE;
\
- if (((h)->flags & UV__HANDLE_REF) != 0) uv__active_handle_rm(h);
\
- }
\
- while (0)
-
-#define uv__handle_ref(h)
\
- do {
\
- if (((h)->flags & UV__HANDLE_REF) != 0) break;
\
- (h)->flags |= UV__HANDLE_REF;
\
- if (((h)->flags & UV__HANDLE_CLOSING) != 0) break;
\
- if (((h)->flags & UV__HANDLE_ACTIVE) != 0) uv__active_handle_add(h);
\
- }
\
- while (0)
-
-#define uv__handle_unref(h)
\
- do {
\
- if (((h)->flags & UV__HANDLE_REF) == 0) break;
\
- (h)->flags &= ~UV__HANDLE_REF;
\
- if (((h)->flags & UV__HANDLE_CLOSING) != 0) break;
\
- if (((h)->flags & UV__HANDLE_ACTIVE) != 0) uv__active_handle_rm(h);
\
- }
\
- while (0)
+ if (handle->type != UV_TCP)
+ return UV_EINVAL;
-#define uv__has_ref(h)
\
- (((h)->flags & UV__HANDLE_REF) != 0)
+ if (addr->sa_family == AF_INET)
+ addrlen = sizeof(struct sockaddr_in);
+ else if (addr->sa_family == AF_INET6)
+ addrlen = sizeof(struct sockaddr_in6);
+ else
+ return UV_EINVAL;
-#if defined(_WIN32)
-# define uv__handle_platform_init(h) ((h)->u.fd = -1)
+ return uv__tcp_connect(req, handle, addr, addrlen, cb);
+}
+
+
+int uv_udp_send(uv_udp_send_t* req,
+ uv_udp_t* handle,
+ const uv_buf_t bufs[],
+ unsigned int nbufs,
+ const struct sockaddr* addr,
+ uv_udp_send_cb send_cb) {
+ unsigned int addrlen;
+
+ if (handle->type != UV_UDP)
+ return UV_EINVAL;
+
+ if (addr->sa_family == AF_INET)
+ addrlen = sizeof(struct sockaddr_in);
+ else if (addr->sa_family == AF_INET6)
+ addrlen = sizeof(struct sockaddr_in6);
+ else
+ return UV_EINVAL;
+
+ return uv__udp_send(req, handle, bufs, nbufs, addr, addrlen, send_cb);
+}
+
+
+int uv_udp_try_send(uv_udp_t* handle,
+ const uv_buf_t bufs[],
+ unsigned int nbufs,
+ const struct sockaddr* addr) {
+ unsigned int addrlen;
+
+ if (handle->type != UV_UDP)
+ return UV_EINVAL;
+
+ if (addr->sa_family == AF_INET)
+ addrlen = sizeof(struct sockaddr_in);
+ else if (addr->sa_family == AF_INET6)
+ addrlen = sizeof(struct sockaddr_in6);
+ else
+ return UV_EINVAL;
+
+ return uv__udp_try_send(handle, bufs, nbufs, addr, addrlen);
+}
+
+
+int uv_udp_recv_start(uv_udp_t* handle,
+ uv_alloc_cb alloc_cb,
+ uv_udp_recv_cb recv_cb) {
+ if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL)
+ return UV_EINVAL;
+ else
+ return uv__udp_recv_start(handle, alloc_cb, recv_cb);
+}
+
+
+int uv_udp_recv_stop(uv_udp_t* handle) {
+ if (handle->type != UV_UDP)
+ return UV_EINVAL;
+ else
+ return uv__udp_recv_stop(handle);
+}
+
+
+void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
+ QUEUE queue;
+ QUEUE* q;
+ uv_handle_t* h;
+
+ QUEUE_MOVE(&loop->handle_queue, &queue);
+ while (!QUEUE_EMPTY(&queue)) {
+ q = QUEUE_HEAD(&queue);
+ h = QUEUE_DATA(q, uv_handle_t, handle_queue);
+
+ QUEUE_REMOVE(q);
+ QUEUE_INSERT_TAIL(&loop->handle_queue, q);
+
+ if (h->flags & UV__HANDLE_INTERNAL) continue;
+ walk_cb(h, arg);
+ }
+}
+
+
+static void uv__print_handles(uv_loop_t* loop, int only_active, FILE*
stream) {
+ const char* type;
+ QUEUE* q;
+ uv_handle_t* h;
+
+ if (loop == NULL)
+ loop = uv_default_loop();
+
+ QUEUE_FOREACH(q, &loop->handle_queue) {
+ h = QUEUE_DATA(q, uv_handle_t, handle_queue);
+
+ if (only_active && !uv__is_active(h))
+ continue;
+
+ switch (h->type) {
+#define X(uc, lc) case UV_##uc: type = #lc; break;
+ UV_HANDLE_TYPE_MAP(X)
+#undef X
+ default: type = "<unknown>";
+ }
+
+ fprintf(stream,
+ "[%c%c%c] %-8s %p\n",
+ "R-"[!(h->flags & UV__HANDLE_REF)],
+ "A-"[!(h->flags & UV__HANDLE_ACTIVE)],
+ "I-"[!(h->flags & UV__HANDLE_INTERNAL)],
+ type,
+ (void*)h);
+ }
+}
+
+
+void uv_print_all_handles(uv_loop_t* loop, FILE* stream) {
+ uv__print_handles(loop, 0, stream);
+}
+
+
+void uv_print_active_handles(uv_loop_t* loop, FILE* stream) {
+ uv__print_handles(loop, 1, stream);
+}
+
+
+void uv_ref(uv_handle_t* handle) {
+ uv__handle_ref(handle);
+}
+
+
+void uv_unref(uv_handle_t* handle) {
+ uv__handle_unref(handle);
+}
+
+
+int uv_has_ref(const uv_handle_t* handle) {
+ return uv__has_ref(handle);
+}
+
+
+void uv_stop(uv_loop_t* loop) {
+ loop->stop_flag = 1;
+}
+
+
+uint64_t uv_now(const uv_loop_t* loop) {
+ return loop->time;
+}
+
+
+
+size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs) {
+ unsigned int i;
+ size_t bytes;
+
+ bytes = 0;
+ for (i = 0; i < nbufs; i++)
+ bytes += (size_t) bufs[i].len;
+
+ return bytes;
+}
+
+int uv_recv_buffer_size(uv_handle_t* handle, int* value) {
+ return uv__socket_sockopt(handle, SO_RCVBUF, value);
+}
+
+int uv_send_buffer_size(uv_handle_t* handle, int *value) {
+ return uv__socket_sockopt(handle, SO_SNDBUF, value);
+}
+
+int uv_fs_event_getpath(uv_fs_event_t* handle, char* buffer, size_t*
size) {
+ size_t required_len;
+
+ if (!uv__is_active(handle)) {
+ *size = 0;
+ return UV_EINVAL;
+ }
+
+ required_len = strlen(handle->path);
+ if (required_len >= *size) {
+ *size = required_len + 1;
+ return UV_ENOBUFS;
+ }
+
+ memcpy(buffer, handle->path, required_len);
+ *size = required_len;
+ buffer[required_len] = '\0';
+
+ return 0;
+}
+
+/* The windows implementation does not have the same structure layout as
+ * the unix implementation (nbufs is not directly inside req but is
+ * contained in a nested union/struct) so this function locates it.
+*/
+static unsigned int* uv__get_nbufs(uv_fs_t* req) {
+#ifdef _WIN32
+ return &req->fs.info.nbufs;
#else
-# define uv__handle_platform_init(h) ((h)->next_closing = NULL)
+ return &req->nbufs;
#endif
+}
-#define uv__handle_init(loop_, h, type_)
\
- do {
\
- (h)->loop = (loop_);
\
- (h)->type = (type_);
\
- (h)->flags = UV__HANDLE_REF; /* Ref the loop when active. */
\
- QUEUE_INSERT_TAIL(&(loop_)->handle_queue, &(h)->handle_queue);
\
- uv__handle_platform_init(h);
\
- }
\
- while (0)
+/* uv_fs_scandir() uses the system allocator to allocate memory on non-
Windows
+ * systems. So, the memory should be released using free(). On Windows,
+ * uv__malloc() is used, so use uv__free() to free memory.
+*/
+#ifdef _WIN32
+# define uv__fs_scandir_free uv__free
+#else
+# define uv__fs_scandir_free free
+#endif
-/* Note: uses an open-coded version of SET_REQ_SUCCESS() because of
- * a circular dependency between src/uv-common.h and src/win/internal.h.
- */
-#if defined(_WIN32)
-# define UV_REQ_INIT(req, typ)
\
- do {
\
- (req)->type = (typ);
\
- (req)->u.io.overlapped.Internal = 0; /* SET_REQ_SUCCESS() */
\
- }
\
- while (0)
+void uv__fs_scandir_cleanup(uv_fs_t* req) {
+ uv__dirent_t** dents;
+
+ unsigned int* nbufs = uv__get_nbufs(req);
+
+ dents = req->ptr;
+ if (*nbufs > 0 && *nbufs != (unsigned int) req->result)
+ (*nbufs)--;
+ for (; *nbufs < (unsigned int) req->result; (*nbufs)++)
+ uv__fs_scandir_free(dents[*nbufs]);
+
+ uv__fs_scandir_free(req->ptr);
+ req->ptr = NULL;
+}
+
+
+int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) {
+ uv__dirent_t** dents;
+ uv__dirent_t* dent;
+ unsigned int* nbufs;
+
+ /* Check to see if req passed */
+ if (req->result < 0)
+ return req->result;
+
+ /* Ptr will be null if req was canceled or no files found */
+ if (!req->ptr)
+ return UV_EOF;
+
+ nbufs = uv__get_nbufs(req);
+ assert(nbufs);
+
+ dents = req->ptr;
+
+ /* Free previous entity */
+ if (*nbufs > 0)
+ uv__fs_scandir_free(dents[*nbufs - 1]);
+
+ /* End was already reached */
+ if (*nbufs == (unsigned int) req->result) {
+ uv__fs_scandir_free(dents);
+ req->ptr = NULL;
+ return UV_EOF;
+ }
+
+ dent = dents[(*nbufs)++];
+
+ ent->name = dent->d_name;
+#ifdef HAVE_DIRENT_TYPES
+ switch (dent->d_type) {
+ case UV__DT_DIR:
+ ent->type = UV_DIRENT_DIR;
+ break;
+ case UV__DT_FILE:
+ ent->type = UV_DIRENT_FILE;
+ break;
+ case UV__DT_LINK:
+ ent->type = UV_DIRENT_LINK;
+ break;
+ case UV__DT_FIFO:
+ ent->type = UV_DIRENT_FIFO;
+ break;
+ case UV__DT_SOCKET:
+ ent->type = UV_DIRENT_SOCKET;
+ break;
+ case UV__DT_CHAR:
+ ent->type = UV_DIRENT_CHAR;
+ break;
+ case UV__DT_BLOCK:
+ ent->type = UV_DIRENT_BLOCK;
+ break;
+ default:
+ ent->type = UV_DIRENT_UNKNOWN;
+ }
#else
-# define UV_REQ_INIT(req, typ)
\
- do {
\
- (req)->type = (typ);
\
- }
\
- while (0)
-#endif
-
-#define uv__req_init(loop, req, typ)
\
- do {
\
- UV_REQ_INIT(req, typ);
\
- uv__req_register(loop, req);
\
- }
\
- while (0)
-
-/* Allocator prototypes */
-void *uv__calloc(size_t count, size_t size);
-char *uv__strdup(const char* s);
-char *uv__strndup(const char* s, size_t n);
-void* uv__malloc(size_t size);
-void uv__free(void* ptr);
-void* uv__realloc(void* ptr, size_t size);
+ ent->type = UV_DIRENT_UNKNOWN;
+#endif
+
+ return 0;
+}
+
+
+int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
+ va_list ap;
+ int err;
+
+ va_start(ap, option);
+ /* Any platform-agnostic options should be handled here. */
+ err = uv__loop_configure(loop, option, ap);
+ va_end(ap);
+
+ return err;
+}
+
+
+static uv_loop_t default_loop_struct;
+static uv_loop_t* default_loop_ptr;
+
+
+uv_loop_t* uv_default_loop(void) {
+ if (default_loop_ptr != NULL)
+ return default_loop_ptr;
+
+ if (uv_loop_init(&default_loop_struct))
+ return NULL;
+
+ default_loop_ptr = &default_loop_struct;
+ return default_loop_ptr;
+}
+
+
+uv_loop_t* uv_loop_new(void) {
+ uv_loop_t* loop;
+
+ loop = uv__malloc(sizeof(*loop));
+ if (loop == NULL)
+ return NULL;
+
+ if (uv_loop_init(loop)) {
+ uv__free(loop);
+ return NULL;
+ }
+
+ return loop;
+}
+
+
+int uv_loop_close(uv_loop_t* loop) {
+ QUEUE* q;
+ uv_handle_t* h;
+#ifndef NDEBUG
+ void* saved_data;
+#endif
+
+ if (!QUEUE_EMPTY(&(loop)->active_reqs))
+ return UV_EBUSY;
+
+ QUEUE_FOREACH(q, &loop->handle_queue) {
+ h = QUEUE_DATA(q, uv_handle_t, handle_queue);
+ if (!(h->flags & UV__HANDLE_INTERNAL))
+ return UV_EBUSY;
+ }
+
+ uv__loop_close(loop);
+
+#ifndef NDEBUG
+ saved_data = loop->data;
+ memset(loop, -1, sizeof(*loop));
+ loop->data = saved_data;
+#endif
+ if (loop == default_loop_ptr)
+ default_loop_ptr = NULL;
+
+ return 0;
+}
+
+
+void uv_loop_delete(uv_loop_t* loop) {
+ uv_loop_t* default_loop;
+ int err;
+
+ default_loop = default_loop_ptr;
-#endif /* UV_COMMON_H_ */
+ err = uv_loop_close(loop);
+ (void) err; /* Squelch compiler warnings. */
+ assert(err == 0);
+ if (loop != default_loop)
+ uv__free(loop);
+}
}}}
--
Ticket URL: <https://trac.macports.org/ticket/55415#comment:16>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list