1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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:
matz 2001-01-18 08:43:14 +00:00
parent 24a286efe1
commit 0b3092922d
9 changed files with 93 additions and 44 deletions

View file

@ -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>
* 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>
* 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>

1
ToDo
View file

@ -43,6 +43,7 @@ Hacking Interpreter
* remove stdio dependency from IOs.
* warn for inconsistent local variable usage (lv m and method m at the same time).
* MicroRuby
* Built-in Interactive Ruby.
Standard Libraries

1
eval.c
View file

@ -6300,7 +6300,6 @@ block_pass(self, node)
}
POP_TAG();
POP_ITER();
printf("state: %d(%d)\n", state, _block.tag->dst);
if (_block.tag->dst == state) {
if (orphan) {
state &= TAG_MASK;

View file

@ -420,7 +420,7 @@ enum sock_recv_type {
RECV_RECV, /* BasicSocket#recv(no from) */
RECV_IP, /* IPSocket#recvfrom */
RECV_UNIX, /* UNIXSocket#recvfrom */
RECV_SOCKET, /* Socket#recvfrom */
RECV_SOCKET /* Socket#recvfrom */
};
static VALUE

48
io.c
View file

@ -3022,7 +3022,7 @@ struct foreach_arg {
};
static VALUE
rb_io_foreach_line(arg)
io_s_foreach(arg)
struct foreach_arg *arg;
{
VALUE str;
@ -3048,21 +3048,14 @@ rb_io_s_foreach(argc, argv, io)
arg.argc = argc - 1;
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
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
rb_io_readline_line(arg)
io_s_readlines(arg)
struct foreach_arg *arg;
{
VALUE line, ary;
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;
return rb_io_readlines(arg->argc, &arg->sep, arg->io);
}
static VALUE
@ -3080,7 +3073,35 @@ rb_io_s_readlines(argc, argv, io)
arg.argc = argc - 1;
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
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
@ -3115,7 +3136,7 @@ argf_set_pos(self, offset)
VALUE self, offset;
{
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) {
@ -3365,6 +3386,7 @@ Init_IO()
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, "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, "pipe", rb_io_s_pipe, 0);

View file

@ -1,5 +1,5 @@
# date.rb: Written by Tadayoshi Funaba 1998-2000
# $Id: date.rb,v 1.22 2000-07-16 10:23:40+09 tadf Exp $
# date2.rb: Written by Tadayoshi Funaba 1998-2001
# $Id: date2.rb,v 1.23 2001-01-18 12:09:47+09 tadf Exp $
class Date
@ -128,16 +128,15 @@ class Date
end
if d < 0
ny, nm = clfloor(y * 12 + m, 12)
nm, = clfloor(m + 1, 1)
la = nil
31.downto 1 do |z|
break if la = exist3?(y, m, z, sg)
end
ns = ns?(la, sg)
d = jd_to_civil(civil_to_jd(ny, nm, 1, ns) + d, ns)[-1]
nm, = clfloor(nm + 1, 1)
jd = civil_to_jd(ny, nm, d + 1, sg)
ns = ns?(jd, sg)
return unless [y, m] == jd_to_civil(jd, sg)[0..1]
return unless [ny, nm, 1] == jd_to_civil(jd - d, ns)
else
jd = civil_to_jd(y, m, d, sg)
return unless [y, m, d] == jd_to_civil(jd, sg)
end
jd = civil_to_jd(y, m, d, sg)
return unless [y, m, d] == jd_to_civil(jd, sg)
jd
end
@ -154,16 +153,15 @@ class Date
def exist2? (y, d, sg=ITALY)
if d < 0
ny = y + 1
la = nil
366.downto 1 do |z|
break if la = exist2?(y, z, sg)
end
ns = ns?(la, sg)
d = jd_to_ordinal(ordinal_to_jd(ny, 1, ns) + d, ns)[-1]
ny, = clfloor(y + 1, 1)
jd = ordinal_to_jd(ny, d + 1, sg)
ns = ns?(jd, sg)
return unless [y] == jd_to_ordinal(jd, sg)[0..0]
return unless [ny, 1] == jd_to_ordinal(jd - d, ns)
else
jd = ordinal_to_jd(y, d, sg)
return unless [y, d] == jd_to_ordinal(jd, sg)
end
jd = ordinal_to_jd(y, d, sg)
return unless [y, d] == jd_to_ordinal(jd, sg)
jd
end

View file

@ -608,7 +608,7 @@ class RubyLex
identify_quotation
elsif peek(0) == '='
getc
Token(OP_ASGIN, "%")
Token(TkOPASGN, :%)
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
identify_quotation
else

View file

@ -288,7 +288,7 @@ rb_obj_taint(obj)
VALUE obj;
{
rb_secure(4);
if (OBJ_TAINTED(obj)) {
if (!OBJ_TAINTED(obj)) {
if (OBJ_FROZEN(obj)) {
rb_error_frozen("object");
}
@ -302,7 +302,7 @@ rb_obj_untaint(obj)
VALUE obj;
{
rb_secure(3);
if (!OBJ_TAINTED(obj)) {
if (OBJ_TAINTED(obj)) {
if (OBJ_FROZEN(obj)) {
rb_error_frozen("object");
}
@ -315,7 +315,7 @@ VALUE
rb_obj_freeze(obj)
VALUE obj;
{
if (OBJ_FROZEN(obj)) {
if (!OBJ_FROZEN(obj)) {
if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj)) {
rb_raise(rb_eSecurityError, "Insecure: can't freeze object");
}

30
pack.c
View file

@ -1625,8 +1625,12 @@ pack_unpack(str, fmt)
p = RARRAY(a)->ptr;
pend = p + RARRAY(a)->len;
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;
}
p++;
}
if (p == pend) {
@ -1649,13 +1653,31 @@ pack_unpack(str, fmt)
break;
else {
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 *));
s += sizeof(char *);
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;