mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* dln.c (conv_to_posix_path): removed.
* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): return VALUE instead of a pointer to static buffer. * ruby.c (push_include_cygwin): fixed buffer overflow. [ruby-dev:31297] * ruby.c (ruby_init_loadpath): not convert built-in paths. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ee4c1a6e5
commit
d772c1af14
4 changed files with 136 additions and 129 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
Thu Jul 26 13:37:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* dln.c (conv_to_posix_path): removed.
|
||||||
|
|
||||||
|
* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): return
|
||||||
|
VALUE instead of a pointer to static buffer.
|
||||||
|
|
||||||
|
* ruby.c (push_include_cygwin): fixed buffer overflow.
|
||||||
|
[ruby-dev:31297]
|
||||||
|
|
||||||
|
* ruby.c (ruby_init_loadpath): not convert built-in paths.
|
||||||
|
|
||||||
Sun Jul 22 16:07:12 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Jul 22 16:07:12 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* intern.h (is_ruby_native_thread): removed since declared as an int
|
* intern.h (is_ruby_native_thread): removed since declared as an int
|
||||||
|
|
29
dln.c
29
dln.c
|
@ -1676,35 +1676,6 @@ dln_find_file(fname, path)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__CYGWIN32__)
|
|
||||||
const char *
|
|
||||||
conv_to_posix_path(win32, posix, len)
|
|
||||||
char *win32;
|
|
||||||
char *posix;
|
|
||||||
int len;
|
|
||||||
{
|
|
||||||
char *first = win32;
|
|
||||||
char *p = win32;
|
|
||||||
char *dst = posix;
|
|
||||||
|
|
||||||
posix[0] = '\0';
|
|
||||||
for (p = win32; *p; p++)
|
|
||||||
if (*p == ';') {
|
|
||||||
*p = 0;
|
|
||||||
cygwin32_conv_to_posix_path(first, posix);
|
|
||||||
posix += strlen(posix);
|
|
||||||
*posix++ = ':';
|
|
||||||
first = p + 1;
|
|
||||||
*p = ';';
|
|
||||||
}
|
|
||||||
if (len < strlen(first))
|
|
||||||
fprintf(stderr, "PATH length too long: %s\n", first);
|
|
||||||
else
|
|
||||||
cygwin32_conv_to_posix_path(first, posix);
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static char fbuf[MAXPATHLEN];
|
static char fbuf[MAXPATHLEN];
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
|
218
ruby.c
218
ruby.c
|
@ -15,6 +15,9 @@
|
||||||
#if defined _WIN32 || defined __CYGWIN__
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined __CYGWIN__
|
||||||
|
#include <sys/cygwin.h>
|
||||||
|
#endif
|
||||||
#ifdef _WIN32_WCE
|
#ifdef _WIN32_WCE
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
#include "wince.h"
|
#include "wince.h"
|
||||||
|
@ -109,129 +112,143 @@ NULL
|
||||||
|
|
||||||
extern VALUE rb_load_path;
|
extern VALUE rb_load_path;
|
||||||
|
|
||||||
#define STATIC_FILE_LENGTH 255
|
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
|
||||||
|
#define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined DOSISH || defined __CYGWIN__
|
||||||
|
static inline void
|
||||||
|
translate_char(char *p, int from, int to)
|
||||||
|
{
|
||||||
|
while (*p) {
|
||||||
|
if ((unsigned char)*p == from)
|
||||||
|
*p = to;
|
||||||
|
p = CharNext(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined _WIN32 || defined __CYGWIN__ || defined __DJGPP__
|
#if defined _WIN32 || defined __CYGWIN__ || defined __DJGPP__
|
||||||
static char *
|
static VALUE
|
||||||
rubylib_mangle(s, l)
|
rubylib_mangled_path(const char *s, unsigned int l)
|
||||||
char *s;
|
|
||||||
unsigned int l;
|
|
||||||
{
|
{
|
||||||
static char *newp, *oldp;
|
static char *newp, *oldp;
|
||||||
static int newl, oldl, notfound;
|
static int newl, oldl, notfound;
|
||||||
static char newsub[STATIC_FILE_LENGTH+1];
|
char *ptr;
|
||||||
|
VALUE ret;
|
||||||
|
|
||||||
if (!newp && !notfound) {
|
if (!newp && !notfound) {
|
||||||
newp = getenv("RUBYLIB_PREFIX");
|
newp = getenv("RUBYLIB_PREFIX");
|
||||||
if (newp) {
|
if (newp) {
|
||||||
char *s;
|
oldp = newp = strdup(newp);
|
||||||
|
|
||||||
oldp = newp;
|
|
||||||
while (*newp && !ISSPACE(*newp) && *newp != ';') {
|
while (*newp && !ISSPACE(*newp) && *newp != ';') {
|
||||||
newp++; oldl++; /* Skip digits. */
|
newp = CharNext(newp); /* Skip digits. */
|
||||||
}
|
}
|
||||||
|
oldl = newp - oldp;
|
||||||
while (*newp && (ISSPACE(*newp) || *newp == ';')) {
|
while (*newp && (ISSPACE(*newp) || *newp == ';')) {
|
||||||
newp++; /* Skip whitespace. */
|
newp = CharNext(newp); /* Skip whitespace. */
|
||||||
}
|
}
|
||||||
newl = strlen(newp);
|
newl = strlen(newp);
|
||||||
if (newl == 0 || oldl == 0 || newl > STATIC_FILE_LENGTH) {
|
if (newl == 0 || oldl == 0) {
|
||||||
rb_fatal("malformed RUBYLIB_PREFIX");
|
rb_fatal("malformed RUBYLIB_PREFIX");
|
||||||
}
|
}
|
||||||
strcpy(newsub, newp);
|
translate_char(newp, '\\', '/');
|
||||||
s = newsub;
|
|
||||||
while (*s) {
|
|
||||||
if (*s == '\\') *s = '/';
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
notfound = 1;
|
notfound = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (l == 0) {
|
|
||||||
l = strlen(s);
|
|
||||||
}
|
|
||||||
if (!newp || l < oldl || strncasecmp(oldp, s, oldl) != 0) {
|
if (!newp || l < oldl || strncasecmp(oldp, s, oldl) != 0) {
|
||||||
static char ret[STATIC_FILE_LENGTH+1];
|
return rb_str_new(s, l);
|
||||||
strncpy(ret, s, l);
|
}
|
||||||
ret[l] = 0;
|
ret = rb_str_new(0, l + newl - oldl);
|
||||||
|
ptr = RSTRING_PTR(ret);
|
||||||
|
memcpy(ptr, newp, newl);
|
||||||
|
memcpy(ptr + newl, s + oldl, l - oldl);
|
||||||
|
ptr[l + newl - oldl] = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
if (l + newl - oldl > STATIC_FILE_LENGTH || newl > STATIC_FILE_LENGTH) {
|
|
||||||
rb_fatal("malformed RUBYLIB_PREFIX");
|
|
||||||
}
|
|
||||||
strcpy(newsub + newl, s + oldl);
|
|
||||||
newsub[l + newl - oldl] = 0;
|
|
||||||
return newsub;
|
|
||||||
}
|
}
|
||||||
#define rubylib_mangled_path(s, l) rb_str_new2(rubylib_mangle((s), (l)))
|
|
||||||
#define rubylib_mangled_path2(s) rb_str_new2(rubylib_mangle((s), 0))
|
static VALUE
|
||||||
|
rubylib_mangled_path2(const char *s)
|
||||||
|
{
|
||||||
|
return rubylib_mangled_path(s, strlen(s));
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define rubylib_mangled_path(s, l) rb_str_new((s), (l))
|
#define rubylib_mangled_path rb_str_new
|
||||||
#define rubylib_mangled_path2(s) rb_str_new2(s)
|
#define rubylib_mangled_path2 rb_str_new2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void push_include _((const char *path));
|
||||||
|
|
||||||
|
static void
|
||||||
|
push_include(path)
|
||||||
|
const char *path;
|
||||||
|
{
|
||||||
|
const char sep = PATH_SEP_CHAR;
|
||||||
|
const char *p, *s;
|
||||||
|
|
||||||
|
p = path;
|
||||||
|
while (*p) {
|
||||||
|
while (*p == sep)
|
||||||
|
p++;
|
||||||
|
if (!*p) break;
|
||||||
|
for (s = p; *s && *s != sep; s = CharNext(s));
|
||||||
|
rb_ary_push(rb_load_path, rubylib_mangled_path(p, s - p));
|
||||||
|
p = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
static void
|
||||||
|
push_include_cygwin(const char *path)
|
||||||
|
{
|
||||||
|
const char *p, *s;
|
||||||
|
char rubylib[FILENAME_MAX];
|
||||||
|
VALUE buf = 0;
|
||||||
|
|
||||||
|
p = path;
|
||||||
|
while (*p) {
|
||||||
|
unsigned int len;
|
||||||
|
while (*p == ';')
|
||||||
|
p++;
|
||||||
|
if (!*p) break;
|
||||||
|
for (s = p; *s && *s != ';'; s = CharNext(s));
|
||||||
|
len = s - p;
|
||||||
|
if (*s) {
|
||||||
|
if (!buf) {
|
||||||
|
buf = rb_str_new(p, len);
|
||||||
|
p = RSTRING_PTR(buf);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_str_resize(buf, len);
|
||||||
|
p = strncpy(RSTRING_PTR(buf), p, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cygwin_conv_to_posix_path(p, rubylib) == 0)
|
||||||
|
p = rubylib;
|
||||||
|
push_include(p);
|
||||||
|
if (!*s) break;
|
||||||
|
p = s + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define push_include push_include_cygwin
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_incpush(path)
|
ruby_incpush(path)
|
||||||
const char *path;
|
const char *path;
|
||||||
{
|
{
|
||||||
const char sep = PATH_SEP_CHAR;
|
if (path == 0)
|
||||||
|
return;
|
||||||
if (path == 0) return;
|
push_include(path);
|
||||||
#if defined(__CYGWIN__)
|
|
||||||
{
|
|
||||||
char rubylib[FILENAME_MAX];
|
|
||||||
conv_to_posix_path(path, rubylib, FILENAME_MAX);
|
|
||||||
path = rubylib;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (strchr(path, sep)) {
|
|
||||||
const char *p, *s;
|
|
||||||
VALUE ary = rb_ary_new();
|
|
||||||
|
|
||||||
p = path;
|
|
||||||
while (*p) {
|
|
||||||
while (*p == sep) p++;
|
|
||||||
if ((s = strchr(p, sep)) != 0) {
|
|
||||||
rb_ary_push(ary, rubylib_mangled_path(p, (int)(s-p)));
|
|
||||||
p = s + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rb_ary_push(ary, rubylib_mangled_path2(p));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rb_ary_concat(rb_load_path, ary);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rb_ary_push(rb_load_path, rubylib_mangled_path2(path));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined DOSISH || defined __CYGWIN__
|
#if defined DOSISH || defined __CYGWIN__
|
||||||
#define LOAD_RELATIVE 1
|
#define LOAD_RELATIVE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined DOSISH || defined __CYGWIN__
|
|
||||||
static inline void translate_char _((char *, int, int));
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
translate_char(p, from, to)
|
|
||||||
char *p;
|
|
||||||
int from, to;
|
|
||||||
{
|
|
||||||
while (*p) {
|
|
||||||
if ((unsigned char)*p == from)
|
|
||||||
*p = to;
|
|
||||||
#ifdef CharNext /* defined as CharNext[AW] on Windows. */
|
|
||||||
p = CharNext(p);
|
|
||||||
#else
|
|
||||||
p += mblen(p, MB_CUR_MAX);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_init_loadpath()
|
ruby_init_loadpath()
|
||||||
{
|
{
|
||||||
|
@ -260,13 +277,19 @@ ruby_init_loadpath()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
libpath[FILENAME_MAX] = '\0';
|
libpath[FILENAME_MAX] = '\0';
|
||||||
#if defined DOSISH || defined __CYGWIN__
|
#if defined DOSISH
|
||||||
translate_char(libpath, '\\', '/');
|
translate_char(libpath, '\\', '/');
|
||||||
|
#elif defined __CYGWIN__
|
||||||
|
{
|
||||||
|
char rubylib[FILENAME_MAX];
|
||||||
|
cygwin_conv_to_posix_path(libpath, rubylib);
|
||||||
|
strncpy(libpath, rubylib, sizeof(libpath));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
p = strrchr(libpath, '/');
|
p = strrchr(libpath, '/');
|
||||||
if (p) {
|
if (p) {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
if (p-libpath > 3 && !strcasecmp(p-4, "/bin")) {
|
if (p - libpath > 3 && !strcasecmp(p - 4, "/bin")) {
|
||||||
p -= 4;
|
p -= 4;
|
||||||
*p = 0;
|
*p = 0;
|
||||||
}
|
}
|
||||||
|
@ -282,30 +305,31 @@ ruby_init_loadpath()
|
||||||
#else
|
#else
|
||||||
#define RUBY_RELATIVE(path) (path)
|
#define RUBY_RELATIVE(path) (path)
|
||||||
#endif
|
#endif
|
||||||
|
#define incpush(path) rb_ary_push(rb_load_path, rubylib_mangled_path2(path))
|
||||||
|
|
||||||
if (rb_safe_level() == 0) {
|
if (rb_safe_level() == 0) {
|
||||||
ruby_incpush(getenv("RUBYLIB"));
|
ruby_incpush(getenv("RUBYLIB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RUBY_SEARCH_PATH
|
#ifdef RUBY_SEARCH_PATH
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
|
incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
|
incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
|
||||||
#ifdef RUBY_SITE_THIN_ARCHLIB
|
#ifdef RUBY_SITE_THIN_ARCHLIB
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
|
incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
|
||||||
#endif
|
#endif
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
|
incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
|
incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
|
||||||
|
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_LIB));
|
incpush(RUBY_RELATIVE(RUBY_LIB));
|
||||||
#ifdef RUBY_THIN_ARCHLIB
|
#ifdef RUBY_THIN_ARCHLIB
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
|
incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
|
||||||
#endif
|
#endif
|
||||||
ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
|
incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
|
||||||
|
|
||||||
if (rb_safe_level() == 0) {
|
if (rb_safe_level() == 0) {
|
||||||
ruby_incpush(".");
|
incpush(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define RUBY_VERSION "1.8.6"
|
#define RUBY_VERSION "1.8.6"
|
||||||
#define RUBY_RELEASE_DATE "2007-07-22"
|
#define RUBY_RELEASE_DATE "2007-07-26"
|
||||||
#define RUBY_VERSION_CODE 186
|
#define RUBY_VERSION_CODE 186
|
||||||
#define RUBY_RELEASE_CODE 20070722
|
#define RUBY_RELEASE_CODE 20070726
|
||||||
#define RUBY_PATCHLEVEL 5000
|
#define RUBY_PATCHLEVEL 5000
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define RUBY_VERSION_TEENY 6
|
#define RUBY_VERSION_TEENY 6
|
||||||
#define RUBY_RELEASE_YEAR 2007
|
#define RUBY_RELEASE_YEAR 2007
|
||||||
#define RUBY_RELEASE_MONTH 7
|
#define RUBY_RELEASE_MONTH 7
|
||||||
#define RUBY_RELEASE_DAY 22
|
#define RUBY_RELEASE_DAY 26
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue