Skip to content

Commit c30183b

Browse files
committed
* 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_6@12481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 887e101 commit c30183b

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Tue May 29 11:01:06 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* win32/win32.c (rb_w32_opendir): store attributes of the second
4+
entries or later too.
5+
6+
* win32/win32.c (rb_w32_opendir, rb_w32_readdir): eliminate magic
7+
numbers.
8+
19
Thu Jun 7 20:10:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
210

311
* eval.c, intern.h, ext/thread/thread.c: should not free queue

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2007-06-07"
33
#define RUBY_VERSION_CODE 186
44
#define RUBY_RELEASE_CODE 20070607
5-
#define RUBY_PATCHLEVEL 31
5+
#define RUBY_PATCHLEVEL 32
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

win32/win32.c

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181

8282
#define TO_SOCKET(x) _get_osfhandle(x)
8383

84-
bool NtSyncProcess = TRUE;
85-
8684
static struct ChildRecord *CreateChild(const char *, const char *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE);
8785
static bool has_redirection(const char *);
8886
static void StartSockets ();
@@ -502,26 +500,6 @@ FindFreeChildSlot(void)
502500
}
503501

504502

505-
int
506-
SafeFree(char **vec, int vecc)
507-
{
508-
// vec
509-
// |
510-
// V ^---------------------V
511-
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
512-
// | | | .... | NULL | | ..... |\0 | | ..... |\0 |...
513-
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
514-
// |- elements+1 -| ^ 1st element ^ 2nd element
515-
516-
char *p;
517-
518-
p = (char *)vec;
519-
free(p);
520-
521-
return 0;
522-
}
523-
524-
525503
/*
526504
ruby -lne 'BEGIN{$cmds = Hash.new(0); $mask = 1}'
527505
-e '$cmds[$_.downcase] |= $mask' -e '$mask <<= 1 if ARGF.eof'
@@ -1423,8 +1401,12 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
14231401
// return the pointer to the current file name.
14241402
//
14251403

1426-
#define GetBit(bits, i) ((bits)[(i) / 8] & (1 << (i) % 8))
1427-
#define SetBit(bits, i) ((bits)[(i) / 8] |= (1 << (i) % 8))
1404+
#define GetBit(bits, i) ((bits)[(i) / CHAR_BIT] & (1 << (i) % CHAR_BIT))
1405+
#define SetBit(bits, i) ((bits)[(i) / CHAR_BIT] |= (1 << (i) % CHAR_BIT))
1406+
1407+
#define BitOfIsDir(n) ((n) * 2)
1408+
#define BitOfIsRep(n) ((n) * 2 + 1)
1409+
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
14281410

14291411
DIR *
14301412
rb_w32_opendir(const char *filename)
@@ -1497,9 +1479,9 @@ rb_w32_opendir(const char *filename)
14971479
strcpy(p->start, fd.cFileName);
14981480
p->bits[0] = 0;
14991481
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1500-
SetBit(p->bits, 0);
1482+
SetBit(p->bits, BitOfIsDir(0));
15011483
if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1502-
SetBit(p->bits, 1);
1484+
SetBit(p->bits, BitOfIsRep(0));
15031485
p->nfiles++;
15041486

15051487
//
@@ -1511,21 +1493,34 @@ rb_w32_opendir(const char *filename)
15111493
while (FindNextFile(fh, &fd)) {
15121494
char *newpath;
15131495

1514-
len = strlen(fd.cFileName);
1496+
len = strlen(fd.cFileName) + 1;
15151497

15161498
//
15171499
// bump the string table size by enough for the
15181500
// new name and it's null terminator
15191501
//
15201502

1521-
newpath = (char *)realloc(p->start, idx+len+1);
1503+
newpath = (char *)realloc(p->start, idx + len);
15221504
if (newpath == NULL) {
15231505
goto error;
15241506
}
15251507
p->start = newpath;
15261508
strcpy(&p->start[idx], fd.cFileName);
1509+
1510+
if (p->nfiles % DIRENT_PER_CHAR == 0) {
1511+
char *tmp = realloc(p->bits, p->nfiles / DIRENT_PER_CHAR + 1);
1512+
if (!tmp)
1513+
goto error;
1514+
p->bits = tmp;
1515+
p->bits[p->nfiles / DIRENT_PER_CHAR] = 0;
1516+
}
1517+
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1518+
SetBit(p->bits, BitOfIsDir(p->nfiles));
1519+
if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1520+
SetBit(p->bits, BitOfIsRep(p->nfiles));
1521+
15271522
p->nfiles++;
1528-
idx += len+1;
1523+
idx += len;
15291524
}
15301525
FindClose(fh);
15311526
p->size = idx;
@@ -1576,8 +1571,8 @@ rb_w32_readdir(DIR *dirp)
15761571
//
15771572
// Attributes
15781573
//
1579-
dirp->dirstr.d_isdir = GetBit(dirp->bits, dirp->loc * 2);
1580-
dirp->dirstr.d_isrep = GetBit(dirp->bits, dirp->loc * 2 + 1);
1574+
dirp->dirstr.d_isdir = GetBit(dirp->bits, BitOfIsDir(dirp->loc));
1575+
dirp->dirstr.d_isrep = GetBit(dirp->bits, BitOfIsRep(dirp->loc));
15811576

15821577
//
15831578
// Now set up for the next call to readdir
@@ -2698,7 +2693,7 @@ poll_child_status(struct ChildRecord *child, int *stat_loc)
26982693
}
26992694

27002695
rb_pid_t
2701-
waitpid (rb_pid_t pid, int *stat_loc, int options)
2696+
waitpid(rb_pid_t pid, int *stat_loc, int options)
27022697
{
27032698
DWORD timeout;
27042699

0 commit comments

Comments
 (0)