From 9b60fa3acd9b48441f8f0a2062cfd2df7ebeeb8b Mon Sep 17 00:00:00 2001 From: David Klempner Date: Wed, 4 Feb 2015 09:48:53 -0800 Subject: Make gpr_timespec no longer be a typedef for struct timespec in posix The problem is that for the typedef to work we need _POSIX_C_SOURCE to be defined properly before any file that uses gpr_timespec includes anything. This is extremely fragile unless we change CFLAGS, which probably isn't worth doing for this. --- include/grpc/support/time.h | 4 ++-- include/grpc/support/time_posix.h | 5 ++++- src/core/support/sync_posix.c | 11 ++++++++++- src/core/support/time_posix.c | 25 +++++++++++++++++++++---- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h index 6327a2cffb..70e4afdf6b 100644 --- a/include/grpc/support/time.h +++ b/include/grpc/support/time.h @@ -34,8 +34,8 @@ #ifndef __GRPC_SUPPORT_TIME_H__ #define __GRPC_SUPPORT_TIME_H__ /* Time support. - We use gpr_timespec, which is typedefed to struct timespec on platforms which - have it. On some machines, absolute times may be in local time. */ + We use gpr_timespec, which is analogous to struct timespec. On some + machines, absolute times may be in local time. */ /* Platform specific header declares gpr_timespec. gpr_timespec contains: diff --git a/include/grpc/support/time_posix.h b/include/grpc/support/time_posix.h index 9ff6f7f493..85dee5fc21 100644 --- a/include/grpc/support/time_posix.h +++ b/include/grpc/support/time_posix.h @@ -38,6 +38,9 @@ #include #include -typedef struct timespec gpr_timespec; +typedef struct gpr_timespec { + time_t tv_sec; + long tv_nsec; +} gpr_timespec; #endif /* __GRPC_SUPPORT_TIME_POSIX_H__ */ diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c index 7f0e4a95a4..a28a4c6bf4 100644 --- a/src/core/support/sync_posix.c +++ b/src/core/support/sync_posix.c @@ -33,11 +33,17 @@ /* Posix gpr synchroization support code. */ +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199309L +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199309L +#endif + #include #ifdef GPR_POSIX_SYNC #include +#include #include #include #include @@ -67,7 +73,10 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) { if (gpr_time_cmp(abs_deadline, gpr_inf_future) == 0) { err = pthread_cond_wait(cv, mu); } else { - err = pthread_cond_timedwait(cv, mu, &abs_deadline); + struct timespec abs_deadline_ts; + abs_deadline_ts.tv_sec = abs_deadline.tv_sec; + abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; + err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); } GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN); return err == ETIMEDOUT; diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index 9e11f8a865..7f0f028183 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -34,7 +34,8 @@ /* Posix code for gpr time support. */ /* So we get nanosleep and clock_* */ -#ifndef _POSIX_C_SOURCE +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199309L +#undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199309L #endif @@ -47,11 +48,25 @@ #include #include +static struct timespec timespec_from_gpr(gpr_timespec gts) { + struct timespec rv; + rv.tv_sec = gts.tv_sec; + rv.tv_nsec = gts.tv_nsec; + return rv; +} + #if _POSIX_TIMERS > 0 +static gpr_timespec gpr_from_timespec(struct timespec ts) { + gpr_timespec rv; + rv.tv_sec = ts.tv_sec; + rv.tv_nsec = ts.tv_nsec; + return rv; +} + gpr_timespec gpr_now(void) { - gpr_timespec now; + struct timespec now; clock_gettime(CLOCK_REALTIME, &now); - return now; + return gpr_from_timespec(now); } #else /* For some reason Apple's OSes haven't implemented clock_gettime. */ @@ -69,6 +84,7 @@ gpr_timespec gpr_now(void) { void gpr_sleep_until(gpr_timespec until) { gpr_timespec now; gpr_timespec delta; + struct timespec delta_ts; for (;;) { /* We could simplify by using clock_nanosleep instead, but it might be @@ -79,7 +95,8 @@ void gpr_sleep_until(gpr_timespec until) { } delta = gpr_time_sub(until, now); - if (nanosleep(&delta, NULL) == 0) { + delta_ts = timespec_from_gpr(delta); + if (nanosleep(&delta_ts, NULL) == 0) { break; } } -- cgit v1.2.3 From 0c61dc52a17b33fd11e2c85ee7797da517f01df2 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Wed, 4 Feb 2015 13:24:04 -0800 Subject: Remove the platform specific time headers --- include/grpc/support/time.h | 21 +++++------------- include/grpc/support/time_posix.h | 46 --------------------------------------- include/grpc/support/time_win32.h | 46 --------------------------------------- 3 files changed, 6 insertions(+), 107 deletions(-) delete mode 100644 include/grpc/support/time_posix.h delete mode 100644 include/grpc/support/time_win32.h diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h index 690fbc10e7..9fb1d0bc97 100644 --- a/include/grpc/support/time.h +++ b/include/grpc/support/time.h @@ -37,28 +37,19 @@ We use gpr_timespec, which is analogous to struct timespec. On some machines, absolute times may be in local time. */ -/* Platform specific header declares gpr_timespec. - gpr_timespec contains: - time_t tv_sec; // seconds since start of 1970 - int tv_nsec; // nanoseconds; always in 0..999999999; never negative. - */ - #include - -#if defined(GPR_POSIX_TIME) -#include -#elif defined(GPR_WIN32) -#include -#else -#error could not determine platform for time -#endif - #include +#include #ifdef __cplusplus extern "C" { #endif +typedef struct gpr_timespec { + time_t tv_sec; + int tv_nsec; +} gpr_timespec; + /* Time constants. */ extern const gpr_timespec gpr_time_0; /* The zero time interval. */ extern const gpr_timespec gpr_inf_future; /* The far future */ diff --git a/include/grpc/support/time_posix.h b/include/grpc/support/time_posix.h deleted file mode 100644 index 85dee5fc21..0000000000 --- a/include/grpc/support/time_posix.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright 2014, 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. - * - */ - -#ifndef __GRPC_SUPPORT_TIME_POSIX_H__ -#define __GRPC_SUPPORT_TIME_POSIX_H__ -/* Posix variant of gpr_time_platform.h */ - -#include -#include - -typedef struct gpr_timespec { - time_t tv_sec; - long tv_nsec; -} gpr_timespec; - -#endif /* __GRPC_SUPPORT_TIME_POSIX_H__ */ diff --git a/include/grpc/support/time_win32.h b/include/grpc/support/time_win32.h deleted file mode 100644 index e62ad64b8f..0000000000 --- a/include/grpc/support/time_win32.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright 2014, 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. - * - */ - -#ifndef __GRPC_SUPPORT_TIME_WIN32_H__ -#define __GRPC_SUPPORT_TIME_WIN32_H__ -/* Win32 variant of gpr_time_platform.h */ - -#include -#include - -typedef struct gpr_timespec { - time_t tv_sec; - long tv_nsec; -} gpr_timespec; - -#endif /* __GRPC_SUPPORT_TIME_WIN32_H__ */ -- cgit v1.2.3 From e5437de181fb0ccea7978c6dfa735169ad65cc69 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Wed, 4 Feb 2015 14:06:03 -0800 Subject: Add a missing mdstr_unref This fixes most of the asan reported leaks. --- src/core/surface/call.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 5a24264cce..2b6f042eb9 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -318,6 +318,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call *c, maybe_set_status_code(c, status); if (details) { maybe_set_status_details(c, details); + grpc_mdstr_unref(details); } gpr_mu_unlock(&c->read_mu); return grpc_call_cancel(c); -- cgit v1.2.3 From 6393dd36f1a3d2c0c1125f65e0c8329e1385e0b6 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Wed, 4 Feb 2015 14:23:39 -0800 Subject: Fixing build.json by removing files that are no longer present. --- Makefile | 2 -- build.json | 2 -- vsprojects/vs2013/gpr.vcxproj | 2 -- vsprojects/vs2013/gpr.vcxproj.filters | 6 ------ 4 files changed, 12 deletions(-) diff --git a/Makefile b/Makefile index 846d9772d4..d0b5e34f3e 100644 --- a/Makefile +++ b/Makefile @@ -1272,8 +1272,6 @@ PUBLIC_HEADERS_C += \ include/grpc/support/sync_win32.h \ include/grpc/support/thd.h \ include/grpc/support/time.h \ - include/grpc/support/time_posix.h \ - include/grpc/support/time_win32.h \ include/grpc/support/useful.h \ LIBGPR_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGPR_SRC)))) diff --git a/build.json b/build.json index 6fa3495aa3..d8a295f35c 100644 --- a/build.json +++ b/build.json @@ -221,8 +221,6 @@ "include/grpc/support/sync_win32.h", "include/grpc/support/thd.h", "include/grpc/support/time.h", - "include/grpc/support/time_posix.h", - "include/grpc/support/time_win32.h", "include/grpc/support/useful.h" ], "headers": [ diff --git a/vsprojects/vs2013/gpr.vcxproj b/vsprojects/vs2013/gpr.vcxproj index c77a61d782..0d429ab43d 100644 --- a/vsprojects/vs2013/gpr.vcxproj +++ b/vsprojects/vs2013/gpr.vcxproj @@ -92,8 +92,6 @@ - - diff --git a/vsprojects/vs2013/gpr.vcxproj.filters b/vsprojects/vs2013/gpr.vcxproj.filters index e385efcfb2..a992558654 100644 --- a/vsprojects/vs2013/gpr.vcxproj.filters +++ b/vsprojects/vs2013/gpr.vcxproj.filters @@ -138,12 +138,6 @@ include\grpc\support - - include\grpc\support - - - include\grpc\support - include\grpc\support -- cgit v1.2.3 From 05fce429e2a6503a839ac2a7f6854dafc6d188e9 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Wed, 4 Feb 2015 14:40:42 -0800 Subject: Fix a memory leak and a gpr_strdup/free mismatch in json_test --- test/core/json/json_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/core/json/json_test.c b/test/core/json/json_test.c index 11659a5716..6d0227ad39 100644 --- a/test/core/json/json_test.c +++ b/test/core/json/json_test.c @@ -151,7 +151,7 @@ static void test_pairs() { GPR_ASSERT(!json); } - free(scratchpad); + gpr_free(scratchpad); } } @@ -166,6 +166,7 @@ static void test_atypical() { grpc_json_destroy(json->child); json->child = brother; grpc_json_destroy(json); + gpr_free(scratchpad); } int main(int argc, char **argv) { -- cgit v1.2.3