[前][次][番号順一覧][スレッド一覧]

ruby-changes:27708

From: nobu <ko1@a...>
Date: Fri, 15 Mar 2013 14:51:48 +0900 (JST)
Subject: [ruby-changes:27708] nobu:r39760 (trunk): file.c: rb_sys_fail_path_with_func

nobu	2013-03-15 14:51:37 +0900 (Fri, 15 Mar 2013)

  New Revision: 39760

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39760

  Log:
    file.c: rb_sys_fail_path_with_func
    
    * file.c (rb_sys_fail_path_with_func): share same function, and path
      may be nil.

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/file.c
    trunk/internal.h
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39759)
+++ ChangeLog	(revision 39760)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Mar 15 14:51:33 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_sys_fail_path_with_func): share same function, and path
+	  may be nil.
+
 Fri Mar 15 08:24:51 2013  NARUSE, Yui  <naruse@r...>
 
 	* file.c (rb_sys_fail_path): define & use rb_sys_fail_path0 like r39752
Index: io.c
===================================================================
--- io.c	(revision 39759)
+++ io.c	(revision 39760)
@@ -399,21 +399,6 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd https://github.com/ruby/ruby/blob/trunk/io.c#L399
 #  endif
 #endif
 
-#ifdef RUBY_FUNCTION_NAME_STRING
-# define rb_sys_fail_path(path) rb_sys_fail_path0(RUBY_FUNCTION_NAME_STRING, path)
-NORETURN(static void rb_sys_fail_path0(const char *,VALUE));
-static void
-rb_sys_fail_path0(const char *func_name, VALUE path)
-{
-    VALUE mesg = rb_str_new_cstr(func_name);
-    rb_str_buf_cat2(mesg, ": ");
-    rb_str_buf_append(mesg, path);
-    rb_sys_fail_str(mesg);
-}
-#else
-# define rb_sys_fail_path(path) rb_sys_fail_str(path)
-#endif
-
 static int io_fflush(rb_io_t *);
 static rb_io_t *flush_before_seek(rb_io_t *fptr);
 
Index: dir.c
===================================================================
--- dir.c	(revision 39759)
+++ dir.c	(revision 39760)
@@ -79,8 +79,6 @@ char *strchr(char*,char); https://github.com/ruby/ruby/blob/trunk/dir.c#L79
 #define opendir(p) rb_w32_uopendir(p)
 #endif
 
-#define rb_sys_fail_path(path) rb_sys_fail_str(path)
-
 #define FNM_NOESCAPE	0x01
 #define FNM_PATHNAME	0x02
 #define FNM_DOTMATCH	0x04
Index: internal.h
===================================================================
--- internal.h	(revision 39759)
+++ internal.h	(revision 39760)
@@ -122,6 +122,13 @@ VALUE rb_get_path_check_to_string(VALUE, https://github.com/ruby/ruby/blob/trunk/internal.h#L122
 VALUE rb_get_path_check_convert(VALUE, VALUE, int);
 void Init_File(void);
 
+#ifdef RUBY_FUNCTION_NAME_STRING
+NORETURN(void rb_sys_fail_path_with_func(const char *func_name, VALUE path));
+# define rb_sys_fail_path(path) rb_sys_fail_path_with_func(RUBY_FUNCTION_NAME_STRING, path)
+#else
+# define rb_sys_fail_path(path) rb_sys_fail_str(path)
+#endif
+
 #ifdef _WIN32
 /* file.c, win32/file.c */
 void rb_w32_init_file(void);
Index: file.c
===================================================================
--- file.c	(revision 39759)
+++ file.c	(revision 39760)
@@ -103,18 +103,19 @@ int flock(int, int); https://github.com/ruby/ruby/blob/trunk/file.c#L103
 #endif
 
 #ifdef RUBY_FUNCTION_NAME_STRING
-# define rb_sys_fail_path(path) rb_sys_fail_path0(RUBY_FUNCTION_NAME_STRING, path)
-NORETURN(static void rb_sys_fail_path0(const char *,VALUE));
-static void
-rb_sys_fail_path0(const char *func_name, VALUE path)
+void
+rb_sys_fail_path_with_func(const char *func_name, VALUE path)
 {
     VALUE mesg = rb_str_new_cstr(func_name);
-    rb_str_buf_cat2(mesg, ": ");
-    rb_str_buf_append(mesg, path);
+    if (!NIL_P(path)) {
+	/* RUBY_FUNCTION_NAME_STRING, aka __func__/__FUNCTION__ is not a
+	 * preprocessor macro but a static constant array, so string
+	 * literal concatenation is not allowed */
+	rb_str_buf_cat2(mesg, ": ");
+	rb_str_buf_append(mesg, path);
+    }
     rb_sys_fail_str(mesg);
 }
-#else
-# define rb_sys_fail_path(path) rb_sys_fail_str(path)
 #endif
 
 #if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]