summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-20 08:17:53 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-20 08:17:53 +0000
commitb03649bc2a0764fffb969b71f4bf18dcc12fe869 (patch)
tree5143f75961c0b79afea08c2beb768c40b8847d73
parent7946d2357af1a142d7490a05f7f33531a3f28e81 (diff)
* ext/dbm/dbm.c (fdbm_closed): new method DBM#closed?
* ext/gdbm/gdbm.c (fgdbm_closed): new method GDBM#closed? * ext/sdbm/init.c (fsdbm_closed): new method SDBM#closed? * test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb, test/sdbm/test_sdbm.rb (teardown): close all db objects before deleting data files. * win32/win32.{ch} (unlink): hook runtime function to change file attribute before unlinking. merge from 1.8, see [ruby-dev:26360] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--ext/dbm/dbm.c16
-rw-r--r--ext/gdbm/gdbm.c16
-rw-r--r--ext/sdbm/init.c16
-rw-r--r--test/dbm/test_dbm.rb4
-rw-r--r--test/gdbm/test_gdbm.rb4
-rw-r--r--test/sdbm/test_sdbm.rb4
-rw-r--r--win32/win32.c20
-rw-r--r--win32/win32.h3
9 files changed, 95 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 601e5d4..bbb2710 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Mon Jun 20 17:15:51 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * ext/dbm/dbm.c (fdbm_closed): new method DBM#closed?
+
+ * ext/gdbm/gdbm.c (fgdbm_closed): new method GDBM#closed?
+
+ * ext/sdbm/init.c (fsdbm_closed): new method SDBM#closed?
+
+ * test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb, test/sdbm/test_sdbm.rb
+ (teardown): close all db objects before deleting data files.
+
+ * win32/win32.{ch} (unlink): hook runtime function to change
+ file attribute before unlinking.
+ merge from 1.8, see [ruby-dev:26360]
+
Mon Jun 20 02:15:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (define_final): document fix: finalizers never get called
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index f7b4c8c..bbc3528 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -71,6 +71,21 @@ fdbm_close(obj)
return Qnil;
}
+static VALUE
+fdbm_closed(obj)
+ VALUE obj;
+{
+ struct dbmdata *dbmp;
+
+ Data_Get_Struct(obj, struct dbmdata, dbmp);
+ if (dbmp == 0)
+ return Qtrue;
+ if (dbmp->di_dbm == 0)
+ return Qtrue;
+
+ return Qfalse;
+}
+
static VALUE fdbm_alloc _((VALUE));
static VALUE
fdbm_alloc(klass)
@@ -719,6 +734,7 @@ Init_dbm()
rb_define_method(rb_cDBM, "initialize", fdbm_initialize, -1);
rb_define_method(rb_cDBM, "close", fdbm_close, 0);
+ rb_define_method(rb_cDBM, "closed?", fdbm_closed, 0);
rb_define_method(rb_cDBM, "[]", fdbm_aref, 1);
rb_define_method(rb_cDBM, "fetch", fdbm_fetch_m, -1);
rb_define_method(rb_cDBM, "[]=", fdbm_store, 2);
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index d55b04c..a0e2e95 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -72,6 +72,21 @@ fgdbm_close(obj)
return Qnil;
}
+static VALUE
+fgdbm_closed(obj)
+ VALUE obj;
+{
+ struct dbmdata *dbmp;
+
+ Data_Get_Struct(obj, struct dbmdata, dbmp);
+ if (dbmp == 0)
+ return Qtrue;
+ if (dbmp->di_dbm == 0)
+ return Qtrue;
+
+ return Qfalse;
+}
+
static VALUE fgdbm_s_alloc _((VALUE));
static VALUE
@@ -909,6 +924,7 @@ Init_gdbm()
rb_define_method(rb_cGDBM, "initialize", fgdbm_initialize, -1);
rb_define_method(rb_cGDBM, "close", fgdbm_close, 0);
+ rb_define_method(rb_cGDBM, "closed?", fgdbm_closed, 0);
rb_define_method(rb_cGDBM, "[]", fgdbm_aref, 1);
rb_define_method(rb_cGDBM, "fetch", fgdbm_fetch_m, -1);
rb_define_method(rb_cGDBM, "[]=", fgdbm_store, 2);
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index 07e5567..c8883c9 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -62,6 +62,21 @@ fsdbm_close(obj)
return Qnil;
}
+static VALUE
+fsdbm_closed(obj)
+ VALUE obj;
+{
+ struct dbmdata *dbmp;
+
+ Data_Get_Struct(obj, struct dbmdata, dbmp);
+ if (dbmp == 0)
+ return Qtrue;
+ if (dbmp->di_dbm == 0)
+ return Qtrue;
+
+ return Qfalse;
+}
+
static VALUE fsdbm_alloc _((VALUE));
static VALUE
fsdbm_alloc(klass)
@@ -700,6 +715,7 @@ Init_sdbm()
rb_define_method(rb_cDBM, "initialize", fsdbm_initialize, -1);
rb_define_method(rb_cDBM, "close", fsdbm_close, 0);
+ rb_define_method(rb_cDBM, "closed?", fsdbm_closed, 0);
rb_define_method(rb_cDBM, "[]", fsdbm_aref, 1);
rb_define_method(rb_cDBM, "fetch", fsdbm_fetch_m, -1);
rb_define_method(rb_cDBM, "[]=", fsdbm_store, 2);
diff --git a/test/dbm/test_dbm.rb b/test/dbm/test_dbm.rb
index f089d63..a5e2c4f 100644
--- a/test/dbm/test_dbm.rb
+++ b/test/dbm/test_dbm.rb
@@ -42,7 +42,9 @@ if defined? DBM
def teardown
assert_nil(@dbm.close)
assert_nil(@dbm_rdonly.close)
- GC.start
+ ObjectSpace.each_object(DBM) do |obj|
+ obj.close unless obj.closed?
+ end
File.delete *Dir.glob("tmptest_dbm*").to_a
p Dir.glob("tmptest_dbm*") if $DEBUG
end
diff --git a/test/gdbm/test_gdbm.rb b/test/gdbm/test_gdbm.rb
index 0b913e3..d2f3a94 100644
--- a/test/gdbm/test_gdbm.rb
+++ b/test/gdbm/test_gdbm.rb
@@ -39,7 +39,9 @@ if defined? GDBM
def teardown
assert_nil(@gdbm.close)
assert_nil(@gdbm_rdonly.close)
- GC.start
+ ObjectSpace.each_object(GDBM) do |obj|
+ obj.close unless obj.closed?
+ end
File.delete *Dir.glob("tmptest_gdbm*").to_a
p Dir.glob("tmptest_gdbm*") if $DEBUG
end
diff --git a/test/sdbm/test_sdbm.rb b/test/sdbm/test_sdbm.rb
index 9945064..d94b5e9 100644
--- a/test/sdbm/test_sdbm.rb
+++ b/test/sdbm/test_sdbm.rb
@@ -12,7 +12,9 @@ class TestSDBM < Test::Unit::TestCase
end
def teardown
assert_nil(@sdbm.close)
- GC.start
+ ObjectSpace.each_object(SDBM) do |obj|
+ obj.close unless obj.closed?
+ end
File.delete *Dir.glob("tmptest_sdbm*").to_a
p Dir.glob("tmptest_sdbm*") if $DEBUG
end
diff --git a/win32/win32.c b/win32/win32.c
index 3e126e6..4c916f1 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3638,6 +3638,26 @@ rb_w32_rmdir(const char *path)
return ret;
}
+#undef unlink
+int
+rb_w32_unlink(const char *path)
+{
+ DWORD attr;
+ int ret;
+ RUBY_CRITICAL({
+ attr = GetFileAttributes(path);
+ if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
+ attr &= ~FILE_ATTRIBUTE_READONLY;
+ SetFileAttributes(path, attr);
+ }
+ ret = unlink(path);
+ if (ret < 0 && attr != (DWORD)-1) {
+ SetFileAttributes(path, attr);
+ }
+ });
+ return ret;
+}
+
//
// Fix bcc32's stdio bug
//
diff --git a/win32/win32.h b/win32/win32.h
index f073048..c6aabc4 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -131,6 +131,8 @@ extern "C++" {
#define mkdir(p, m) rb_w32_mkdir(p, m)
#undef rmdir
#define rmdir(p) rb_w32_rmdir(p)
+#undef unlink
+#define unlink(p) rb_w32_unlink(p)
#ifdef __MINGW32__
struct timezone {
@@ -197,6 +199,7 @@ extern int rb_w32_isatty(int);
#endif
extern int rb_w32_mkdir(const char *, int);
extern int rb_w32_rmdir(const char *);
+extern int rb_w32_unlink(const char*);
#ifdef __BORLANDC__
extern int rb_w32_fstat(int, struct stat *);