diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index f552d3c8a28..94a10da21b6 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 +#include #ifdef __cplusplus extern "C" { diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index d5294b2efa8..61cee9a5b10 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 +#endif /* _MSC_VER < 1700 */ +#else +#include +#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 - /* 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 989b86f2aad..d0364155997 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 +#include #ifdef __cplusplus extern "C" { diff --git a/setup.py b/setup.py index 1a3c838a10e..d73286f88fe 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 1295009809d..9d6e0170269 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 d7ad9e5215b..9e14b967e0a 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 real_time.seconds + 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 fd1443e7904..3967c3045f7 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()