Ruby: include/ruby/internal/intern/error.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

error.h
Go to the documentation of this file.
1#ifndef RBIMPL_INTERN_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_INTERN_ERROR_H
23#include "ruby/internal/attr/format.h"
24#include "ruby/internal/attr/noreturn.h"
25#include "ruby/internal/dllexport.h"
26#include "ruby/internal/value.h"
27#include "ruby/internal/fl_type.h"
28#include "ruby/backward/2/assume.h"
29
35#define UNLIMITED_ARGUMENTS (-1)
36
37#define rb_exc_new2 rb_exc_new_cstr
38#define rb_exc_new3 rb_exc_new_str
41#define rb_check_arity rb_check_arity
44 RBIMPL_SYMBOL_EXPORT_BEGIN()
45
46/* error.c */
47
48
66 VALUE rb_exc_new(VALUE etype, const char *ptr, long len);
67
68 RBIMPL_ATTR_NONNULL(())
78 VALUE rb_exc_new_cstr(VALUE etype, const char *str);
79
89 VALUE rb_exc_new_str(VALUE etype, VALUE str);
90
91 RBIMPL_ATTR_NORETURN()
92 RBIMPL_ATTR_NONNULL((1))
93 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
105void rb_loaderror(const char *fmt, ...);
106
107 RBIMPL_ATTR_NORETURN()
108 RBIMPL_ATTR_NONNULL((2))
109 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
120void rb_loaderror_with_path(VALUE path, const char *fmt, ...);
121
122 RBIMPL_ATTR_NORETURN()
123 RBIMPL_ATTR_NONNULL((2))
124 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
134void rb_name_error(ID name, const char *fmt, ...);
135
136 RBIMPL_ATTR_NORETURN()
137 RBIMPL_ATTR_NONNULL((2))
138 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
147void rb_name_error_str(VALUE name, const char *fmt, ...);
148
149 RBIMPL_ATTR_NORETURN()
150 RBIMPL_ATTR_NONNULL((2))
151 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
166void rb_frozen_error_raise(VALUE recv, const char *fmt, ...);
167
168 RBIMPL_ATTR_NORETURN()
169 RBIMPL_ATTR_NONNULL(())
179void rb_invalid_str(const char *str, const char *type);
180
181 RBIMPL_ATTR_NORETURN()
182 RBIMPL_ATTR_NONNULL(())
191void rb_error_frozen(const char *what);
192
193 RBIMPL_ATTR_NORETURN()
202void rb_error_frozen_object(VALUE what);
203
211void rb_check_frozen(VALUE obj);
212
223void rb_check_copyable(VALUE obj, VALUE orig);
224
225 RBIMPL_ATTR_NORETURN()
238MJIT_STATIC void rb_error_arity(int argc, int min, int max);
239
240 RBIMPL_SYMBOL_EXPORT_END()
241
247#define rb_check_frozen_internal(obj) do { \
248 VALUE frozen_obj = (obj); \
249 if (RB_UNLIKELY(RB_OBJ_FROZEN(frozen_obj))) { \
250 rb_error_frozen_object(frozen_obj); \
251 } \
252 } while (0)
253
255static inline void
256rb_check_frozen_inline(VALUE obj)
257{
258 if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) {
259 rb_error_frozen_object(obj);
260 }
261}
262
264#define rb_check_frozen rb_check_frozen_inline
265
279static inline int
280rb_check_arity(int argc, int min, int max)
281{
282 if ((argc < min) || (max != UNLIMITED_ARGUMENTS && argc > max))
283 rb_error_arity(argc, min, max);
284 return argc;
285}
286
287#endif /* RBIMPL_INTERN_ERROR_H */
assume.h
Defines ASSUME / RB_LIKELY / UNREACHABLE.
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
fl_type.h
Defines enum ruby_fl_type.
RB_OBJ_FROZEN
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
Definition fl_type.h:921
format.h
Defines RBIMPL_ATTR_FORMAT.
RBIMPL_ATTR_FORMAT
#define RBIMPL_ATTR_FORMAT(x, y, z)
Wraps (or simulates) __attribute__((format))
Definition format.h:29
rb_name_error
void rb_name_error(ID name, const char *fmt,...)
Raises an instance of rb_eNameError.
Definition error.c:1784
rb_check_copyable
void rb_check_copyable(VALUE obj, VALUE orig)
Ensures that the passed object can be initialize_copy relationship.
Definition error.c:3526
rb_error_frozen
void rb_error_frozen(const char *what)
Identical to rb_frozen_error_raise(), except its raising exception has a message like "can't modify f...
Definition error.c:3466
rb_name_error_str
void rb_name_error_str(VALUE name, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
Definition error.c:1799
rb_frozen_error_raise
void rb_frozen_error_raise(VALUE recv, const char *fmt,...)
Raises an instance of rb_eFrozenError.
Definition error.c:3472
rb_invalid_str
void rb_invalid_str(const char *str, const char *type)
Honestly I don't understand the name, but it raises an instance of rb_eArgError.
Definition error.c:2182
rb_exc_new
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Creates an instance of the passed exception class.
Definition error.c:1129
rb_error_frozen_object
void rb_error_frozen_object(VALUE what)
Identical to rb_error_frozen(), except it takes arbitrary Ruby object instead of C's string.
Definition error.c:3498
rb_exc_new_str
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
Definition error.c:1142
rb_loaderror
void rb_loaderror(const char *fmt,...)
Raises an instance of rb_eLoadError.
Definition error.c:3169
rb_loaderror_with_path
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Identical to rb_loaderror(), except it additionally takes which file is unable to load.
Definition error.c:3181
UNLIMITED_ARGUMENTS
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
Definition error.h:35
rb_check_frozen_inline
static void rb_check_frozen_inline(VALUE obj)
Just another name of rb_check_frozen.
Definition error.h:256
rb_check_frozen
#define rb_check_frozen
Just another name of rb_check_frozen.
Definition error.h:264
rb_check_arity
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
Definition error.h:280
rb_exc_new_cstr
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1670
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
noreturn.h
Defines RBIMPL_ATTR_NORETURN.
RBIMPL_ATTR_NORETURN
#define RBIMPL_ATTR_NORETURN()
Wraps (or simulates) [[noreturn]]
Definition noreturn.h:38
value.h
Defines VALUE and ID.
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40