diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index f552d3c8a28afe8360e5826fe377dd32ca049a33..94a10da21b6bf7fd7ef82dbb9ab6ea2b84e3eee4 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -34,7 +34,7 @@ #ifndef GRPC_IMPL_CODEGEN_COMPRESSION_TYPES_H #define GRPC_IMPL_CODEGEN_COMPRESSION_TYPES_H -#include <stdint.h> +#include <grpc/support/port_platform.h> #ifdef __cplusplus extern "C" { diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index d5294b2efa8b5f8e68873a4fb98e7b21fa1d8f39..61cee9a5b1090e48ab82cc076142c498baba8624 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -34,6 +34,23 @@ #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H +#ifdef _MSC_VER +#if _MSC_VER < 1700 +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +#include <stdint.h> +#endif /* _MSC_VER < 1700 */ +#else +#include <stdint.h> +#endif /* _MSC_VER */ + /* Get windows.h included everywhere (we need it) */ #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) #ifndef WIN32_LEAN_AND_MEAN @@ -254,10 +271,6 @@ #define GPR_FORBID_UNREACHABLE_CODE 1 #endif -/* For a common case, assume that the platform has a C99-like stdint.h */ - -#include <stdint.h> - /* Cache line alignment */ #ifndef GPR_CACHELINE_SIZE_LOG #if defined(__i386__) || defined(__x86_64__) diff --git a/include/grpc/impl/codegen/propagation_bits.h b/include/grpc/impl/codegen/propagation_bits.h index 989b86f2aad8f06531bbc61af37a8eb78582bbc3..d03641559974ba89335787a3edc5daa25bab754e 100644 --- a/include/grpc/impl/codegen/propagation_bits.h +++ b/include/grpc/impl/codegen/propagation_bits.h @@ -34,7 +34,7 @@ #ifndef GRPC_IMPL_CODEGEN_H #define GRPC_IMPL_CODEGEN_H -#include <stdint.h> +#include <grpc/support/port_platform.h> #ifdef __cplusplus extern "C" { diff --git a/setup.py b/setup.py index 1a3c838a10e36d0e4d6ba51c8d46360d1b3ebb16..d73286f88fe23660c00b575e15db105a5ee56ba4 100644 --- a/setup.py +++ b/setup.py @@ -82,14 +82,16 @@ CYTHON_HELPER_C_FILES = ( CORE_C_FILES = () if not "win32" in sys.platform: - CORE_C_FILES += tuple(grpc_core_dependencies.CORE_SOURCE_FILES) + CORE_C_FILES += tuple(grpc_core_dependencies.CORE_SOURCE_FILES) EXTENSION_INCLUDE_DIRECTORIES = ( (PYTHON_STEM,) + CORE_INCLUDE + BORINGSSL_INCLUDE + ZLIB_INCLUDE) -EXTENSION_LIBRARIES = ('m',) +EXTENSION_LIBRARIES = () if "linux" in sys.platform: - EXTENSION_LIBRARIES += ('rt',) + EXTENSION_LIBRARIES += ('rt',) +if not "win32" in sys.platform: + EXTENSION_LIBRARIES += ('m',) DEFINE_MACROS = (('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600)) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 1295009809dcb4f43c3138a5c75f562166c3fcbc..9d6e0170269fe12febbbc75f3864897fd4eee64e 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -28,11 +28,14 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cimport libc.time -from libc.stdint cimport int64_t, uint32_t, int32_t cdef extern from "grpc/_cython/loader.h": + ctypedef int int32_t + ctypedef unsigned uint32_t + ctypedef long int64_t + int pygrpc_load_core(const char*) void *gpr_malloc(size_t size) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index d7ad9e5215bdfb98697df0cbf6af89e9f0bef95f..9e14b967e0aa3dcd1e4fc422ab1b2989f59b7061 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -146,8 +146,13 @@ cdef class Timespec: gpr_convert_clock_type(self.c_time, GPR_CLOCK_REALTIME)) return <double>real_time.seconds + <double>real_time.nanoseconds / 1e9 - infinite_future = Timespec(float("+inf")) - infinite_past = Timespec(float("-inf")) + @staticmethod + def infinite_future(): + return Timespec(float("+inf")) + + @staticmethod + def infinite_past(): + return Timespec(float("-inf")) cdef class CallDetails: diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx index fd1443e79046fc3a8469db34c1d9b6f12a7ecf03..3967c3045f72da3d627a73b984488c9c1b49f741 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -47,16 +47,19 @@ include "grpc/_cython/_cygrpc/server.pyx.pxi" cdef class _ModuleState: + cdef bint is_loaded + def __cinit__(self): filename = pkg_resources.resource_filename( - __name__, '_windows/grpc_c.64.python') - directory = os.path.dirname(filename) - if not pygrpc_load_core(directory): + 'grpc._cython', '_windows/grpc_c.64.python') + if not pygrpc_load_core(filename): raise ImportError('failed to load core gRPC library') grpc_init() + self.is_loaded = True def __dealloc__(self): - grpc_shutdown() + if self.is_loaded: + grpc_shutdown() _module_state = _ModuleState()