[#31320] Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...>

-----BEGIN PGP SIGNED MESSAGE-----

124 messages 2007/08/01
[#31321] Re: Import RubyGems to Ruby 1.9 — Nobuyoshi Nakada <nobu@...> 2007/08/01

なかだです。

[#31329] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/08/01

-----BEGIN PGP SIGNED MESSAGE-----

[#31918] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/09/30

-----BEGIN PGP SIGNED MESSAGE-----

[#31970] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/08

-----BEGIN PGP SIGNED MESSAGE-----

[#32023] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/10/11

まつもと ゆきひろです

[#32062] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/15

-----BEGIN PGP SIGNED MESSAGE-----

[#32066] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/10/15

まつもと ゆきひろです

[#32068] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/15

-----BEGIN PGP SIGNED MESSAGE-----

[#32069] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/10/15

まつもと ゆきひろです

[#32070] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/15

-----BEGIN PGP SIGNED MESSAGE-----

[#32073] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/10/15

まつもと ゆきひろです

[#32079] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/16

-----BEGIN PGP SIGNED MESSAGE-----

[#32080] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/10/16

まつもと ゆきひろです

[#32132] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/23

-----BEGIN PGP SIGNED MESSAGE-----

[#32081] Re: Import RubyGems to Ruby 1.9 — Takahiro Kambe <taca@...> 2007/10/16

In message <471447D5.5050902@sarion.co.jp>

[#32087] Re: Import RubyGems to Ruby 1.9 — "Akinori MUSHA" <knu@...> 2007/10/17

 Rubygems は、基本的に他のパッケージシステムから包みやすい作り

[#32104] Re: Import RubyGems to Ruby 1.9 — akira yamada <akira@...> 2007/10/20

Tuesday 16 October 2007 14:09:13 に NAKAMURA, Hiroshi さんは書きました:

[#32109] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/10/20

-----BEGIN PGP SIGNED MESSAGE-----

[#31332] Re: Import RubyGems to Ruby 1.9 — Tadayoshi Funaba <tadf@...> 2007/08/01

> ちなみに「ruby/1.9.1の標準添付からどのライブラリを外すか?」という議論も

[#31858] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/09/25

-----BEGIN PGP SIGNED MESSAGE-----

[#31872] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/09/27

-----BEGIN PGP SIGNED MESSAGE-----

[#31905] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/09/29

-----BEGIN PGP SIGNED MESSAGE-----

[#31906] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/09/29

まつもと ゆきひろです

[#31910] Re: Import RubyGems to Ruby 1.9 — "NAKAMURA, Hiroshi" <nakahiro@...> 2007/09/30

-----BEGIN PGP SIGNED MESSAGE-----

[#31920] Re: Import RubyGems to Ruby 1.9 — Yukihiro Matsumoto <matz@...> 2007/09/30

まつもと ゆきひろです

[#31323] Bignum#to_s の Karatsuba 基数変換による高速化 — "Kenta Murata" <muraken@...>

むらけんです.

16 messages 2007/08/01
[#31326] Re: Bignum#to_s の Karatsuba 基数変換による高速化 — Yukihiro Matsumoto <matz@...> 2007/08/01

まつもと ゆきひろです

[#31327] Re: Bignum#to_s の Karatsuba 基数変換による高速化 — "Kenta Murata" <muraken@...> 2007/08/01

むらけんです.

[#31328] Re: Bignum#to_s の Karatsuba 基数変換による高速化 — Yukihiro Matsumoto <matz@...> 2007/08/01

まつもと ゆきひろです

[#31525] いくつかのバグ報告と提案(5点) — eklerni <eklerni@...>

From:eklerni

13 messages 2007/08/20

[#31539] strtod の精度 — Satoshi Nakagawa <snakagawa@...>

中川といいます。

27 messages 2007/08/20
[#31542] Re: strtod の精度 — Yukihiro Matsumoto <matz@...> 2007/08/20

まつもと ゆきひろです

[ruby-dev:31644] Re: IO.sysdup2, IO.sysdup, IO.sysclose

From: Tanaka Akira <akr@...>
Date: 2007-08-24 17:15:17 UTC
List: ruby-dev #31644
In article <E1IObRL-0002Ax-0Q@x31>,
  Yukihiro Matsumoto <matz@ruby-lang.org> writes:

> sysopen, syscloseをベースにFixnumを使った関数ベースで操作す
> るのと、IO::FDのようなオブジェクトにラップしたものでどちらが
> 使いやすいかは、私には一概に判断できませんが、どうなんでしょ
> うね。Unixプログラミングに慣れていると関数ベースの方が目に優
> しいですが。

なるほど、そうかもしれません。両方作ってみました。

ただ、IO::FD.dup(fd) が dup という名前で引数を要求するのが微
妙に苦しいです。まぁ、クラスを dup する必要はまずないとは思
いますが。

オブジェクトの利点は、file descriptor を整数と区別することで
すかね。file descriptor であるという意図を表現するのに便利で
す。

> 過去に拡張ライブラリを取り込んだ経緯だと、まず手元で動くもの
> を作って実際に使っていただいてから、判断していたように思いま
> す。現時点では標準添付にすべきか、それともgemで提供する程度で
> 十分なのか判断に困ります。

たしかに。

ただ、やりたいことは shell で簡単にできる話なので、そのくら
いは標準でできてほしいと思います。また、このあたりは POSIX
で定義されている範囲ですし。

Index: ext/io/fd/extconf.rb
===================================================================
--- ext/io/fd/extconf.rb	(リビジョン 0)
+++ ext/io/fd/extconf.rb	(リビジョン 0)
@@ -0,0 +1,3 @@
+require 'mkmf'
+
+create_makefile("io/fd")
Index: ext/io/fd/fd.c
===================================================================
--- ext/io/fd/fd.c	(リビジョン 0)
+++ ext/io/fd/fd.c	(リビジョン 0)
@@ -0,0 +1,227 @@
+#include "ruby.h"
+#include "rubyio.h"
+#include <unistd.h>
+
+static VALUE FD;
+
+static void
+fd_mark(void *ptr)
+{
+}
+
+static void
+fd_free(void *ptr)
+{
+}
+
+static VALUE
+fd_s_allocate(VALUE klass)
+{
+    return Data_Wrap_Struct(klass, fd_mark, fd_free, (void*)-1);
+}
+
+static VALUE
+fd_new(int fd)
+{
+    VALUE v = fd_s_allocate(FD);
+    DATA_PTR(v) = (void*)fd;
+    return v;
+}
+
+#define IS_FD(obj) (RDATA(obj)->dmark == (RUBY_DATA_FUNC)fd_mark)
+
+static int
+check_fd(VALUE self)
+{
+    Check_Type(self, T_DATA);
+    if (!IS_FD(self)) {
+        rb_raise(rb_eTypeError, "wrong argument type %s (expected IO::FD)",
+                 rb_class2name(CLASS_OF(self)));
+    }
+    return (int)DATA_PTR(self);
+}
+
+static int
+get_fd(VALUE v)
+{
+    switch (TYPE(v)) {
+      case T_DATA:
+        return check_fd(v);
+
+      case T_FIXNUM:
+        return FIX2INT(v);
+
+      default:
+        return NUM2INT(rb_to_int(v));
+    }
+}
+
+/*
+ * call-seq: IO::FD.new(fd)
+ *
+ * returns newly created IO::FD object.
+ *
+ *  IO::FD.new(1) #=> #<IO::FD:1>
+ */
+
+static VALUE
+fd_initialize(VALUE self, VALUE fd_v)
+{
+    DATA_PTR(self) = get_fd(fd_v);
+    return self;
+}
+
+/*
+ * returns the file descriptor as an integer.
+ *
+ *  IO::FD.new(10).to_i #=> 10
+ */
+
+static VALUE
+fd_to_i(VALUE self)
+{
+    return INT2NUM((int)DATA_PTR(self));
+}
+
+static VALUE
+fd_inspect(VALUE self)
+{
+    return rb_sprintf("#<IO::FD:%d>", (int)DATA_PTR(self));
+}
+
+/*
+ * invokes dup system call.
+ * It returns newly created IO::FD object for the duplicated file descriptor.
+ *
+ *  IO::FD.new(0).dup #=> #<IO::FD:3>
+ */
+
+static VALUE
+fd_dup(VALUE oldfd_v)
+{
+    int oldfd, ret;
+
+    oldfd = get_fd(oldfd_v);
+    ret = dup(oldfd);
+    if (ret == -1) {
+        rb_sys_fail(0);
+    }
+    return fd_new(ret);
+}
+
+/*
+ * call-seq: IO::FD.dup(fd)
+ *
+ * invokes dup system call.
+ * It returns newly created IO::FD object for the duplicated file descriptor.
+ *
+ * _fd_ should be an IO::FD object or an integer.
+ *
+ *  IO::FD.dup(0) #=> #<IO::FD:3>
+ */
+
+static VALUE
+fd_s_dup(VALUE klass, VALUE oldfd_v)
+{
+    return fd_dup(oldfd_v);
+}
+
+/*
+ * call-seq: dup2(newfd)
+ *
+ * invokes dup2 system call.
+ * It returns newly created IO::FD object for the duplicated file descriptor.
+ *
+ * _newfd_ should be an IO::FD object or an integer.
+ *
+ *  IO::FD.new(0).dup2(10) #=> #<IO::FD:10>
+ */
+
+static VALUE
+fd_dup2(VALUE oldfd_v, VALUE newfd_v)
+{
+    int oldfd, newfd, ret;
+
+    oldfd = get_fd(oldfd_v);
+    newfd = get_fd(newfd_v);
+    ret = dup2(oldfd, newfd);
+    if (ret == -1) {
+        rb_sys_fail(0);
+    }
+    return fd_new(ret);
+}
+
+/*
+ * call-seq: IO::FD.dup2(oldfd, newfd)
+ *
+ * invokes dup2 system call.
+ * It returns newly created IO::FD object for the duplicated file descriptor.
+ *
+ * _oldfd_ and _newfd_ should be an IO::FD object or an integer.
+ *
+ *  IO::FD.new(0).dup2(10) #=> #<IO::FD:10>
+ */
+
+static VALUE
+fd_s_dup2(VALUE klass, VALUE oldfd_v, VALUE newfd_v)
+{
+    return fd_dup2(oldfd_v, newfd_v);
+}
+
+/*
+ * invokes close system call.
+ * It returns nil.
+ *
+ *  IO::FD.new(5).close #=> nil
+ */
+
+static VALUE
+fd_close(VALUE fd_v)
+{
+    int fd, ret;
+
+    fd = get_fd(fd_v);
+    ret = close(fd);
+    if (ret == -1) {
+        rb_sys_fail(0);
+    }
+    return Qnil;
+}
+
+/*
+ * call-seq: IO::FD.close(fd)
+ *
+ * invokes close system call.
+ * It returns nil.
+ *
+ * _fd_ should be an IO::FD object or an integer.
+ *
+ *  IO::FD.close(5) #=> nil
+ */
+
+static VALUE
+fd_s_close(VALUE klass, VALUE fd_v)
+{
+    return fd_close(fd_v);
+}
+
+/*
+ * IO::FD class
+ */
+
+void
+Init_fd()
+{
+    FD = rb_define_class_under(rb_cIO, "FD", rb_cData);
+    rb_define_alloc_func(FD, fd_s_allocate);
+    rb_define_singleton_method(FD, "dup", fd_s_dup, 1);
+    rb_define_singleton_method(FD, "dup2", fd_s_dup2, 2);
+    rb_define_singleton_method(FD, "close", fd_s_close, 1);
+
+    rb_define_method(FD, "initialize", fd_initialize, 1);
+    rb_define_method(FD, "to_i", fd_to_i, 0);
+    rb_define_method(FD, "inspect", fd_inspect, 0);
+    rb_define_method(FD, "dup", fd_dup, 0);
+    rb_define_method(FD, "dup2", fd_dup2, 1);
+    rb_define_method(FD, "close", fd_close, 0);
+}
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread