Commit c1ccc790 authored by lahiker42's avatar lahiker42

Suppress warnings that emerge with -Wcast-qual and -Wshadow

(thanks in part to Robert Edmonds for this patch).



git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@75 00440858-1255-0410-a3e6-75ea37f81c3a
parent dd9d5f3c
...@@ -215,22 +215,22 @@ sint64_size (int64_t v) ...@@ -215,22 +215,22 @@ sint64_size (int64_t v)
static size_t static size_t
required_field_get_packed_size (const ProtobufCFieldDescriptor *field, required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
void *member) const void *member)
{ {
size_t rv = get_tag_size (field->id); size_t rv = get_tag_size (field->id);
switch (field->type) switch (field->type)
{ {
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
return rv + sint32_size (*(int32_t *) member); return rv + sint32_size (*(const int32_t *) member);
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT32:
return rv + int32_size (*(uint32_t *) member); return rv + int32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT32:
return rv + uint32_size (*(uint32_t *) member); return rv + uint32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SINT64:
return rv + sint64_size (*(int64_t *) member); return rv + sint64_size (*(const int64_t *) member);
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_UINT64:
return rv + uint64_size (*(uint64_t *) member); return rv + uint64_size (*(const uint64_t *) member);
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_FIXED32:
return rv + 4; return rv + 4;
...@@ -245,21 +245,21 @@ required_field_get_packed_size (const ProtobufCFieldDescriptor *field, ...@@ -245,21 +245,21 @@ required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
return rv + 8; return rv + 8;
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_ENUM:
// TODO: is this correct for negative-valued enums? // TODO: is this correct for negative-valued enums?
return rv + uint32_size (*(uint32_t *) member); return rv + uint32_size (*(const uint32_t *) member);
case PROTOBUF_C_TYPE_STRING: case PROTOBUF_C_TYPE_STRING:
{ {
size_t len = strlen (*(char**) member); size_t len = strlen (*(char * const *) member);
return rv + uint32_size (len) + len; return rv + uint32_size (len) + len;
} }
case PROTOBUF_C_TYPE_BYTES: case PROTOBUF_C_TYPE_BYTES:
{ {
size_t len = ((ProtobufCBinaryData*) member)->len; size_t len = ((const ProtobufCBinaryData*) member)->len;
return rv + uint32_size (len) + len; return rv + uint32_size (len) + len;
} }
//case PROTOBUF_C_TYPE_GROUP: //case PROTOBUF_C_TYPE_GROUP:
case PROTOBUF_C_TYPE_MESSAGE: case PROTOBUF_C_TYPE_MESSAGE:
{ {
size_t subrv = protobuf_c_message_get_packed_size (*(ProtobufCMessage **) member); size_t subrv = protobuf_c_message_get_packed_size (*(ProtobufCMessage * const *) member);
return rv + uint32_size (subrv) + subrv; return rv + uint32_size (subrv) + subrv;
} }
} }
...@@ -269,12 +269,12 @@ required_field_get_packed_size (const ProtobufCFieldDescriptor *field, ...@@ -269,12 +269,12 @@ required_field_get_packed_size (const ProtobufCFieldDescriptor *field,
static size_t static size_t
optional_field_get_packed_size (const ProtobufCFieldDescriptor *field, optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has, const protobuf_c_boolean *has,
void *member) const void *member)
{ {
if (field->type == PROTOBUF_C_TYPE_MESSAGE if (field->type == PROTOBUF_C_TYPE_MESSAGE
|| field->type == PROTOBUF_C_TYPE_STRING) || field->type == PROTOBUF_C_TYPE_STRING)
{ {
if (*(void**)member == NULL) if (*(void * const *)member == NULL)
return 0; return 0;
} }
else else
...@@ -288,11 +288,11 @@ optional_field_get_packed_size (const ProtobufCFieldDescriptor *field, ...@@ -288,11 +288,11 @@ optional_field_get_packed_size (const ProtobufCFieldDescriptor *field,
static size_t static size_t
repeated_field_get_packed_size (const ProtobufCFieldDescriptor *field, repeated_field_get_packed_size (const ProtobufCFieldDescriptor *field,
size_t count, size_t count,
void *member) const void *member)
{ {
size_t rv = get_tag_size (field->id) * count; size_t rv = get_tag_size (field->id) * count;
unsigned i; unsigned i;
void *array = * (void **) member; void *array = * (void * const *) member;
switch (field->type) switch (field->type)
{ {
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
...@@ -371,15 +371,15 @@ size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message) ...@@ -371,15 +371,15 @@ size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message)
for (i = 0; i < message->descriptor->n_fields; i++) for (i = 0; i < message->descriptor->n_fields; i++)
{ {
const ProtobufCFieldDescriptor *field = message->descriptor->fields + i; const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
void *member = ((char *) message) + field->offset; const void *member = ((const char *) message) + field->offset;
void *qmember = ((char *) message) + field->quantifier_offset; const void *qmember = ((const char *) message) + field->quantifier_offset;
if (field->label == PROTOBUF_C_LABEL_REQUIRED) if (field->label == PROTOBUF_C_LABEL_REQUIRED)
rv += required_field_get_packed_size (field, member); rv += required_field_get_packed_size (field, member);
else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
rv += optional_field_get_packed_size (field, qmember, member); rv += optional_field_get_packed_size (field, qmember, member);
else else
rv += repeated_field_get_packed_size (field, * (size_t *) qmember, member); rv += repeated_field_get_packed_size (field, * (const size_t *) qmember, member);
} }
for (i = 0; i < message->n_unknown_fields; i++) for (i = 0; i < message->n_unknown_fields; i++)
rv += unknown_field_get_packed_size (&message->unknown_fields[i]); rv += unknown_field_get_packed_size (&message->unknown_fields[i]);
...@@ -533,7 +533,7 @@ static size_t tag_pack (uint32_t id, uint8_t *out) ...@@ -533,7 +533,7 @@ static size_t tag_pack (uint32_t id, uint8_t *out)
} }
static size_t static size_t
required_field_pack (const ProtobufCFieldDescriptor *field, required_field_pack (const ProtobufCFieldDescriptor *field,
void *member, const void *member,
uint8_t *out) uint8_t *out)
{ {
size_t rv = tag_pack (field->id, out); size_t rv = tag_pack (field->id, out);
...@@ -541,43 +541,43 @@ required_field_pack (const ProtobufCFieldDescriptor *field, ...@@ -541,43 +541,43 @@ required_field_pack (const ProtobufCFieldDescriptor *field,
{ {
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
return rv + sint32_pack (*(int32_t *) member, out + rv); return rv + sint32_pack (*(const int32_t *) member, out + rv);
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT32:
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
return rv + int32_pack (*(uint32_t *) member, out + rv); return rv + int32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_ENUM:
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
return rv + uint32_pack (*(uint32_t *) member, out + rv); return rv + uint32_pack (*(const uint32_t *) member, out + rv);
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SINT64:
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
return rv + sint64_pack (*(int64_t *) member, out + rv); return rv + sint64_pack (*(const int64_t *) member, out + rv);
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_UINT64:
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
return rv + uint64_pack (*(uint64_t *) member, out + rv); return rv + uint64_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_FLOAT:
out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT; out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
return rv + fixed32_pack (*(uint64_t *) member, out + rv); return rv + fixed32_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_DOUBLE:
out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT; out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
return rv + fixed64_pack (*(uint64_t *) member, out + rv); return rv + fixed64_pack (*(const uint64_t *) member, out + rv);
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BOOL:
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
return rv + boolean_pack (*(protobuf_c_boolean *) member, out + rv); return rv + boolean_pack (*(const protobuf_c_boolean *) member, out + rv);
case PROTOBUF_C_TYPE_STRING: case PROTOBUF_C_TYPE_STRING:
{ {
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + string_pack (*(char**) member, out + rv); return rv + string_pack (*(char * const *) member, out + rv);
} }
case PROTOBUF_C_TYPE_BYTES: case PROTOBUF_C_TYPE_BYTES:
{ {
const ProtobufCBinaryData * bd = ((ProtobufCBinaryData*) member); const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + binary_data_pack (bd, out + rv); return rv + binary_data_pack (bd, out + rv);
} }
...@@ -585,7 +585,7 @@ required_field_pack (const ProtobufCFieldDescriptor *field, ...@@ -585,7 +585,7 @@ required_field_pack (const ProtobufCFieldDescriptor *field,
case PROTOBUF_C_TYPE_MESSAGE: case PROTOBUF_C_TYPE_MESSAGE:
{ {
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
return rv + prefixed_message_pack (*(ProtobufCMessage **) member, return rv + prefixed_message_pack (*(ProtobufCMessage * const *) member,
out + rv); out + rv);
} }
} }
...@@ -595,13 +595,13 @@ required_field_pack (const ProtobufCFieldDescriptor *field, ...@@ -595,13 +595,13 @@ required_field_pack (const ProtobufCFieldDescriptor *field,
static size_t static size_t
optional_field_pack (const ProtobufCFieldDescriptor *field, optional_field_pack (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has, const protobuf_c_boolean *has,
void *member, const void *member,
uint8_t *out) uint8_t *out)
{ {
if (field->type == PROTOBUF_C_TYPE_MESSAGE if (field->type == PROTOBUF_C_TYPE_MESSAGE
|| field->type == PROTOBUF_C_TYPE_STRING) || field->type == PROTOBUF_C_TYPE_STRING)
{ {
if (*(void**)member == NULL) if (*(void * const *)member == NULL)
return 0; return 0;
} }
else else
...@@ -646,10 +646,10 @@ static inline size_t sizeof_elt_in_repeated_array (ProtobufCType type) ...@@ -646,10 +646,10 @@ static inline size_t sizeof_elt_in_repeated_array (ProtobufCType type)
static size_t static size_t
repeated_field_pack (const ProtobufCFieldDescriptor *field, repeated_field_pack (const ProtobufCFieldDescriptor *field,
size_t count, size_t count,
void *member, const void *member,
uint8_t *out) uint8_t *out)
{ {
char *array = * (char **) member; char *array = * (char * const *) member;
size_t siz; size_t siz;
unsigned i; unsigned i;
size_t rv = 0; size_t rv = 0;
...@@ -680,15 +680,15 @@ size_t protobuf_c_message_pack (const ProtobufCMessage *message, ...@@ -680,15 +680,15 @@ size_t protobuf_c_message_pack (const ProtobufCMessage *message,
for (i = 0; i < message->descriptor->n_fields; i++) for (i = 0; i < message->descriptor->n_fields; i++)
{ {
const ProtobufCFieldDescriptor *field = message->descriptor->fields + i; const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
void *member = ((char *) message) + field->offset; const void *member = ((const char *) message) + field->offset;
void *qmember = ((char *) message) + field->quantifier_offset; const void *qmember = ((const char *) message) + field->quantifier_offset;
if (field->label == PROTOBUF_C_LABEL_REQUIRED) if (field->label == PROTOBUF_C_LABEL_REQUIRED)
rv += required_field_pack (field, member, out + rv); rv += required_field_pack (field, member, out + rv);
else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
rv += optional_field_pack (field, qmember, member, out + rv); rv += optional_field_pack (field, qmember, member, out + rv);
else else
rv += repeated_field_pack (field, * (size_t *) qmember, member, out + rv); rv += repeated_field_pack (field, * (const size_t *) qmember, member, out + rv);
} }
for (i = 0; i < message->n_unknown_fields; i++) for (i = 0; i < message->n_unknown_fields; i++)
rv += unknown_field_pack (&message->unknown_fields[i], out + rv); rv += unknown_field_pack (&message->unknown_fields[i], out + rv);
...@@ -698,7 +698,7 @@ size_t protobuf_c_message_pack (const ProtobufCMessage *message, ...@@ -698,7 +698,7 @@ size_t protobuf_c_message_pack (const ProtobufCMessage *message,
/* === pack_to_buffer() === */ /* === pack_to_buffer() === */
static size_t static size_t
required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
void *member, const void *member,
ProtobufCBuffer *buffer) ProtobufCBuffer *buffer)
{ {
size_t rv; size_t rv;
...@@ -708,64 +708,64 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, ...@@ -708,64 +708,64 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
{ {
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
rv += sint32_pack (*(int32_t *) member, scratch + rv); rv += sint32_pack (*(const int32_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT32:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
rv += int32_pack (*(uint32_t *) member, scratch + rv); rv += int32_pack (*(const uint32_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_ENUM:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
rv += uint32_pack (*(uint32_t *) member, scratch + rv); rv += uint32_pack (*(const uint32_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SINT64:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
rv += sint64_pack (*(int64_t *) member, scratch + rv); rv += sint64_pack (*(const int64_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_UINT64:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
rv += uint64_pack (*(uint64_t *) member, scratch + rv); rv += uint64_pack (*(const uint64_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_FLOAT:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
rv += fixed32_pack (*(uint64_t *) member, scratch + rv); rv += fixed32_pack (*(const uint64_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_DOUBLE:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
rv += fixed64_pack (*(uint64_t *) member, scratch + rv); rv += fixed64_pack (*(const uint64_t *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BOOL:
scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; scratch[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
rv += boolean_pack (*(protobuf_c_boolean *) member, scratch + rv); rv += boolean_pack (*(const protobuf_c_boolean *) member, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
break; break;
case PROTOBUF_C_TYPE_STRING: case PROTOBUF_C_TYPE_STRING:
{ {
size_t sublen = strlen (*(char **) member); size_t sublen = strlen (*(char * const *) member);
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
rv += uint32_pack (sublen, scratch + rv); rv += uint32_pack (sublen, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
buffer->append (buffer, sublen, *(uint8_t**)member); buffer->append (buffer, sublen, *(uint8_t * const *)member);
rv += sublen; rv += sublen;
break; break;
} }
case PROTOBUF_C_TYPE_BYTES: case PROTOBUF_C_TYPE_BYTES:
{ {
const ProtobufCBinaryData * bd = ((ProtobufCBinaryData*) member); const ProtobufCBinaryData * bd = ((const ProtobufCBinaryData*) member);
size_t sublen = bd->len; size_t sublen = bd->len;
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
rv += uint32_pack (sublen, scratch + rv); rv += uint32_pack (sublen, scratch + rv);
...@@ -782,7 +782,7 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, ...@@ -782,7 +782,7 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
ProtobufCBufferSimple simple_buffer ProtobufCBufferSimple simple_buffer
= PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch); = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_buffer_scratch);
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
sublen = protobuf_c_message_pack_to_buffer (*(ProtobufCMessage **) member, sublen = protobuf_c_message_pack_to_buffer (*(ProtobufCMessage * const *) member,
&simple_buffer.base); &simple_buffer.base);
rv += uint32_pack (sublen, scratch + rv); rv += uint32_pack (sublen, scratch + rv);
buffer->append (buffer, rv, scratch); buffer->append (buffer, rv, scratch);
...@@ -799,13 +799,13 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, ...@@ -799,13 +799,13 @@ required_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
static size_t static size_t
optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
const protobuf_c_boolean *has, const protobuf_c_boolean *has,
void *member, const void *member,
ProtobufCBuffer *buffer) ProtobufCBuffer *buffer)
{ {
if (field->type == PROTOBUF_C_TYPE_MESSAGE if (field->type == PROTOBUF_C_TYPE_MESSAGE
|| field->type == PROTOBUF_C_TYPE_STRING) || field->type == PROTOBUF_C_TYPE_STRING)
{ {
if (*(void**)member == NULL) if (*(void * const *)member == NULL)
return 0; return 0;
} }
else else
...@@ -819,10 +819,10 @@ optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, ...@@ -819,10 +819,10 @@ optional_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
static size_t static size_t
repeated_field_pack_to_buffer (const ProtobufCFieldDescriptor *field, repeated_field_pack_to_buffer (const ProtobufCFieldDescriptor *field,
unsigned count, unsigned count,
void *member, const void *member,
ProtobufCBuffer *buffer) ProtobufCBuffer *buffer)
{ {
char *array = * (char **) member; char *array = * (char * const *) member;
size_t siz; size_t siz;
unsigned i; unsigned i;
/* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */ /* CONSIDER: optimize this case a bit (by putting the loop inside the switch) */
...@@ -858,15 +858,15 @@ protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message, ...@@ -858,15 +858,15 @@ protobuf_c_message_pack_to_buffer (const ProtobufCMessage *message,
for (i = 0; i < message->descriptor->n_fields; i++) for (i = 0; i < message->descriptor->n_fields; i++)
{ {
const ProtobufCFieldDescriptor *field = message->descriptor->fields + i; const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
void *member = ((char *) message) + field->offset; const void *member = ((const char *) message) + field->offset;
void *qmember = ((char *) message) + field->quantifier_offset; const void *qmember = ((const char *) message) + field->quantifier_offset;
if (field->label == PROTOBUF_C_LABEL_REQUIRED) if (field->label == PROTOBUF_C_LABEL_REQUIRED)
rv += required_field_pack_to_buffer (field, member, buffer); rv += required_field_pack_to_buffer (field, member, buffer);
else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) else if (field->label == PROTOBUF_C_LABEL_OPTIONAL)
rv += optional_field_pack_to_buffer (field, qmember, member, buffer); rv += optional_field_pack_to_buffer (field, qmember, member, buffer);
else else
rv += repeated_field_pack_to_buffer (field, * (size_t *) qmember, member, buffer); rv += repeated_field_pack_to_buffer (field, * (const size_t *) qmember, member, buffer);
} }
for (i = 0; i < message->n_unknown_fields; i++) for (i = 0; i < message->n_unknown_fields; i++)
rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer); rv += unknown_field_pack_to_buffer (&message->unknown_fields[i], buffer);
...@@ -1309,17 +1309,17 @@ protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc, ...@@ -1309,17 +1309,17 @@ protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
if (last_field->id != tag) if (last_field->id != tag)
{ {
/* lookup field */ /* lookup field */
int rv = int_range_lookup (desc->n_field_ranges, int field_index = int_range_lookup (desc->n_field_ranges,
desc->field_ranges, desc->field_ranges,
tag); tag);
if (rv < 0) if (field_index < 0)
{ {
field = NULL; field = NULL;
n_unknown++; n_unknown++;
} }
else else
{ {
field = desc->fields + rv; field = desc->fields + field_index;
last_field = field; last_field = field;
} }
} }
......
...@@ -207,21 +207,21 @@ GenerateHelperFunctionDefinitions(io::Printer* printer) ...@@ -207,21 +207,21 @@ GenerateHelperFunctionDefinitions(io::Printer* printer)
" (const $classname$ *message)\n" " (const $classname$ *message)\n"
"{\n" "{\n"
" PROTOBUF_C_ASSERT (message->base.descriptor == &$lcclassname$__descriptor);\n" " PROTOBUF_C_ASSERT (message->base.descriptor == &$lcclassname$__descriptor);\n"
" return protobuf_c_message_get_packed_size ((ProtobufCMessage*)(message));\n" " return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));\n"
"}\n" "}\n"
"size_t $lcclassname$__pack\n" "size_t $lcclassname$__pack\n"
" (const $classname$ *message,\n" " (const $classname$ *message,\n"
" uint8_t *out)\n" " uint8_t *out)\n"
"{\n" "{\n"
" PROTOBUF_C_ASSERT (message->base.descriptor == &$lcclassname$__descriptor);\n" " PROTOBUF_C_ASSERT (message->base.descriptor == &$lcclassname$__descriptor);\n"
" return protobuf_c_message_pack ((ProtobufCMessage*)message, out);\n" " return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);\n"
"}\n" "}\n"
"size_t $lcclassname$__pack_to_buffer\n" "size_t $lcclassname$__pack_to_buffer\n"
" (const $classname$ *message,\n" " (const $classname$ *message,\n"
" ProtobufCBuffer *buffer)\n" " ProtobufCBuffer *buffer)\n"
"{\n" "{\n"
" PROTOBUF_C_ASSERT (message->base.descriptor == &$lcclassname$__descriptor);\n" " PROTOBUF_C_ASSERT (message->base.descriptor == &$lcclassname$__descriptor);\n"
" return protobuf_c_message_pack_to_buffer ((ProtobufCMessage*)message, buffer);\n" " return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);\n"
"}\n" "}\n"
"$classname$ *\n" "$classname$ *\n"
" $lcclassname$__unpack\n" " $lcclassname$__unpack\n"
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
namespace google { namespace google {
......
...@@ -53,7 +53,7 @@ TEST_ENUM_TYPE_NAME enum_random[] = { ...@@ -53,7 +53,7 @@ TEST_ENUM_TYPE_NAME enum_random[] = {
T(0), T(2097152), T(268435455), T(127), T(16383), T(16384) }; T(0), T(2097152), T(268435455), T(127), T(16383), T(16384) };
#undef T #undef T
const char *repeated_strings_0[] = { "onestring" }; char *repeated_strings_0[] = { "onestring" };
const char *repeated_strings_1[] = { "two", "string" }; char *repeated_strings_1[] = { "two", "string" };
const char *repeated_strings_2[] = { "many", "tiny", "little", "strings", "should", "be", "handled" }; char *repeated_strings_2[] = { "many", "tiny", "little", "strings", "should", "be", "handled" };
const char *repeated_strings_3[] = { "one very long strings XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }; char *repeated_strings_3[] = { "one very long strings XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment