Ruby  3.1.4p223 (2023-03-30 revision HEAD)
ruby.h
Go to the documentation of this file.
1 #ifndef RUBY_RUBY_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RUBY_RUBY_H 1
15 #include "ruby/internal/config.h"
16 
17 /* @shyouhei doesn't understand why we need <intrinsics.h> at this very
18  * beginning of the entire <ruby.h> circus. */
19 #ifdef HAVE_INTRINSICS_H
20 # include <intrinsics.h>
21 #endif
22 
23 #include <stdarg.h>
24 
25 #include "defines.h"
26 #include "ruby/internal/anyargs.h"
28 #include "ruby/internal/core.h"
29 #include "ruby/internal/ctype.h"
31 #include "ruby/internal/error.h"
32 #include "ruby/internal/eval.h"
33 #include "ruby/internal/event.h"
34 #include "ruby/internal/fl_type.h"
35 #include "ruby/internal/gc.h"
36 #include "ruby/internal/glob.h"
37 #include "ruby/internal/globals.h"
40 #include "ruby/internal/iterator.h"
41 #include "ruby/internal/memory.h"
42 #include "ruby/internal/method.h"
43 #include "ruby/internal/module.h"
44 #include "ruby/internal/newobj.h"
45 #include "ruby/internal/rgengc.h"
48 #include "ruby/internal/symbol.h"
49 #include "ruby/internal/value.h"
51 #include "ruby/internal/variable.h"
52 #include "ruby/assert.h"
53 #include "ruby/backward/2/assume.h"
54 #include "ruby/backward/2/inttypes.h"
55 #include "ruby/backward/2/limits.h"
56 
58 
59 /* Module#methods, #singleton_methods and so on return Symbols */
67 #define USE_SYMBOL_AS_METHOD_NAME 1
68 
80 
90 #define FilePathValue(v) (RB_GC_GUARD(v) = rb_get_path(v))
91 
98 
103 #define FilePathStringValue(v) ((v) = rb_get_path(v))
104 
106 #if defined(HAVE_BUILTIN___BUILTIN_CONSTANT_P) && defined(HAVE_STMT_AND_DECL_IN_EXPR)
107 # define rb_varargs_argc_check_runtime(argc, vargc) \
108  (((argc) <= (vargc)) ? (argc) : \
109  (rb_fatal("argc(%d) exceeds actual arguments(%d)", \
110  argc, vargc), 0))
111 # define rb_varargs_argc_valid_p(argc, vargc) \
112  ((argc) == 0 ? (vargc) <= 1 : /* [ruby-core:85266] [Bug #14425] */ \
113  (argc) == (vargc))
114 # if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
115 # ifdef HAVE_ATTRIBUTE_ERRORFUNC
116 ERRORFUNC((" argument length doesn't match"), int rb_varargs_bad_length(int,int));
117 # else
118 # define rb_varargs_bad_length(argc, vargc) \
119  ((argc)/rb_varargs_argc_valid_p(argc, vargc))
120 # endif
121 # define rb_varargs_argc_check(argc, vargc) \
122  __builtin_choose_expr(__builtin_constant_p(argc), \
123  (rb_varargs_argc_valid_p(argc, vargc) ? (argc) : \
124  rb_varargs_bad_length(argc, vargc)), \
125  rb_varargs_argc_check_runtime(argc, vargc))
126 # else
127 # define rb_varargs_argc_check(argc, vargc) \
128  rb_varargs_argc_check_runtime(argc, vargc)
129 # endif
130 #endif
140 const char *rb_class2name(VALUE klass);
141 
149 const char *rb_obj_classname(VALUE obj);
150 
161 void rb_p(VALUE obj);
162 
177 VALUE rb_equal(VALUE lhs, VALUE rhs);
178 
190 VALUE rb_require(const char *feature);
191 
192 #include "ruby/intern.h"
193 
201 #define RUBY_VM 1 /* YARV */
202 
210 #define HAVE_NATIVETHREAD
211 
222 int ruby_native_thread_p(void);
223 
229 #define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();}
230 
232 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 4)
250 int ruby_snprintf(char *str, size_t n, char const *fmt, ...);
251 
253 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 0)
271 int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap);
272 
274 #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
275 # /* Skip it; clang -pedantic doesn't like the following */
276 #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO) && defined(__OPTIMIZE__)
277 # define rb_yield_values(argc, ...) \
278 __extension__({ \
279  const int rb_yield_values_argc = (argc); \
280  const VALUE rb_yield_values_args[] = {__VA_ARGS__}; \
281  const int rb_yield_values_nargs = \
282  (int)(sizeof(rb_yield_values_args) / sizeof(VALUE)); \
283  rb_yield_values2( \
284  rb_varargs_argc_check(rb_yield_values_argc, rb_yield_values_nargs), \
285  rb_yield_values_nargs ? rb_yield_values_args : NULL); \
286  })
287 
288 # define rb_funcall(recv, mid, argc, ...) \
289 __extension__({ \
290  const int rb_funcall_argc = (argc); \
291  const VALUE rb_funcall_args[] = {__VA_ARGS__}; \
292  const int rb_funcall_nargs = \
293  (int)(sizeof(rb_funcall_args) / sizeof(VALUE)); \
294  rb_funcallv(recv, mid, \
295  rb_varargs_argc_check(rb_funcall_argc, rb_funcall_nargs), \
296  rb_funcall_nargs ? rb_funcall_args : NULL); \
297  })
298 #endif
301 #ifndef RUBY_DONT_SUBST
302 #include "ruby/subst.h"
303 #endif
304 
305 #if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
306 # include "ruby/backward.h"
307 #endif
308 
310 
311 #endif /* RUBY_RUBY_H */
Function overloads to issue warnings around ANYARGS.
Conversion between C's arithmtic types and Ruby's numeric types.
Defines ASSUME / RB_LIKELY / UNREACHABLE.
Core data structures, definitions and manipulations.
Our own, locale independent, character handling routines.
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
Debugging and tracing APIs.
Defines enum ruby_fl_type.
#define RBIMPL_ATTR_FORMAT(x, y, z)
Wraps (or simulates) __attribute__((format))
Definition: format.h:27
Declares rb_glob().
Ruby-level global variables / constants, visible from C.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
Definition: object.c:120
Defines RBIMPL_HAS_WARNING.
Declares rb_raise().
Declares rb_eval_string().
Registering values to the GC.
Creation and modification of Ruby methods.
Defines rb_intern.
Declares rb_define_variable().
Interpreter embedding APIs.
Block related APIs.
Memory management stuff.
Creation and modification of Ruby modules.
Defines NEWOBJ.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
RGENGC write-barrier APIs.
VALUE rb_get_path(VALUE obj)
Converts an object to a path.
Definition: file.c:245
const char * rb_class2name(VALUE klass)
Queries the name of the passed class.
Definition: variable.c:300
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
Definition: variable.c:309
VALUE rb_require(const char *feature)
Identical to rb_require_string(), except it takes C's string instead of Ruby's.
Definition: load.c:1270
void rb_p(VALUE obj)
Inspects an object.
Definition: io.c:8277
int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap)
Identical to ruby_snprintf(), except it takes a va_list.
Definition: sprintf.c:1008
VALUE rb_get_path_no_checksafe(VALUE)
Definition: file.c:239
int ruby_native_thread_p(void)
Queries if the thread which calls this function is a ruby's thread.
Definition: thread.c:5539
int ruby_snprintf(char *str, size_t n, char const *fmt,...)
Our own locale-insensitive version of snprintf(3).
Definition: sprintf.c:1035
Compile-time static implementation of rb_scan_args().
Defines enum ruby_special_consts.
Defines old _.
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40
Defines enum ruby_value_type.