Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created December 26, 2016 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frsyuki/b171b99c898d7da0e1a2ca3bd6f8b195 to your computer and use it in GitHub Desktop.
Save frsyuki/b171b99c898d7da0e1a2ca3bd6f8b195 to your computer and use it in GitHub Desktop.
An experimental patch.
diff --git a/ext/msgpack/unpacker.c b/ext/msgpack/unpacker.c
index 8b1f699..6b2f7af 100644
--- a/ext/msgpack/unpacker.c
+++ b/ext/msgpack/unpacker.c
@@ -690,6 +690,12 @@ int msgpack_unpacker_read_map_header(msgpack_unpacker_t* uk, uint32_t* result_si
return 0;
}
+static int hash_update_callback(st_data_t *key, st_data_t *val, st_data_t arg, int existing)
+{
+ *val = (VALUE)arg;
+ return ST_CONTINUE;
+}
+
int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth)
{
while(true) {
@@ -732,7 +738,12 @@ int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth)
#endif
#endif
} else {
- rb_hash_aset(top->object, top->key, uk->last_object);
+ VALUE key = top->key;
+ VALUE value = uk->last_object;
+ if (rb_obj_class(key) == rb_cString) {
+ key = rb_str_new_frozen(key);
+ }
+ st_update(rb_hash_tbl(top->object), (st_data_t)key, hash_update_callback, (st_data_t)value);
}
top->type = STACK_TYPE_MAP_KEY;
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment