Permalink
Browse files

* 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: http://svn.ruby-lang.org/repos/ruby/trunk@1748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
matz committed Sep 19, 2001
1 parent ceb972c commit 4f38192327badc642b66fb2e0605b9e70c398b4d
Showing with 94 additions and 50 deletions.
  1. +11 −0 ChangeLog
  2. +2 −2 ToDo
  3. +55 −31 dir.c
  4. +1 −1 eval.c
  5. +4 −5 file.c
  6. +0 −1 parse.y
  7. +3 −7 regex.c
  8. +16 −1 string.c
  9. +2 −2 version.h
View
@@ -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>
* lib/net/telnet.rb: waitfor(): improvement. thanks to
View
4 ToDo
@@ -28,7 +28,7 @@ Language Spec.
* jar like combined library package.
* resumable Exception via Exception#resume.
* method combination, e.g. before, after, around, etc.
-* .. or something like defactive in Emacs.
+* .. or something like defadvice in Emacs.
Hacking Interpreter
@@ -87,7 +87,7 @@ Standard Libraries
* library to load per-user profile seeking .ruby_profile or ruby.ini file.
* warning framework (warn, warning for Ruby level)
* 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
View
86 dir.c
@@ -234,11 +234,16 @@ fnmatch(pat, string, flags)
VALUE rb_cDir;
+struct dir_data {
+ DIR *dir;
+ char *path;
+};
+
static void
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));
@@ -249,8 +254,11 @@ dir_s_new(argc, argv, klass)
VALUE *argv;
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);
return obj;
@@ -260,22 +268,25 @@ static VALUE
dir_initialize(dir, dirname)
VALUE dir, dirname;
{
- DIR *dirp;
+ struct dir_data *dp;
SafeStringValue(dirname);
- if (DATA_PTR(dir)) closedir(DATA_PTR(dir));
- DATA_PTR(dir) = NULL;
- dirp = opendir(RSTRING(dirname)->ptr);
- if (dirp == NULL) {
+ Data_Get_Struct(dir, struct dir_data, dp);
+ if (dp->dir) closedir(dp->dir);
+ if (dp->path) free(dp->path);
+ dp->dir = NULL;
+ dp->path = NULL;
+ dp->dir = opendir(RSTRING(dirname)->ptr);
+ if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) {
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);
}
}
- DATA_PTR(dir) = dirp;
+ dp->path = strdup(RSTRING(dirname)->ptr);
return dir;
}
@@ -284,7 +295,8 @@ static VALUE
dir_s_open(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);
if (rb_block_given_p()) {
@@ -301,22 +313,34 @@ dir_closed()
}
#define GetDIR(obj, dirp) {\
- Data_Get_Struct(obj, DIR, dirp);\
- if (dirp == NULL) dir_closed();\
+ Data_Get_Struct(obj, struct dir_data, dirp);\
+ 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
dir_read(dir)
VALUE dir;
{
- DIR *dirp;
+ struct dir_data *dirp;
struct dirent *dp;
GetDIR(dir, dirp);
errno = 0;
- dp = readdir(dirp);
- if (dp)
+ dp = readdir(dirp->dir);
+ if (dp) {
return rb_tainted_str_new(dp->d_name, NAMLEN(dp));
+ }
else if (errno == 0) { /* end of stream */
return Qnil;
}
@@ -330,13 +354,13 @@ static VALUE
dir_each(dir)
VALUE dir;
{
- DIR *dirp;
+ struct dir_data *dirp;
struct dirent *dp;
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)));
- if (DATA_PTR(dir) == NULL) dir_closed();
+ if (dirp->dir == NULL) dir_closed();
}
return dir;
}
@@ -346,11 +370,11 @@ dir_tell(dir)
VALUE dir;
{
#ifdef HAVE_TELLDIR
- DIR *dirp;
+ struct dir_data *dirp;
long pos;
GetDIR(dir, dirp);
- pos = telldir(dirp);
+ pos = telldir(dirp->dir);
return rb_int2inum(pos);
#else
rb_notimplement();
@@ -361,11 +385,11 @@ static VALUE
dir_seek(dir, pos)
VALUE dir, pos;
{
- DIR *dirp;
+ struct dir_data *dirp;
#ifdef HAVE_SEEKDIR
GetDIR(dir, dirp);
- seekdir(dirp, NUM2INT(pos));
+ seekdir(dirp->dir, NUM2INT(pos));
return dir;
#else
rb_notimplement();
@@ -376,23 +400,22 @@ static VALUE
dir_rewind(dir)
VALUE dir;
{
- DIR *dirp;
+ struct dir_data *dirp;
GetDIR(dir, dirp);
- rewinddir(dirp);
+ rewinddir(dirp->dir);
return dir;
}
static VALUE
dir_close(dir)
VALUE dir;
{
- DIR *dirp;
+ struct dir_data *dirp;
- Data_Get_Struct(dir, DIR, dirp);
- if (dirp == NULL) dir_closed();
- closedir(dirp);
- DATA_PTR(dir) = NULL;
+ GetDIR(dir, dirp);
+ closedir(dirp->dir);
+ dirp->dir = NULL;
return Qnil;
}
@@ -978,6 +1001,7 @@ Init_Dir()
rb_define_singleton_method(rb_cDir, "entries", dir_entries, 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,"each", dir_each, 0);
rb_define_method(rb_cDir,"rewind", dir_rewind, 0);
View
2 eval.c
@@ -8211,7 +8211,7 @@ rb_thread_abort_exc_set(thread, val)
th->errinfo = Qnil;\
th->last_status = 0;\
th->last_line = 0;\
- th->last_match = 0;\
+ th->last_match = Qnil;\
th->abort = 0;\
th->priority = 0;\
th->gid = 1;\
View
9 file.c
@@ -76,7 +76,7 @@ static VALUE rb_cStat;
static int
apply2files(func, vargs, arg)
- int (*func)();
+ void (*func)();
VALUE vargs;
void *arg;
{
@@ -87,8 +87,7 @@ apply2files(func, vargs, arg)
for (i=0; i<args->len; i++) {
path = args->ptr[i];
SafeStringValue(path);
- if ((*func)(RSTRING(path)->ptr, arg) < 0)
- rb_sys_fail(RSTRING(path)->ptr);
+ (*func)(RSTRING(path)->ptr, arg);
}
return args->len;
@@ -913,7 +912,7 @@ chmod_internal(path, mode)
const char *path;
int mode;
{
- if (chmod(path, mode) == -1)
+ if (chmod(path, mode) < 0)
rb_sys_fail(path);
}
@@ -963,7 +962,7 @@ lchmod_internal(path, mode)
const char *path;
int mode;
{
- if (lchmod(path, mode) == -1)
+ if (lchmod(path, mode) < 0)
rb_sys_fail(path);
}
View
@@ -3459,7 +3459,6 @@ yylex()
c = tLPAREN_ARG;
}
else if (lex_state == EXPR_ARG) {
- rb_warning("%s (...) interpreted as method call", tok());
c = tLPAREN_ARG;
yylval.id = last_id;
}
View
10 regex.c
@@ -1271,13 +1271,9 @@ re_compile_pattern(pattern, size, bufp)
if (bufp->allocated == 0) {
bufp->allocated = INIT_BUF_SIZE;
- if (bufp->buffer)
- /* EXTEND_BUFFER loses when bufp->allocated is 0. */
- bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE);
- else
- /* Caller did not allocate a buffer. Do it for them. */
- bufp->buffer = (char*)xmalloc(INIT_BUF_SIZE);
- if (!bufp->buffer) goto memory_exhausted;
+ /* EXTEND_BUFFER loses when bufp->allocated is 0. */
+ bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE);
+ if (!bufp->buffer) goto memory_exhausted; /* this not happen */
begalt = b = bufp->buffer;
}
View
@@ -302,6 +302,21 @@ rb_str_s_new(argc, argv, klass)
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
rb_str_length(str)
VALUE str;
@@ -2992,7 +3007,7 @@ Init_String()
rb_include_module(rb_cString, rb_mComparable);
rb_include_module(rb_cString, rb_mEnumerable);
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, "dup", rb_str_dup, 0);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
View
@@ -1,4 +1,4 @@
#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_RELEASE_CODE 20010908
+#define RUBY_RELEASE_CODE 20010919

0 comments on commit 4f38192

Please sign in to comment.