[Bug #19635] Preserve errno

The following functions are turned into macros and no longer can be
used as expressions in core.
- rb_sys_fail
- rb_sys_fail_str
- rb_sys_fail_path
This commit is contained in:
Nobuyoshi Nakada 2023-05-12 10:48:35 +09:00
parent a1b01e7701
commit e3385f8783
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
2 changed files with 20 additions and 2 deletions

View File

@ -3312,12 +3312,14 @@ rb_syserr_fail_str(int e, VALUE mesg)
rb_exc_raise(rb_syserr_new_str(e, mesg));
}
#undef rb_sys_fail
void
rb_sys_fail(const char *mesg)
{
rb_exc_raise(make_errno_exc(mesg));
}
#undef rb_sys_fail_str
void
rb_sys_fail_str(VALUE mesg)
{

View File

@ -29,15 +29,31 @@
#define rb_raise_static(e, m) \
rb_raise_cstr_i((e), rb_str_new_static((m), rb_strlen_lit(m)))
#ifdef RUBY_FUNCTION_NAME_STRING
# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
# define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
# define rb_syserr_new_path(err, path) rb_syserr_new_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
#else
# define rb_sys_fail_path(path) rb_sys_fail_str(path)
# define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
# define rb_syserr_new_path(err, path) rb_syserr_new_str((err), (path))
#endif
#define rb_sys_fail(mesg) \
do { \
int errno_to_fail = errno; \
rb_syserr_fail(errno_to_fail, (mesg)); \
} while (0)
#define rb_sys_fail_str(mesg) \
do { \
int errno_to_fail = errno; \
rb_syserr_fail_str(errno_to_fail, (mesg)); \
} while (0)
#define rb_sys_fail_path(path) \
do { \
int errno_to_fail = errno; \
rb_syserr_fail_path(errno_to_fail, (path)); \
} while (0)
/* error.c */
extern long rb_backtrace_length_limit;
extern VALUE rb_eEAGAIN;