Ruby: include/ruby/ruby.h Source File

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

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/abi.h"
27#include "ruby/internal/anyargs.h"
28#include "ruby/internal/arithmetic.h"
29#include "ruby/internal/core.h"
30#include "ruby/internal/ctype.h"
31#include "ruby/internal/dllexport.h"
32#include "ruby/internal/error.h"
33#include "ruby/internal/eval.h"
34#include "ruby/internal/event.h"
35#include "ruby/internal/fl_type.h"
36#include "ruby/internal/gc.h"
37#include "ruby/internal/glob.h"
38#include "ruby/internal/globals.h"
39#include "ruby/internal/has/warning.h"
40#include "ruby/internal/interpreter.h"
41#include "ruby/internal/iterator.h"
42#include "ruby/internal/memory.h"
43#include "ruby/internal/method.h"
44#include "ruby/internal/module.h"
45#include "ruby/internal/newobj.h"
46#include "ruby/internal/rgengc.h"
47#include "ruby/internal/scan_args.h"
48#include "ruby/internal/special_consts.h"
49#include "ruby/internal/symbol.h"
50#include "ruby/internal/value.h"
51#include "ruby/internal/value_type.h"
52#include "ruby/internal/variable.h"
53#include "ruby/assert.h"
54#include "ruby/backward/2/assume.h"
55#include "ruby/backward/2/inttypes.h"
56#include "ruby/backward/2/limits.h"
57
58 RBIMPL_SYMBOL_EXPORT_BEGIN()
59
60/* Module#methods, #singleton_methods and so on return Symbols */
68#define USE_SYMBOL_AS_METHOD_NAME 1
69
80 VALUE rb_get_path(VALUE obj);
81
91#define FilePathValue(v) (RB_GC_GUARD(v) = rb_get_path(v))
92
98 VALUE rb_get_path_no_checksafe(VALUE);
99
104#define FilePathStringValue(v) ((v) = rb_get_path(v))
105
107#if defined(HAVE_BUILTIN___BUILTIN_CONSTANT_P) && defined(HAVE_STMT_AND_DECL_IN_EXPR)
108# define rb_varargs_argc_check_runtime(argc, vargc) \
109 (((argc) <= (vargc)) ? (argc) : \
110 (rb_fatal("argc(%d) exceeds actual arguments(%d)", \
111 argc, vargc), 0))
112# define rb_varargs_argc_valid_p(argc, vargc) \
113 ((argc) == 0 ? (vargc) <= 1 : /* [ruby-core:85266] [Bug #14425] */ \
114 (argc) == (vargc))
115# if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
116# ifdef HAVE_ATTRIBUTE_ERRORFUNC
117ERRORFUNC((" argument length doesn't match"), int rb_varargs_bad_length(int,int));
118# else
119# define rb_varargs_bad_length(argc, vargc) \
120 ((argc)/rb_varargs_argc_valid_p(argc, vargc))
121# endif
122# define rb_varargs_argc_check(argc, vargc) \
123 __builtin_choose_expr(__builtin_constant_p(argc), \
124 (rb_varargs_argc_valid_p(argc, vargc) ? (argc) : \
125 rb_varargs_bad_length(argc, vargc)), \
126 rb_varargs_argc_check_runtime(argc, vargc))
127# else
128# define rb_varargs_argc_check(argc, vargc) \
129 rb_varargs_argc_check_runtime(argc, vargc)
130# endif
131#endif
141const char *rb_class2name(VALUE klass);
142
150const char *rb_obj_classname(VALUE obj);
151
162void rb_p(VALUE obj);
163
178 VALUE rb_equal(VALUE lhs, VALUE rhs);
179
191 VALUE rb_require(const char *feature);
192
193#include "ruby/intern.h"
194
202#define RUBY_VM 1 /* YARV */
203
211#define HAVE_NATIVETHREAD
212
223int ruby_native_thread_p(void);
224
230#define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();}
231
232 RBIMPL_ATTR_NONNULL((3))
233 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 4)
251int ruby_snprintf(char *str, size_t n, char const *fmt, ...);
252
253 RBIMPL_ATTR_NONNULL((3))
254 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 0)
272int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap);
273
275#if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
276# /* Skip it; clang -pedantic doesn't like the following */
277#elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO) && defined(__OPTIMIZE__)
278# define rb_yield_values(argc, ...) \
279__extension__({ \
280 const int rb_yield_values_argc = (argc); \
281 const VALUE rb_yield_values_args[] = {__VA_ARGS__}; \
282 const int rb_yield_values_nargs = \
283 (int)(sizeof(rb_yield_values_args) / sizeof(VALUE)); \
284 rb_yield_values2( \
285 rb_varargs_argc_check(rb_yield_values_argc, rb_yield_values_nargs), \
286 rb_yield_values_nargs ? rb_yield_values_args : NULL); \
287 })
288
289# define rb_funcall(recv, mid, argc, ...) \
290__extension__({ \
291 const int rb_funcall_argc = (argc); \
292 const VALUE rb_funcall_args[] = {__VA_ARGS__}; \
293 const int rb_funcall_nargs = \
294 (int)(sizeof(rb_funcall_args) / sizeof(VALUE)); \
295 rb_funcallv(recv, mid, \
296 rb_varargs_argc_check(rb_funcall_argc, rb_funcall_nargs), \
297 rb_funcall_nargs ? rb_funcall_args : NULL); \
298 })
299#endif
302#ifndef RUBY_DONT_SUBST
303#include "ruby/subst.h"
304#endif
305
306#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
307# include "ruby/backward.h"
308#endif
309
310 RBIMPL_SYMBOL_EXPORT_END()
311
312#endif /* RUBY_RUBY_H */
anyargs.h
Function overloads to issue warnings around ANYARGS.
arithmetic.h
Conversion between C's arithmetic types and Ruby's numeric types.
assert.h
assume.h
Defines ASSUME / RB_LIKELY / UNREACHABLE.
core.h
Core data structures, definitions and manipulations.
ctype.h
Our own, locale independent, character handling routines.
defines.h
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
event.h
Debugging and tracing APIs.
fl_type.h
Defines enum ruby_fl_type.
RBIMPL_ATTR_FORMAT
#define RBIMPL_ATTR_FORMAT(x, y, z)
Wraps (or simulates) __attribute__((format))
Definition format.h:29
glob.h
Declares rb_glob().
globals.h
Ruby-level global variables / constants, visible from C.
rb_equal
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
Definition object.c:123
warning.h
Defines RBIMPL_HAS_WARNING.
error.h
Declares rb_raise().
eval.h
Declares rb_eval_string().
gc.h
Registering values to the GC.
method.h
Creation and modification of Ruby methods.
symbol.h
Defines rb_intern.
variable.h
Declares rb_define_variable().
intern.h
interpreter.h
Interpreter embedding APIs.
iterator.h
Block related APIs.
memory.h
Memory management stuff.
module.h
Creation and modification of Ruby modules.
newobj.h
Defines NEWOBJ.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
rgengc.h
RGENGC write-barrier APIs.
rb_get_path
VALUE rb_get_path(VALUE obj)
Converts an object to a path.
Definition file.c:247
rb_class2name
const char * rb_class2name(VALUE klass)
Queries the name of the passed class.
Definition variable.c:316
rb_require
VALUE rb_require(const char *feature)
Identical to rb_require_string(), except it takes C's string instead of Ruby's.
Definition load.c:1329
rb_obj_classname
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
Definition variable.c:325
rb_p
void rb_p(VALUE obj)
Inspects an object.
Definition io.c:8978
ruby_vsnprintf
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:1018
rb_get_path_no_checksafe
VALUE rb_get_path_no_checksafe(VALUE)
Definition file.c:241
ruby_native_thread_p
int ruby_native_thread_p(void)
Queries if the thread which calls this function is a ruby's thread.
Definition thread.c:5443
ruby_snprintf
int ruby_snprintf(char *str, size_t n, char const *fmt,...)
Our own locale-insensitive version of snprintf(3).
Definition sprintf.c:1045
scan_args.h
Compile-time static implementation of rb_scan_args().
special_consts.h
Defines enum ruby_special_consts.
stdarg.h
Defines old _.
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
value_type.h
Defines enum ruby_value_type.