* string.c (rb_str_init): String.new() => ""

* dir.c (dir_path): new method.

* dir.c (dir_initialize): wrap DIR into struct, along with path
  information.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-09-19 06:54:11 +00:00
parent 67245eec71
commit 6767cd760a
9 changed files with 94 additions and 50 deletions

View File

@ -1,3 +1,14 @@
Tue Sep 18 11:44:26 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_init): String.new() => ""
Tue Sep 11 20:53:56 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (dir_path): new method.
* dir.c (dir_initialize): wrap DIR into struct, along with path
information.
Sat Sep 8 07:13:42 2001 Wakou Aoyama <wakou@fsinet.or.jp> Sat Sep 8 07:13:42 2001 Wakou Aoyama <wakou@fsinet.or.jp>
* lib/net/telnet.rb: waitfor(): improvement. thanks to * lib/net/telnet.rb: waitfor(): improvement. thanks to

4
ToDo
View File

@ -28,7 +28,7 @@ Language Spec.
* jar like combined library package. * jar like combined library package.
* resumable Exception via Exception#resume. * resumable Exception via Exception#resume.
* method combination, e.g. before, after, around, etc. * method combination, e.g. before, after, around, etc.
* .. or something like defactive in Emacs. * .. or something like defadvice in Emacs.
Hacking Interpreter Hacking Interpreter
@ -87,7 +87,7 @@ Standard Libraries
* library to load per-user profile seeking .ruby_profile or ruby.ini file. * library to load per-user profile seeking .ruby_profile or ruby.ini file.
* warning framework (warn, warning for Ruby level) * warning framework (warn, warning for Ruby level)
* marshal should not depend on sprintf/strtod (works bad for locale). * marshal should not depend on sprintf/strtod (works bad for locale).
* ternary arg - a.pow(b,c) == a**b%c * ternary arg pow: a.pow(b,c) == a**b%c
Extension Libraries Extension Libraries

86
dir.c
View File

@ -234,11 +234,16 @@ fnmatch(pat, string, flags)
VALUE rb_cDir; VALUE rb_cDir;
struct dir_data {
DIR *dir;
char *path;
};
static void static void
free_dir(dir) free_dir(dir)
DIR *dir; struct dir_data *dir;
{ {
if (dir) closedir(dir); if (dir && dir->dir) closedir(dir->dir);
} }
static VALUE dir_close _((VALUE)); static VALUE dir_close _((VALUE));
@ -249,8 +254,11 @@ dir_s_new(argc, argv, klass)
VALUE *argv; VALUE *argv;
VALUE klass; VALUE klass;
{ {
VALUE obj = Data_Wrap_Struct(klass, 0, free_dir, 0); struct dir_data *dirp;
VALUE obj = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dirp);
dirp->dir = NULL;
dirp->path = NULL;
rb_obj_call_init(obj, argc, argv); rb_obj_call_init(obj, argc, argv);
return obj; return obj;
@ -260,22 +268,25 @@ static VALUE
dir_initialize(dir, dirname) dir_initialize(dir, dirname)
VALUE dir, dirname; VALUE dir, dirname;
{ {
DIR *dirp; struct dir_data *dp;
SafeStringValue(dirname); SafeStringValue(dirname);
if (DATA_PTR(dir)) closedir(DATA_PTR(dir)); Data_Get_Struct(dir, struct dir_data, dp);
DATA_PTR(dir) = NULL; if (dp->dir) closedir(dp->dir);
dirp = opendir(RSTRING(dirname)->ptr); if (dp->path) free(dp->path);
if (dirp == NULL) { dp->dir = NULL;
dp->path = NULL;
dp->dir = opendir(RSTRING(dirname)->ptr);
if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) { if (errno == EMFILE || errno == ENFILE) {
rb_gc(); rb_gc();
dirp = opendir(RSTRING(dirname)->ptr); dp->dir = opendir(RSTRING(dirname)->ptr);
} }
if (dirp == NULL) { if (dp->dir == NULL) {
rb_sys_fail(RSTRING(dirname)->ptr); rb_sys_fail(RSTRING(dirname)->ptr);
} }
} }
DATA_PTR(dir) = dirp; dp->path = strdup(RSTRING(dirname)->ptr);
return dir; return dir;
} }
@ -284,7 +295,8 @@ static VALUE
dir_s_open(klass, dirname) dir_s_open(klass, dirname)
VALUE klass, dirname; VALUE klass, dirname;
{ {
VALUE dir = Data_Wrap_Struct(klass, 0, free_dir, 0); struct dir_data *dp;
VALUE dir = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dp);
dir_initialize(dir, dirname); dir_initialize(dir, dirname);
if (rb_block_given_p()) { if (rb_block_given_p()) {
@ -301,22 +313,34 @@ dir_closed()
} }
#define GetDIR(obj, dirp) {\ #define GetDIR(obj, dirp) {\
Data_Get_Struct(obj, DIR, dirp);\ Data_Get_Struct(obj, struct dir_data, dirp);\
if (dirp == NULL) dir_closed();\ if (dirp->dir == NULL) dir_closed();\
}
static VALUE
dir_path(dir)
VALUE dir;
{
struct dir_data *dirp;
GetDIR(dir, dirp);
if (!dirp->path) return Qnil;
return rb_str_new2(dirp->path);
} }
static VALUE static VALUE
dir_read(dir) dir_read(dir)
VALUE dir; VALUE dir;
{ {
DIR *dirp; struct dir_data *dirp;
struct dirent *dp; struct dirent *dp;
GetDIR(dir, dirp); GetDIR(dir, dirp);
errno = 0; errno = 0;
dp = readdir(dirp); dp = readdir(dirp->dir);
if (dp) if (dp) {
return rb_tainted_str_new(dp->d_name, NAMLEN(dp)); return rb_tainted_str_new(dp->d_name, NAMLEN(dp));
}
else if (errno == 0) { /* end of stream */ else if (errno == 0) { /* end of stream */
return Qnil; return Qnil;
} }
@ -330,13 +354,13 @@ static VALUE
dir_each(dir) dir_each(dir)
VALUE dir; VALUE dir;
{ {
DIR *dirp; struct dir_data *dirp;
struct dirent *dp; struct dirent *dp;
GetDIR(dir, dirp); GetDIR(dir, dirp);
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
rb_yield(rb_tainted_str_new(dp->d_name, NAMLEN(dp))); rb_yield(rb_tainted_str_new(dp->d_name, NAMLEN(dp)));
if (DATA_PTR(dir) == NULL) dir_closed(); if (dirp->dir == NULL) dir_closed();
} }
return dir; return dir;
} }
@ -346,11 +370,11 @@ dir_tell(dir)
VALUE dir; VALUE dir;
{ {
#ifdef HAVE_TELLDIR #ifdef HAVE_TELLDIR
DIR *dirp; struct dir_data *dirp;
long pos; long pos;
GetDIR(dir, dirp); GetDIR(dir, dirp);
pos = telldir(dirp); pos = telldir(dirp->dir);
return rb_int2inum(pos); return rb_int2inum(pos);
#else #else
rb_notimplement(); rb_notimplement();
@ -361,11 +385,11 @@ static VALUE
dir_seek(dir, pos) dir_seek(dir, pos)
VALUE dir, pos; VALUE dir, pos;
{ {
DIR *dirp; struct dir_data *dirp;
#ifdef HAVE_SEEKDIR #ifdef HAVE_SEEKDIR
GetDIR(dir, dirp); GetDIR(dir, dirp);
seekdir(dirp, NUM2INT(pos)); seekdir(dirp->dir, NUM2INT(pos));
return dir; return dir;
#else #else
rb_notimplement(); rb_notimplement();
@ -376,10 +400,10 @@ static VALUE
dir_rewind(dir) dir_rewind(dir)
VALUE dir; VALUE dir;
{ {
DIR *dirp; struct dir_data *dirp;
GetDIR(dir, dirp); GetDIR(dir, dirp);
rewinddir(dirp); rewinddir(dirp->dir);
return dir; return dir;
} }
@ -387,12 +411,11 @@ static VALUE
dir_close(dir) dir_close(dir)
VALUE dir; VALUE dir;
{ {
DIR *dirp; struct dir_data *dirp;
Data_Get_Struct(dir, DIR, dirp); GetDIR(dir, dirp);
if (dirp == NULL) dir_closed(); closedir(dirp->dir);
closedir(dirp); dirp->dir = NULL;
DATA_PTR(dir) = NULL;
return Qnil; return Qnil;
} }
@ -978,6 +1001,7 @@ Init_Dir()
rb_define_singleton_method(rb_cDir, "entries", dir_entries, 1); rb_define_singleton_method(rb_cDir, "entries", dir_entries, 1);
rb_define_method(rb_cDir,"initialize", dir_initialize, 1); rb_define_method(rb_cDir,"initialize", dir_initialize, 1);
rb_define_method(rb_cDir,"path", dir_path, 0);
rb_define_method(rb_cDir,"read", dir_read, 0); rb_define_method(rb_cDir,"read", dir_read, 0);
rb_define_method(rb_cDir,"each", dir_each, 0); rb_define_method(rb_cDir,"each", dir_each, 0);
rb_define_method(rb_cDir,"rewind", dir_rewind, 0); rb_define_method(rb_cDir,"rewind", dir_rewind, 0);

2
eval.c
View File

@ -8211,7 +8211,7 @@ rb_thread_abort_exc_set(thread, val)
th->errinfo = Qnil;\ th->errinfo = Qnil;\
th->last_status = 0;\ th->last_status = 0;\
th->last_line = 0;\ th->last_line = 0;\
th->last_match = 0;\ th->last_match = Qnil;\
th->abort = 0;\ th->abort = 0;\
th->priority = 0;\ th->priority = 0;\
th->gid = 1;\ th->gid = 1;\

9
file.c
View File

@ -76,7 +76,7 @@ static VALUE rb_cStat;
static int static int
apply2files(func, vargs, arg) apply2files(func, vargs, arg)
int (*func)(); void (*func)();
VALUE vargs; VALUE vargs;
void *arg; void *arg;
{ {
@ -87,8 +87,7 @@ apply2files(func, vargs, arg)
for (i=0; i<args->len; i++) { for (i=0; i<args->len; i++) {
path = args->ptr[i]; path = args->ptr[i];
SafeStringValue(path); SafeStringValue(path);
if ((*func)(RSTRING(path)->ptr, arg) < 0) (*func)(RSTRING(path)->ptr, arg);
rb_sys_fail(RSTRING(path)->ptr);
} }
return args->len; return args->len;
@ -913,7 +912,7 @@ chmod_internal(path, mode)
const char *path; const char *path;
int mode; int mode;
{ {
if (chmod(path, mode) == -1) if (chmod(path, mode) < 0)
rb_sys_fail(path); rb_sys_fail(path);
} }
@ -963,7 +962,7 @@ lchmod_internal(path, mode)
const char *path; const char *path;
int mode; int mode;
{ {
if (lchmod(path, mode) == -1) if (lchmod(path, mode) < 0)
rb_sys_fail(path); rb_sys_fail(path);
} }

View File

@ -3459,7 +3459,6 @@ yylex()
c = tLPAREN_ARG; c = tLPAREN_ARG;
} }
else if (lex_state == EXPR_ARG) { else if (lex_state == EXPR_ARG) {
rb_warning("%s (...) interpreted as method call", tok());
c = tLPAREN_ARG; c = tLPAREN_ARG;
yylval.id = last_id; yylval.id = last_id;
} }

10
regex.c
View File

@ -1271,13 +1271,9 @@ re_compile_pattern(pattern, size, bufp)
if (bufp->allocated == 0) { if (bufp->allocated == 0) {
bufp->allocated = INIT_BUF_SIZE; bufp->allocated = INIT_BUF_SIZE;
if (bufp->buffer) /* EXTEND_BUFFER loses when bufp->allocated is 0. */
/* EXTEND_BUFFER loses when bufp->allocated is 0. */ bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE);
bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE); if (!bufp->buffer) goto memory_exhausted; /* this not happen */
else
/* Caller did not allocate a buffer. Do it for them. */
bufp->buffer = (char*)xmalloc(INIT_BUF_SIZE);
if (!bufp->buffer) goto memory_exhausted;
begalt = b = bufp->buffer; begalt = b = bufp->buffer;
} }

View File

@ -302,6 +302,21 @@ rb_str_s_new(argc, argv, klass)
return str; return str;
} }
static VALUE rb_str_replace _((VALUE, VALUE));
static VALUE
rb_str_init(argc, argv, str)
int argc;
VALUE *argv;
VALUE str;
{
VALUE orig;
if (rb_scan_args(argc, argv, "01", &orig) == 1)
rb_str_replace(str, orig);
return str;
}
static VALUE static VALUE
rb_str_length(str) rb_str_length(str)
VALUE str; VALUE str;
@ -2992,7 +3007,7 @@ Init_String()
rb_include_module(rb_cString, rb_mComparable); rb_include_module(rb_cString, rb_mComparable);
rb_include_module(rb_cString, rb_mEnumerable); rb_include_module(rb_cString, rb_mEnumerable);
rb_define_singleton_method(rb_cString, "new", rb_str_s_new, -1); rb_define_singleton_method(rb_cString, "new", rb_str_s_new, -1);
rb_define_method(rb_cString, "initialize", rb_str_replace, 1); rb_define_method(rb_cString, "initialize", rb_str_init, -1);
rb_define_method(rb_cString, "clone", rb_str_clone, 0); rb_define_method(rb_cString, "clone", rb_str_clone, 0);
rb_define_method(rb_cString, "dup", rb_str_dup, 0); rb_define_method(rb_cString, "dup", rb_str_dup, 0);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1); rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);

View File

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.1" #define RUBY_VERSION "1.7.1"
#define RUBY_RELEASE_DATE "2001-09-08" #define RUBY_RELEASE_DATE "2001-09-19"
#define RUBY_VERSION_CODE 171 #define RUBY_VERSION_CODE 171
#define RUBY_RELEASE_CODE 20010908 #define RUBY_RELEASE_CODE 20010919