rb_hash_has_key() and friends non-static...
From:
Sean Chittenden <sean@...>
Date:
2002-05-29 04:17:13 UTC
List:
ruby-core #86
I'm doing a lot of work with Ruby in C and am using some of Ruby's native data structures inside of my C code (no sense in re-inventing the wheel). I'm finding it is hard to use the data structures without w/o using rb_funcall(). For the major data types, would it be okay if I started removing some of the static declarations for functions to make them globally available? Actually, I was thinking that having a ruby_hash.h with the "publicly available" functions that can be used by external libraries would be very handy for external module developers, IMHO. Ruby has such a rich set of data types to work that it makes writing C cake. Thoughts on the attached? I haven't looked at the install target yet, but wanted to bounce this off of folks 1st. I can go through and expose more of the other major data types if people like this. -sc -- Sean Chittenden
Attachments (1)
patch
(4.9 KB, text/x-diff)
Index: hash.c
===================================================================
RCS file: /src/ruby/hash.c,v
retrieving revision 1.67
diff -u -r1.67 hash.c
--- hash.c 2002/05/21 05:39:18 1.67
+++ hash.c 2002/05/29 04:09:24
@@ -55,19 +55,6 @@
return (VALUE)rb_eql(args[0], args[1]);
}
-static VALUE
-eql_failed()
-{
- return Qfalse;
-}
-
-static VALUE
-any_eql(args)
- VALUE *args;
-{
- return rb_rescue(eql, (VALUE)args, eql_failed, 0);
-}
-
static int
rb_any_cmp(a, b)
VALUE a, b;
@@ -259,7 +246,7 @@
return hash;
}
-static VALUE
+VALUE
rb_hash_clone(hash)
VALUE hash;
{
@@ -287,7 +274,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_rehash(hash)
VALUE hash;
{
@@ -339,7 +326,7 @@
return val;
}
-static VALUE
+VALUE
rb_hash_default(argc, argv, hash)
int argc;
VALUE *argv;
@@ -354,7 +341,7 @@
return RHASH(hash)->ifnone;
}
-static VALUE
+VALUE
rb_hash_set_default(hash, ifnone)
VALUE hash, ifnone;
{
@@ -376,7 +363,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_index(hash, value)
VALUE hash, value;
{
@@ -390,7 +377,7 @@
return args[1];
}
-static VALUE
+VALUE
rb_hash_indexes(argc, argv, hash)
int argc;
VALUE *argv;
@@ -449,7 +436,7 @@
return ST_DELETE;
}
-static VALUE
+VALUE
rb_hash_shift(hash)
VALUE hash;
{
@@ -542,7 +529,7 @@
return ST_DELETE;
}
-static VALUE
+VALUE
rb_hash_clear(hash)
VALUE hash;
{
@@ -577,7 +564,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_replace(hash, hash2)
VALUE hash, hash2;
{
@@ -588,7 +575,7 @@
return hash;
}
-static VALUE
+VALUE
rb_hash_size(hash)
VALUE hash;
{
@@ -664,7 +651,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_to_a(hash)
VALUE hash;
{
@@ -677,7 +664,7 @@
return ary;
}
-static VALUE
+VALUE
rb_hash_sort(hash)
VALUE hash;
{
@@ -721,7 +708,7 @@
return str;
}
-static VALUE
+VALUE
rb_hash_inspect(hash)
VALUE hash;
{
@@ -738,7 +725,7 @@
return rb_ary_to_s(rb_hash_to_a(hash));
}
-static VALUE
+VALUE
rb_hash_to_s(hash)
VALUE hash;
{
@@ -762,7 +749,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_keys(hash)
VALUE hash;
{
@@ -783,7 +770,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_values(hash)
VALUE hash;
{
@@ -795,7 +782,7 @@
return ary;
}
-static VALUE
+VALUE
rb_hash_has_key(hash, key)
VALUE hash;
VALUE key;
@@ -818,7 +805,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_has_value(hash, val)
VALUE hash;
VALUE val;
@@ -855,7 +842,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_equal(hash1, hash2)
VALUE hash1, hash2;
{
@@ -916,7 +903,7 @@
return ST_CONTINUE;
}
-static VALUE
+VALUE
rb_hash_update(hash1, hash2)
VALUE hash1, hash2;
{
Index: intern.h
===================================================================
RCS file: /src/ruby/intern.h,v
retrieving revision 1.88
diff -u -r1.88 intern.h
--- intern.h 2002/04/26 00:40:28 1.88
+++ intern.h 2002/05/29 04:09:24
@@ -219,13 +219,7 @@
VALUE rb_gc_disable _((void));
VALUE rb_gc_start _((void));
/* hash.c */
-VALUE rb_hash _((VALUE));
-VALUE rb_hash_new _((void));
-VALUE rb_hash_freeze _((VALUE));
-VALUE rb_hash_aref _((VALUE, VALUE));
-VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
-VALUE rb_hash_delete_if _((VALUE));
-VALUE rb_hash_delete _((VALUE,VALUE));
+#include "ruby_hash.h"
int rb_path_check _((char*));
int rb_env_path_tainted _((void));
/* io.c */
--- /dev/null Tue May 28 21:08:21 2002
+++ ruby_hash.h Tue May 28 21:01:20 2002
@@ -0,0 +1,40 @@
+#ifndef __RUBY_HASH_H__
+#define __RUBY_HASH_H__
+
+#include "ruby.h"
+
+#define HASH_DELETED FL_USER1
+#define HASH_PROC_DEFAULT FL_USER2
+
+VALUE rb_cHash;
+
+VALUE rb_hash(VALUE obj);
+VALUE rb_hash_freeze(VALUE hash);
+VALUE rb_hash_new();
+VALUE rb_hash_clone(VALUE hash);
+VALUE rb_hash_rehash(VALUE hash);
+VALUE rb_hash_aref(VALUE hash, VALUE key);
+VALUE rb_hash_default(int argc, VALUE *argv, VALUE hash);
+VALUE rb_hash_set_default(VALUE hash, VALUE ifnone);
+VALUE rb_hash_index(VALUE hash, VALUE value);
+VALUE rb_hash_indexes(int argc, VALUE *argv, VALUE hash);
+VALUE rb_hash_delete(VALUE hash, VALUE key);
+VALUE rb_hash_delete_if(VALUE hash);
+VALUE rb_hash_shift(VALUE hash);
+VALUE rb_hash_select(int argc, VALUE *argv, VALUE hash);
+VALUE rb_hash_clear(VALUE hash);
+VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val);
+VALUE rb_hash_replace(VALUE hash, VALUE hash2);
+VALUE rb_hash_size(VALUE hash);
+VALUE rb_hash_to_a(VALUE hash);
+VALUE rb_hash_sort(VALUE hash);
+VALUE rb_hash_inspect(VALUE hash);
+VALUE rb_hash_to_s(VALUE hash);
+VALUE rb_hash_keys(VALUE hash);
+VALUE rb_hash_values(VALUE hash);
+VALUE rb_hash_has_key(VALUE hash, VALUE key);
+VALUE rb_hash_has_value(VALUE hash, VALUE val);
+VALUE rb_hash_equal(VALUE hash1, VALUE hash2);
+VALUE rb_hash_update(VALUE hash1, VALUE hash2);
+
+#endif