aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/support
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-03-19 19:21:15 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-03-19 19:21:15 +0100
commitf0863b02270f1b95d5c8b9f3f962959e4cbbdd42 (patch)
treee8a441a621d0addfa82a8fc3052080e78a012a2a /src/core/support
parentf358573091ef9c14c39ea56d9d9883410a533992 (diff)
parent43c5fe6825098b127e33159d3cf14ac937ce7db5 (diff)
Merge branch 'master' of github.com:google/grpc into freebsd
Conflicts: Makefile templates/Makefile.template
Diffstat (limited to 'src/core/support')
-rw-r--r--src/core/support/cpu_iphone.c53
-rw-r--r--src/core/support/cpu_posix.c2
-rw-r--r--src/core/support/env_win32.c15
-rw-r--r--src/core/support/file_win32.c2
-rw-r--r--src/core/support/log_win32.c8
-rw-r--r--src/core/support/string_win32.c6
-rw-r--r--src/core/support/sync_win32.c1
-rw-r--r--src/core/support/time_win32.c4
8 files changed, 76 insertions, 15 deletions
diff --git a/src/core/support/cpu_iphone.c b/src/core/support/cpu_iphone.c
new file mode 100644
index 0000000000..d412a6d7ee
--- /dev/null
+++ b/src/core/support/cpu_iphone.c
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc/support/port_platform.h>
+
+#ifdef GPR_CPU_IPHONE
+
+/* Probably 2 instead of 1, but see comment on gpr_cpu_current_cpu. */
+unsigned gpr_cpu_num_cores(void) {
+ return 1;
+}
+
+/* Most code that's using this is using it to shard across work queues. So
+ unless profiling shows it's a problem or there appears a way to detect the
+ currently running CPU core, let's have it shard the default way.
+ Note that the interface in cpu.h lets gpr_cpu_num_cores return 0, but doing
+ it makes it impossible for gpr_cpu_current_cpu to satisfy its stated range,
+ and some code might be relying on it. */
+unsigned gpr_cpu_current_cpu(void) {
+ return 0;
+}
+
+#endif /* GPR_CPU_IPHONE */
diff --git a/src/core/support/cpu_posix.c b/src/core/support/cpu_posix.c
index 5f45fb0bc3..99484e37fb 100644
--- a/src/core/support/cpu_posix.c
+++ b/src/core/support/cpu_posix.c
@@ -74,4 +74,4 @@ unsigned gpr_cpu_current_cpu(void) {
return shard_ptr(&magic_thread_local);
}
-#endif /* GPR_CPU_LINUX */
+#endif /* GPR_CPU_POSIX */
diff --git a/src/core/support/env_win32.c b/src/core/support/env_win32.c
index 177cc36a30..9b4cd698ad 100644
--- a/src/core/support/env_win32.c
+++ b/src/core/support/env_win32.c
@@ -36,6 +36,7 @@
#ifdef GPR_WIN32
#include "src/core/support/env.h"
+#include "src/core/support/string.h"
#include <stdlib.h>
@@ -43,14 +44,16 @@
#include <grpc/support/log.h>
char *gpr_getenv(const char *name) {
- size_t required_size;
+ size_t size;
char *result = NULL;
+ char *duplicated;
+ errno_t err;
- getenv_s(&required_size, NULL, 0, name);
- if (required_size == 0) return NULL;
- result = gpr_malloc(required_size);
- getenv_s(&required_size, result, required_size, name);
- return result;
+ err = _dupenv_s(&result, &size, name);
+ if (err) return NULL;
+ duplicated = gpr_strdup(result);
+ free(result);
+ return duplicated;
}
void gpr_setenv(const char *name, const char *value) {
diff --git a/src/core/support/file_win32.c b/src/core/support/file_win32.c
index fe209af9b2..f59d3af397 100644
--- a/src/core/support/file_win32.c
+++ b/src/core/support/file_win32.c
@@ -72,7 +72,7 @@ FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) {
if (_tfopen_s(&result, tmp_filename, TEXT("wb+")) != 0) goto end;
end:
- if (result && tmp_filename) {
+ if (result && tmp_filename_out) {
*tmp_filename_out = gpr_tchar_to_char(tmp_filename);
}
diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c
index 720dc141f5..159c7e052c 100644
--- a/src/core/support/log_win32.c
+++ b/src/core/support/log_win32.c
@@ -43,6 +43,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
+#include "src/core/support/string.h"
#include "src/core/support/string_win32.h"
void gpr_log(const char *file, int line, gpr_log_severity severity,
@@ -55,7 +56,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
va_start(args, format);
ret = _vscprintf(format, args);
va_end(args);
- if (!(0 <= ret && ret < ~(size_t)0)) {
+ if (ret < 0) {
message = NULL;
} else {
/* Allocate a new buffer, with space for the NUL terminator. */
@@ -66,7 +67,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
va_start(args, format);
ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args);
va_end(args);
- if (ret != strp_buflen - 1) {
+ if ((size_t)ret != strp_buflen - 1) {
/* This should never happen. */
gpr_free(message);
message = NULL;
@@ -90,7 +91,7 @@ void gpr_default_log(gpr_log_func_args *args) {
strcpy(time_buffer, "error:strftime");
}
- fprintf(stderr, "%s%s.%09u %5u %s:%d] %s\n",
+ fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), GetCurrentThreadId(),
args->file, args->line, args->message);
@@ -105,6 +106,7 @@ char *gpr_format_message(DWORD messageid) {
NULL, messageid,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)(&tmessage), 0, NULL);
+ if (status == 0) return gpr_strdup("Unable to retreive error string");
message = gpr_tchar_to_char(tmessage);
LocalFree(tmessage);
return message;
diff --git a/src/core/support/string_win32.c b/src/core/support/string_win32.c
index 583abd27d8..6d1d6337a9 100644
--- a/src/core/support/string_win32.c
+++ b/src/core/support/string_win32.c
@@ -44,6 +44,8 @@
#include <grpc/support/alloc.h>
+#include "src/core/support/string.h"
+
int gpr_asprintf(char **strp, const char *format, ...) {
va_list args;
int ret;
@@ -53,7 +55,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = _vscprintf(format, args);
va_end(args);
- if (!(0 <= ret && ret < ~(size_t)0)) {
+ if (ret < 0) {
*strp = NULL;
return -1;
}
@@ -69,7 +71,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args);
va_end(args);
- if (ret == strp_buflen - 1) {
+ if ((size_t)ret == strp_buflen - 1) {
return ret;
}
diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c
index c9a977cc80..cc31d9b052 100644
--- a/src/core/support/sync_win32.c
+++ b/src/core/support/sync_win32.c
@@ -37,6 +37,7 @@
#ifdef GPR_WIN32
+#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <grpc/support/log.h>
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c
index 8256849655..f221cb5790 100644
--- a/src/core/support/time_win32.c
+++ b/src/core/support/time_win32.c
@@ -42,8 +42,8 @@
gpr_timespec gpr_now(void) {
gpr_timespec now_tv;
- struct __timeb32 now_tb;
- _ftime32_s(&now_tb);
+ struct _timeb now_tb;
+ _ftime_s(&now_tb);
now_tv.tv_sec = now_tb.time;
now_tv.tv_nsec = now_tb.millitm * 1000000;
return now_tv;