raise a more clear exception for range error on Fixnums on 64-bit

This commit is contained in:
Mike Dirolf 2009-08-03 11:08:10 -04:00
parent 5dc64d8c1d
commit 2e4a7f153f
1 changed files with 5 additions and 0 deletions

View File

@ -198,6 +198,11 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
case T_FIXNUM:
{
int int_value = FIX2INT(value);
if (rb_funcall(value, rb_intern(">"), 1, INT2NUM(2147483647)) == Qtrue ||
rb_funcall(value, rb_intern("<"), 1, INT2NUM(-2147483648)) == Qtrue) {
rb_raise(rb_eRangeError, "MongoDB can only handle 4-byte ints"
" - try converting to a double before saving");
}
write_name_and_type(buffer, key, 0x10);
buffer_write_bytes(buffer, (char*)&int_value, 4);
break;