ruby/ruby-1.8.x-RHASH_SIZE-rb_hash_lookup-def.patch
Mamoru Tasaka 0ad7b67678 - Patch36 (ruby-1.8.x-RHASH_SIZE-rb_hash_lookup-def.patch) also backport
rb_hash_lookup definition (bug 592936)
2010-05-17 12:50:20 +00:00

66 lines
1.8 KiB
Diff

Sat Apr 19 18:42:04 2008 Akinori MUSHA <knu@iDaemons.org>
* intern.h, hash.c (rb_hash_lookup): New internal function to
check if a key exists in a hash, ignoring #default; backported
from 1.9.
Thu Aug 30 08:24:18 2007 Tanaka Akira <akr@fsij.org>
* ruby.h (RHASH_TBL): defined for compatibility to 1.9.
* (RHASH_ITER_LEV): ditto.
* (RHASH_IFNONE): ditto.
* (RHASH_SIZE): ditto.
* (RHASH_EMPTY_P): ditto.
Index: ruby_1_8/ruby.h
===================================================================
--- ruby_1_8/ruby.h (revision 13310)
+++ ruby_1_8/ruby.h (revision 13311)
@@ -374,6 +374,11 @@
int iter_lev;
VALUE ifnone;
};
+#define RHASH_TBL(h) (RHASH(h)->tbl)
+#define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
+#define RHASH_IFNONE(h) (RHASH(h)->ifnone)
+#define RHASH_SIZE(h) (RHASH(h)->tbl->num_entries)
+#define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0)
struct RFile {
struct RBasic basic;
Index: ruby_1_8/hash.c
===================================================================
--- ruby_1_8/hash.c (revision 16077)
+++ ruby_1_8/hash.c (revision 16078)
@@ -454,6 +454,18 @@
return val;
}
+VALUE
+rb_hash_lookup(hash, key)
+ VALUE hash, key;
+{
+ VALUE val;
+
+ if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
+ return Qnil; /* without Hash#default */
+ }
+ return val;
+}
+
/*
* call-seq:
* hsh.fetch(key [, default] ) => obj
Index: ruby_1_8/intern.h
===================================================================
--- ruby_1_8/intern.h (revision 16077)
+++ ruby_1_8/intern.h (revision 16078)
@@ -270,6 +270,7 @@
VALUE rb_hash_new _((void));
VALUE rb_hash_freeze _((VALUE));
VALUE rb_hash_aref _((VALUE, VALUE));
+VALUE rb_hash_lookup _((VALUE, VALUE));
VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
VALUE rb_hash_delete_if _((VALUE));
VALUE rb_hash_delete _((VALUE,VALUE));