[ruby] Fix shorten-64-to-32 errors on macOS
Since the extconf.rb pass `-Werror`, the gem won't compile.
diff --git a/lib/rb/ext/binary_protocol_accelerated.c b/lib/rb/ext/binary_protocol_accelerated.c
index 65cbe5f..c9ae4d2 100644
--- a/lib/rb/ext/binary_protocol_accelerated.c
+++ b/lib/rb/ext/binary_protocol_accelerated.c
@@ -82,7 +82,7 @@
rb_raise(rb_eStandardError, "Value should be a string");
}
str = convert_to_utf8_byte_buffer(str);
- write_i32_direct(trans, RSTRING_LEN(str));
+ write_i32_direct(trans, (int32_t)RSTRING_LEN(str));
rb_funcall(trans, write_method_id, 1, str);
}
@@ -223,7 +223,7 @@
CHECK_NIL(buf);
VALUE trans = GET_TRANSPORT(self);
buf = force_binary_encoding(buf);
- write_i32_direct(trans, RSTRING_LEN(buf));
+ write_i32_direct(trans, (int32_t)RSTRING_LEN(buf));
rb_funcall(trans, write_method_id, 1, buf);
return Qnil;
}
@@ -403,9 +403,9 @@
void Init_binary_protocol_accelerated() {
VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
- VERSION_1 = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_1")));
- VERSION_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_MASK")));
- TYPE_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("TYPE_MASK")));
+ VERSION_1 = (int)rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_1")));
+ VERSION_MASK = (int)rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_MASK")));
+ TYPE_MASK = (int)rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("TYPE_MASK")));
VALUE bpa_class = rb_define_class_under(thrift_module, "BinaryProtocolAccelerated", thrift_binary_protocol_class);
diff --git a/lib/rb/ext/compact_protocol.c b/lib/rb/ext/compact_protocol.c
index fab2170..c98c09e 100644
--- a/lib/rb/ext/compact_protocol.c
+++ b/lib/rb/ext/compact_protocol.c
@@ -315,7 +315,7 @@
VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf) {
buf = force_binary_encoding(buf);
VALUE transport = GET_TRANSPORT(self);
- write_varint32(transport, RSTRING_LEN(buf));
+ write_varint32(transport, (uint32_t)RSTRING_LEN(buf));
WRITE(transport, StringValuePtr(buf), RSTRING_LEN(buf));
return Qnil;
}
@@ -452,7 +452,7 @@
}
int8_t type = (version_and_type >> TYPE_SHIFT_AMOUNT) & TYPE_BITS;
- int32_t seqid = read_varint64(self);
+ int32_t seqid = (int32_t)read_varint64(self);
VALUE messageName = rb_thrift_compact_proto_read_string(self);
return rb_ary_new3(3, messageName, INT2FIX(type), INT2NUM(seqid));
}
@@ -490,7 +490,7 @@
}
VALUE rb_thrift_compact_proto_read_map_begin(VALUE self) {
- int32_t size = read_varint64(self);
+ int32_t size = (int32_t)read_varint64(self);
uint8_t key_and_value_type = size == 0 ? 0 : read_byte_direct(self);
return rb_ary_new3(3, INT2FIX(get_ttype(key_and_value_type >> 4)), INT2FIX(get_ttype(key_and_value_type & 0xf)), INT2FIX(size));
}
@@ -499,7 +499,7 @@
uint8_t size_and_type = read_byte_direct(self);
int32_t size = (size_and_type >> 4) & 0x0f;
if (size == 15) {
- size = read_varint64(self);
+ size = (int32_t)read_varint64(self);
}
uint8_t type = get_ttype(size_and_type & 0x0f);
return rb_ary_new3(2, INT2FIX(type), INT2FIX(size));
@@ -528,7 +528,7 @@
}
VALUE rb_thrift_compact_proto_read_i32(VALUE self) {
- return INT2NUM(zig_zag_to_int(read_varint64(self)));
+ return INT2NUM(zig_zag_to_int((int32_t)read_varint64(self)));
}
VALUE rb_thrift_compact_proto_read_i64(VALUE self) {
@@ -569,10 +569,10 @@
thrift_compact_protocol_class = rb_const_get(thrift_module, rb_intern("CompactProtocol"));
rb_global_variable(&thrift_compact_protocol_class);
- VERSION = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION")));
- VERSION_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION_MASK")));
- TYPE_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_MASK")));
- TYPE_BITS = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_BITS")));
+ VERSION = (int32_t)rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION")));
+ VERSION_MASK = (int32_t)rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION_MASK")));
+ TYPE_MASK = (int32_t)rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_MASK")));
+ TYPE_BITS = (int32_t)rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_BITS")));
TYPE_SHIFT_AMOUNT = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_SHIFT_AMOUNT")));
PROTOCOL_ID = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("PROTOCOL_ID")));
diff --git a/lib/rb/ext/memory_buffer.c b/lib/rb/ext/memory_buffer.c
index 8b52c4a..96604af 100644
--- a/lib/rb/ext/memory_buffer.c
+++ b/lib/rb/ext/memory_buffer.c
@@ -54,7 +54,7 @@
index += length;
if (index > RSTRING_LEN(buf)) {
- index = RSTRING_LEN(buf);
+ index = (int)RSTRING_LEN(buf);
}
if (index >= GARBAGE_BUFFER_SIZE) {
rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c
index 79cbabe..e8255a9 100644
--- a/lib/rb/ext/struct.c
+++ b/lib/rb/ext/struct.c
@@ -225,7 +225,7 @@
}
static void write_container(int ttype, VALUE field_info, VALUE value, VALUE protocol) {
- int sz, i;
+ long sz, i;
if (ttype == TTYPE_MAP) {
VALUE keys;