diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-05-14 11:27:23 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-05-14 11:27:23 +0000 |
commit | aa6e98139c8e1ea442fb2182341aaa08ff55b529 (patch) | |
tree | a509eb830418991995bfe3b840d4bf270ff7f0e2 /ruby_1_9_3/ext/-test- | |
parent | 9e9d191cf367caa17776231a2d0fad0da47b160a (diff) |
add tag v1_9_3_426
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_3_426@40733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_9_3/ext/-test-')
32 files changed, 490 insertions, 0 deletions
diff --git a/ruby_1_9_3/ext/-test-/array/resize/extconf.rb b/ruby_1_9_3/ext/-test-/array/resize/extconf.rb new file mode 100644 index 0000000000..6500a878fc --- /dev/null +++ b/ruby_1_9_3/ext/-test-/array/resize/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/array/resize") diff --git a/ruby_1_9_3/ext/-test-/array/resize/resize.c b/ruby_1_9_3/ext/-test-/array/resize/resize.c new file mode 100644 index 0000000000..08bcee3e7a --- /dev/null +++ b/ruby_1_9_3/ext/-test-/array/resize/resize.c @@ -0,0 +1,14 @@ +#include "ruby/ruby.h" + +static VALUE +ary_resize(VALUE ary, VALUE len) +{ + rb_ary_resize(ary, NUM2LONG(len)); + return ary; +} + +void +Init_resize(void) +{ + rb_define_method(rb_cArray, "__resize__", ary_resize, 1); +} diff --git a/ruby_1_9_3/ext/-test-/bug-3571/bug.c b/ruby_1_9_3/ext/-test-/bug-3571/bug.c new file mode 100644 index 0000000000..72d6bd1021 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/bug-3571/bug.c @@ -0,0 +1,23 @@ +#include <ruby.h> + +static VALUE +bug_i(VALUE i, VALUE arg) +{ + rb_notimplement(); + return ID2SYM(rb_frame_this_func()); +} + +static VALUE +bug_start(VALUE self, VALUE hash) +{ + VALUE ary = rb_ary_new3(1, Qnil); + rb_block_call(ary, rb_intern("map"), 0, 0, bug_i, self); + return ary; +} + +void +Init_bug(void) +{ + VALUE mBug = rb_define_module("Bug"); + rb_define_module_function(mBug, "start", bug_start, 0); +} diff --git a/ruby_1_9_3/ext/-test-/bug-3571/extconf.rb b/ruby_1_9_3/ext/-test-/bug-3571/extconf.rb new file mode 100644 index 0000000000..6390fce219 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/bug-3571/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/bug-3571/bug") diff --git a/ruby_1_9_3/ext/-test-/bug-3662/bug.c b/ruby_1_9_3/ext/-test-/bug-3662/bug.c new file mode 100644 index 0000000000..9375dace10 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/bug-3662/bug.c @@ -0,0 +1,16 @@ +#include <ruby.h> + +static VALUE +bug_funcall(int argc, VALUE *argv, VALUE self) +{ + if (argc < 1) rb_raise(rb_eArgError, "not enough argument"); + return rb_funcall2(self, rb_to_id(*argv), argc-1, argv+1); +} + +void +Init_bug(void) +{ + VALUE mBug = rb_define_module("Bug"); + rb_define_module_function(mBug, "funcall", bug_funcall, -1); + rb_define_module_function(mBug, "notimplement", rb_f_notimplement, -1); +} diff --git a/ruby_1_9_3/ext/-test-/bug-3662/extconf.rb b/ruby_1_9_3/ext/-test-/bug-3662/extconf.rb new file mode 100644 index 0000000000..7a1b73023c --- /dev/null +++ b/ruby_1_9_3/ext/-test-/bug-3662/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/bug-3662/bug") diff --git a/ruby_1_9_3/ext/-test-/funcall/extconf.rb b/ruby_1_9_3/ext/-test-/funcall/extconf.rb new file mode 100644 index 0000000000..8a9179ab2f --- /dev/null +++ b/ruby_1_9_3/ext/-test-/funcall/extconf.rb @@ -0,0 +1,2 @@ +require 'mkmf' +create_makefile("-test-/funcall/funcall") diff --git a/ruby_1_9_3/ext/-test-/funcall/passing_block.c b/ruby_1_9_3/ext/-test-/funcall/passing_block.c new file mode 100644 index 0000000000..0200f80369 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/funcall/passing_block.c @@ -0,0 +1,30 @@ +#include "ruby.h" + +VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*); + +static VALUE +with_funcall2(int argc, VALUE *argv, VALUE self) +{ + return rb_funcall2(self, rb_intern("target"), argc, argv); +} + +static VALUE +with_funcall_passing_block(int argc, VALUE *argv, VALUE self) +{ + return rb_funcall_passing_block(self, rb_intern("target"), argc, argv); +} + +void +Init_funcall(void) +{ + VALUE cRelay = rb_path2class("TestFuncall::Relay"); + + rb_define_singleton_method(cRelay, + "with_funcall2", + with_funcall2, + -1); + rb_define_singleton_method(cRelay, + "with_funcall_passing_block", + with_funcall_passing_block, + -1); +} diff --git a/ruby_1_9_3/ext/-test-/load/dot.dot/dot.dot.c b/ruby_1_9_3/ext/-test-/load/dot.dot/dot.dot.c new file mode 100644 index 0000000000..936d28931a --- /dev/null +++ b/ruby_1_9_3/ext/-test-/load/dot.dot/dot.dot.c @@ -0,0 +1 @@ +void Init_dot(void) {} diff --git a/ruby_1_9_3/ext/-test-/load/dot.dot/extconf.rb b/ruby_1_9_3/ext/-test-/load/dot.dot/extconf.rb new file mode 100644 index 0000000000..6287db6bd8 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/load/dot.dot/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/load/dot.dot/dot.dot") diff --git a/ruby_1_9_3/ext/-test-/old_thread_select/depend b/ruby_1_9_3/ext/-test-/old_thread_select/depend new file mode 100644 index 0000000000..a2bc836e1f --- /dev/null +++ b/ruby_1_9_3/ext/-test-/old_thread_select/depend @@ -0,0 +1,2 @@ +old_thread_select.o: $(top_srcdir)/thread.c \ + $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/io.h diff --git a/ruby_1_9_3/ext/-test-/old_thread_select/extconf.rb b/ruby_1_9_3/ext/-test-/old_thread_select/extconf.rb new file mode 100644 index 0000000000..8b410218fa --- /dev/null +++ b/ruby_1_9_3/ext/-test-/old_thread_select/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/old_thread_select/old_thread_select") diff --git a/ruby_1_9_3/ext/-test-/old_thread_select/old_thread_select.c b/ruby_1_9_3/ext/-test-/old_thread_select/old_thread_select.c new file mode 100644 index 0000000000..e374f02355 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/old_thread_select/old_thread_select.c @@ -0,0 +1,75 @@ +/* test case for deprecated C API */ +#include "ruby/ruby.h" +#include "ruby/io.h" + +static fd_set * array2fdset(fd_set *fds, VALUE ary, int *max) +{ + long i; + + if (NIL_P(ary)) + return NULL; + + FD_ZERO(fds); + Check_Type(ary, T_ARRAY); + for (i = 0; i < RARRAY_LEN(ary); i++) { + VALUE val = RARRAY_PTR(ary)[i]; + int fd; + + Check_Type(val, T_FIXNUM); + fd = FIX2INT(val); + if (fd >= *max) + *max = fd + 1; + FD_SET(fd, fds); + } + + return fds; +} + +static void fdset2array(VALUE dst, fd_set *fds, int max) +{ + int i; + + rb_ary_clear(dst); + + for (i = 0; i < max; i++) { + if (FD_ISSET(i, fds)) + rb_ary_push(dst, INT2NUM(i)); + } +} + +static VALUE +old_thread_select(VALUE klass, VALUE r, VALUE w, VALUE e, VALUE timeout) +{ + struct timeval tv; + struct timeval *tvp = NULL; + fd_set rfds, wfds, efds; + fd_set *rp, *wp, *ep; + int rc; + int max = 0; + + if (!NIL_P(timeout)) { + tv = rb_time_timeval(timeout); + tvp = &tv; + } + rp = array2fdset(&rfds, r, &max); + wp = array2fdset(&wfds, w, &max); + ep = array2fdset(&efds, e, &max); + rc = rb_thread_select(max, rp, wp, ep, tvp); + if (rc == -1) + rb_sys_fail("rb_wait_for_single_fd"); + + if (rp) + fdset2array(r, &rfds, max); + if (wp) + fdset2array(w, &wfds, max); + if (ep) + fdset2array(e, &efds, max); + return INT2NUM(rc); +} + +void +Init_old_thread_select(void) +{ + rb_define_singleton_method(rb_cIO, "old_thread_select", + old_thread_select, 4); +} diff --git a/ruby_1_9_3/ext/-test-/st/numhash/extconf.rb b/ruby_1_9_3/ext/-test-/st/numhash/extconf.rb new file mode 100644 index 0000000000..867fd75d2a --- /dev/null +++ b/ruby_1_9_3/ext/-test-/st/numhash/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/st/numhash") diff --git a/ruby_1_9_3/ext/-test-/st/numhash/numhash.c b/ruby_1_9_3/ext/-test-/st/numhash/numhash.c new file mode 100644 index 0000000000..e186cd43d9 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/st/numhash/numhash.c @@ -0,0 +1,69 @@ +#include <ruby.h> +#include <ruby/st.h> + +static void +numhash_free(void *ptr) +{ + if (ptr) st_free_table(ptr); +} + +static VALUE +numhash_alloc(VALUE klass) +{ + return Data_Wrap_Struct(klass, 0, numhash_free, 0); +} + +static VALUE +numhash_init(VALUE self) +{ + st_table *tbl = (st_table *)DATA_PTR(self); + if (tbl) st_free_table(tbl); + DATA_PTR(self) = st_init_numtable(); + return self; +} + +static VALUE +numhash_aref(VALUE self, VALUE key) +{ + st_data_t data; + if (!SPECIAL_CONST_P(key)) rb_raise(rb_eArgError, "not a special const"); + if (st_lookup((st_table *)DATA_PTR(self), (st_data_t)key, &data)) + return (VALUE)data; + return Qnil; +} + +static VALUE +numhash_aset(VALUE self, VALUE key, VALUE data) +{ + if (!SPECIAL_CONST_P(key)) rb_raise(rb_eArgError, "not a special const"); + if (!SPECIAL_CONST_P(data)) rb_raise(rb_eArgError, "not a special const"); + st_insert((st_table *)DATA_PTR(self), (st_data_t)key, (st_data_t)data); + return self; +} + +static int +numhash_i(st_data_t key, st_data_t value, st_data_t arg, int error) +{ + VALUE ret; + if (key == 0 && value == 0 && error == 1) rb_raise(rb_eRuntimeError, "numhash modified"); + ret = rb_yield_values(3, (VALUE)key, (VALUE)value, (VALUE)arg); + if (ret == Qtrue) return ST_CHECK; + return ST_CONTINUE; +} + +static VALUE +numhash_each(VALUE self) +{ + return st_foreach((st_table *)DATA_PTR(self), numhash_i, self) ? Qtrue : Qfalse; +} + +void +Init_numhash(void) +{ + VALUE st = rb_define_class_under(rb_define_module("Bug"), "StNumHash", rb_cData); + rb_define_alloc_func(st, numhash_alloc); + rb_define_method(st, "initialize", numhash_init, 0); + rb_define_method(st, "[]", numhash_aref, 1); + rb_define_method(st, "[]=", numhash_aset, 2); + rb_define_method(st, "each", numhash_each, 0); +} diff --git a/ruby_1_9_3/ext/-test-/string/cstr.c b/ruby_1_9_3/ext/-test-/string/cstr.c new file mode 100644 index 0000000000..d4ff360575 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/cstr.c @@ -0,0 +1,20 @@ +#include "ruby.h" + +static VALUE +bug_str_cstr_term(VALUE str) +{ + long len; + char *s; + rb_str_modify(str); + len = RSTRING_LEN(str); + RSTRING_PTR(str)[len] = 'x'; + s = StringValueCStr(str); + rb_gc(); + return INT2NUM(s[len]); +} + +void +Init_cstr(VALUE klass) +{ + rb_define_method(klass, "cstr_term", bug_str_cstr_term, 0); +} diff --git a/ruby_1_9_3/ext/-test-/string/ellipsize.c b/ruby_1_9_3/ext/-test-/string/ellipsize.c new file mode 100644 index 0000000000..0451519492 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/ellipsize.c @@ -0,0 +1,13 @@ +#include "ruby.h" + +static VALUE +bug_str_ellipsize(VALUE str, VALUE len) +{ + return rb_str_ellipsize(str, NUM2LONG(len)); +} + +void +Init_ellipsize(VALUE klass) +{ + rb_define_method(klass, "ellipsize", bug_str_ellipsize, 1); +} diff --git a/ruby_1_9_3/ext/-test-/string/enc_associate.c b/ruby_1_9_3/ext/-test-/string/enc_associate.c new file mode 100644 index 0000000000..d6614fb298 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/enc_associate.c @@ -0,0 +1,14 @@ +#include "ruby.h" +#include "ruby/encoding.h" + +VALUE +bug_str_enc_associate(VALUE str, VALUE enc) +{ + return rb_enc_associate(str, rb_to_encoding(enc)); +} + +void +Init_enc_associate(VALUE klass) +{ + rb_define_method(klass, "associate_encoding!", bug_str_enc_associate, 1); +} diff --git a/ruby_1_9_3/ext/-test-/string/extconf.rb b/ruby_1_9_3/ext/-test-/string/extconf.rb new file mode 100644 index 0000000000..42c10b994b --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/extconf.rb @@ -0,0 +1,6 @@ +$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] +inits = $srcs.map {|s| File.basename(s, ".*")} +inits.delete("init") +inits.map! {|s|"X(#{s})"} +$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\"" +create_makefile("-test-/string/string") diff --git a/ruby_1_9_3/ext/-test-/string/init.c b/ruby_1_9_3/ext/-test-/string/init.c new file mode 100644 index 0000000000..0b3e4a6ff2 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/init.c @@ -0,0 +1,11 @@ +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);} + +void +Init_string(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "String", rb_cString); + TEST_INIT_FUNCS(init); +} diff --git a/ruby_1_9_3/ext/-test-/string/modify.c b/ruby_1_9_3/ext/-test-/string/modify.c new file mode 100644 index 0000000000..ddd2efd8f0 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/modify.c @@ -0,0 +1,22 @@ +#include "ruby.h" + +VALUE +bug_str_modify(VALUE str) +{ + rb_str_modify(str); + return str; +} + +VALUE +bug_str_modify_expand(VALUE str, VALUE expand) +{ + rb_str_modify_expand(str, NUM2LONG(expand)); + return str; +} + +void +Init_modify(VALUE klass) +{ + rb_define_method(klass, "modify!", bug_str_modify, 0); + rb_define_method(klass, "modify_expand!", bug_str_modify_expand, 1); +} diff --git a/ruby_1_9_3/ext/-test-/string/set_len.c b/ruby_1_9_3/ext/-test-/string/set_len.c new file mode 100644 index 0000000000..3c7d19d778 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/string/set_len.c @@ -0,0 +1,14 @@ +#include "ruby.h" + +static VALUE +bug_str_set_len(VALUE str, VALUE len) +{ + rb_str_set_len(str, NUM2LONG(len)); + return str; +} + +void +Init_set_len(VALUE klass) +{ + rb_define_method(klass, "set_len", bug_str_set_len, 1); +} diff --git a/ruby_1_9_3/ext/-test-/wait_for_single_fd/depend b/ruby_1_9_3/ext/-test-/wait_for_single_fd/depend new file mode 100644 index 0000000000..d9cd50a542 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/wait_for_single_fd/depend @@ -0,0 +1,2 @@ +wait_for_single_fd.o: $(top_srcdir)/thread.c \ + $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/io.h diff --git a/ruby_1_9_3/ext/-test-/wait_for_single_fd/extconf.rb b/ruby_1_9_3/ext/-test-/wait_for_single_fd/extconf.rb new file mode 100644 index 0000000000..1a28b23da3 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/wait_for_single_fd/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/wait_for_single_fd/wait_for_single_fd") diff --git a/ruby_1_9_3/ext/-test-/wait_for_single_fd/wait_for_single_fd.c b/ruby_1_9_3/ext/-test-/wait_for_single_fd/wait_for_single_fd.c new file mode 100644 index 0000000000..d406724a3f --- /dev/null +++ b/ruby_1_9_3/ext/-test-/wait_for_single_fd/wait_for_single_fd.c @@ -0,0 +1,30 @@ +#include "ruby/ruby.h" +#include "ruby/io.h" + +static VALUE +wait_for_single_fd(VALUE ign, VALUE fd, VALUE events, VALUE timeout) +{ + struct timeval tv; + struct timeval *tvp = NULL; + int rc; + + if (!NIL_P(timeout)) { + tv = rb_time_timeval(timeout); + tvp = &tv; + } + + rc = rb_wait_for_single_fd(NUM2INT(fd), NUM2INT(events), tvp); + if (rc == -1) + rb_sys_fail("rb_wait_for_single_fd"); + return INT2NUM(rc); +} + +void +Init_wait_for_single_fd(void) +{ + rb_define_const(rb_cObject, "RB_WAITFD_IN", INT2NUM(RB_WAITFD_IN)); + rb_define_const(rb_cObject, "RB_WAITFD_OUT", INT2NUM(RB_WAITFD_OUT)); + rb_define_const(rb_cObject, "RB_WAITFD_PRI", INT2NUM(RB_WAITFD_PRI)); + rb_define_singleton_method(rb_cIO, "wait_for_single_fd", + wait_for_single_fd, 3); +} diff --git a/ruby_1_9_3/ext/-test-/win32/dln/dlntest.c b/ruby_1_9_3/ext/-test-/win32/dln/dlntest.c new file mode 100644 index 0000000000..3e6037ac07 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/dln/dlntest.c @@ -0,0 +1,17 @@ +#include <ruby.h> + +extern __declspec(dllimport) void dlntest_ordinal(void); + +static VALUE +dln_dlntest(VALUE self) +{ + dlntest_ordinal(); + return self; +} + +void +Init_dln(void) +{ + VALUE m = rb_define_module_under(rb_define_module("Bug"), "Win32"); + rb_define_module_function(m, "dlntest", dln_dlntest, 0); +} diff --git a/ruby_1_9_3/ext/-test-/win32/dln/extconf.rb b/ruby_1_9_3/ext/-test-/win32/dln/extconf.rb new file mode 100644 index 0000000000..0b5089af14 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/dln/extconf.rb @@ -0,0 +1,36 @@ +if $mingw or $mswin + $objs = ["dlntest.o"] + testdll = "$(topdir)/dlntest.dll" + $cleanfiles << testdll + config_string('cleanobjs') {|t| $cleanfiles.concat(t.gsub(/\$\*/, 'dlntest').split)} + + create_makefile("-test-/win32/dln") + m = File.read("Makefile") + dlntestlib = "dlntest.#{$LIBEXT}" + m.sub!(/^OBJS =.*/) {"#{$&} #{dlntestlib}"} + FileUtils.rm_f(RbConfig.expand(testdll.dup)) + open("Makefile", "wb") do |mf| + mf.puts m, "\n" + sodir = $extout ? "$(RUBYARCHDIR)/" : '' + mf.print "#{sodir}$(DLLIB): #{dlntestlib}" + mf.puts + mf.puts "#{dlntestlib}: $(topdir)/dlntest.dll" + mf.puts + if $mingw + mf.puts "$(topdir)/dlntest.dll: DEFFILE := $(srcdir)/libdlntest.def" + mf.puts "$(topdir)/dlntest.dll: DLDFLAGS += -Wl,--out-implib,#{dlntestlib}" + end + mf.puts depend_rules("$(topdir)/dlntest.dll: libdlntest.o libdlntest.def") + mf.puts "\t$(ECHO) linking shared-object $(@F)\n" + mf.print "\t-$(Q)$(RM) $@\n" + mf.print "\t-$(Q)$(MAKEDIRS) $(@D)\n" if $extout + link_so = LINK_SO.gsub(/^/, "\t$(Q) ") + link_so.sub!(/\$\(LOCAL_LIBS\)/, '') + link_so.gsub!(/-\$\(arch\)/, '') + link_so.gsub!(/:.so=/, ':.dll=') + link_so.sub!(/\$\(OBJS\)/, "libdlntest.#{$OBJEXT}") + link_so.sub!(/\$\(DEFFILE\)/, "$(srcdir)/libdlntest.def") + mf.puts link_so + mf.puts + end +end diff --git a/ruby_1_9_3/ext/-test-/win32/dln/libdlntest.c b/ruby_1_9_3/ext/-test-/win32/dln/libdlntest.c new file mode 100644 index 0000000000..040ae8125d --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/dln/libdlntest.c @@ -0,0 +1,4 @@ +extern __declspec(dllexport) void +dlntest_ordinal(void) +{ +} diff --git a/ruby_1_9_3/ext/-test-/win32/dln/libdlntest.def b/ruby_1_9_3/ext/-test-/win32/dln/libdlntest.def new file mode 100644 index 0000000000..85bc9c7a55 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/dln/libdlntest.def @@ -0,0 +1,2 @@ +EXPORTS +dlntest_ordinal @1 NONAME diff --git a/ruby_1_9_3/ext/-test-/win32/fd_setsize/depend b/ruby_1_9_3/ext/-test-/win32/fd_setsize/depend new file mode 100644 index 0000000000..4936d6b28c --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/fd_setsize/depend @@ -0,0 +1,2 @@ +fd_setsize.o: $(top_srcdir)/win32/win32.c \ + $(hdrdir)/ruby/ruby.h diff --git a/ruby_1_9_3/ext/-test-/win32/fd_setsize/extconf.rb b/ruby_1_9_3/ext/-test-/win32/fd_setsize/extconf.rb new file mode 100644 index 0000000000..ed40f8b1d7 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/fd_setsize/extconf.rb @@ -0,0 +1,3 @@ +if $mingw or $mswin + create_makefile("-test-/win32/fd_setsize") +end diff --git a/ruby_1_9_3/ext/-test-/win32/fd_setsize/fd_setsize.c b/ruby_1_9_3/ext/-test-/win32/fd_setsize/fd_setsize.c new file mode 100644 index 0000000000..8da8b1eaa0 --- /dev/null +++ b/ruby_1_9_3/ext/-test-/win32/fd_setsize/fd_setsize.c @@ -0,0 +1,55 @@ +#undef FD_SETSIZE +/* redefine smaller size then default 64 */ +#define FD_SETSIZE 32 +#include <ruby.h> + +static VALUE +test_select(VALUE self) +{ + int sd = socket(AF_INET, SOCK_DGRAM, 0); + struct timeval zero; + fd_set read; + fd_set write; + fd_set error; + + zero.tv_sec = 0; + zero.tv_usec = 0; + + FD_ZERO(&read); + FD_ZERO(&write); + FD_ZERO(&error); + + FD_SET(sd, &read); + FD_SET(sd, &write); + FD_SET(sd, &error); + + select(sd+1, &read, &write, &error, &zero); + + return Qtrue; +} + +static VALUE +test_fdset(VALUE self) +{ + int i; + fd_set set; + + FD_ZERO(&set); + + for (i = 0; i < FD_SETSIZE * 2; i++) { + int sd = socket(AF_INET, SOCK_DGRAM, 0); + FD_SET(sd, &set); + if (set.fd_count > FD_SETSIZE) { + return Qfalse; + } + } + return Qtrue; +} + +void +Init_fd_setsize(void) +{ + VALUE m = rb_define_module_under(rb_define_module("Bug"), "Win32"); + rb_define_module_function(m, "test_select", test_select, 0); + rb_define_module_function(m, "test_fdset", test_fdset, 0); +} |