Ruby: internal/error.h Source File

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
12#include "ruby/internal/config.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 */
43extern long rb_backtrace_length_limit;
44extern VALUE rb_eEAGAIN;
45extern VALUE rb_eEWOULDBLOCK;
46extern VALUE rb_eEINPROGRESS;
47void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
48 NORETURN(void rb_async_bug_errno(const char *,int));
49const char *rb_builtin_type_name(int t);
50const char *rb_builtin_class_name(VALUE x);
51 PRINTF_ARGS(void rb_warn_deprecated(const char *fmt, const char *suggest, ...), 1, 3);
52 PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *fmt, const char *removal, ...), 1, 3);
53 VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
54 PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
55 PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
56 PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
57 rb_warning_category_t rb_warning_category_from_name(VALUE category);
58bool rb_warning_category_enabled_p(rb_warning_category_t category);
59 VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method);
60 VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv);
61 VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name);
62 PRINTF_ARGS(VALUE rb_warning_string(const char *fmt, ...), 1, 2);
63 NORETURN(void rb_vraise(VALUE, const char *, va_list));
64 NORETURN(static inline void rb_raise_cstr(VALUE etype, const char *mesg));
65 NORETURN(static inline void rb_raise_cstr_i(VALUE etype, VALUE mesg));
66 NORETURN(static inline void rb_name_err_raise_str(VALUE mesg, VALUE recv, VALUE name));
67 NORETURN(static inline void rb_name_err_raise(const char *mesg, VALUE recv, VALUE name));
68 NORETURN(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
77 NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
78 NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
79 VALUE 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{
93 VALUE str = rb_str_new_cstr(mesg);
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 */
NORETURN
#define NORETURN(x)
Definition: attributes.h:152
PRINTF_ARGS
#define PRINTF_ARGS(decl, string_index, first_to_check)
Definition: attributes.h:112
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_bug_reporter_add
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
Definition: error.c:587
rb_syntax_error_append
VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding *, const char *, va_list)
Definition: error.c:125
rb_warn_deprecated_to_remove
void rb_warn_deprecated_to_remove(const char *fmt, const char *removal,...)
Definition: error.c:496
rb_enc_warn
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
Definition: error.c:428
rb_sys_enc_warning
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt,...)
Definition: error.c:3197
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:712
rb_syserr_enc_warning
void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt,...)
Definition: error.c:3209
rb_nomethod_err_new
VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
Definition: error.c:1809
rb_builtin_type_name
const char * rb_builtin_type_name(int t)
Definition: error.c:890
rb_warning_string
VALUE rb_warning_string(const char *fmt,...)
Definition: error.c:460
rb_vraise
void rb_vraise(VALUE, const char *, va_list)
Definition: error.c:2911
rb_builtin_class_name
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:937
rb_warn_deprecated
void rb_warn_deprecated(const char *fmt, const char *suggest,...)
Definition: error.c:480
rb_name_err_new
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1728
rb_warning_category_from_name
rb_warning_category_t rb_warning_category_from_name(VALUE category)
Definition: error.c:163
rb_exc_new_str
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Definition: error.c:1107
rb_eEAGAIN
VALUE rb_eEAGAIN
Definition: error.c:69
rb_backtrace_length_limit
long rb_backtrace_length_limit
Definition: error.c:68
rb_report_bug_valist
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
Definition: error.c:839
rb_eEINPROGRESS
VALUE rb_eEINPROGRESS
Definition: error.c:71
rb_async_bug_errno
void rb_async_bug_errno(const char *, int)
Definition: error.c:817
rb_warning_category_enabled_p
bool rb_warning_category_enabled_p(rb_warning_category_t category)
Definition: error.c:182
rb_eEWOULDBLOCK
VALUE rb_eEWOULDBLOCK
Definition: error.c:70
rb_key_err_new
VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name)
Definition: error.c:2087
encoding.h
config.h
Thin wrapper to ruby/config.h.
rb_warning_category_t
rb_warning_category_t
Definition: error.h:32
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: string.h:219
intern.h
string.h
Internal header for String.
rb_fstring_cstr
#define rb_fstring_cstr(...)
Definition: internal.h:71
name
const char * name
Definition: nkf.c:208
ruby.h
stdarg.h
Defines old _.
stdbool.h
C99 shim for <stdbool.h>
__sFILE
Definition: vsnprintf.c:169
OnigEncodingTypeST
Definition: onigmo.h:160
file
Definition: gzappend.c:170
rb_data_type_struct
Definition: rtypeddata.h:70
t
#define t
Definition: symbol.c:253
VALUE
unsigned long VALUE
Definition: value.h:38
T_DATA
#define T_DATA
Definition: value_type.h:59
ruby_value_type
ruby_value_type
C-level type of an object.
Definition: value_type.h:110
err
int err
Definition: win32.c:142