blob: fedaea07e9013cfd8d287cbc6a39e13d3795b9dc [file] [log] [blame]
From f7b4492d37b35a64a3a6c5bbbdb375494095b6ff Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:09:43 -0400
Subject: [PATCH 2/9] Fix warnings
---
include/uv/win.h | 5 +++
src/idna.c | 2 +-
src/inet.c | 4 ++
src/threadpool.c | 4 ++
src/unix/core.c | 12 ++++-
src/unix/darwin.c | 106 +++++++++++++++++++++++---------------------
src/unix/internal.h | 4 +-
src/unix/thread.c | 6 ---
src/uv-common.c | 8 ++++
src/win/fs-event.c | 2 +
src/win/fs.c | 2 +
src/win/pipe.c | 2 +
src/win/process.c | 2 +
src/win/tty.c | 2 +
14 files changed, 99 insertions(+), 62 deletions(-)
diff --git a/include/uv/win.h b/include/uv/win.h
index 56a4cf11..10d5e8f1 100644
--- a/include/uv/win.h
+++ b/include/uv/win.h
@@ -201,11 +201,16 @@ typedef int (WSAAPI* LPFN_WSARECVFROM)
LPWSAOVERLAPPED overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
+#pragma warning(push)
+#pragma warning(disable : 28251)
+
#ifndef _NTDEF_
typedef LONG NTSTATUS;
typedef NTSTATUS *PNTSTATUS;
#endif
+#pragma warning(pop)
+
#ifndef RTL_CONDITION_VARIABLE_INIT
typedef PVOID CONDITION_VARIABLE, *PCONDITION_VARIABLE;
#endif
diff --git a/src/idna.c b/src/idna.c
index 93d982ca..36a39a08 100644
--- a/src/idna.c
+++ b/src/idna.c
@@ -106,7 +106,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
char** d, char* de) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789";
const char* ss;
- unsigned c;
+ unsigned c = 0;
unsigned h;
unsigned k;
unsigned n;
diff --git a/src/inet.c b/src/inet.c
index ca8b6ac8..1b190255 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -27,6 +27,10 @@
#include "uv.h"
#include "uv-common.h"
+#ifdef _WIN32
+#pragma warning(disable : 6001)
+#endif
+
#define UV__INET_ADDRSTRLEN 16
#define UV__INET6_ADDRSTRLEN 46
diff --git a/src/threadpool.c b/src/threadpool.c
index 1241ace1..718972c3 100644
--- a/src/threadpool.c
+++ b/src/threadpool.c
@@ -27,6 +27,10 @@
#include <stdlib.h>
+#ifdef _WIN32
+#pragma warning(disable: 6001 6011)
+#endif
+
#define MAX_THREADPOOL_SIZE 1024
static uv_once_t once = UV_ONCE_INIT;
diff --git a/src/unix/core.c b/src/unix/core.c
index 6353b0e3..223c5513 100644
--- a/src/unix/core.c
+++ b/src/unix/core.c
@@ -544,6 +544,16 @@ int uv__accept(int sockfd) {
return peerfd;
}
+#if defined(__APPLE__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
+#if defined(__LP64__)
+ extern "C" int close$NOCANCEL(int);
+#else
+ extern "C" int close$NOCANCEL$UNIX2003(int);
+#endif
+#pragma GCC diagnostic pop
+#endif
/* close() on macos has the "interesting" quirk that it fails with EINTR
* without closing the file descriptor when a thread is in the cancel state.
@@ -558,10 +568,8 @@ int uv__close_nocancel(int fd) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
#if defined(__LP64__) || TARGET_OS_IPHONE
- extern int close$NOCANCEL(int);
return close$NOCANCEL(fd);
#else
- extern int close$NOCANCEL$UNIX2003(int);
return close$NOCANCEL$UNIX2003(fd);
#endif
#pragma GCC diagnostic pop
diff --git a/src/unix/darwin.c b/src/unix/darwin.c
index 5fbf7342..eeb35720 100644
--- a/src/unix/darwin.c
+++ b/src/unix/darwin.c
@@ -253,64 +253,68 @@ static int uv__get_cpu_speed(uint64_t* speed) {
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
- kr = pIOMasterPort(MACH_PORT_NULL, &mach_port);
- assert(kr == KERN_SUCCESS);
- CFMutableDictionaryRef classes_to_match
- = pIOServiceMatching("IOPlatformDevice");
- kr = pIOServiceGetMatchingServices(mach_port, classes_to_match, &it);
- assert(kr == KERN_SUCCESS);
- service = pIOIteratorNext(it);
-
- CFStringRef device_type_str = S("device_type");
- CFStringRef clock_frequency_str = S("clock-frequency");
-
- while (service != 0) {
- CFDataRef data;
- data = pIORegistryEntryCreateCFProperty(service,
- device_type_str,
- NULL,
- 0);
- if (data) {
- const UInt8* raw = pCFDataGetBytePtr(data);
- if (strncmp((char*)raw, "cpu", 3) == 0 ||
- strncmp((char*)raw, "processor", 9) == 0) {
- CFDataRef freq_ref;
- freq_ref = pIORegistryEntryCreateCFProperty(service,
- clock_frequency_str,
- NULL,
- 0);
- if (freq_ref) {
- const UInt8* freq_ref_ptr = pCFDataGetBytePtr(freq_ref);
- CFIndex len = pCFDataGetLength(freq_ref);
- if (len == 8)
- memcpy(speed, freq_ref_ptr, 8);
- else if (len == 4) {
- uint32_t v;
- memcpy(&v, freq_ref_ptr, 4);
- *speed = v;
- } else {
- *speed = 0;
- }
+ // Braces ensure goto doesn't jump into device_type_str's and
+ // clock_frequency_str's lifetimes after their initialization
+ {
+ kr = pIOMasterPort(MACH_PORT_NULL, &mach_port);
+ assert(kr == KERN_SUCCESS);
+ CFMutableDictionaryRef classes_to_match
+ = pIOServiceMatching("IOPlatformDevice");
+ kr = pIOServiceGetMatchingServices(mach_port, classes_to_match, &it);
+ assert(kr == KERN_SUCCESS);
+ service = pIOIteratorNext(it);
- pCFRelease(freq_ref);
- pCFRelease(data);
- break;
+ CFStringRef device_type_str = S("device_type");
+ CFStringRef clock_frequency_str = S("clock-frequency");
+
+ while (service != 0) {
+ CFDataRef data;
+ data = pIORegistryEntryCreateCFProperty(service,
+ device_type_str,
+ NULL,
+ 0);
+ if (data) {
+ const UInt8* raw = pCFDataGetBytePtr(data);
+ if (strncmp((char*)raw, "cpu", 3) == 0 ||
+ strncmp((char*)raw, "processor", 9) == 0) {
+ CFDataRef freq_ref;
+ freq_ref = pIORegistryEntryCreateCFProperty(service,
+ clock_frequency_str,
+ NULL,
+ 0);
+ if (freq_ref) {
+ const UInt8* freq_ref_ptr = pCFDataGetBytePtr(freq_ref);
+ CFIndex len = pCFDataGetLength(freq_ref);
+ if (len == 8)
+ memcpy(speed, freq_ref_ptr, 8);
+ else if (len == 4) {
+ uint32_t v;
+ memcpy(&v, freq_ref_ptr, 4);
+ *speed = v;
+ } else {
+ *speed = 0;
+ }
+
+ pCFRelease(freq_ref);
+ pCFRelease(data);
+ break;
+ }
}
+ pCFRelease(data);
}
- pCFRelease(data);
- }
- service = pIOIteratorNext(it);
- }
+ service = pIOIteratorNext(it);
+ }
- pIOObjectRelease(it);
+ pIOObjectRelease(it);
- err = 0;
+ err = 0;
- if (device_type_str != NULL)
- pCFRelease(device_type_str);
- if (clock_frequency_str != NULL)
- pCFRelease(clock_frequency_str);
+ if (device_type_str != NULL)
+ pCFRelease(device_type_str);
+ if (clock_frequency_str != NULL)
+ pCFRelease(clock_frequency_str);
+ }
out:
if (core_foundation_handle != NULL)
diff --git a/src/unix/internal.h b/src/unix/internal.h
index cee35c21..f9d1666d 100644
--- a/src/unix/internal.h
+++ b/src/unix/internal.h
@@ -312,8 +312,8 @@ UV_UNUSED(static void uv__update_time(uv_loop_t* loop)) {
loop->time = uv__hrtime(UV_CLOCK_FAST) / 1000000;
}
-UV_UNUSED(static char* uv__basename_r(const char* path)) {
- char* s;
+UV_UNUSED(static const char* uv__basename_r(const char* path)) {
+ const char* s;
s = strrchr(path, '/');
if (s == NULL)
diff --git a/src/unix/thread.c b/src/unix/thread.c
index 759cd0c2..64726bd6 100644
--- a/src/unix/thread.c
+++ b/src/unix/thread.c
@@ -244,12 +244,6 @@ int uv_thread_create_ex(uv_thread_t* tid,
size_t stack_size;
size_t min_stack_size;
- /* Used to squelch a -Wcast-function-type warning. */
- union {
- void (*in)(void*);
- void* (*out)(void*);
- } f;
-
stack_size =
params->flags & UV_THREAD_HAS_STACK_SIZE ? params->stack_size : 0;
diff --git a/src/uv-common.c b/src/uv-common.c
index dfb606e3..49026c03 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -758,6 +758,10 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
}
}
+#ifdef __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wvarargs"
+#endif
int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
va_list ap;
@@ -771,6 +775,10 @@ int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
return err;
}
+#ifdef __clang__
+# pragma clang diagnostic pop
+#endif
+
static uv_loop_t default_loop_struct;
static uv_loop_t* default_loop_ptr;
diff --git a/src/win/fs-event.c b/src/win/fs-event.c
index 15046731..3244a4e4 100644
--- a/src/win/fs-event.c
+++ b/src/win/fs-event.c
@@ -19,6 +19,8 @@
* IN THE SOFTWARE.
*/
+#define _CRT_NONSTDC_NO_WARNINGS
+
#include <assert.h>
#include <errno.h>
#include <stdio.h>
diff --git a/src/win/fs.c b/src/win/fs.c
index 8374012f..f71b3c04 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -19,6 +19,8 @@
* IN THE SOFTWARE.
*/
+#define _CRT_NONSTDC_NO_WARNINGS
+
#include <assert.h>
#include <stdlib.h>
#include <direct.h>
diff --git a/src/win/pipe.c b/src/win/pipe.c
index cd77061a..f413a72d 100644
--- a/src/win/pipe.c
+++ b/src/win/pipe.c
@@ -19,6 +19,8 @@
* IN THE SOFTWARE.
*/
+#define _CRT_NONSTDC_NO_WARNINGS
+
#include <assert.h>
#include <io.h>
#include <stdio.h>
diff --git a/src/win/process.c b/src/win/process.c
index e857db3e..a49016f6 100644
--- a/src/win/process.c
+++ b/src/win/process.c
@@ -19,6 +19,8 @@
* IN THE SOFTWARE.
*/
+#define _CRT_NONSTDC_NO_WARNINGS
+
#include <assert.h>
#include <io.h>
#include <stdio.h>
diff --git a/src/win/tty.c b/src/win/tty.c
index 267ca645..d7522668 100644
--- a/src/win/tty.c
+++ b/src/win/tty.c
@@ -19,6 +19,8 @@
* IN THE SOFTWARE.
*/
+#define _CRT_NONSTDC_NO_WARNINGS
+
#include <assert.h>
#include <io.h>
#include <string.h>