Skip to content

Commit 581b200

Browse files
committed
small cleanups
1 parent 1164b40 commit 581b200

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

build_config.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
MRuby::Build.new do |conf|
22
toolchain :gcc
33
enable_debug
4-
# conf.enable_sanitizer "address,undefined"
4+
conf.enable_sanitizer "address,undefined"
55
conf.cc.flags << '-fno-omit-frame-pointer'
6-
# conf.enable_debug
6+
conf.enable_debug
77
conf.enable_test
88
conf.gembox 'default'
99
conf.gem File.expand_path(File.dirname(__FILE__))

src/mrb_msgpack.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ static void mrb_msgpack_pack_hash_value(mrb_state* mrb, mrb_value self, Packer&
119119
mrb_int arena_index = mrb_gc_arena_save(mrb);
120120

121121
struct Ctx {
122-
mrb_state* mrb;
123122
Packer* pk;
124123
mrb_int arena_index;
125-
} ctx{mrb, &pk, arena_index};
124+
} ctx{&pk, arena_index};
126125

127126
mrb_hash_foreach(mrb, mrb_hash_ptr(self),
128127
[](mrb_state* mrb, mrb_value key, mrb_value val, void* data) -> int {
@@ -438,11 +437,9 @@ mrb_unpack_msgpack_obj(mrb_state* mrb, const msgpack::object& obj)
438437
return mrb_convert_number(mrb, obj.via.u64);
439438
case msgpack::type::NEGATIVE_INTEGER:
440439
return mrb_convert_number(mrb, obj.via.i64);
441-
#ifndef MRB_WITHOUT_FLOAT
442440
case msgpack::type::FLOAT32:
443441
case msgpack::type::FLOAT64:
444442
return mrb_convert_number(mrb, obj.via.f64);
445-
#endif
446443
case msgpack::type::STR:
447444
return mrb_str_new(mrb, obj.via.str.ptr, obj.via.str.size);
448445
case msgpack::type::BIN:
@@ -452,7 +449,7 @@ mrb_unpack_msgpack_obj(mrb_state* mrb, const msgpack::object& obj)
452449
case msgpack::type::MAP:
453450
return mrb_unpack_msgpack_obj_map(mrb, obj);
454451
case msgpack::type::EXT: {
455-
auto ext_type = mrb_convert_number(mrb, obj.via.ext.type());
452+
auto ext_type = obj.via.ext.type();
456453
#ifdef MRB_MSGPACK_SYMBOLS
457454
if (ext_type == MRB_MSGPACK_SYMBOLS_EXT) {
458455
# ifdef MRB_MSGPACK_SYMBOLS_AS_INT
@@ -473,7 +470,7 @@ mrb_unpack_msgpack_obj(mrb_state* mrb, const msgpack::object& obj)
473470
}
474471
#endif // MRB_MSGPACK_SYMBOLS
475472
mrb_value unpacker = mrb_hash_get(mrb,
476-
mrb_const_get(mrb, mrb_obj_value(mrb_module_get_id(mrb, MRB_SYM(MessagePack))), MRB_SYM(_ExtUnpackers)), ext_type);
473+
mrb_const_get(mrb, mrb_obj_value(mrb_module_get_id(mrb, MRB_SYM(MessagePack))), MRB_SYM(_ExtUnpackers)), mrb_convert_number(mrb, ext_type));
477474
if (likely(mrb_type(unpacker) == MRB_TT_PROC)) {
478475
return mrb_yield(mrb, unpacker, mrb_str_new(mrb, obj.via.ext.data(), obj.via.ext.size));
479476
} else {
@@ -588,9 +585,10 @@ mrb_msgpack_object_handle_new(mrb_state *mrb, mrb_value self)
588585
static mrb_value
589586
mrb_msgpack_object_handle_value(mrb_state *mrb, mrb_value self)
590587
{
591-
msgpack_object_handle* handle = static_cast<msgpack_object_handle*>(DATA_PTR(self));
588+
msgpack_object_handle* handle = static_cast<msgpack_object_handle*>(mrb_data_get_ptr(mrb, self, &msgpack_object_handle_type));
592589
if (unlikely(!handle)) {
593590
mrb_raise(mrb, E_MSGPACK_ERROR, "ObjectHandle is not initialized");
591+
return mrb_undef_value();
594592
}
595593
return mrb_unpack_msgpack_obj(mrb, handle->oh.get());
596594
}
@@ -604,7 +602,11 @@ mrb_msgpack_unpack_lazy_m(mrb_state *mrb, mrb_value self)
604602

605603
try {
606604
mrb_value object_handle = mrb_obj_new(mrb, mrb_class_get_under_id(mrb, mrb_class_ptr(self), MRB_SYM(ObjectHandle)), 1, &data);
607-
msgpack_object_handle* handle = static_cast<msgpack_object_handle*>(DATA_PTR(object_handle));
605+
msgpack_object_handle* handle = static_cast<msgpack_object_handle*>(mrb_data_get_ptr(mrb, object_handle, &msgpack_object_handle_type));
606+
if (unlikely(!handle)) {
607+
mrb_raise(mrb, E_MSGPACK_ERROR, "ObjectHandle is not initialized");
608+
return mrb_undef_value();
609+
}
608610
msgpack::unpack(handle->oh, RSTRING_PTR(data), RSTRING_LEN(data), handle->off);
609611

610612
return object_handle;
@@ -636,7 +638,7 @@ mrb_msgpack_object_handle_at_pointer(mrb_state *mrb, mrb_value self)
636638
mrb_get_args(mrb, "S", &str);
637639
std::string_view pointer(RSTRING_PTR(str), RSTRING_LEN(str));
638640

639-
auto *handle = static_cast<msgpack_object_handle*>(DATA_PTR(self));
641+
msgpack_object_handle *handle = static_cast<msgpack_object_handle*>(mrb_data_get_ptr(mrb, self, &msgpack_object_handle_type));
640642
if (unlikely(!handle)) {
641643
mrb_raise(mrb, E_MSGPACK_ERROR, "ObjectHandle is not initialized");
642644
return mrb_undef_value();

0 commit comments

Comments
 (0)