ruby-changes:4825
From: ko1@a...
Date: Thu, 8 May 2008 06:44:11 +0900 (JST)
Subject: [ruby-changes:4825] nobu - Ruby:r16319 (trunk): * dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions.
nobu 2008-05-08 06:43:54 +0900 (Thu, 08 May 2008) New Revision: 16319 Modified files: trunk/ChangeLog trunk/dln.c trunk/dln.h trunk/file.c trunk/process.c trunk/ruby.c Log: * dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions. * file.c (rb_find_file_ext, rb_find_file), process.c (proc_exec_v), (rb_proc_exec, proc_spawn_v, proc_spawn), ruby.c (process_options): use reentrant versions. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/file.c?r1=16319&r2=16318&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=16319&r2=16318&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16319&r2=16318&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/dln.c?r1=16319&r2=16318&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=16319&r2=16318&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/dln.h?r1=16319&r2=16318&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16318) +++ ChangeLog (revision 16319) @@ -1,3 +1,11 @@ +Thu May 8 06:43:52 2008 Nobuyoshi Nakada <nobu@r...> + + * dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions. + + * file.c (rb_find_file_ext, rb_find_file), process.c (proc_exec_v), + (rb_proc_exec, proc_spawn_v, proc_spawn), ruby.c (process_options): + use reentrant versions. + Thu May 8 06:27:33 2008 Nobuyoshi Nakada <nobu@r...> * thread.c (rb_thread_key_p): thread local storage stores ID. Index: dln.c =================================================================== --- dln.c (revision 16318) +++ dln.c (revision 16319) @@ -1568,10 +1568,10 @@ return 0; /* dummy return */ } -static char *dln_find_1(const char *fname, const char *path, int exe_flag); +static char *dln_find_1(const char *fname, const char *path, char *buf, int size, int exe_flag); char * -dln_find_exe(const char *fname, const char *path) +dln_find_exe_r(const char *fname, const char *path, char *buf, int size) { if (!path) { path = getenv(PATH_ENV); @@ -1584,25 +1584,38 @@ path = "/usr/local/bin:/usr/ucb:/usr/bin:/bin:."; #endif } - return dln_find_1(fname, path, 1); + return dln_find_1(fname, path, buf, size, 1); } char * -dln_find_file(const char *fname, const char *path) +dln_find_file_r(const char *fname, const char *path, char *buf, int size) { #ifndef __MACOS__ if (!path) path = "."; - return dln_find_1(fname, path, 0); + return dln_find_1(fname, path, buf, size, 0); #else if (!path) path = "."; - return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, 0)); + return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, buf, size, 0)); #endif } static char fbuf[MAXPATHLEN]; +char * +dln_find_exe(const char *fname, const char *path) +{ + return dln_find_exe_r(fname, path, fbuf, sizeof(fbuf)); +} + +char * +dln_find_file(const char *fname, const char *path) +{ + return dln_find_file_r(fname, path, fbuf, sizeof(fbuf)); +} + static char * -dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking for executable. */) +dln_find_1(const char *fname, const char *path, char *fbuf, int size, + int exe_flag /* non 0 if looking for executable. */) { register const char *dp; register const char *ep; @@ -1642,7 +1655,7 @@ /* find the length of that component */ l = ep - dp; bp = fbuf; - fspace = sizeof fbuf - 2; + fspace = size - 2; if (l > 0) { /* ** If the length of the component is zero length, Index: process.c =================================================================== --- process.c (revision 16318) +++ process.c (revision 16319) @@ -51,6 +51,12 @@ #ifdef HAVE_SYS_RESOURCE_H # include <sys/resource.h> #endif +#ifdef HAVE_SYS_PARAM_H +# include <sys/param.h> +#endif +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif #include "ruby/st.h" #ifdef __EMX__ @@ -963,7 +969,7 @@ #define after_exec() \ (rb_thread_start_timer_thread(), rb_disable_interrupt()) -extern char *dln_find_exe(const char *fname, const char *path); +#include "dln.h" static void security(const char *str) @@ -978,9 +984,11 @@ static int proc_exec_v(char **argv, const char *prog) { + char fbuf[MAXPATHLEN]; + if (!prog) prog = argv[0]; - prog = dln_find_exe(prog, 0); + prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf)); if (!prog) { errno = ENOENT; return -1; @@ -1015,7 +1023,7 @@ *p = '\\'; new_argv[0] = COMMAND; argv = new_argv; - prog = dln_find_exe(argv[0], 0); + prog = dln_find_exe_r(argv[0], 0, fbuf, sizeof(fbuf)); if (!prog) { errno = ENOENT; return -1; @@ -1081,7 +1089,8 @@ if (status != -1) exit(status); #elif defined(__human68k__) || defined(__CYGWIN32__) || defined(__EMX__) - char *shell = dln_find_exe("sh", 0); + char fbuf[MAXPATHLEN]; + char *shell = dln_find_exe_r("sh", 0, fbuf, sizeof(fbuf)); int status = -1; before_exec(); if (shell) @@ -1128,13 +1137,14 @@ static rb_pid_t proc_spawn_v(char **argv, char *prog) { + char fbuf[MAXPATHLEN]; char *extension; rb_pid_t status; if (!prog) prog = argv[0]; security(prog); - prog = dln_find_exe(prog, 0); + prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf)); if (!prog) return -1; @@ -1155,7 +1165,7 @@ *p = '\\'; new_argv[0] = COMMAND; argv = new_argv; - prog = dln_find_exe(argv[0], 0); + prog = dln_find_exe_r(argv[0], 0, fbuf, sizeof(fbuf)); if (!prog) { errno = ENOENT; return -1; @@ -1192,13 +1202,14 @@ static rb_pid_t proc_spawn(char *str) { + char fbuf[MAXPATHLEN]; char *s, *t; char **argv, **a; rb_pid_t status; for (s = str; *s; s++) { if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) { - char *shell = dln_find_exe("sh", 0); + char *shell = dln_find_exe_r("sh", 0, fbuf, sizeof(fbuf)); before_exec(); status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str); rb_last_status_set(status == -1 ? 127 : status, 0); Index: dln.h =================================================================== --- dln.h (revision 16318) +++ dln.h (revision 16319) @@ -30,6 +30,8 @@ char *dln_find_exe(const char*,const char*); char *dln_find_file(const char*,const char*); +char *dln_find_exe_r(const char*,const char*,char*,int); +char *dln_find_file_r(const char*,const char*,char*,int); #ifdef USE_DLN_A_OUT extern char *dln_argv0; Index: ruby.c =================================================================== --- ruby.c (revision 16318) +++ ruby.c (revision 16319) @@ -953,6 +953,7 @@ VALUE parser; rb_encoding *enc, *lenc; const char *s; + char fbuf[MAXPATHLEN]; int i = proc_options(argc, argv, opt); int safe; @@ -1033,10 +1034,10 @@ opt->script = 0; if (path) { - opt->script = dln_find_file(argv[0], path); + opt->script = dln_find_file_r(argv[0], path, fbuf, sizeof(fbuf)); } if (!opt->script) { - opt->script = dln_find_file(argv[0], getenv(PATH_ENV)); + opt->script = dln_find_file_r(argv[0], getenv(PATH_ENV), fbuf, sizeof(fbuf)); } if (!opt->script) opt->script = argv[0]; Index: file.c =================================================================== --- file.c (revision 16318) +++ file.c (revision 16319) @@ -4334,11 +4334,12 @@ OBJ_FREEZE(fname); for (i = 0; i < RARRAY_LEN(load_path); i++) { VALUE str = RARRAY_PTR(load_path)[i]; + char fbuf[MAXPATHLEN]; FilePathValue(str); if (RSTRING_LEN(str) == 0) continue; path = RSTRING_PTR(str); - found = dln_find_file(StringValueCStr(fname), path); + found = dln_find_file_r(StringValueCStr(fname), path, fbuf, sizeof(fbuf)); if (found && file_load_ok(found)) { *filep = rb_str_new2(found); return j+1; @@ -4354,6 +4355,7 @@ VALUE tmp, load_path; char *f = StringValueCStr(path); char *lpath; + char fbuf[MAXPATHLEN]; if (f[0] == '~') { path = rb_file_expand_path(path, Qnil); @@ -4411,7 +4413,7 @@ if (!lpath) { return 0; /* no path, no load */ } - if (!(f = dln_find_file(f, lpath))) { + if (!(f = dln_find_file_r(f, lpath, fbuf, sizeof(fbuf)))) { return 0; } if (rb_safe_level() >= 1 && !fpath_check(f)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/