[#11680] fork_and_kill_other_threads — "NAKAMURA, Hiroshi" <nakahiro@...>

なひです。[ruby-list:26165]からもって来ました。

27 messages 2000/12/02
[#11681] Re: fork_and_kill_other_threads — Masatoshi SEKI <m_seki@...> 2000/12/02

[#11682] Re: fork_and_kill_other_threads — matz@... (Yukihiro Matsumoto) 2000/12/02

まつもと ゆきひろです

[#11685] Re: fork_and_kill_other_threads — nobu.nakada@... 2000/12/03

なかだです。

[#11687] Re: fork_and_kill_other_threads — matz@... (Yukihiro Matsumoto) 2000/12/03

まつもと ゆきひろです

[#11708] Re: fork_and_kill_other_threads — Kazuhiro NISHIYAMA <zn@...> 2000/12/06

On Sun, 3 Dec 2000 23:33:41 +0900

[#11709] Re: fork_and_kill_other_threads — matz@... (Yukihiro Matsumoto) 2000/12/06

まつもと ゆきひろです

[#11710] Re: fork_and_kill_other_threads — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/12/06

なひです。

[#11713] Re: fork_and_kill_other_threads — matz@... (Yukihiro Matsumoto) 2000/12/06

まつもと ゆきひろです

[#11716] Re: fork_and_kill_other_threads — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/12/06

なひです。

[#11718] Re: fork_and_kill_other_threads — matz@... (Yukihiro Matsumoto) 2000/12/06

まつもと ゆきひろです

[#11722] Re: fork_and_kill_other_threads — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/12/07

なひです。

[#11733] Ruby I18N 改め M17N — とみたまさひろ <tommy@...>

とみたです。

17 messages 2000/12/07
[#11735] Re: Ruby I18N 改め M17N — matz@... (Yukihiro Matsumoto) 2000/12/08

まつもと ゆきひろです

[#11751] Re: Ruby I18N 改め M17N — とみたまさひろ <tommy@...> 2000/12/13

とみたです。

[#11752] Re: Ruby I18N 改め M17N — matz@... (Yukihiro Matsumoto) 2000/12/13

まつもと ゆきひろです

[#11789] mswin32 [Q & patch] mkmf.rb — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

14 messages 2000/12/18
[#11790] Re: mswin32 [Q & patch] mkmf.rb — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/12/19

なかだです。

[#11848] Where'd all the Ruby's history gone? — "Akinori MUSHA" <knu@...>

 さっき気付いたんですが、 Ruby のレポジトリから過去分がごっそり

27 messages 2000/12/25
[#11853] Re: Where'd all the Ruby's history gone? — matz@... (Yukihiro Matsumoto) 2000/12/26

まつもと ゆきひろです

[#11861] Re: Where'd all the Ruby's history gone? — Kazuhiro NISHIYAMA <zn@...> 2000/12/26

On Tue, 26 Dec 2000 14:58:07 +0900

[#11862] Re: Where'd all the Ruby's history gone? — matz@... (Yukihiro Matsumoto) 2000/12/26

まつもと ゆきひろです

[#11869] Re: Where'd all the Ruby's history gone? — "Akinori MUSHA" <knu@...> 2000/12/26

At Tue, 26 Dec 2000 17:44:57 +0900,

[#11894] Re: Where'd all the Ruby's history gone? — Kazuhiro NISHIYAMA <zn@...> 2000/12/29

On Tue, 26 Dec 2000 21:24:19 +0900

[#11895] Re: Where'd all the Ruby's history gone? — "Akinori MUSHA" <knu@...> 2000/12/29

At Fri, 29 Dec 2000 18:56:03 +0900,

[#11896] Re: Where'd all the Ruby's history gone? — Kazuhiro NISHIYAMA <zn@...> 2000/12/29

On Fri, 29 Dec 2000 19:07:12 +0900

[#11852] local variable extent problem? — Tanaka Akira <akr@...17n.org>

どうも、Ruby のバグのような気がするものを見つけたのですが、もしかした

21 messages 2000/12/26
[#11855] Re: local variable extent problem? — matz@... (Yukihiro Matsumoto) 2000/12/26

まつもと ゆきひろです

[#11857] Re: local variable extent problem? — Tanaka Akira <akr@...17n.org> 2000/12/26

In article <977817486.100168.31162.nullmailer@ev.netlab.zetabits.com>,

[#11859] Re: local variable extent problem? — matz@... (Yukihiro Matsumoto) 2000/12/26

まつもと ゆきひろです

[#11860] Re: local variable extent problem? — Tanaka Akira <akr@...17n.org> 2000/12/26

In article <977819010.870991.31953.nullmailer@ev.netlab.zetabits.com>,

[#11863] Re: local variable extent problem? — matz@... (Yukihiro Matsumoto) 2000/12/26

まつもと ゆきひろです

[#11865] Re: local variable extent problem? — "Akinori MUSHA" <knu@...> 2000/12/26

At Tue, 26 Dec 2000 17:50:11 +0900,

[#11874] Re: local variable extent problem? — matz@... (Yukihiro Matsumoto) 2000/12/26

まつもと ゆきひろです

[ruby-dev:11733] Ruby I18N 改め M17N

From: とみたまさひろ <tommy@...>
Date: 2000-12-07 18:08:37 UTC
List: ruby-dev #11733
とみたです。

Ruby の多言語化について [ruby-dev:11445] で作ったサンプルを
C で拡張ライブラリとして書き直してみました。

実装してるメソッドがまだほとんどないんですが、こんな感じで
使えます。

まつもとさんの意図するところと、そんなにズレてないんじゃないかと
思うんですが、どんなもんでしょ。

% gcc -I /usr/local/lib/ruby/1.6/i686-linux/ -fPIC -g -shared -o mbstring.so mbstring.c
% gcc -I /usr/local/lib/ruby/1.6/i686-linux/ -fPIC -g -shared -o eucjp.so eucjp.c ./mbstring.so
% gcc -I /usr/local/lib/ruby/1.6/i686-linux/ -fPIC -g -shared -o sjis.so sjis.c ./mbstring.so

% ruby -r./eucjp -e 'e=EucJp::new("あいうえお"); p e.length, e[1]'
5
42148

% ruby -r./eucjp -r./sjis -e 'e=EucJp::new("abc"); s=Sjis::new("abc"); p e == s'
false

---
とみたまさひろ <tommy@tmtm.org> http://www.tmtm.org
日本MySQLユーザ会 http://www.mysql.gr.jp

Attachments (4)

mbstring.c (2.04 KB, text/x-csrc)
#include "ruby.h"
#include "mbstring.h"

static struct mbstr_ctype** ctype_list = NULL;
static int n_ctype_list =  0;

VALUE	cMBString;

void mbstr_set_ctype(struct mbstr_ctype* p)
{
    REALLOC_N(ctype_list, struct mbstr_ctype*, n_ctype_list+1);
    ctype_list[n_ctype_list++] = p;
}

struct mbstr_ctype* get_mbstr_ctype(VALUE obj)
{
    int i;
    for (i = 0; i < n_ctype_list; i++) {
	if (ctype_list[i]->klass == RBASIC(obj)->klass)
	    return ctype_list[i];
    }
    rb_raise(rb_eArgError, "MBString: unknown class: %d", RBASIC(obj)->klass);
}

static VALUE length(VALUE obj)
{
    struct mbstr_ctype* p = get_mbstr_ctype(obj);
    char* ptr = RSTRING(obj)->ptr;
    char* e = ptr + RSTRING(obj)->len;
    int	i, c;

    for (i=0, c=0; i<RSTRING(obj)->len; c++)
	i += p->char_width(ptr+i, e);
    return INT2FIX(c);
}

static VALUE aref(int argc, VALUE *argv, VALUE obj)
{
    struct mbstr_ctype* p = get_mbstr_ctype(obj);
    char* ptr = RSTRING(obj)->ptr;
    int len = RSTRING(obj)->len;
    char* e = ptr + len;
    int ret = 0;
    int idx;
    int i, c, l;

    if (argc != 1 || TYPE(argv[0]) != T_FIXNUM)
	rb_raise(rb_eArgError, "not implemented");
    idx = FIX2LONG(argv[0]);
    for (i=0, c=0; i<len && c<idx; c++)
	i += p->char_width(ptr+i, e);
    if (i >= len)
	return Qnil;
    for (l=p->char_width(ptr+i, e); l>0; l--)
	ret = ret * 256 + (unsigned char)ptr[i++];
    return INT2FIX(ret);
}

static VALUE equal(VALUE obj, VALUE arg)
{
    if (RBASIC(obj)->klass != RBASIC(arg)->klass)
	return Qfalse;
    if (RSTRING(obj)->len != RSTRING(arg)->len)
	return Qfalse;
    if (memcmp(RSTRING(obj)->ptr, RSTRING(arg)->ptr, RSTRING(obj)->len) != 0)
	return Qfalse;
    return Qtrue;
}

void Init_mbstring(void)
{
    cMBString = rb_define_class("MBString", rb_cString);
    rb_define_method(cMBString, "==", equal, 1);
    rb_define_method(cMBString, "===", equal, 1);
    rb_define_method(cMBString, "eql?", equal, 1);
    rb_define_method(cMBString, "length", length, 0);
    rb_define_method(cMBString, "size", length, 0);
    rb_define_method(cMBString, "[]", aref, -1);
}
mbstring.h (122 Bytes, text/x-c++hdr)
struct mbstr_ctype {
    VALUE	klass;
    int		(*char_width)(unsigned char*, unsigned char*);
};

extern VALUE cMBString;
eucjp.c (524 Bytes, text/x-csrc)
#include "ruby.h"
#include "mbstring.h"

VALUE cEucJp;

static struct mbstr_ctype eucjp_ctype;

static int char_width(unsigned char* ptr, unsigned char* e)
{
    return *ptr < 0x80 ? 1 :
	0xa1 <= *ptr && *ptr <= 0xfe && e-ptr >= 2 ? 2 :
	*ptr == 0x8e && e-ptr >= 2 ? 2 :
	*ptr == 0x8f && e-ptr >= 3 ? 3 :
	1;
}

void Init_eucjp(void)
{
    rb_require("mbstring");
    cEucJp = rb_define_class("EucJp", cMBString);
    eucjp_ctype.klass = cEucJp;
    eucjp_ctype.char_width = char_width;
    mbstr_set_ctype(&eucjp_ctype);
}
sjis.c (447 Bytes, text/x-csrc)
#include "ruby.h"
#include "mbstring.h"

VALUE cSjis;

static struct mbstr_ctype sjis_ctype;

static int char_width(unsigned char* ptr, unsigned char* e)
{
    return *ptr <= 0x80 || 0xa0 <= *ptr && *ptr <= 0xdf ? 1 :
	e-ptr >=2 ? 2 :
	1;
}

void Init_sjis(void)
{
    rb_require("mbstring");
    cSjis = rb_define_class("Sjis", cMBString);
    sjis_ctype.klass = cSjis;
    sjis_ctype.char_width = char_width;
    mbstr_set_ctype(&sjis_ctype);
}

In This Thread

Prev Next