summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
commit1fe40b7cc5e92105f636d670d77b059fe4a4c50b (patch)
tree02dfc7bab198fc494d9d4f1f3bf1072d292fed66 /file.c
parentd902111a57dfcf3c9b017b0ebd1b49f19142168c (diff)
* marshal.c (r_object): better allocation type check for
TYPE_UCLASS. usage of allocation framework is disabled for now. * variable.c (rb_class_path): Module may have subclass. * string.c (rb_str_update): should maintain original negative offset. * string.c (rb_str_subpat_set): ditto * string.c (rb_str_aset): ditto. * re.c (rb_reg_nth_match): should check negative nth. * re.c (rb_reg_nth_defined): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/file.c b/file.c
index 68b658991e..e9c4edcaa0 100644
--- a/file.c
+++ b/file.c
@@ -113,11 +113,12 @@ stat_new_0(klass, st)
VALUE klass;
struct stat *st;
{
- struct stat *nst;
- if (!st) rb_bug("stat_new() called with bad value");
+ struct stat *nst = 0;
- nst = ALLOC(struct stat);
- *nst = *st;
+ if (st) {
+ nst = ALLOC(struct stat);
+ *nst = *st;
+ }
return Data_Wrap_Struct(klass, NULL, free, nst);
}
@@ -134,7 +135,7 @@ get_stat(self)
{
struct stat* st;
Data_Get_Struct(self, struct stat, st);
- if (!st) rb_bug("collapsed File::Stat");
+ if (!st) rb_raise(rb_eTypeError, "uninitialized File::Stat");
return st;
}
@@ -1883,26 +1884,27 @@ rb_f_test(argc, argv)
}
static VALUE
-rb_stat_s_new(klass, fname)
- VALUE klass, fname;
+rb_stat_s_alloc(klass)
+ VALUE klass;
{
- VALUE s;
- struct stat st;
+ return stat_new_0(klass, 0);
+}
+
+static VALUE
+rb_stat_init(obj, fname)
+ VALUE obj, fname;
+{
+ struct stat st, *nst;
Check_SafeStr(fname);
+
if (stat(RSTRING(fname)->ptr, &st) == -1) {
rb_sys_fail(RSTRING(fname)->ptr);
}
- s = stat_new_0(klass, &st);
- rb_obj_call_init(s, 1, &fname);
- return s;
-}
+ nst = ALLOC(struct stat);
+ *nst = st;
+ DATA_PTR(obj) = nst;
-static VALUE
-rb_stat_init(klass, fname)
- VALUE klass, fname;
-{
- /* do nothing */
return Qnil;
}
@@ -2505,7 +2507,7 @@ Init_File()
rb_define_global_function("test", rb_f_test, -1);
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
- rb_define_singleton_method(rb_cStat, "new", rb_stat_s_new, 1);
+ rb_define_singleton_method(rb_cStat, "allocate", rb_stat_s_alloc, 0);
rb_define_method(rb_cStat, "initialize", rb_stat_init, 1);
rb_include_module(rb_cStat, rb_mComparable);