[#18121] [Ruby 1.8.7 - Bug #405] (Open) ssl.rb:31: [BUG] Bus Error — Anonymous <redmine@...>

Issue #405 has been reported by Anonymous.

14 messages 2008/08/04

[#18130] Re: New array methods cycle, choice, shuffle (plus bug in cycle) — Brian Candler <B.Candler@...>

> Seriously though... Array.first is a noun.

10 messages 2008/08/05

[#18319] NEW Command: absolute_path() -- — "C.E. Thornton" <admin@...>

Core,

14 messages 2008/08/16
[#18321] Re: NEW Command: absolute_path() -- — Yukihiro Matsumoto <matz@...> 2008/08/18

Hi,

[#18381] [Bug #496] DRb.start_service(nil) is very slow — Hongli Lai <redmine@...>

Bug #496: DRb.start_service(nil) is very slow

11 messages 2008/08/25

[ruby-core:18194] Re: Expand_path -- Proposal: An alternate method

From: "C.E. Thornton" <admin@...>
Date: 2008-08-08 05:48:57 UTC
List: ruby-core #18194
Nobuyoshi Nakada wrote:
> Hi,
>
> At Fri, 8 Aug 2008 12:03:00 +0900,
> C.E. Thornton wrote in [ruby-core:18188]:
>   
>> I have included a patch for your evaluation for "absolute_path()".
>>     
>
> It's insufficient, file_expand_path() is called twice inside
> itself, and also 2 more in 1.8 head and 1.9
>   
Nobuyoshi,

I have enclosed the modified patch. 

If this sufficient, I will make patches for
1.8 head and 1.9 --

Chuck T.

-- 
Competency and chastity have much in common,
they both encompass their own punishment! 
 
-- C.E. Thornton -- Hawthorne Press --

Attachments (1)

patch (3.02 KB, text/plain)
--- file.c	2008-08-08 01:53:53.000000000 +0000
+++ file.c_new	2008-08-08 06:46:38.000000000 +0000
@@ -2481,8 +2481,9 @@
 static int is_absolute_path _((const char*));
 
 static VALUE
-file_expand_path(fname, dname, result)
+file_expand_path(fname, dname, abs_mode, result)
     VALUE fname, dname, result;
+    int abs_mode;
 {
     char *s, *buf, *b, *p, *pend, *root;
     long buflen, dirlen;
@@ -2492,7 +2493,7 @@
     BUFINIT();
     tainted = OBJ_TAINTED(fname);
 
-    if (s[0] == '~') {
+    if (s[0] == '~' && abs_mode == 0) {
 	if (isdirsep(s[1]) || s[1] == '\0') {
 	    char *dir = getenv("HOME");
 
@@ -2553,7 +2554,7 @@
 	    /* specified drive, but not full path */
 	    int same = 0;
 	    if (!NIL_P(dname)) {
-		file_expand_path(dname, Qnil, result);
+		file_expand_path(dname, Qnil, abs_mode, result);
 		BUFINIT();
 		if (has_drive_letter(p) && TOLOWER(p[0]) == TOLOWER(s[0])) {
 		    /* ok, same drive */
@@ -2576,7 +2577,7 @@
 #endif
     else if (!is_absolute_path(s)) {
 	if (!NIL_P(dname)) {
-	    file_expand_path(dname, Qnil, result);
+	    file_expand_path(dname, Qnil, abs_mode, result);
 	    BUFINIT();
 	}
 	else {
@@ -2684,7 +2685,7 @@
 rb_file_expand_path(fname, dname)
     VALUE fname, dname;
 {
-    return file_expand_path(fname, dname, rb_str_new(0, MAXPATHLEN + 2));
+    return file_expand_path(fname, dname, 0, rb_str_new(0, MAXPATHLEN + 2));
 }
 
 /*
@@ -2719,6 +2720,41 @@
     return rb_file_expand_path(fname, dname);
 }
 
+VALUE
+rb_file_absolute_path(fname, dname)
+    VALUE fname, dname;
+{
+    return file_expand_path(fname, dname, 1, rb_str_new(0, MAXPATHLEN + 2));
+}
+
+/*
+ *  call-seq:
+ *     File.absolute_path(file_name [, dir_string] ) -> abs_file_name
+ *  
+ *  Converts a pathname to an absolute pathname. Relative paths are
+ *  referenced from the current working directory of the process unless
+ *  <i>dir_string</i> is given, in which case it will be used as the
+ *  starting point. If the given pathname starts with a ``<code>~</code>''
+ *  it is NOT expanded, it is treated as a normal directory name.
+ *     
+ *     File.absolute_path("~oracle/bin")       #=> "<relative_path>/~oracle/bin"
+ */
+
+VALUE
+rb_file_s_absolute_path(argc, argv)
+    int argc;
+    VALUE *argv;
+{
+    VALUE fname, dname;
+
+    if (argc == 1) {
+	return rb_file_absolute_path(argv[0], Qnil);
+    }
+    rb_scan_args(argc, argv, "11", &fname, &dname);
+
+    return rb_file_absolute_path(fname, dname);
+}
+
 static int
 rmext(p, e)
     const char *p, *e;
@@ -4463,6 +4499,7 @@
     rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1);
     rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2);
     rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
+    rb_define_singleton_method(rb_cFile, "absolute_path", rb_file_s_absolute_path, -1);
     rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);
     rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1);
     rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);

In This Thread