Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
error.h
Go to the documentation of this file.
1#ifndef INTERNAL_ERROR_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_ERROR_H
13#include <stdarg.h> /* for va_list */
14#include "internal/string.h" /* for rb_fstring_cstr */
15#include "ruby/internal/stdbool.h" /* for bool */
16#include "ruby/encoding.h" /* for rb_encoding */
17#include "ruby/intern.h" /* for rb_exc_raise */
18#include "ruby/ruby.h" /* for enum ruby_value_type */
19
20#ifdef Check_Type
21# undef Check_Type /* in ruby/ruby.h */
22#endif
23
24#ifdef rb_raise_static
25# undef rb_raise_static
26# undef rb_sys_fail_path
27# undef rb_syserr_fail_path
28#endif
29
30#define rb_raise_static(e, m) \
31 rb_raise_cstr_i((e), rb_str_new_static((m), rb_strlen_lit(m)))
32#ifdef RUBY_FUNCTION_NAME_STRING
33# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
34# define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
35# define rb_syserr_new_path(err, path) rb_syserr_new_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
36#else
37# define rb_sys_fail_path(path) rb_sys_fail_str(path)
38# define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
39# define rb_syserr_new_path(err, path) rb_syserr_new_str((err), (path))
40#endif
41
42/* error.c */
44extern VALUE rb_eEAGAIN;
47void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
48NORETURN(void rb_async_bug_errno(const char *,int));
49const char *rb_builtin_type_name(int t);
50const char *rb_builtin_class_name(VALUE x);
51PRINTF_ARGS(void rb_warn_deprecated(const char *fmt, const char *suggest, ...), 1, 3);
52PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *fmt, const char *removal, ...), 1, 3);
53VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
54PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
55PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
56PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
59VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method);
60VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv);
62PRINTF_ARGS(VALUE rb_warning_string(const char *fmt, ...), 1, 2);
63NORETURN(void rb_vraise(VALUE, const char *, va_list));
64NORETURN(static inline void rb_raise_cstr(VALUE etype, const char *mesg));
65NORETURN(static inline void rb_raise_cstr_i(VALUE etype, VALUE mesg));
66NORETURN(static inline void rb_name_err_raise_str(VALUE mesg, VALUE recv, VALUE name));
67NORETURN(static inline void rb_name_err_raise(const char *mesg, VALUE recv, VALUE name));
68NORETURN(static inline void rb_key_err_raise(VALUE mesg, VALUE recv, VALUE name));
69static inline void Check_Type(VALUE v, enum ruby_value_type t);
70static inline bool rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type);
71#define rb_typeddata_is_instance_of rb_typeddata_is_instance_of_inline
72
73RUBY_SYMBOL_EXPORT_BEGIN
74/* error.c (export) */
75int rb_bug_reporter_add(void (*func)(FILE *, void *), void *data);
76#ifdef RUBY_FUNCTION_NAME_STRING
77NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
78NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
79VALUE rb_syserr_new_path_in(const char *func_name, int n, VALUE path);
80#endif
81RUBY_SYMBOL_EXPORT_END
82
83static inline void
84rb_raise_cstr_i(VALUE etype, VALUE mesg)
85{
86 VALUE exc = rb_exc_new_str(etype, mesg);
87 rb_exc_raise(exc);
88}
89
90static inline void
91rb_raise_cstr(VALUE etype, const char *mesg)
92{
94 rb_raise_cstr_i(etype, str);
95}
96
97static inline void
98rb_name_err_raise_str(VALUE mesg, VALUE recv, VALUE name)
99{
100 VALUE exc = rb_name_err_new(mesg, recv, name);
101 rb_exc_raise(exc);
102}
103
104static inline void
105rb_name_err_raise(const char *mesg, VALUE recv, VALUE name)
106{
107 VALUE str = rb_fstring_cstr(mesg);
108 rb_name_err_raise_str(str, recv, name);
109}
110
111static inline void
112rb_key_err_raise(VALUE mesg, VALUE recv, VALUE name)
113{
114 VALUE exc = rb_key_err_new(mesg, recv, name);
115 rb_exc_raise(exc);
116}
117
118static inline bool
119rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type)
120{
121 return RB_TYPE_P(obj, T_DATA) && RTYPEDDATA_P(obj) && (RTYPEDDATA_TYPE(obj) == data_type);
122}
123
124#endif /* INTERNAL_ERROR_H */
#define NORETURN(x)
Definition: attributes.h:152
#define PRINTF_ARGS(decl, string_index, first_to_check)
Definition: attributes.h:112
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
Definition: error.c:587
VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding *, const char *, va_list)
Definition: error.c:125
void rb_warn_deprecated_to_remove(const char *fmt, const char *removal,...)
Definition: error.c:496
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
Definition: error.c:428
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt,...)
Definition: error.c:3197
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:712
void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt,...)
Definition: error.c:3209
VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
Definition: error.c:1809
const char * rb_builtin_type_name(int t)
Definition: error.c:890
VALUE rb_warning_string(const char *fmt,...)
Definition: error.c:460
void rb_vraise(VALUE, const char *, va_list)
Definition: error.c:2911
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:937
void rb_warn_deprecated(const char *fmt, const char *suggest,...)
Definition: error.c:480
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1728
rb_warning_category_t rb_warning_category_from_name(VALUE category)
Definition: error.c:163
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Definition: error.c:1107
VALUE rb_eEAGAIN
Definition: error.c:69
long rb_backtrace_length_limit
Definition: error.c:68
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
Definition: error.c:839
VALUE rb_eEINPROGRESS
Definition: error.c:71
void rb_async_bug_errno(const char *, int)
Definition: error.c:817
bool rb_warning_category_enabled_p(rb_warning_category_t category)
Definition: error.c:182
VALUE rb_eEWOULDBLOCK
Definition: error.c:70
VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name)
Definition: error.c:2087
Thin wrapper to ruby/config.h.
rb_warning_category_t
Definition: error.h:32
#define rb_str_new_cstr(str)
Definition: string.h:219
Internal header for String.
#define rb_fstring_cstr(...)
Definition: internal.h:71
const char * name
Definition: nkf.c:208
Defines old _.
C99 shim for <stdbool.h>
Definition: gzappend.c:170
#define t
Definition: symbol.c:253
unsigned long VALUE
Definition: value.h:38
#define T_DATA
Definition: value_type.h:59
ruby_value_type
C-level type of an object.
Definition: value_type.h:110
int err
Definition: win32.c:142