RUBY-173 better hash class detection for BSON
This commit is contained in:
parent
a867ddd341
commit
7ca4683843
@ -85,6 +85,7 @@ static VALUE InvalidKeyName;
|
|||||||
static VALUE InvalidStringEncoding;
|
static VALUE InvalidStringEncoding;
|
||||||
static VALUE InvalidDocument;
|
static VALUE InvalidDocument;
|
||||||
static VALUE DigestMD5;
|
static VALUE DigestMD5;
|
||||||
|
static VALUE RB_HASH;
|
||||||
|
|
||||||
#if HAVE_RUBY_ENCODING_H
|
#if HAVE_RUBY_ENCODING_H
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
@ -535,7 +536,8 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
allow_id = 1;
|
allow_id = 1;
|
||||||
if (strcmp(rb_obj_classname(hash), "Hash") == 0) {
|
// Ensure that hash doesn't contain both '_id' and :_id
|
||||||
|
if ((rb_obj_classname(hash), "Hash") == 0) {
|
||||||
if ((rb_funcall(hash, rb_intern("has_key?"), 1, id_str) == Qtrue) &&
|
if ((rb_funcall(hash, rb_intern("has_key?"), 1, id_str) == Qtrue) &&
|
||||||
(rb_funcall(hash, rb_intern("has_key?"), 1, id_sym) == Qtrue)) {
|
(rb_funcall(hash, rb_intern("has_key?"), 1, id_sym) == Qtrue)) {
|
||||||
VALUE oid_sym = rb_hash_delete(hash, id_sym);
|
VALUE oid_sym = rb_hash_delete(hash, id_sym);
|
||||||
@ -561,7 +563,7 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_
|
|||||||
|
|
||||||
write_function(key, value, pack_extra(buffer, check_keys));
|
write_function(key, value, pack_extra(buffer, check_keys));
|
||||||
}
|
}
|
||||||
} else if (strncmp(rb_obj_classname(hash), "Hash", 4) == 0) {
|
} else if (rb_obj_is_kind_of(hash, RB_HASH) == Qtrue) {
|
||||||
rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys));
|
rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys));
|
||||||
} else {
|
} else {
|
||||||
buffer_free(buffer);
|
buffer_free(buffer);
|
||||||
@ -932,6 +934,7 @@ void Init_cbson() {
|
|||||||
InvalidDocument = rb_const_get(bson, rb_intern("InvalidDocument"));
|
InvalidDocument = rb_const_get(bson, rb_intern("InvalidDocument"));
|
||||||
rb_require("bson/ordered_hash");
|
rb_require("bson/ordered_hash");
|
||||||
OrderedHash = rb_const_get(bson, rb_intern("OrderedHash"));
|
OrderedHash = rb_const_get(bson, rb_intern("OrderedHash"));
|
||||||
|
RB_HASH = rb_const_get(bson, rb_intern("Hash"));
|
||||||
|
|
||||||
CBson = rb_define_module("CBson");
|
CBson = rb_define_module("CBson");
|
||||||
ext_version = rb_str_new2(VERSION);
|
ext_version = rb_str_new2(VERSION);
|
||||||
|
Loading…
Reference in New Issue
Block a user