* io.c (rb_io_s_read): new method to call IO#read from
pathname. In addition, it accepts third optional argument to specify starting point. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
24a286efe1
commit
0b3092922d
@ -1,3 +1,9 @@
|
|||||||
|
Thu Jan 18 04:28:14 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_io_s_read): new method to call IO#read from
|
||||||
|
pathname. In addition, it accepts third optional argument to
|
||||||
|
specify starting point.
|
||||||
|
|
||||||
Wed Jan 17 13:28:26 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
Wed Jan 17 13:28:26 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: remove DEFS definition.
|
* configure.in: remove DEFS definition.
|
||||||
@ -15,7 +21,8 @@ Tue Jan 16 17:00:50 2001 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
|||||||
Mon Jan 15 16:00:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Mon Jan 15 16:00:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* pack.c (pack_unpack): should check associated pointer packed by
|
* pack.c (pack_unpack): should check associated pointer packed by
|
||||||
pack("P"). restriction added.
|
pack("P"). Thus pointers can be retrieved only from pointer
|
||||||
|
packed strings. restriction added.
|
||||||
|
|
||||||
Sun Jan 14 21:49:28 2001 Koji Arai <JCA02266@nifty.ne.jp>
|
Sun Jan 14 21:49:28 2001 Koji Arai <JCA02266@nifty.ne.jp>
|
||||||
|
|
||||||
|
1
ToDo
1
ToDo
@ -43,6 +43,7 @@ Hacking Interpreter
|
|||||||
* remove stdio dependency from IOs.
|
* remove stdio dependency from IOs.
|
||||||
* warn for inconsistent local variable usage (lv m and method m at the same time).
|
* warn for inconsistent local variable usage (lv m and method m at the same time).
|
||||||
* MicroRuby
|
* MicroRuby
|
||||||
|
* Built-in Interactive Ruby.
|
||||||
|
|
||||||
Standard Libraries
|
Standard Libraries
|
||||||
|
|
||||||
|
1
eval.c
1
eval.c
@ -6300,7 +6300,6 @@ block_pass(self, node)
|
|||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
POP_ITER();
|
POP_ITER();
|
||||||
printf("state: %d(%d)\n", state, _block.tag->dst);
|
|
||||||
if (_block.tag->dst == state) {
|
if (_block.tag->dst == state) {
|
||||||
if (orphan) {
|
if (orphan) {
|
||||||
state &= TAG_MASK;
|
state &= TAG_MASK;
|
||||||
|
@ -420,7 +420,7 @@ enum sock_recv_type {
|
|||||||
RECV_RECV, /* BasicSocket#recv(no from) */
|
RECV_RECV, /* BasicSocket#recv(no from) */
|
||||||
RECV_IP, /* IPSocket#recvfrom */
|
RECV_IP, /* IPSocket#recvfrom */
|
||||||
RECV_UNIX, /* UNIXSocket#recvfrom */
|
RECV_UNIX, /* UNIXSocket#recvfrom */
|
||||||
RECV_SOCKET, /* Socket#recvfrom */
|
RECV_SOCKET /* Socket#recvfrom */
|
||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
48
io.c
48
io.c
@ -3022,7 +3022,7 @@ struct foreach_arg {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_foreach_line(arg)
|
io_s_foreach(arg)
|
||||||
struct foreach_arg *arg;
|
struct foreach_arg *arg;
|
||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str;
|
||||||
@ -3048,21 +3048,14 @@ rb_io_s_foreach(argc, argv, io)
|
|||||||
arg.argc = argc - 1;
|
arg.argc = argc - 1;
|
||||||
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
||||||
if (NIL_P(arg.io)) return Qnil;
|
if (NIL_P(arg.io)) return Qnil;
|
||||||
return rb_ensure(rb_io_foreach_line, (VALUE)&arg, rb_io_close, arg.io);
|
return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_readline_line(arg)
|
io_s_readlines(arg)
|
||||||
struct foreach_arg *arg;
|
struct foreach_arg *arg;
|
||||||
{
|
{
|
||||||
VALUE line, ary;
|
return rb_io_readlines(arg->argc, &arg->sep, arg->io);
|
||||||
|
|
||||||
ary = rb_ary_new();
|
|
||||||
while (!NIL_P(line = rb_io_gets_internal(arg->argc, &arg->sep, arg->io))) {
|
|
||||||
rb_ary_push(ary, line);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -3080,7 +3073,35 @@ rb_io_s_readlines(argc, argv, io)
|
|||||||
arg.argc = argc - 1;
|
arg.argc = argc - 1;
|
||||||
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
||||||
if (NIL_P(arg.io)) return Qnil;
|
if (NIL_P(arg.io)) return Qnil;
|
||||||
return rb_ensure(rb_io_readline_line, (VALUE)&arg, rb_io_close, arg.io);
|
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
io_s_read(arg)
|
||||||
|
struct foreach_arg *arg;
|
||||||
|
{
|
||||||
|
return io_read(arg->argc, &arg->sep, arg->io);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_io_s_read(argc, argv, io)
|
||||||
|
int argc;
|
||||||
|
VALUE *argv;
|
||||||
|
VALUE io;
|
||||||
|
{
|
||||||
|
VALUE fname, offset;
|
||||||
|
struct foreach_arg arg;
|
||||||
|
|
||||||
|
rb_scan_args(argc, argv, "12", &fname, &arg.sep, &offset);
|
||||||
|
Check_SafeStr(fname);
|
||||||
|
|
||||||
|
arg.argc = argc ? 1 : 0;
|
||||||
|
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
||||||
|
if (NIL_P(arg.io)) return Qnil;
|
||||||
|
if (!NIL_P(offset)) {
|
||||||
|
rb_io_seek(1, &offset, arg.io);
|
||||||
|
}
|
||||||
|
return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -3115,7 +3136,7 @@ argf_set_pos(self, offset)
|
|||||||
VALUE self, offset;
|
VALUE self, offset;
|
||||||
{
|
{
|
||||||
if (!next_argv()) {
|
if (!next_argv()) {
|
||||||
rb_raise(rb_eArgError, "no stream to pos");
|
rb_raise(rb_eArgError, "no stream to set position");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TYPE(current_file) != T_FILE) {
|
if (TYPE(current_file) != T_FILE) {
|
||||||
@ -3365,6 +3386,7 @@ Init_IO()
|
|||||||
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
|
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
|
||||||
rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
|
rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
|
||||||
rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1);
|
rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1);
|
||||||
|
rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
|
||||||
rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
|
rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
|
||||||
rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, 0);
|
rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, 0);
|
||||||
|
|
||||||
|
38
lib/date.rb
38
lib/date.rb
@ -1,5 +1,5 @@
|
|||||||
# date.rb: Written by Tadayoshi Funaba 1998-2000
|
# date2.rb: Written by Tadayoshi Funaba 1998-2001
|
||||||
# $Id: date.rb,v 1.22 2000-07-16 10:23:40+09 tadf Exp $
|
# $Id: date2.rb,v 1.23 2001-01-18 12:09:47+09 tadf Exp $
|
||||||
|
|
||||||
class Date
|
class Date
|
||||||
|
|
||||||
@ -128,16 +128,15 @@ class Date
|
|||||||
end
|
end
|
||||||
if d < 0
|
if d < 0
|
||||||
ny, nm = clfloor(y * 12 + m, 12)
|
ny, nm = clfloor(y * 12 + m, 12)
|
||||||
nm, = clfloor(m + 1, 1)
|
nm, = clfloor(nm + 1, 1)
|
||||||
la = nil
|
jd = civil_to_jd(ny, nm, d + 1, sg)
|
||||||
31.downto 1 do |z|
|
ns = ns?(jd, sg)
|
||||||
break if la = exist3?(y, m, z, sg)
|
return unless [y, m] == jd_to_civil(jd, sg)[0..1]
|
||||||
end
|
return unless [ny, nm, 1] == jd_to_civil(jd - d, ns)
|
||||||
ns = ns?(la, sg)
|
else
|
||||||
d = jd_to_civil(civil_to_jd(ny, nm, 1, ns) + d, ns)[-1]
|
jd = civil_to_jd(y, m, d, sg)
|
||||||
|
return unless [y, m, d] == jd_to_civil(jd, sg)
|
||||||
end
|
end
|
||||||
jd = civil_to_jd(y, m, d, sg)
|
|
||||||
return unless [y, m, d] == jd_to_civil(jd, sg)
|
|
||||||
jd
|
jd
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -154,16 +153,15 @@ class Date
|
|||||||
|
|
||||||
def exist2? (y, d, sg=ITALY)
|
def exist2? (y, d, sg=ITALY)
|
||||||
if d < 0
|
if d < 0
|
||||||
ny = y + 1
|
ny, = clfloor(y + 1, 1)
|
||||||
la = nil
|
jd = ordinal_to_jd(ny, d + 1, sg)
|
||||||
366.downto 1 do |z|
|
ns = ns?(jd, sg)
|
||||||
break if la = exist2?(y, z, sg)
|
return unless [y] == jd_to_ordinal(jd, sg)[0..0]
|
||||||
end
|
return unless [ny, 1] == jd_to_ordinal(jd - d, ns)
|
||||||
ns = ns?(la, sg)
|
else
|
||||||
d = jd_to_ordinal(ordinal_to_jd(ny, 1, ns) + d, ns)[-1]
|
jd = ordinal_to_jd(y, d, sg)
|
||||||
|
return unless [y, d] == jd_to_ordinal(jd, sg)
|
||||||
end
|
end
|
||||||
jd = ordinal_to_jd(y, d, sg)
|
|
||||||
return unless [y, d] == jd_to_ordinal(jd, sg)
|
|
||||||
jd
|
jd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -608,7 +608,7 @@ class RubyLex
|
|||||||
identify_quotation
|
identify_quotation
|
||||||
elsif peek(0) == '='
|
elsif peek(0) == '='
|
||||||
getc
|
getc
|
||||||
Token(OP_ASGIN, "%")
|
Token(TkOPASGN, :%)
|
||||||
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
||||||
identify_quotation
|
identify_quotation
|
||||||
else
|
else
|
||||||
|
6
object.c
6
object.c
@ -288,7 +288,7 @@ rb_obj_taint(obj)
|
|||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (OBJ_TAINTED(obj)) {
|
if (!OBJ_TAINTED(obj)) {
|
||||||
if (OBJ_FROZEN(obj)) {
|
if (OBJ_FROZEN(obj)) {
|
||||||
rb_error_frozen("object");
|
rb_error_frozen("object");
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ rb_obj_untaint(obj)
|
|||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
rb_secure(3);
|
rb_secure(3);
|
||||||
if (!OBJ_TAINTED(obj)) {
|
if (OBJ_TAINTED(obj)) {
|
||||||
if (OBJ_FROZEN(obj)) {
|
if (OBJ_FROZEN(obj)) {
|
||||||
rb_error_frozen("object");
|
rb_error_frozen("object");
|
||||||
}
|
}
|
||||||
@ -315,7 +315,7 @@ VALUE
|
|||||||
rb_obj_freeze(obj)
|
rb_obj_freeze(obj)
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
if (OBJ_FROZEN(obj)) {
|
if (!OBJ_FROZEN(obj)) {
|
||||||
if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj)) {
|
if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj)) {
|
||||||
rb_raise(rb_eSecurityError, "Insecure: can't freeze object");
|
rb_raise(rb_eSecurityError, "Insecure: can't freeze object");
|
||||||
}
|
}
|
||||||
|
30
pack.c
30
pack.c
@ -1625,8 +1625,12 @@ pack_unpack(str, fmt)
|
|||||||
p = RARRAY(a)->ptr;
|
p = RARRAY(a)->ptr;
|
||||||
pend = p + RARRAY(a)->len;
|
pend = p + RARRAY(a)->len;
|
||||||
while (p < pend) {
|
while (p < pend) {
|
||||||
if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t)
|
if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) {
|
||||||
|
if (len > RSTRING(*p)->len) {
|
||||||
|
len = RSTRING(*p)->len;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (p == pend) {
|
if (p == pend) {
|
||||||
@ -1649,13 +1653,31 @@ pack_unpack(str, fmt)
|
|||||||
break;
|
break;
|
||||||
else {
|
else {
|
||||||
char *t;
|
char *t;
|
||||||
VALUE str = rb_str_new(0, 0);
|
VALUE a, tmp;
|
||||||
|
VALUE *p, *pend;
|
||||||
|
|
||||||
|
|
||||||
|
if (!(a = rb_str_associated(str))) {
|
||||||
|
rb_raise(rb_eArgError, "no associated pointer");
|
||||||
|
}
|
||||||
memcpy(&t, s, sizeof(char *));
|
memcpy(&t, s, sizeof(char *));
|
||||||
s += sizeof(char *);
|
s += sizeof(char *);
|
||||||
|
|
||||||
if (t) {
|
if (t) {
|
||||||
rb_str_cat2(str, t);
|
p = RARRAY(a)->ptr;
|
||||||
|
pend = p + RARRAY(a)->len;
|
||||||
|
while (p < pend) {
|
||||||
|
if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
if (p == pend) {
|
||||||
|
rb_raise(rb_eArgError, "non associated pointer");
|
||||||
|
}
|
||||||
|
tmp = rb_str_new2(t);
|
||||||
}
|
}
|
||||||
rb_ary_push(ary, str);
|
rb_ary_push(ary, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user