Skip to content

Commit 9d2b69a

Browse files
committed
* dir.c (ruby_glob): glob function not using ruby exception system.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ca32aea commit 9d2b69a

File tree

4 files changed

+60
-44
lines changed

4 files changed

+60
-44
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Wed Sep 14 22:40:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* dir.c (ruby_glob): glob function not using ruby exception system.
4+
15
Wed Sep 14 17:24:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
26

37
* dir.c: changed `foo (*bar)_((boo))' to `foo (*bar)(boo)`.

dir.c

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -890,33 +890,38 @@ dir_s_rmdir(VALUE obj, VALUE dir)
890890
return INT2FIX(0);
891891
}
892892

893+
#define GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1))
894+
#define sys_warning(val) \
895+
((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)(val), 0))
896+
893897
/* System call with warning */
894898
static int
895-
do_stat(const char *path, struct stat *pst)
899+
do_stat(const char *path, struct stat *pst, int flags)
900+
896901
{
897902
int ret = stat(path, pst);
898903
if (ret < 0 && errno != ENOENT)
899-
rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0);
904+
sys_warning(path);
900905

901906
return ret;
902907
}
903908

904909
static int
905-
do_lstat(const char *path, struct stat *pst)
910+
do_lstat(const char *path, struct stat *pst, int flags)
906911
{
907912
int ret = lstat(path, pst);
908913
if (ret < 0 && errno != ENOENT)
909-
rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0);
914+
sys_warning(path);
910915

911916
return ret;
912917
}
913918

914919
static DIR *
915-
do_opendir(const char *path)
920+
do_opendir(const char *path, int flags)
916921
{
917922
DIR *dirp = opendir(path);
918923
if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
919-
rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0);
924+
sys_warning(path);
920925

921926
return dirp;
922927
}
@@ -1118,19 +1123,7 @@ glob_func_caller(VALUE val)
11181123
return Qnil;
11191124
}
11201125

1121-
static int
1122-
glob_call_func(void (*func) (const char *, VALUE), const char *path, VALUE arg)
1123-
{
1124-
int status;
1125-
struct glob_args args;
1126-
1127-
args.func = func;
1128-
args.c = path;
1129-
args.v = arg;
1130-
1131-
rb_protect(glob_func_caller, (VALUE)&args, &status);
1132-
return status;
1133-
}
1126+
#define glob_call_func(func, path, arg) (*func)(path, arg)
11341127

11351128
static int
11361129
glob_helper(
@@ -1141,7 +1134,7 @@ glob_helper(
11411134
struct glob_pattern **beg,
11421135
struct glob_pattern **end,
11431136
int flags,
1144-
void (*func) (const char *, VALUE),
1137+
int (*func)(const char *, VALUE),
11451138
VALUE arg)
11461139
{
11471140
struct stat st;
@@ -1176,7 +1169,7 @@ glob_helper(
11761169

11771170
if (*path) {
11781171
if (match_all && exist == UNKNOWN) {
1179-
if (do_lstat(path, &st) == 0) {
1172+
if (do_lstat(path, &st, flags) == 0) {
11801173
exist = YES;
11811174
isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
11821175
}
@@ -1186,7 +1179,7 @@ glob_helper(
11861179
}
11871180
}
11881181
if (match_dir && isdir == UNKNOWN) {
1189-
if (do_stat(path, &st) == 0) {
1182+
if (do_stat(path, &st, flags) == 0) {
11901183
exist = YES;
11911184
isdir = S_ISDIR(st.st_mode) ? YES : NO;
11921185
}
@@ -1211,7 +1204,7 @@ glob_helper(
12111204

12121205
if (magical || recursive) {
12131206
struct dirent *dp;
1214-
DIR *dirp = do_opendir(*path ? path : ".");
1207+
DIR *dirp = do_opendir(*path ? path : ".", flags);
12151208
if (dirp == NULL) return 0;
12161209

12171210
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
@@ -1221,7 +1214,7 @@ glob_helper(
12211214
if (recursive && strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0
12221215
&& fnmatch("*", dp->d_name, flags) == 0) {
12231216
#ifndef _WIN32
1224-
if (do_lstat(buf, &st) == 0)
1217+
if (do_lstat(buf, &st, flags) == 0)
12251218
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
12261219
else
12271220
new_isdir = NO;
@@ -1293,18 +1286,14 @@ glob_helper(
12931286
}
12941287

12951288
static int
1296-
rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE arg)
1289+
ruby_glob0(const char *path, int flags, int (*func)(const char *, VALUE), VALUE arg)
12971290
{
12981291
struct glob_pattern *list;
12991292
const char *root, *start;
13001293
char *buf;
13011294
int n;
13021295
int status;
13031296

1304-
if (flags & FNM_CASEFOLD) {
1305-
rb_warn("Dir.glob() ignores File::FNM_CASEFOLD");
1306-
}
1307-
13081297
start = root = path;
13091298
#if defined DOSISH
13101299
flags |= FNM_CASEFOLD;
@@ -1328,28 +1317,42 @@ rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE
13281317
return status;
13291318
}
13301319

1331-
struct rb_glob_args {
1332-
void (*func)(const char*, VALUE);
1333-
VALUE arg;
1334-
};
1320+
int
1321+
ruby_glob(const char *path, int flags, int (*func)(const char *, VALUE), VALUE arg)
1322+
{
1323+
return ruby_glob0(path, flags & ~GLOB_VERBOSE, func, arg);
1324+
}
13351325

1336-
static void
1326+
static int
13371327
rb_glob_caller(const char *path, VALUE a)
13381328
{
1339-
struct rb_glob_args *args = (struct rb_glob_args *)a;
1340-
(*args->func)(path, args->arg);
1329+
int status;
1330+
struct glob_args *args = (struct glob_args *)a;
1331+
1332+
args->c = path;
1333+
rb_protect(glob_func_caller, a, &status);
1334+
return status;
13411335
}
13421336

1343-
void
1344-
rb_glob(const char *path, void (*func) (const char *, VALUE), VALUE arg)
1337+
static int
1338+
rb_glob2(const char *path, int flags, void (*func)(const char *, VALUE), VALUE arg)
13451339
{
1346-
struct rb_glob_args args;
1347-
int status;
1340+
struct glob_args args;
13481341

13491342
args.func = func;
1350-
args.arg = arg;
1351-
status = rb_glob2(path, 0, rb_glob_caller, (VALUE)&args);
1343+
args.v = arg;
13521344

1345+
if (flags & FNM_CASEFOLD) {
1346+
rb_warn("Dir.glob() ignores File::FNM_CASEFOLD");
1347+
}
1348+
1349+
return ruby_glob0(path, flags | GLOB_VERBOSE, rb_glob_caller, (VALUE)&args);
1350+
}
1351+
1352+
void
1353+
rb_glob(const char *path, void (*func) (const char *, VALUE), VALUE arg)
1354+
{
1355+
int status = rb_glob2(path, 0, func, arg);
13531356
if (status) rb_jump_tag(status);
13541357
}
13551358

ruby.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
#if defined(__cplusplus)
1818
extern "C" {
19+
#if 0
20+
} /* satisfy cc-mode */
21+
#endif
1922
#endif
2023

2124
#include "config.h"
@@ -490,6 +493,7 @@ struct RBignum {
490493
void rb_obj_infect(VALUE,VALUE);
491494

492495
void rb_glob(const char*,void(*)(const char*,VALUE),VALUE);
496+
int ruby_glob(const char*,int,int(*)(const char*,VALUE),VALUE);
493497

494498
VALUE rb_define_class(const char*,VALUE);
495499
VALUE rb_define_module(const char*);
@@ -735,6 +739,9 @@ void ruby_native_thread_kill(int);
735739
#endif
736740

737741
#if defined(__cplusplus)
742+
#if 0
743+
{ /* satisfy cc-mode */
744+
#endif
738745
} /* extern "C" { */
739746
#endif
740747

win32/win32.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ typedef struct _NtCmdLineElement {
10241024
#define NTMALLOC 0x2 // string in element was malloc'ed
10251025
#define NTSTRING 0x4 // element contains a quoted string
10261026

1027-
static void
1027+
static int
10281028
insert(const char *path, VALUE vinfo)
10291029
{
10301030
NtCmdLineElement *tmpcurr;
@@ -1038,6 +1038,8 @@ insert(const char *path, VALUE vinfo)
10381038
strcpy(tmpcurr->str, path);
10391039
**tail = tmpcurr;
10401040
*tail = &tmpcurr->next;
1041+
1042+
return 0;
10411043
}
10421044

10431045
#ifdef HAVE_SYS_PARAM_H
@@ -1062,7 +1064,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
10621064
for (p = buf; *p; p = CharNext(p))
10631065
if (*p == '\\')
10641066
*p = '/';
1065-
rb_glob(buf, insert, (VALUE)&tail);
1067+
ruby_glob(buf, 0, insert, (VALUE)&tail);
10661068
if (buf != buffer)
10671069
free(buf);
10681070

0 commit comments

Comments
 (0)