diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | dir.c | 101 | ||||
-rw-r--r-- | ruby.h | 8 | ||||
-rw-r--r-- | win32/win32.c | 6 |
4 files changed, 67 insertions, 52 deletions
@@ -1,3 +1,7 @@ +Wed Sep 14 22:40:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * dir.c (ruby_glob): glob function not using ruby exception system. + Wed Sep 14 01:26:03 2005 Minero Aoki <aamine@loveruby.net> * lib/net/https.rb: backported from trunk, rev 1.3. @@ -786,6 +786,10 @@ dir_s_rmdir(obj, dir) return INT2FIX(0); } +#define GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1)) +#define sys_warning(val) \ + ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)(val), 0)) + /* Return nonzero if S has any special globbing chars in it. */ static int has_magic(s, send, flags) @@ -895,31 +899,16 @@ glob_func_caller(val) return Qnil; } -static int -glob_call_func(func, path, arg) - void (*func) _((const char*, VALUE)); - const char *path; - VALUE arg; -{ - int status; - struct glob_args args; - - args.func = func; - args.c = path; - args.v = arg; - - rb_protect(glob_func_caller, (VALUE)&args, &status); - return status; -} +#define glob_call_func(func, path, arg) (*func)(path, arg) -static int glob_helper _((const char *path, const char *sub, int flags, void (*func)(const char *,VALUE), VALUE arg)); +static int glob_helper _((const char *path, const char *sub, int flags, int (*func)(const char *,VALUE), VALUE arg)); static int glob_helper(path, sub, flags, func, arg) const char *path; const char *sub; int flags; - void (*func) _((const char *, VALUE)); + int (*func) _((const char *, VALUE)); VALUE arg; { struct stat st; @@ -955,7 +944,7 @@ glob_helper(path, sub, flags, func, arg) else if (errno != ENOENT) { /* In case stat error is other than ENOENT and we may want to know what is wrong. */ - rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)path, 0); + sys_warning(path); } xfree(newpath); return status; @@ -982,7 +971,7 @@ glob_helper(path, sub, flags, func, arg) magic = extract_elem(p); if (stat(dir, &st) < 0) { if (errno != ENOENT) - rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)dir, 0); + sys_warning(dir); free(base); free(magic); break; @@ -998,7 +987,7 @@ glob_helper(path, sub, flags, func, arg) } dirp = opendir(dir); if (dirp == NULL) { - rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)dir, 0); + sys_warning(dir); free(base); free(magic); break; @@ -1026,7 +1015,7 @@ glob_helper(path, sub, flags, func, arg) sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name); if (lstat(buf, &st) < 0) { if (errno != ENOENT) - rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)buf, 0); + sys_warning(buf); continue; } if (S_ISDIR(st.st_mode)) { @@ -1073,7 +1062,7 @@ glob_helper(path, sub, flags, func, arg) } } else { - rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)link->path, 0); + sys_warning(link->path); } } tmp = link; @@ -1091,30 +1080,54 @@ glob_helper(path, sub, flags, func, arg) return status; } -static int -rb_glob2(path, flags, func, arg) +int +ruby_glob(path, flags, func, arg) const char *path; int flags; - void (*func) _((const char *, VALUE)); + int (*func) _((const char *, VALUE)); VALUE arg; { + return glob_helper(path, 0, flags & ~GLOB_VERBOSE, func, arg); +} + +int +ruby_globi(path, flags, func, arg) + const char *path; + int flags; + int (*func) _((const char *, VALUE)); + VALUE arg; +{ + return glob_helper(path, 0, flags | FNM_CASEFOLD, func, arg); +} + +static int rb_glob_caller _((const char *, VALUE)); + +static int +rb_glob_caller(path, a) + const char *path; + VALUE a; +{ int status; + struct glob_args *args = (struct glob_args *)a; - status = glob_helper(path, 0, flags, func, arg); + args->c = path; + rb_protect(glob_func_caller, a, &status); return status; } -struct rb_glob_args { - void (*func) _((const char*, VALUE)); +static int +rb_glob2(path, flags, func, arg) + const char *path; + int flags; + void (*func) _((const char *, VALUE)); VALUE arg; -}; - -static void -rb_glob_caller(path, a) - VALUE path, a; { - struct rb_glob_args *args = (struct rb_glob_args *)a; - (*args->func)(RSTRING(path)->ptr, args->arg); + struct glob_args args; + + args.func = func; + args.v = arg; + + return glob_helper(path, 0, flags | GLOB_VERBOSE, rb_glob_caller, (VALUE)&args); } void @@ -1123,13 +1136,7 @@ rb_glob(path, func, arg) void (*func) _((const char*, VALUE)); VALUE arg; { - struct rb_glob_args args; - int status; - - args.func = func; - args.arg = arg; - status = rb_glob2(path, 0, rb_glob_caller, (VALUE)&args); - + int status = rb_glob2(path, 0, func, arg); if (status) rb_jump_tag(status); } @@ -1139,13 +1146,7 @@ rb_globi(path, func, arg) void (*func) _((const char*, VALUE)); VALUE arg; { - struct rb_glob_args args; - int status; - - args.func = func; - args.arg = arg; - status = rb_glob2(path, FNM_CASEFOLD, rb_glob_caller, (VALUE)&args); - + int status = rb_glob2(path, FNM_CASEFOLD, func, arg); if (status) rb_jump_tag(status); } @@ -16,6 +16,9 @@ #if defined(__cplusplus) extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif #endif #include "config.h" @@ -483,6 +486,8 @@ void rb_extend_object _((VALUE,VALUE)); void rb_define_variable _((const char*,VALUE*)); void rb_define_virtual_variable _((const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS))); void rb_define_hooked_variable _((const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS))); +int ruby_glob _((const char*,int,int(*)(const char*,VALUE),VALUE)); +int ruby_globi _((const char*,int,int(*)(const char*,VALUE),VALUE)); void rb_define_readonly_variable _((const char*,VALUE*)); void rb_define_const _((VALUE,const char*,VALUE)); void rb_define_global_const _((const char*,VALUE)); @@ -698,6 +703,9 @@ RUBY_EXTERN int is_ruby_native_thread(); #endif #if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif } /* extern "C" { */ #endif diff --git a/win32/win32.c b/win32/win32.c index f0b73a1088..cc128613d8 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1027,7 +1027,7 @@ typedef struct _NtCmdLineElement { #define NTMALLOC 0x2 // string in element was malloc'ed #define NTSTRING 0x4 // element contains a quoted string -static void +static int insert(const char *path, VALUE vinfo) { NtCmdLineElement *tmpcurr; @@ -1041,6 +1041,8 @@ insert(const char *path, VALUE vinfo) strcpy(tmpcurr->str, path); **tail = tmpcurr; *tail = &tmpcurr->next; + + return 0; } #ifdef HAVE_SYS_PARAM_H @@ -1065,7 +1067,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail) for (p = buf; *p; p = CharNext(p)) if (*p == '\\') *p = '/'; - rb_globi(buf, insert, (VALUE)&tail); + ruby_globi(buf, 0, insert, (VALUE)&tail); if (buf != buffer) free(buf); |