Skip to content

Commit

Permalink
Merge pull request grpc#4562 from ctiller/ints
Browse files Browse the repository at this point in the history
Switch to using C99 types for fixed size integers
  • Loading branch information
jboeuf committed Jan 6, 2016
2 parents 38b6eee + 6a56221 commit bbb94bd
Show file tree
Hide file tree
Showing 236 changed files with 1,539 additions and 1,605 deletions.
4 changes: 2 additions & 2 deletions include/grpc++/client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ class PropagationOptions {
return *this;
}

gpr_uint32 c_bitmask() const { return propagate_; }
uint32_t c_bitmask() const { return propagate_; }

private:
gpr_uint32 propagate_;
uint32_t propagate_;
};

namespace testing {
Expand Down
10 changes: 5 additions & 5 deletions include/grpc++/impl/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WriteOptions {
inline void Clear() { flags_ = 0; }

/// Returns raw flags bitset.
inline gpr_uint32 flags() const { return flags_; }
inline uint32_t flags() const { return flags_; }

/// Sets flag for the disabling of compression for the next message write.
///
Expand Down Expand Up @@ -126,13 +126,13 @@ class WriteOptions {
}

private:
void SetBit(const gpr_uint32 mask) { flags_ |= mask; }
void SetBit(const uint32_t mask) { flags_ |= mask; }

void ClearBit(const gpr_uint32 mask) { flags_ &= ~mask; }
void ClearBit(const uint32_t mask) { flags_ &= ~mask; }

bool GetBit(const gpr_uint32 mask) const { return (flags_ & mask) != 0; }
bool GetBit(const uint32_t mask) const { return (flags_ & mask) != 0; }

gpr_uint32 flags_;
uint32_t flags_;
};

/// Default argument for CallOpSet. I is unused by the class, but can be
Expand Down
4 changes: 2 additions & 2 deletions include/grpc++/support/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class Slice GRPC_FINAL {
size_t size() const { return GPR_SLICE_LENGTH(slice_); }

/// Raw pointer to the beginning (first element) of the slice.
const gpr_uint8* begin() const { return GPR_SLICE_START_PTR(slice_); }
const uint8_t* begin() const { return GPR_SLICE_START_PTR(slice_); }

/// Raw pointer to the end (one byte \em past the last element) of the slice.
const gpr_uint8* end() const { return GPR_SLICE_END_PTR(slice_); }
const uint8_t* end() const { return GPR_SLICE_END_PTR(slice_); }

private:
friend class ByteBuffer;
Expand Down
25 changes: 12 additions & 13 deletions include/grpc/census.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ census_timestamp census_start_rpc_op_timestamp(void);
functions, maybe it should be set once at census initialization.
*/
typedef struct {
const char *(*get_rpc_service_name)(gpr_int64 id);
const char *(*get_rpc_method_name)(gpr_int64 id);
const char *(*get_rpc_service_name)(int64_t id);
const char *(*get_rpc_method_name)(int64_t id);
} census_rpc_name_info;

/**
Expand Down Expand Up @@ -205,7 +205,7 @@ typedef struct {
@return A new census context.
*/
census_context *census_start_client_rpc_op(
const census_context *context, gpr_int64 rpc_name_id,
const census_context *context, int64_t rpc_name_id,
const census_rpc_name_info *rpc_name_info, const char *peer, int trace_mask,
const census_timestamp *start_time);

Expand Down Expand Up @@ -233,7 +233,7 @@ void census_set_rpc_client_peer(census_context *context, const char *peer);
@return A new census context.
*/
census_context *census_start_server_rpc_op(
const char *buffer, gpr_int64 rpc_name_id,
const char *buffer, int64_t rpc_name_id,
const census_rpc_name_info *rpc_name_info, const char *peer, int trace_mask,
census_timestamp *start_time);

Expand Down Expand Up @@ -276,8 +276,8 @@ census_context *census_start_op(census_context *context, const char *family,
*/
void census_end_op(census_context *context, int status);

#define CENSUS_TRACE_RECORD_START_OP ((gpr_uint32)0)
#define CENSUS_TRACE_RECORD_END_OP ((gpr_uint32)1)
#define CENSUS_TRACE_RECORD_START_OP ((uint32_t)0)
#define CENSUS_TRACE_RECORD_END_OP ((uint32_t)1)

/** Insert a trace record into the trace stream. The record consists of an
arbitrary size buffer, the size of which is provided in 'n'.
Expand All @@ -286,15 +286,15 @@ void census_end_op(census_context *context, int status);
@param buffer Pointer to buffer to use
@param n Number of bytes in buffer
*/
void census_trace_print(census_context *context, gpr_uint32 type,
void census_trace_print(census_context *context, uint32_t type,
const char *buffer, size_t n);

/** Trace record. */
typedef struct {
census_timestamp timestamp; /* Time of record creation */
gpr_uint64 trace_id; /* Trace ID associated with record */
gpr_uint64 op_id; /* Operation ID associated with record */
gpr_uint32 type; /* Type (as used in census_trace_print() */
uint64_t trace_id; /* Trace ID associated with record */
uint64_t op_id; /* Operation ID associated with record */
uint32_t type; /* Type (as used in census_trace_print() */
const char *buffer; /* Buffer (from census_trace_print() */
size_t buf_size; /* Number of bytes inside buffer */
} census_trace_record;
Expand Down Expand Up @@ -403,7 +403,7 @@ void census_tag_set_close(census_tag_set_iterator *it);
/* A single value to be recorded comprises two parts: an ID for the particular
* metric and the value to be recorded against it. */
typedef struct {
gpr_uint32 metric_id;
uint32_t metric_id;
double value;
} census_value;

Expand Down Expand Up @@ -439,8 +439,7 @@ typedef struct census_view census_view;
@return A new census view
*/
census_view *census_view_create(gpr_uint32 metric_id,
const census_tag_set *tags,
census_view *census_view_create(uint32_t metric_id, const census_tag_set *tags,
const census_aggregation *aggregations,
size_t naggregations);

Expand Down
2 changes: 1 addition & 1 deletion include/grpc/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ typedef enum {
} grpc_compression_level;

typedef struct grpc_compression_options {
gpr_uint32 enabled_algorithms_bitset; /**< All algs are enabled by default */
uint32_t enabled_algorithms_bitset; /**< All algs are enabled by default */
grpc_compression_algorithm default_compression_algorithm; /**< for channel */
} grpc_compression_options;

Expand Down
18 changes: 9 additions & 9 deletions include/grpc/grpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ typedef struct grpc_metadata {
const char *key;
const char *value;
size_t value_length;
gpr_uint32 flags;
uint32_t flags;

/** The following fields are reserved for grpc internal use.
There is no need to initialize them, and they will be set to garbage
Expand Down Expand Up @@ -326,7 +326,7 @@ typedef struct grpc_op {
/** Operation type, as defined by grpc_op_type */
grpc_op_type op;
/** Write flags bitset for grpc_begin_messages */
gpr_uint32 flags;
uint32_t flags;
/** Reserved for future usage */
void *reserved;
union {
Expand Down Expand Up @@ -408,20 +408,20 @@ void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
/* Propagation bits: this can be bitwise or-ed to form propagation_mask for
* grpc_call */
/** Propagate deadline */
#define GRPC_PROPAGATE_DEADLINE ((gpr_uint32)1)
#define GRPC_PROPAGATE_DEADLINE ((uint32_t)1)
/** Propagate census context */
#define GRPC_PROPAGATE_CENSUS_STATS_CONTEXT ((gpr_uint32)2)
#define GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT ((gpr_uint32)4)
#define GRPC_PROPAGATE_CENSUS_STATS_CONTEXT ((uint32_t)2)
#define GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT ((uint32_t)4)
/** Propagate cancellation */
#define GRPC_PROPAGATE_CANCELLATION ((gpr_uint32)8)
#define GRPC_PROPAGATE_CANCELLATION ((uint32_t)8)

/* Default propagation mask: clients of the core API are encouraged to encode
deltas from this in their implementations... ie write:
GRPC_PROPAGATE_DEFAULTS & ~GRPC_PROPAGATE_DEADLINE to disable deadline
propagation. Doing so gives flexibility in the future to define new
propagation types that are default inherited or not. */
#define GRPC_PROPAGATE_DEFAULTS \
((gpr_uint32)(( \
((uint32_t)(( \
0xffff | GRPC_PROPAGATE_DEADLINE | GRPC_PROPAGATE_CENSUS_STATS_CONTEXT | \
GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT | GRPC_PROPAGATE_CANCELLATION)))

Expand Down Expand Up @@ -526,7 +526,7 @@ void grpc_channel_watch_connectivity_state(
*/
grpc_call *grpc_channel_create_call(grpc_channel *channel,
grpc_call *parent_call,
gpr_uint32 propagation_mask,
uint32_t propagation_mask,
grpc_completion_queue *completion_queue,
const char *method, const char *host,
gpr_timespec deadline, void *reserved);
Expand All @@ -542,7 +542,7 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method,

/** Create a call given a handle returned from grpc_channel_register_call */
grpc_call *grpc_channel_create_registered_call(
grpc_channel *channel, grpc_call *parent_call, gpr_uint32 propagation_mask,
grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
grpc_completion_queue *completion_queue, void *registered_call_handle,
gpr_timespec deadline, void *reserved);

Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/atm.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// Atomic operations act on an intergral_type gpr_atm that is guaranteed to
// be the same size as a pointer.
typedef gpr_intptr gpr_atm;
typedef intptr_t gpr_atm;
// A memory barrier, providing both acquire and release semantics, but not
// otherwise acting on memory.
Expand Down
10 changes: 5 additions & 5 deletions include/grpc/support/atm_gcc_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@
__atomic_* interface. */
#include <grpc/support/port_platform.h>

typedef gpr_intptr gpr_atm;
typedef intptr_t gpr_atm;

#define gpr_atm_full_barrier() (__atomic_thread_fence(__ATOMIC_SEQ_CST))

#define gpr_atm_acq_load(p) (__atomic_load_n((p), __ATOMIC_ACQUIRE))
#define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
#define gpr_atm_rel_store(p, value) \
(__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELEASE))
(__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELEASE))
#define gpr_atm_no_barrier_store(p, value) \
(__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELAXED))
(__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELAXED))

#define gpr_atm_no_barrier_fetch_add(p, delta) \
(__atomic_fetch_add((p), (gpr_intptr)(delta), __ATOMIC_RELAXED))
(__atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_RELAXED))
#define gpr_atm_full_fetch_add(p, delta) \
(__atomic_fetch_add((p), (gpr_intptr)(delta), __ATOMIC_ACQ_REL))
(__atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_ACQ_REL))

static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_RELAXED,
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/atm_gcc_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
interface */
#include <grpc/support/port_platform.h>

typedef gpr_intptr gpr_atm;
typedef intptr_t gpr_atm;

#define GPR_ATM_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory")

Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/atm_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/* Win32 variant of atm_platform.h */
#include <grpc/support/port_platform.h>

typedef gpr_intptr gpr_atm;
typedef intptr_t gpr_atm;

#define gpr_atm_full_barrier MemoryBarrier

Expand Down
6 changes: 3 additions & 3 deletions include/grpc/support/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ double gpr_histogram_count(gpr_histogram *histogram);
double gpr_histogram_sum(gpr_histogram *histogram);
double gpr_histogram_sum_of_squares(gpr_histogram *histogram);

const gpr_uint32 *gpr_histogram_get_contents(gpr_histogram *histogram,
size_t *count);
const uint32_t *gpr_histogram_get_contents(gpr_histogram *histogram,
size_t *count);
void gpr_histogram_merge_contents(gpr_histogram *histogram,
const gpr_uint32 *data, size_t data_count,
const uint32_t *data, size_t data_count,
double min_seen, double max_seen, double sum,
double sum_of_squares, double count);

Expand Down
16 changes: 0 additions & 16 deletions include/grpc/support/port_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,6 @@
#error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS
#endif

typedef int16_t gpr_int16;
typedef int32_t gpr_int32;
typedef int64_t gpr_int64;
typedef uint8_t gpr_uint8;
typedef uint16_t gpr_uint16;
typedef uint32_t gpr_uint32;
typedef uint64_t gpr_uint64;
typedef intmax_t gpr_intmax;
typedef intptr_t gpr_intptr;
typedef uintmax_t gpr_uintmax;
typedef uintptr_t gpr_uintptr;

/* INT64_MAX is unavailable on some platforms. */
#define GPR_INT64_MAX (gpr_int64)(~(gpr_uint64)0 >> 1)
#define GPR_UINT32_MAX (~(gpr_uint32)0)

/* maximum alignment needed for any type on this platform, rounded up to a
power of two */
#define GPR_MAX_ALIGNMENT 16
Expand Down
10 changes: 5 additions & 5 deletions include/grpc/support/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct gpr_slice_refcount {
void (*unref)(void *);
} gpr_slice_refcount;

#define GPR_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(gpr_uint8 *) - 1)
#define GPR_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1)

/* A gpr_slice s, if initialized, represents the byte range
s.bytes[0..s.length-1].
Expand All @@ -80,12 +80,12 @@ typedef struct gpr_slice {
struct gpr_slice_refcount *refcount;
union {
struct {
gpr_uint8 *bytes;
uint8_t *bytes;
size_t length;
} refcounted;
struct {
gpr_uint8 length;
gpr_uint8 bytes[GPR_SLICE_INLINED_SIZE];
uint8_t length;
uint8_t bytes[GPR_SLICE_INLINED_SIZE];
} inlined;
} data;
} gpr_slice;
Expand All @@ -98,7 +98,7 @@ typedef struct gpr_slice {
: (slice).data.inlined.length)
#define GPR_SLICE_SET_LENGTH(slice, newlen) \
((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
: ((slice).data.inlined.length = (gpr_uint8)(newlen)))
: ((slice).data.inlined.length = (uint8_t)(newlen)))
#define GPR_SLICE_END_PTR(slice) \
GPR_SLICE_START_PTR(slice) + GPR_SLICE_LENGTH(slice)
#define GPR_SLICE_IS_EMPTY(slice) (GPR_SLICE_LENGTH(slice) == 0)
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/slice_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice);
void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n);
/* add a very small (less than 8 bytes) amount of data to the end of a slice
buffer: returns a pointer into which to add the data */
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len);
uint8_t *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len);
/* pop the last buffer, but don't unref it */
void gpr_slice_buffer_pop(gpr_slice_buffer *sb);
/* clear a slice buffer, unref all elements */
Expand Down
6 changes: 3 additions & 3 deletions include/grpc/support/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ int gpr_unref(gpr_refcount *r);
synchronize other events. */

/* Initialize *c to the value n. */
void gpr_stats_init(gpr_stats_counter *c, gpr_intptr n);
void gpr_stats_init(gpr_stats_counter *c, intptr_t n);

/* *c += inc. Requires: *c initialized. */
void gpr_stats_inc(gpr_stats_counter *c, gpr_intptr inc);
void gpr_stats_inc(gpr_stats_counter *c, intptr_t inc);

/* Return *c. Requires: *c initialized. */
gpr_intptr gpr_stats_read(const gpr_stats_counter *c);
intptr_t gpr_stats_read(const gpr_stats_counter *c);

/* ==================Example use of interface===================
A producer-consumer queue of up to N integers,
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/thd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
extern "C" {
#endif

typedef gpr_uint64 gpr_thd_id;
typedef uint64_t gpr_thd_id;

/* Thread creation options. */
typedef struct {
Expand Down
6 changes: 3 additions & 3 deletions include/grpc/support/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ typedef enum {
} gpr_clock_type;

typedef struct gpr_timespec {
gpr_int64 tv_sec;
gpr_int32 tv_nsec;
int64_t tv_sec;
int32_t tv_nsec;
/** Against which clock was this time measured? (or GPR_TIMESPAN if
this is a relative time meaure) */
gpr_clock_type clock_type;
Expand Down Expand Up @@ -110,7 +110,7 @@ gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type);
gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type);
gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type);

gpr_int32 gpr_time_to_millis(gpr_timespec timespec);
int32_t gpr_time_to_millis(gpr_timespec timespec);

/* Return 1 if two times are equal or within threshold of each other,
0 otherwise */
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
A minimal wrapper that should be implementable across many compilers,
and implementable efficiently across most modern compilers.
Thread locals have type gpr_intptr.
Thread locals have type intptr_t.
Declaring a thread local variable 'foo':
GPR_TLS_DECL(foo);
Expand Down
Loading

0 comments on commit bbb94bd

Please sign in to comment.