vondruch / rpms / ruby

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