diff --git a/ChangeLog b/ChangeLog index db2fa79f82..e141b698db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Mar 15 14:51:33 2013 Nobuyoshi Nakada + + * 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 * file.c (rb_sys_fail_path): define & use rb_sys_fail_path0 like r39752 diff --git a/dir.c b/dir.c index 27f16ebc4b..5af16ea39a 100644 --- a/dir.c +++ b/dir.c @@ -79,8 +79,6 @@ char *strchr(char*,char); #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 diff --git a/file.c b/file.c index 5cc4b53c6a..6e30c067f3 100644 --- a/file.c +++ b/file.c @@ -103,18 +103,19 @@ int flock(int, int); #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 */ diff --git a/internal.h b/internal.h index bcc0b3667f..0902ac05c2 100644 --- a/internal.h +++ b/internal.h @@ -122,6 +122,13 @@ VALUE rb_get_path_check_to_string(VALUE, int); 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); diff --git a/io.c b/io.c index 837c1b6ded..f3dd3e3814 100644 --- a/io.c +++ b/io.c @@ -399,21 +399,6 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd) # 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);