summaryrefslogtreecommitdiff
path: root/internal/error.h
diff options
context:
space:
mode:
Diffstat (limited to 'internal/error.h')
-rw-r--r--internal/error.h73
1 files changed, 67 insertions, 6 deletions
diff --git a/internal/error.h b/internal/error.h
index 11601858f4..ae9a13fcec 100644
--- a/internal/error.h
+++ b/internal/error.h
@@ -29,15 +29,37 @@
#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;
@@ -50,13 +72,14 @@ 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);
+PRINTF_ARGS(void rb_warn_reserved_name(const char *removal, const char *fmt, ...), 2, 3);
#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)
+# 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)
+# elif RBIMPL_COMPILER_IS(MSVC)
# define RBIMPL_TODO0(x) __pragma(message(x))
# endif
@@ -88,6 +111,14 @@ rb_deprecated_method_to_be_removed(const char *removal)
RBIMPL_ATTR_DIAGNOSE_IF(RUBY_VERSION_STRING_SINCE(removal), "deprecated method to be removed", "error")
{
}
+
+RBIMPL_ATTR_FORCEINLINE()
+static void
+rb_diagnose_reserved_name_at(const char *coming)
+ RBIMPL_ATTR_DIAGNOSE_IF(!RUBY_VERSION_isdigit(coming[0]), "malformed version number", "error")
+ RBIMPL_ATTR_DIAGNOSE_IF(RUBY_VERSION_STRING_SINCE(coming), "reserved name already in use", "error")
+{
+}
# else
RBIMPL_ATTR_ERROR(("deprecated"))
void rb_deprecated_method_to_be_removed(const char *);
@@ -95,16 +126,32 @@ void rb_deprecated_method_to_be_removed(const char *);
(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)
+
+RBIMPL_ATTR_ERROR(("deprecated"))
+void rb_diagnose_reserved_name_at(const char *);
+# define rb_diagnose_reserved_name_at(coming) \
+ (sizeof(char[1-2*(!RUBY_VERSION_isdigit(coming[0]) || RUBY_VERSION_STRING_SINCE(coming))])!=1 ? \
+ rb_diagnose_reserved_name_at(coming) : \
+ 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__))
+
+# define rb_warn_reserved_name_at(coming, ...) \
+ (rb_diagnose_reserved_name_at(#coming), \
+ rb_warn_reserved_name(#coming, __VA_ARGS__))
# 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 rb_warn_reserved_name_at
+# define rb_warn_reserved_name_at(removal, ...) \
+ rb_warn_reserved_name(#removal, __VA_ARGS__)
+#endif
#ifndef RUBY_VERSION_SINCE
# define RUBY_VERSION_SINCE(major, minor) 0
#endif
@@ -120,6 +167,8 @@ VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*,
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);
PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
+PRINTF_ARGS(void rb_enc_compile_warning(rb_encoding *enc, const char *file, int line, const char *fmt, ...), 4, 5);
+PRINTF_ARGS(void rb_enc_compile_warn(rb_encoding *enc, const char *file, int line, const char *fmt, ...), 4, 5);
rb_warning_category_t rb_warning_category_from_name(VALUE category);
bool rb_warning_category_enabled_p(rb_warning_category_t category);
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method);
@@ -136,6 +185,7 @@ NORETURN(static inline void rb_key_err_raise(VALUE mesg, VALUE recv, VALUE name)
static inline void Check_Type(VALUE v, enum ruby_value_type t);
static inline bool rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type);
#define rb_typeddata_is_instance_of rb_typeddata_is_instance_of_inline
+void rb_bug_without_die(const char *fmt, ...);
RUBY_SYMBOL_EXPORT_BEGIN
/* error.c (export) */
@@ -147,6 +197,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)
{
@@ -182,10 +235,18 @@ rb_key_err_raise(VALUE mesg, VALUE recv, VALUE name)
rb_exc_raise(exc);
}
+RBIMPL_ATTR_NONNULL((2))
static inline bool
rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type)
{
- return RB_TYPE_P(obj, T_DATA) && RTYPEDDATA_P(obj) && (RTYPEDDATA_TYPE(obj) == data_type);
+ return rbimpl_obj_typeddata_p(obj) && (RTYPEDDATA_TYPE(obj) == data_type);
}
+typedef enum {
+ rb_stack_overflow_prevention = 0, // VM stack overflow or about to machine stack overflow
+ rb_stack_overflow_signal = 1, // machine stack overflow but may be recoverable
+ rb_stack_overflow_fatal = 2, // fatal machine stack overflow
+} ruby_stack_overflow_critical_level;
+NORETURN(void rb_ec_stack_overflow(struct rb_execution_context_struct *ec, ruby_stack_overflow_critical_level crit));
+
#endif /* INTERNAL_ERROR_H */