Project

General

Profile

Bug #8312 » fix_hash_shift.diff

funny_falcon (Yura Sokolov), 04/23/2013 11:45 PM

View differences:

hash.c
};
static int
shift_i(VALUE key, VALUE value, VALUE arg)
{
struct shift_var *var = (struct shift_var *)arg;
if (var->key != Qundef) return ST_STOP;
var->key = key;
var->val = value;
return ST_DELETE;
}
static int
shift_i_safe(VALUE key, VALUE value, VALUE arg)
{
struct shift_var *var = (struct shift_var *)arg;
......
rb_hash_modify_check(hash);
if (RHASH(hash)->ntbl) {
var.key = Qundef;
rb_hash_foreach(hash, RHASH_ITER_LEV(hash) > 0 ? shift_i_safe : shift_i,
(VALUE)&var);
rb_hash_foreach(hash, shift_i_safe, (VALUE)&var);
if (var.key != Qundef) {
if (RHASH_ITER_LEV(hash) > 0) {
rb_hash_delete_key(hash, var.key);
}
rb_hash_delete_key(hash, var.key);
return rb_assoc_new(var.key, var.val);
}
}
(1-1/3)