aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/optional/capi/ext
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 15:56:33 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 15:56:33 +0000
commit6479a0163aa798ae379962c6b52f6410b11995cc (patch)
tree2a63962dc9a2f66cbb4804b4d2bc4680ed00ab3b /spec/rubyspec/optional/capi/ext
parent938465beb05d481b424e9b06a19124c22a881ee0 (diff)
downloadruby-6479a0163aa798ae379962c6b52f6410b11995cc.tar.gz
Update to ruby/spec@a4bc1d8
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/optional/capi/ext')
-rw-r--r--spec/rubyspec/optional/capi/ext/fixnum_spec.c20
-rw-r--r--spec/rubyspec/optional/capi/ext/gc_spec.c11
-rw-r--r--spec/rubyspec/optional/capi/ext/hash_spec.c10
-rw-r--r--spec/rubyspec/optional/capi/ext/proc_spec.c20
-rw-r--r--spec/rubyspec/optional/capi/ext/range_spec.c19
-rw-r--r--spec/rubyspec/optional/capi/ext/rubyspec.h10
-rw-r--r--spec/rubyspec/optional/capi/ext/st_spec.c82
-rw-r--r--spec/rubyspec/optional/capi/ext/string_spec.c20
8 files changed, 189 insertions, 3 deletions
diff --git a/spec/rubyspec/optional/capi/ext/fixnum_spec.c b/spec/rubyspec/optional/capi/ext/fixnum_spec.c
index 49dd039c52..78d452f936 100644
--- a/spec/rubyspec/optional/capi/ext/fixnum_spec.c
+++ b/spec/rubyspec/optional/capi/ext/fixnum_spec.c
@@ -5,23 +5,37 @@
extern "C" {
#endif
+static VALUE fixnum_spec_FIX2INT(VALUE self, VALUE value) {
+ int i = FIX2INT(value);
+ return INT2NUM(i);
+}
+
+static VALUE fixnum_spec_FIX2UINT(VALUE self, VALUE value) {
+ unsigned int i = FIX2UINT(value);
+ return UINT2NUM(i);
+}
+
#ifdef HAVE_RB_FIX2UINT
static VALUE fixnum_spec_rb_fix2uint(VALUE self, VALUE value) {
- return INT2FIX(rb_fix2uint(value));
+ unsigned int i = rb_fix2uint(value);
+ return UINT2NUM(i);
}
#endif
#ifdef HAVE_RB_FIX2INT
static VALUE fixnum_spec_rb_fix2int(VALUE self, VALUE value) {
- return INT2FIX(rb_fix2int(value));
+ int i = rb_fix2int(value);
+ return INT2NUM(i);
}
#endif
-
void Init_fixnum_spec(void) {
VALUE cls;
cls = rb_define_class("CApiFixnumSpecs", rb_cObject);
+ rb_define_method(cls, "FIX2INT", fixnum_spec_FIX2INT, 1);
+ rb_define_method(cls, "FIX2UINT", fixnum_spec_FIX2UINT, 1);
+
#ifdef HAVE_RB_FIX2UINT
rb_define_method(cls, "rb_fix2uint", fixnum_spec_rb_fix2uint, 1);
#endif
diff --git a/spec/rubyspec/optional/capi/ext/gc_spec.c b/spec/rubyspec/optional/capi/ext/gc_spec.c
index c5895eb0aa..05341bb01d 100644
--- a/spec/rubyspec/optional/capi/ext/gc_spec.c
+++ b/spec/rubyspec/optional/capi/ext/gc_spec.c
@@ -30,6 +30,13 @@ static VALUE gc_spec_rb_gc_disable() {
}
#endif
+#ifdef HAVE_RB_GC
+static VALUE gc_spec_rb_gc() {
+ rb_gc();
+ return Qnil;
+}
+#endif
+
void Init_gc_spec(void) {
VALUE cls;
@@ -54,6 +61,10 @@ void Init_gc_spec(void) {
rb_define_method(cls, "rb_gc_disable", gc_spec_rb_gc_disable, 0);
#endif
+#ifdef HAVE_RB_GC
+ rb_define_method(cls, "rb_gc", gc_spec_rb_gc, 0);
+#endif
+
}
#ifdef __cplusplus
diff --git a/spec/rubyspec/optional/capi/ext/hash_spec.c b/spec/rubyspec/optional/capi/ext/hash_spec.c
index ac45003844..73e7ef5c13 100644
--- a/spec/rubyspec/optional/capi/ext/hash_spec.c
+++ b/spec/rubyspec/optional/capi/ext/hash_spec.c
@@ -23,6 +23,12 @@ VALUE hash_spec_rb_hash_dup(VALUE self, VALUE hash) {
}
#endif
+#ifdef HAVE_RB_HASH_FETCH
+VALUE hash_spec_rb_hash_fetch(VALUE self, VALUE hash, VALUE key) {
+ return rb_hash_fetch(hash, key);
+}
+#endif
+
#ifdef HAVE_RB_HASH_FREEZE
VALUE hash_spec_rb_hash_freeze(VALUE self, VALUE hash) {
return rb_hash_freeze(hash);
@@ -175,6 +181,10 @@ void Init_hash_spec(void) {
rb_define_method(cls, "rb_hash_delete_if", hash_spec_rb_hash_delete_if, 1);
#endif
+#ifdef HAVE_RB_HASH_FETCH
+ rb_define_method(cls, "rb_hash_fetch", hash_spec_rb_hash_fetch, 2);
+#endif
+
#ifdef HAVE_RB_HASH_FOREACH
rb_define_method(cls, "rb_hash_foreach", hash_spec_rb_hash_foreach, 1);
rb_define_method(cls, "rb_hash_foreach_stop", hash_spec_rb_hash_foreach_stop, 1);
diff --git a/spec/rubyspec/optional/capi/ext/proc_spec.c b/spec/rubyspec/optional/capi/ext/proc_spec.c
index b7a47536d9..f9c0f6b1b9 100644
--- a/spec/rubyspec/optional/capi/ext/proc_spec.c
+++ b/spec/rubyspec/optional/capi/ext/proc_spec.c
@@ -17,6 +17,18 @@ VALUE proc_spec_rb_proc_new(VALUE self) {
}
#endif
+#ifdef HAVE_RB_PROC_ARITY
+VALUE proc_spec_rb_proc_arity(VALUE self, VALUE prc) {
+ return INT2FIX(rb_proc_arity(prc));
+}
+#endif
+
+#ifdef HAVE_RB_PROC_CALL
+VALUE proc_spec_rb_proc_call(VALUE self, VALUE prc, VALUE args) {
+ return rb_proc_call(prc, args);
+}
+#endif
+
/* This helper is not strictly necessary but reflects the code in wxRuby that
* originally exposed issues with this Proc.new behavior.
*/
@@ -57,6 +69,14 @@ void Init_proc_spec(void) {
rb_define_method(cls, "rb_proc_new", proc_spec_rb_proc_new, 0);
#endif
+#ifdef HAVE_RB_PROC_ARITY
+ rb_define_method(cls, "rb_proc_arity", proc_spec_rb_proc_arity, 1);
+#endif
+
+#ifdef HAVE_RB_PROC_CALL
+ rb_define_method(cls, "rb_proc_call", proc_spec_rb_proc_call, 2);
+#endif
+
rb_define_method(cls, "rb_Proc_new", proc_spec_rb_Proc_new, 1);
}
diff --git a/spec/rubyspec/optional/capi/ext/range_spec.c b/spec/rubyspec/optional/capi/ext/range_spec.c
index 02aff5a5c2..46ee88a85d 100644
--- a/spec/rubyspec/optional/capi/ext/range_spec.c
+++ b/spec/rubyspec/optional/capi/ext/range_spec.c
@@ -29,6 +29,21 @@ VALUE range_spec_rb_range_values(VALUE self, VALUE range) {
}
#endif
+#ifdef HAVE_RB_RANGE_BEG_LEN
+VALUE range_spec_rb_range_beg_len(VALUE self, VALUE range, VALUE begpv, VALUE lenpv, VALUE lenv, VALUE errv) {
+ long begp = FIX2LONG(begpv);
+ long lenp = FIX2LONG(lenpv);
+ long len = FIX2LONG(lenv);
+ long err = FIX2LONG(errv);
+ VALUE ary = rb_ary_new();
+ VALUE res = rb_range_beg_len(range, &begp, &lenp, len, err);
+ rb_ary_store(ary, 0, LONG2FIX(begp));
+ rb_ary_store(ary, 1, LONG2FIX(lenp));
+ rb_ary_store(ary, 2, res);
+ return ary;
+}
+#endif
+
void Init_range_spec(void) {
VALUE cls;
cls = rb_define_class("CApiRangeSpecs", rb_cObject);
@@ -40,6 +55,10 @@ void Init_range_spec(void) {
#ifdef HAVE_RB_RANGE_VALUES
rb_define_method(cls, "rb_range_values", range_spec_rb_range_values, 1);
#endif
+
+#ifdef HAVE_RB_RANGE_BEG_LEN
+ rb_define_method(cls, "rb_range_beg_len", range_spec_rb_range_beg_len, 5);
+#endif
}
#ifdef __cplusplus
diff --git a/spec/rubyspec/optional/capi/ext/rubyspec.h b/spec/rubyspec/optional/capi/ext/rubyspec.h
index 9cba34b888..8866e39af4 100644
--- a/spec/rubyspec/optional/capi/ext/rubyspec.h
+++ b/spec/rubyspec/optional/capi/ext/rubyspec.h
@@ -299,6 +299,7 @@
#define HAVE_RB_HASH_CLEAR 1
#define HAVE_RB_HASH_DELETE 1
#define HAVE_RB_HASH_DELETE_IF 1
+#define HAVE_RB_HASH_FETCH 1
#define HAVE_RB_HASH_FOREACH 1
#define HAVE_RB_HASH_LOOKUP 1
#define HAVE_RB_HASH_LOOKUP2 1
@@ -372,6 +373,7 @@
#define HAVE_RB_GC_REGISTER_ADDRESS 1
#define HAVE_RB_GC_ENABLE 1
#define HAVE_RB_GC_DISABLE 1
+#define HAVE_RB_GC 1
/* Marshal */
#define HAVE_RB_MARSHAL_DUMP 1
@@ -476,10 +478,13 @@
/* Proc */
#define HAVE_RB_PROC_NEW 1
+#define HAVE_RB_PROC_ARITY 1
+#define HAVE_RB_PROC_CALL 1
/* Range */
#define HAVE_RB_RANGE_NEW 1
#define HAVE_RB_RANGE_VALUES 1
+#define HAVE_RB_RANGE_BEG_LEN 1
/* Rational */
#define HAVE_RB_RATIONAL 1
@@ -499,6 +504,9 @@
#define HAVE_RB_REG_OPTIONS 1
#define HAVE_RB_REG_REGCOMP 1
+/* st */
+#define HAVE_RB_ST 1
+
/* String */
#define HAVE_RB_CSTR2INUM 1
#define HAVE_RB_CSTR_TO_INUM 1
@@ -522,6 +530,8 @@
#define HAVE_RB_STR_NEW3 1
#define HAVE_RB_STR_NEW4 1
#define HAVE_RB_STR_NEW5 1
+#define HAVE_RB_TAINTED_STR_NEW 1
+#define HAVE_RB_TAINTED_STR_NEW2 1
#define HAVE_RB_STR_PLUS 1
#define HAVE_RB_STR_TIMES 1
#define HAVE_RB_STR_RESIZE 1
diff --git a/spec/rubyspec/optional/capi/ext/st_spec.c b/spec/rubyspec/optional/capi/ext/st_spec.c
new file mode 100644
index 0000000000..ea2d81964d
--- /dev/null
+++ b/spec/rubyspec/optional/capi/ext/st_spec.c
@@ -0,0 +1,82 @@
+#include "ruby.h"
+#include "rubyspec.h"
+
+#include <string.h>
+#include <stdarg.h>
+
+#ifdef HAVE_RB_ST
+#include <ruby/st.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_RB_ST
+VALUE st_spec_st_init_numtable(VALUE self) {
+ st_table *tbl = st_init_numtable();
+ int entries = tbl->num_entries;
+ st_free_table(tbl);
+ return INT2FIX(entries);
+}
+
+VALUE st_spec_st_init_numtable_with_size(VALUE self) {
+ st_table *tbl = st_init_numtable_with_size(128);
+ int entries = tbl->num_entries;
+ st_free_table(tbl);
+ return INT2FIX(entries);
+}
+
+VALUE st_spec_st_insert(VALUE self) {
+ int entries;
+ st_table *tbl = st_init_numtable_with_size(128);
+ st_insert(tbl, 1, 1);
+ entries = tbl->num_entries;
+ st_free_table(tbl);
+ return INT2FIX(entries);
+}
+
+static int sum(st_data_t key, st_data_t value, st_data_t arg) {
+ *(int*)arg += value;
+ return ST_CONTINUE;
+}
+
+VALUE st_spec_st_foreach(VALUE self) {
+ int total = 0;
+ st_table *tbl = st_init_numtable_with_size(128);
+ st_insert(tbl, 1, 3);
+ st_insert(tbl, 2, 4);
+ st_foreach(tbl, sum, (st_data_t)&total);
+ st_free_table(tbl);
+ return INT2FIX(total);
+}
+
+VALUE st_spec_st_lookup(VALUE self) {
+ st_data_t result = (st_data_t)0;
+ st_table *tbl = st_init_numtable_with_size(128);
+ st_insert(tbl, 7, 42);
+ st_insert(tbl, 2, 4);
+ st_lookup(tbl, (st_data_t)7, &result);
+ st_free_table(tbl);
+ return INT2FIX(result);
+}
+
+#endif
+
+void Init_st_spec(void) {
+ VALUE cls;
+ cls = rb_define_class("CApiStSpecs", rb_cObject);
+
+#ifdef HAVE_RB_ST
+ rb_define_method(cls, "st_init_numtable", st_spec_st_init_numtable, 0);
+ rb_define_method(cls, "st_init_numtable_with_size", st_spec_st_init_numtable_with_size, 0);
+ rb_define_method(cls, "st_insert", st_spec_st_insert, 0);
+ rb_define_method(cls, "st_foreach", st_spec_st_foreach, 0);
+ rb_define_method(cls, "st_lookup", st_spec_st_lookup, 0);
+#endif
+
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/rubyspec/optional/capi/ext/string_spec.c b/spec/rubyspec/optional/capi/ext/string_spec.c
index 69e66fbde1..0568b42212 100644
--- a/spec/rubyspec/optional/capi/ext/string_spec.c
+++ b/spec/rubyspec/optional/capi/ext/string_spec.c
@@ -257,6 +257,18 @@ VALUE string_spec_rb_str_new5(VALUE self, VALUE str, VALUE ptr, VALUE len) {
}
#endif
+#ifdef HAVE_RB_TAINTED_STR_NEW
+VALUE string_spec_rb_tainted_str_new(VALUE self, VALUE str, VALUE len) {
+ return rb_tainted_str_new(RSTRING_PTR(str), FIX2INT(len));
+}
+#endif
+
+#ifdef HAVE_RB_TAINTED_STR_NEW2
+VALUE string_spec_rb_tainted_str_new2(VALUE self, VALUE str) {
+ return rb_tainted_str_new2(RSTRING_PTR(str));
+}
+#endif
+
#ifdef HAVE_RB_STR_PLUS
VALUE string_spec_rb_str_plus(VALUE self, VALUE str1, VALUE str2) {
return rb_str_plus(str1, str2);
@@ -564,6 +576,14 @@ void Init_string_spec(void) {
rb_define_method(cls, "rb_str_new5", string_spec_rb_str_new5, 3);
#endif
+#ifdef HAVE_RB_TAINTED_STR_NEW
+ rb_define_method(cls, "rb_tainted_str_new", string_spec_rb_tainted_str_new, 2);
+#endif
+
+#ifdef HAVE_RB_TAINTED_STR_NEW2
+ rb_define_method(cls, "rb_tainted_str_new2", string_spec_rb_tainted_str_new2, 1);
+#endif
+
#ifdef HAVE_RB_STR_PLUS
rb_define_method(cls, "rb_str_plus", string_spec_rb_str_plus, 2);
#endif