Skip to content

Commit 0d3d9ef

Browse files
committed
file.c: rb_sys_fail_path_with_func
* file.c (rb_sys_fail_path_with_func): share same function, and path may be nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent bfd52c9 commit 0d3d9ef

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Mar 15 14:51:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* file.c (rb_sys_fail_path_with_func): share same function, and path
4+
may be nil.
5+
16
Fri Mar 15 08:24:51 2013 NARUSE, Yui <naruse@ruby-lang.org>
27

38
* file.c (rb_sys_fail_path): define & use rb_sys_fail_path0 like r39752

dir.c

-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ char *strchr(char*,char);
7979
#define opendir(p) rb_w32_uopendir(p)
8080
#endif
8181

82-
#define rb_sys_fail_path(path) rb_sys_fail_str(path)
83-
8482
#define FNM_NOESCAPE 0x01
8583
#define FNM_PATHNAME 0x02
8684
#define FNM_DOTMATCH 0x04

file.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,19 @@ int flock(int, int);
103103
#endif
104104

105105
#ifdef RUBY_FUNCTION_NAME_STRING
106-
# define rb_sys_fail_path(path) rb_sys_fail_path0(RUBY_FUNCTION_NAME_STRING, path)
107-
NORETURN(static void rb_sys_fail_path0(const char *,VALUE));
108-
static void
109-
rb_sys_fail_path0(const char *func_name, VALUE path)
106+
void
107+
rb_sys_fail_path_with_func(const char *func_name, VALUE path)
110108
{
111109
VALUE mesg = rb_str_new_cstr(func_name);
112-
rb_str_buf_cat2(mesg, ": ");
113-
rb_str_buf_append(mesg, path);
110+
if (!NIL_P(path)) {
111+
/* RUBY_FUNCTION_NAME_STRING, aka __func__/__FUNCTION__ is not a
112+
* preprocessor macro but a static constant array, so string
113+
* literal concatenation is not allowed */
114+
rb_str_buf_cat2(mesg, ": ");
115+
rb_str_buf_append(mesg, path);
116+
}
114117
rb_sys_fail_str(mesg);
115118
}
116-
#else
117-
# define rb_sys_fail_path(path) rb_sys_fail_str(path)
118119
#endif
119120

120121
#if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */

internal.h

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ VALUE rb_get_path_check_to_string(VALUE, int);
122122
VALUE rb_get_path_check_convert(VALUE, VALUE, int);
123123
void Init_File(void);
124124

125+
#ifdef RUBY_FUNCTION_NAME_STRING
126+
NORETURN(void rb_sys_fail_path_with_func(const char *func_name, VALUE path));
127+
# define rb_sys_fail_path(path) rb_sys_fail_path_with_func(RUBY_FUNCTION_NAME_STRING, path)
128+
#else
129+
# define rb_sys_fail_path(path) rb_sys_fail_str(path)
130+
#endif
131+
125132
#ifdef _WIN32
126133
/* file.c, win32/file.c */
127134
void rb_w32_init_file(void);

io.c

-15
Original file line numberDiff line numberDiff line change
@@ -399,21 +399,6 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd)
399399
# endif
400400
#endif
401401

402-
#ifdef RUBY_FUNCTION_NAME_STRING
403-
# define rb_sys_fail_path(path) rb_sys_fail_path0(RUBY_FUNCTION_NAME_STRING, path)
404-
NORETURN(static void rb_sys_fail_path0(const char *,VALUE));
405-
static void
406-
rb_sys_fail_path0(const char *func_name, VALUE path)
407-
{
408-
VALUE mesg = rb_str_new_cstr(func_name);
409-
rb_str_buf_cat2(mesg, ": ");
410-
rb_str_buf_append(mesg, path);
411-
rb_sys_fail_str(mesg);
412-
}
413-
#else
414-
# define rb_sys_fail_path(path) rb_sys_fail_str(path)
415-
#endif
416-
417402
static int io_fflush(rb_io_t *);
418403
static rb_io_t *flush_before_seek(rb_io_t *fptr);
419404

0 commit comments

Comments
 (0)