Skip to content

Commit c6fcd39

Browse files
habermanhonglooker
authored andcommitted
Fixed compiler warnings in the Ruby C extension.
PiperOrigin-RevId: 594106078
1 parent 028200c commit c6fcd39

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

ruby/ext/google/protobuf_c/convert.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
208208
}
209209
break;
210210
default:
211-
break;
211+
rb_raise(cTypeError,
212+
"Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
212213
}
213214

214215
return ret;
@@ -296,7 +297,8 @@ bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
296297
if (upb_Status_IsOk(&status)) {
297298
return return_value;
298299
} else {
299-
rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status));
300+
rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s",
301+
upb_Status_ErrorMessage(&status));
300302
}
301303
}
302304

@@ -309,6 +311,7 @@ uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
309311
if (upb_Status_IsOk(&status)) {
310312
return return_value;
311313
} else {
312-
rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status));
314+
rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s",
315+
upb_Status_ErrorMessage(&status));
313316
}
314317
}

ruby/ext/google/protobuf_c/defs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
862862
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
863863
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
864864
const upb_MessageDef* m;
865-
const upb_MessageDef* msg = Message_Get(msg_rb, &m);
865+
const upb_Message* msg = Message_Get(msg_rb, &m);
866866

867867
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
868868
rb_raise(cTypeError, "has method called on wrong message type");
@@ -882,7 +882,7 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
882882
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
883883
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
884884
const upb_MessageDef* m;
885-
upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
885+
upb_Message* msg = Message_GetMutable(msg_rb, &m);
886886

887887
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
888888
rb_raise(cTypeError, "has method called on wrong message type");
@@ -903,7 +903,7 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
903903
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
904904
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
905905
const upb_MessageDef* m;
906-
upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
906+
upb_Message* msg = Message_GetMutable(msg_rb, &m);
907907
upb_Arena* arena = Arena_get(Message_GetArena(msg_rb));
908908
upb_MessageValue msgval;
909909

ruby/ext/google/protobuf_c/map.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
212212
Map* self = ruby_to_Map(_self);
213213
Map* other = ruby_to_Map(hashmap);
214214
upb_Arena* arena = Arena_get(self->arena);
215-
upb_Message* self_msg = Map_GetMutable(_self);
215+
upb_Map* self_map = Map_GetMutable(_self);
216216

217217
Arena_fuse(other->arena, arena);
218218

@@ -225,7 +225,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
225225
size_t iter = kUpb_Map_Begin;
226226
upb_MessageValue key, val;
227227
while (upb_Map_Next(other->map, &key, &val, &iter)) {
228-
upb_Map_Set(self_msg, key, val, arena);
228+
upb_Map_Set(self_map, key, val, arena);
229229
}
230230
} else {
231231
rb_raise(rb_eArgError, "Unknown type merging into Map");

ruby/ext/google/protobuf_c/message.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
488488
k = Convert_RubyToUpb(key, "", map_init->key_type, NULL);
489489

490490
if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) {
491-
upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
491+
const upb_MiniTable* t =
492+
upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
492493
upb_Message* msg = upb_Message_New(t, map_init->arena);
493494
Message_InitFromValue(msg, map_init->val_type.def.msgdef, val,
494495
map_init->arena);
@@ -519,7 +520,7 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info,
519520
upb_Arena* arena) {
520521
if (info.type == kUpb_CType_Message) {
521522
upb_MessageValue msgval;
522-
upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
523+
const upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
523524
upb_Message* msg = upb_Message_New(t, arena);
524525
Message_InitFromValue(msg, info.def.msgdef, val, arena);
525526
msgval.msg_val = msg;
@@ -635,7 +636,7 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
635636
Message* self = ruby_to_Message(_self);
636637
VALUE arena_rb = Arena_new();
637638
upb_Arena* arena = Arena_get(arena_rb);
638-
upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
639+
const upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
639640
upb_Message* msg = upb_Message_New(t, arena);
640641

641642
Message_InitPtr(_self, msg, arena_rb);
@@ -678,7 +679,8 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
678679
if (upb_Status_IsOk(&status)) {
679680
return return_value;
680681
} else {
681-
rb_raise(cParseError, upb_Status_ErrorMessage(&status));
682+
rb_raise(cParseError, "Message_Equal(): %s",
683+
upb_Status_ErrorMessage(&status));
682684
}
683685
}
684686

@@ -709,7 +711,8 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
709711
if (upb_Status_IsOk(&status)) {
710712
return return_value;
711713
} else {
712-
rb_raise(cParseError, upb_Status_ErrorMessage(&status));
714+
rb_raise(cParseError, "Message_Hash(): %s",
715+
upb_Status_ErrorMessage(&status));
713716
}
714717
}
715718

ruby/ext/google/protobuf_c/shared_convert.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "shared_convert.h"
1313

1414
bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
15-
upb_CType type, upb_MessageDef* msgdef,
15+
upb_CType type, const upb_MessageDef* msgdef,
1616
upb_Status* status) {
1717
switch (type) {
1818
case kUpb_CType_Bool:
@@ -39,7 +39,7 @@ bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
3939
}
4040

4141
uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type,
42-
upb_MessageDef* msgdef, uint64_t seed,
42+
const upb_MessageDef* msgdef, uint64_t seed,
4343
upb_Status* status) {
4444
switch (type) {
4545
case kUpb_CType_Bool:
@@ -61,4 +61,4 @@ uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type,
6161
default:
6262
upb_Status_SetErrorMessage(status, "Internal error, unexpected type");
6363
}
64-
}
64+
}

ruby/ext/google/protobuf_c/shared_convert.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#include "shared_message.h"
1717

1818
bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
19-
upb_CType type, upb_MessageDef* msgdef,
19+
upb_CType type, const upb_MessageDef* msgdef,
2020
upb_Status* status);
2121

2222
uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type,
23-
upb_MessageDef* msgdef, uint64_t seed,
23+
const upb_MessageDef* msgdef, uint64_t seed,
2424
upb_Status* status);
2525

2626
#endif // RUBY_PROTOBUF_SHARED_CONVERT_H_

ruby/ext/google/protobuf_c/shared_message.c

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ uint64_t shared_Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
3232
} else {
3333
upb_Arena_Free(arena);
3434
upb_Status_SetErrorMessage(status, "Error calculating hash");
35+
return 0;
3536
}
3637
}
3738

0 commit comments

Comments
 (0)