From 84e3af38859d7fc6e0abb5c2fc69e7fc04107cf8 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 29 May 2007 01:59:45 +0000 Subject: * win32/win32.c (rb_w32_opendir): store attributes of the second entries or later too. * win32/win32.c (rb_w32_opendir, rb_w32_readdir): eliminate magic numbers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ version.h | 6 +++--- win32/win32.c | 59 +++++++++++++++++++++++++++-------------------------------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2b3d155f7..0bacfe1810 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue May 29 11:01:06 2007 Nobuyoshi Nakada + + * win32/win32.c (rb_w32_opendir): store attributes of the second + entries or later too. + + * win32/win32.c (rb_w32_opendir, rb_w32_readdir): eliminate magic + numbers. + Mon May 28 02:54:05 2007 Masatoshi SEKI * lib/rinda/tuplespace.rb (Rinda::TupleBag#delete): use rindex and diff --git a/version.h b/version.h index ec05cd255d..934a9d11e7 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.8.6" -#define RUBY_RELEASE_DATE "2007-05-26" +#define RUBY_RELEASE_DATE "2007-05-29" #define RUBY_VERSION_CODE 186 -#define RUBY_RELEASE_CODE 20070526 +#define RUBY_RELEASE_CODE 20070529 #define RUBY_PATCHLEVEL 5000 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 26 +#define RUBY_RELEASE_DAY 29 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; diff --git a/win32/win32.c b/win32/win32.c index 99cec1cc93..606f4bf820 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -81,8 +81,6 @@ #define TO_SOCKET(x) _get_osfhandle(x) -bool NtSyncProcess = TRUE; - static struct ChildRecord *CreateChild(const char *, const char *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE); static bool has_redirection(const char *); static void StartSockets (); @@ -502,26 +500,6 @@ FindFreeChildSlot(void) } -int -SafeFree(char **vec, int vecc) -{ - // vec - // | - // V ^---------------------V - // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - // | | | .... | NULL | | ..... |\0 | | ..... |\0 |... - // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - // |- elements+1 -| ^ 1st element ^ 2nd element - - char *p; - - p = (char *)vec; - free(p); - - return 0; -} - - /* ruby -lne 'BEGIN{$cmds = Hash.new(0); $mask = 1}' -e '$cmds[$_.downcase] |= $mask' -e '$mask <<= 1 if ARGF.eof' @@ -1423,8 +1401,12 @@ rb_w32_cmdvector(const char *cmd, char ***vec) // return the pointer to the current file name. // -#define GetBit(bits, i) ((bits)[(i) / 8] & (1 << (i) % 8)) -#define SetBit(bits, i) ((bits)[(i) / 8] |= (1 << (i) % 8)) +#define GetBit(bits, i) ((bits)[(i) / CHAR_BIT] & (1 << (i) % CHAR_BIT)) +#define SetBit(bits, i) ((bits)[(i) / CHAR_BIT] |= (1 << (i) % CHAR_BIT)) + +#define BitOfIsDir(n) ((n) * 2) +#define BitOfIsRep(n) ((n) * 2 + 1) +#define DIRENT_PER_CHAR (CHAR_BIT / 2) DIR * rb_w32_opendir(const char *filename) @@ -1497,9 +1479,9 @@ rb_w32_opendir(const char *filename) strcpy(p->start, fd.cFileName); p->bits[0] = 0; if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - SetBit(p->bits, 0); + SetBit(p->bits, BitOfIsDir(0)); if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - SetBit(p->bits, 1); + SetBit(p->bits, BitOfIsRep(0)); p->nfiles++; // @@ -1511,21 +1493,34 @@ rb_w32_opendir(const char *filename) while (FindNextFile(fh, &fd)) { char *newpath; - len = strlen(fd.cFileName); + len = strlen(fd.cFileName) + 1; // // bump the string table size by enough for the // new name and it's null terminator // - newpath = (char *)realloc(p->start, idx+len+1); + newpath = (char *)realloc(p->start, idx + len); if (newpath == NULL) { goto error; } p->start = newpath; strcpy(&p->start[idx], fd.cFileName); + + if (p->nfiles % DIRENT_PER_CHAR == 0) { + char *tmp = realloc(p->bits, p->nfiles / DIRENT_PER_CHAR + 1); + if (!tmp) + goto error; + p->bits = tmp; + p->bits[p->nfiles / DIRENT_PER_CHAR] = 0; + } + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + SetBit(p->bits, BitOfIsDir(p->nfiles)); + if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + SetBit(p->bits, BitOfIsRep(p->nfiles)); + p->nfiles++; - idx += len+1; + idx += len; } FindClose(fh); p->size = idx; @@ -1576,8 +1571,8 @@ rb_w32_readdir(DIR *dirp) // // Attributes // - dirp->dirstr.d_isdir = GetBit(dirp->bits, dirp->loc * 2); - dirp->dirstr.d_isrep = GetBit(dirp->bits, dirp->loc * 2 + 1); + dirp->dirstr.d_isdir = GetBit(dirp->bits, BitOfIsDir(dirp->loc)); + dirp->dirstr.d_isrep = GetBit(dirp->bits, BitOfIsRep(dirp->loc)); // // Now set up for the next call to readdir @@ -2698,7 +2693,7 @@ poll_child_status(struct ChildRecord *child, int *stat_loc) } rb_pid_t -waitpid (rb_pid_t pid, int *stat_loc, int options) +waitpid(rb_pid_t pid, int *stat_loc, int options) { DWORD timeout; -- cgit v1.2.3