From b03649bc2a0764fffb969b71f4bf18dcc12fe869 Mon Sep 17 00:00:00 2001 From: usa Date: Mon, 20 Jun 2005 08:17:53 +0000 Subject: [PATCH] * 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 --- ChangeLog | 15 +++++++++++++++ ext/dbm/dbm.c | 16 ++++++++++++++++ ext/gdbm/gdbm.c | 16 ++++++++++++++++ ext/sdbm/init.c | 16 ++++++++++++++++ test/dbm/test_dbm.rb | 4 +++- test/gdbm/test_gdbm.rb | 4 +++- test/sdbm/test_sdbm.rb | 4 +++- win32/win32.c | 20 ++++++++++++++++++++ win32/win32.h | 3 +++ 9 files changed, 95 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 601e5d459c..bbb2710c17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Mon Jun 20 17:15:51 2005 NAKAMURA Usaku + + * 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 * gc.c (define_final): document fix: finalizers never get called diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index f7b4c8cc17..bbc35280cc 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 d55b04ce56..a0e2e95b38 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 07e5567329..c8883c9f8d 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 f089d63b6f..a5e2c4f4a1 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 0b913e3a57..d2f3a945a0 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 99450640b3..d94b5e94af 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 3e126e64fc..4c916f15ca 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 f073048074..c6aabc42b5 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 *);