diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-05-12 10:48:35 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-05-12 18:36:01 +0900 |
commit | e3385f87831f036eaba96558cb4d83c8d5c43901 (patch) | |
tree | 6819306188b619e2a91dfe84686423558d1276cf | |
parent | a1b01e7701f9fc370f8dff777aad6d39a2c5a3e3 (diff) |
[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
-rw-r--r-- | error.c | 2 | ||||
-rw-r--r-- | internal/error.h | 20 |
2 files changed, 20 insertions, 2 deletions
@@ -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) { diff --git a/internal/error.h b/internal/error.h index 11601858f4..bbb37e0443 100644 --- a/internal/error.h +++ b/internal/error.h @@ -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; |