diff options
Diffstat (limited to 'internal/error.h')
-rw-r--r-- | internal/error.h | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/internal/error.h b/internal/error.h index 360203aefc..7e41f134d7 100644 --- a/internal/error.h +++ b/internal/error.h @@ -1,7 +1,6 @@ #ifndef INTERNAL_ERROR_H /*-*-C-*-vi:se ft=c:*/ #define INTERNAL_ERROR_H /** - * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. * Permission is hereby granted, to either redistribute and/or @@ -30,28 +29,60 @@ #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) + +#define rb_sys_fail_sprintf(...) \ +do { \ + int errno_to_fail = errno; \ + rb_syserr_fail_str(errno_to_fail, rb_sprintf("" __VA_ARGS__)); \ +} while (0) + /* error.c */ extern long rb_backtrace_length_limit; extern VALUE rb_eEAGAIN; extern VALUE rb_eEWOULDBLOCK; extern VALUE rb_eEINPROGRESS; +RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 0) void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args); NORETURN(void rb_async_bug_errno(const char *,int)); const char *rb_builtin_type_name(int t); const char *rb_builtin_class_name(VALUE x); PRINTF_ARGS(void rb_warn_deprecated(const char *fmt, const char *suggest, ...), 1, 3); PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *removal, const char *fmt, const char *suggest, ...), 2, 4); -#if RUBY_DEBUG && (RBIMPL_HAS_ATTRIBUTE(diagnose_if) || defined(__OPTIMIZE__)) +#if RUBY_DEBUG # include "ruby/version.h" +# define RUBY_VERSION_SINCE(major, minor) (RUBY_API_VERSION_CODE >= (major * 10000) + (minor) * 100) +# define RUBY_VERSION_BEFORE(major, minor) (RUBY_API_VERSION_CODE < (major * 10000) + (minor) * 100) +# if defined(RBIMPL_WARNING_PRAGMA0) +# define RBIMPL_TODO0(x) RBIMPL_WARNING_PRAGMA0(message(x)) +# elif RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0) +# define RBIMPL_TODO0(x) __pragma(message(x)) +# endif + +# if RBIMPL_HAS_ATTRIBUTE(diagnose_if) || defined(__OPTIMIZE__) #define RUBY_VERSION_isdigit(c) ('0'<=(c)&&(c)<='9') // upto 99 @@ -68,32 +99,45 @@ PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *removal, const char *f (RUBY_VERSION__to_number(v, 0) * 10000 + \ ((v)[RUBY_VERSION__number_len(v, 0)] == '.' ? \ RUBY_VERSION__to_number(v, RUBY_VERSION__number_len(v, 0)+1) * 100 : 0)) -#define RUBY_VERSION_SINCE(v) (RUBY_API_VERSION_CODE >= RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v)) -#define RUBY_VERSION_BEFORE(v) (RUBY_API_VERSION_CODE < RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v)) +#define RUBY_VERSION_STRING_SINCE(v) (RUBY_API_VERSION_CODE >= RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v)) +#define RUBY_VERSION_STRING_BEFORE(v) (RUBY_API_VERSION_CODE < RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v)) # if RBIMPL_HAS_ATTRIBUTE(diagnose_if) RBIMPL_ATTR_FORCEINLINE() static void rb_deprecated_method_to_be_removed(const char *removal) RBIMPL_ATTR_DIAGNOSE_IF(!RUBY_VERSION_isdigit(removal[0]), "malformed version number", "error") - RBIMPL_ATTR_DIAGNOSE_IF(RUBY_VERSION_SINCE(removal), "deprecated method to be removed", "error") + RBIMPL_ATTR_DIAGNOSE_IF(RUBY_VERSION_STRING_SINCE(removal), "deprecated method to be removed", "error") { } # else RBIMPL_ATTR_ERROR(("deprecated")) void rb_deprecated_method_to_be_removed(const char *); # define rb_deprecated_method_to_be_removed(removal) \ - (sizeof(char[1-2*(!RUBY_VERSION_isdigit(removal[0]) || RUBY_VERSION_SINCE(removal))])!=1 ? \ + (sizeof(char[1-2*(!RUBY_VERSION_isdigit(removal[0]) || RUBY_VERSION_STRING_SINCE(removal))])!=1 ? \ rb_deprecated_method_to_be_removed(removal) : \ RBIMPL_ASSERT_NOTHING) # endif # define rb_warn_deprecated_to_remove_at(removal, ...) \ (rb_deprecated_method_to_be_removed(#removal), \ rb_warn_deprecated_to_remove(#removal, __VA_ARGS__)) -#else +# endif +#endif +#ifndef rb_warn_deprecated_to_remove_at # define rb_warn_deprecated_to_remove_at(removal, ...) \ rb_warn_deprecated_to_remove(#removal, __VA_ARGS__) #endif +#ifndef RUBY_VERSION_SINCE +# define RUBY_VERSION_SINCE(major, minor) 0 +#endif +#ifndef RUBY_VERSION_BEFORE +# define RUBY_VERSION_BEFORE(major, minor) 0 +#endif +#ifndef RBIMPL_TODO0 +# define RBIMPL_TODO0(x) +#endif +#define RBIMPL_TODO(message) RBIMPL_TODO0("TODO: " message) +RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0) VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list); PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3); PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); @@ -104,6 +148,7 @@ VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method); VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv); VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name); PRINTF_ARGS(VALUE rb_warning_string(const char *fmt, ...), 1, 2); +RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0) NORETURN(void rb_vraise(VALUE, const char *, va_list)); NORETURN(static inline void rb_raise_cstr(VALUE etype, const char *mesg)); NORETURN(static inline void rb_raise_cstr_i(VALUE etype, VALUE mesg)); @@ -124,6 +169,9 @@ VALUE rb_syserr_new_path_in(const char *func_name, int n, VALUE path); #endif RUBY_SYMBOL_EXPORT_END +/* vm.c */ +void rb_free_warning(void); + static inline void rb_raise_cstr_i(VALUE etype, VALUE mesg) { |