Ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e0ba6b95ab71a441357ed5484e33498)
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
26#include "ruby/internal/value.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_trusted rb_check_trusted
42#define rb_check_trusted_inline rb_check_trusted
43#define rb_check_arity rb_check_arity
47
48/* error.c */
49
50
68VALUE rb_exc_new(VALUE etype, const char *ptr, long len);
69
80VALUE rb_exc_new_cstr(VALUE etype, const char *str);
81
91VALUE rb_exc_new_str(VALUE etype, VALUE str);
92
95RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
107void rb_loaderror(const char *fmt, ...);
108
111RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
122void rb_loaderror_with_path(VALUE path, const char *fmt, ...);
123
126RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
136void rb_name_error(ID name, const char *fmt, ...);
137
140RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
149void rb_name_error_str(VALUE name, const char *fmt, ...);
150
153RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
168void rb_frozen_error_raise(VALUE recv, const char *fmt, ...);
169
181void rb_invalid_str(const char *str, const char *type);
182
193void rb_error_frozen(const char *what);
194
204void rb_error_frozen_object(VALUE what);
205
210void rb_error_untrusted(VALUE);
211
219void rb_check_frozen(VALUE obj);
220
225void rb_check_trusted(VALUE);
226
237void rb_check_copyable(VALUE obj, VALUE orig);
238
252MJIT_STATIC void rb_error_arity(int argc, int min, int max);
253
255
261#define rb_check_frozen_internal(obj) do { \
262 VALUE frozen_obj = (obj); \
263 if (RB_UNLIKELY(RB_OBJ_FROZEN(frozen_obj))) { \
264 rb_error_frozen_object(frozen_obj); \
265 } \
266 } while (0)
267
269static inline void
271{
272 if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) {
274 }
275}
276
278#define rb_check_frozen rb_check_frozen_inline
279
293static inline int
294rb_check_arity(int argc, int min, int max)
295{
296 if ((argc < min) || (max != UNLIMITED_ARGUMENTS && argc > max))
297 rb_error_arity(argc, min, max);
298 return argc;
299}
300
301#endif /* RBIMPL_INTERN_ERROR_H */
Defines ASSUME / RB_LIKELY / UNREACHABLE.
#define RB_UNLIKELY(x)
Asserts that the given Boolean expression likely doesn't hold.
Definition: assume.h:52
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:106
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:97
Defines enum ruby_fl_type.
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
Definition: fl_type.h:927
Defines RBIMPL_ATTR_FORMAT.
#define RBIMPL_ATTR_FORMAT(x, y, z)
Wraps (or simulates) __attribute__((format))
Definition: format.h:27
void rb_name_error(ID name, const char *fmt,...)
Raises an instance of rb_eNameError.
Definition: error.c:1687
void rb_check_copyable(VALUE obj, VALUE orig)
Ensures that the passed object can be initialize_copy relationship.
Definition: error.c:3410
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:3337
void rb_error_untrusted(VALUE)
Definition: error.c:3397
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:1702
void rb_frozen_error_raise(VALUE recv, const char *fmt,...)
Raises an instance of rb_eFrozenError.
Definition: error.c:3343
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:2083
VALUE rb_exc_new_cstr(VALUE etype, const char *str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
Definition: error.c:1144
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Creates an instance of the passed exception class.
Definition: error.c:1137
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:3369
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:1150
void rb_loaderror(const char *fmt,...)
Raises an instance of rb_eLoadError.
Definition: error.c:3040
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:3052
void rb_check_trusted(VALUE)
Definition: error.c:3404
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
Definition: error.h:35
static void rb_check_frozen_inline(VALUE obj)
Just another name of rb_check_frozen.
Definition: error.h:270
#define rb_check_frozen
Just another name of rb_check_frozen.
Definition: error.h:278
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
Definition: error.h:294
RBIMPL_ATTR_NORETURN() void rb_eof_error(void)
Utility function to raise rb_eEOFError.
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
Defines RBIMPL_ATTR_NORETURN.
Defines VALUE and ID.