Ensure C89 compatibility in Linux tests

pull/2034/head
Masood Malekghassemi 10 years ago
parent a08694eff2
commit 4b4181ed1c
  1. 13
      src/python/src/grpc/_adapter/_c/utility.c
  2. 2
      tools/run_tests/build_python.sh

@ -40,6 +40,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/slice.h> #include <grpc/support/slice.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include <grpc/support/string_util.h>
#include "grpc/_adapter/_c/types.h" #include "grpc/_adapter/_c/types.h"
@ -156,9 +157,10 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) {
return 0; return 0;
} }
if (PyTuple_Size(op) != OP_TUPLE_SIZE) { if (PyTuple_Size(op) != OP_TUPLE_SIZE) {
char buf[64]; char *buf;
snprintf(buf, sizeof(buf), "expected tuple op of length %d", OP_TUPLE_SIZE); gpr_asprintf(&buf, "expected tuple op of length %d", OP_TUPLE_SIZE);
PyErr_SetString(PyExc_ValueError, buf); PyErr_SetString(PyExc_ValueError, buf);
gpr_free(buf);
return 0; return 0;
} }
type = PyInt_AsLong(PyTuple_GET_ITEM(op, TYPE_INDEX)); type = PyInt_AsLong(PyTuple_GET_ITEM(op, TYPE_INDEX));
@ -353,9 +355,14 @@ double pygrpc_cast_gpr_timespec_to_double(gpr_timespec timespec) {
return timespec.tv_sec + 1e-9*timespec.tv_nsec; return timespec.tv_sec + 1e-9*timespec.tv_nsec;
} }
/* Because C89 doesn't have a way to check for infinity... */
static int pygrpc_isinf(double x) {
return x * 0 != 0;
}
gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds) { gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds) {
gpr_timespec result; gpr_timespec result;
if isinf(seconds) { if (pygrpc_isinf(seconds)) {
result = seconds > 0.0 ? gpr_inf_future : gpr_inf_past; result = seconds > 0.0 ? gpr_inf_future : gpr_inf_past;
} else { } else {
result.tv_sec = (time_t)seconds; result.tv_sec = (time_t)seconds;

@ -38,5 +38,5 @@ rm -rf python2.7_virtual_environment
virtualenv -p /usr/bin/python2.7 python2.7_virtual_environment virtualenv -p /usr/bin/python2.7 python2.7_virtual_environment
source python2.7_virtual_environment/bin/activate source python2.7_virtual_environment/bin/activate
pip install -r src/python/requirements.txt pip install -r src/python/requirements.txt
CFLAGS=-I$root/include LDFLAGS=-L$root/libs/$CONFIG pip install src/python/src CFLAGS="-I$root/include -std=c89" LDFLAGS=-L$root/libs/$CONFIG pip install src/python/src
pip install src/python/interop pip install src/python/interop

Loading…
Cancel
Save