Allow ruby versions 3.2 and 3.4 for installation

This commit is contained in:
2026-01-28 22:12:37 +00:00
parent 1312c09501
commit 515d5559a7
200 changed files with 40636 additions and 22 deletions

58
libs/libruby/ruby/internal/abi.h vendored Normal file
View File

@@ -0,0 +1,58 @@
#ifndef RUBY_ABI_H
#define RUBY_ABI_H
#ifdef RUBY_ABI_VERSION /* should match the definition in config.h */
/* This number represents Ruby's ABI version.
*
* In development Ruby, it should be bumped every time an ABI incompatible
* change is introduced. This will force other developers to rebuild extension
* gems.
*
* The following cases are considered as ABI incompatible changes:
* - Changing any data structures.
* - Changing macros or inline functions causing a change in behavior.
* - Deprecating or removing function declarations.
*
* The following cases are NOT considered as ABI incompatible changes:
* - Any changes that does not involve the header files in the `include`
* directory.
* - Adding macros, inline functions, or function declarations.
* - Backwards compatible refactors.
* - Editing comments.
*
* In released versions of Ruby, this number is not defined since teeny
* versions of Ruby should guarantee ABI compatibility.
*/
#define RUBY_ABI_VERSION 3
/* Windows does not support weak symbols so ruby_abi_version will not exist
* in the shared library. */
#if defined(HAVE_FUNC_WEAK) && !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
# define RUBY_DLN_CHECK_ABI
#endif
#endif /* RUBY_ABI_VERSION */
#ifdef RUBY_DLN_CHECK_ABI
# ifdef __cplusplus
extern "C" {
# endif
RUBY_FUNC_EXPORTED unsigned long long __attribute__((weak))
ruby_abi_version(void)
{
# ifdef RUBY_ABI_VERSION
return RUBY_ABI_VERSION;
# else
return 0;
# endif
}
# ifdef __cplusplus
}
# endif
#endif
#endif

376
libs/libruby/ruby/internal/anyargs.h vendored Normal file
View File

@@ -0,0 +1,376 @@
#ifndef RBIMPL_ANYARGS_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ANYARGS_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Function overloads to issue warnings around #ANYARGS.
*
* For instance ::rb_define_method takes a pointer to #ANYARGS -ed functions,
* which in fact varies 18 different prototypes. We still need to preserve
* #ANYARGS for storages but why not check the consistencies if possible. With
* those complex macro overlays defined in this header file, use of a function
* pointer gets checked against the corresponding arity argument.
*
* ### Q&A ###
*
* - Q: Where did the magic number "18" came from in the description above?
*
* - A: Count the case branch of `vm_method.c:call_cfunc_invoker_func()`. Note
* also that the 18 branches has lasted for at least 25 years. See also
* commit 200e0ee2fd3c1c006c528874a88f684447215524.
*
* - Q: What is this `__weakref__` thing?
*
* - A: That is a kind of function overloading mechanism that GCC provides. In
* this case for instance `rb_define_method_00` is an alias of
* ::rb_define_method, with a strong type.
*
* - Q: What is this `__transparent_union__` thing?
*
* A: That is another kind of function overloading mechanism that GCC
* provides. In this case the attributed function pointer is either
* `VALUE(*)(int,VALUE*,VALUE)` or `VALUE(*)(int,const VALUE*,VALUE)`.
*
* This is better than `void*` or #ANYARGS because we can reject all other
* possibilities than the two.
*
* - Q: What does this #rb_define_method macro mean?
*
* - A: It selects appropriate alias of the ::rb_define_method function,
* depending on the last (arity) argument.
*
* - Q: Why the special case for ::rb_f_notimplement ?
*
* - A: Function pointer to ::rb_f_notimplement is special cased in
* `vm_method.c:rb_add_method_cfunc()`. That should be handled by the
* `__builtin_choose_expr` chain inside of #rb_define_method macro
* expansion. In order to do so, comparison like
* `(func == rb_f_notimplement)` is inappropriate for
* `__builtin_choose_expr`'s expression (which must be a compile-time
* integer constant but the address of ::rb_f_notimplement is not fixed
* until the linker). Instead we are using
* `__builtin_types_compatible_p`, and in doing so we need to distinguish
* ::rb_f_notimplement from others, by type.
*/
#include "ruby/internal/attr/maybe_unused.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/weakref.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/config.h"
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/intern/class.h"
#include "ruby/internal/intern/vm.h"
#include "ruby/internal/method.h"
#include "ruby/internal/value.h"
#include "ruby/backward/2/stdarg.h"
#if defined(__cplusplus)
# include "ruby/backward/cxxanyargs.hpp"
#elif defined(_WIN32) || defined(__CYGWIN__)
# /* Skip due to [Bug #16134] */
#elif ! RBIMPL_HAS_ATTRIBUTE(transparent_union)
# /* :TODO: improve here, please find a way to support. */
#elif ! defined(HAVE_VA_ARGS_MACRO)
# /* :TODO: improve here, please find a way to support. */
#else
# /** @cond INTERNAL_MACRO */
# if ! defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P)
# define RBIMPL_CFUNC_IS_rb_f_notimplement(f) 0
# else
# define RBIMPL_CFUNC_IS_rb_f_notimplement(f) \
__builtin_types_compatible_p( \
__typeof__(f), \
__typeof__(rb_f_notimplement))
# endif
# if ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
# define RBIMPL_ANYARGS_DISPATCH(expr, truthy, falsy) (falsy)
# else
# define RBIMPL_ANYARGS_DISPATCH(expr, truthy, falsy) \
__builtin_choose_expr( \
__builtin_choose_expr( \
__builtin_constant_p(expr), \
(expr), 0), \
(truthy), (falsy))
# endif
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_singleton_method_m2, rb_define_singleton_method_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_singleton_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_singleton_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_singleton_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_singleton_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_singleton_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_singleton_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_singleton_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_singleton_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_singleton_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_singleton_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_singleton_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_singleton_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_singleton_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_singleton_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_singleton_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_singleton_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_singleton_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_protected_method_m2, rb_define_protected_method_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_protected_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_protected_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_protected_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_protected_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_protected_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_protected_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_protected_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_protected_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_protected_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_protected_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_protected_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_protected_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_protected_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_protected_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_protected_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_protected_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_protected_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_private_method_m2, rb_define_private_method_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_private_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_private_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_private_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_private_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_private_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_private_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_private_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_private_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_private_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_private_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_private_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_private_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_private_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_private_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_private_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_private_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_private_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_module_function_m2, rb_define_module_function_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_module_function_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_module_function_00, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_module_function_01, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_module_function_02, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_module_function_03, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_module_function_04, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_module_function_05, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_module_function_06, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_module_function_07, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_module_function_08, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_module_function_09, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_module_function_10, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_module_function_11, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_module_function_12, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_module_function_13, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_module_function_14, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_module_function_15, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_global_function_m2, rb_define_global_function_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_global_function_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_global_function_00, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_global_function_01, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_global_function_02, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_global_function_03, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_global_function_04, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_global_function_05, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_global_function_06, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_global_function_07, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_global_function_08, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_global_function_09, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_global_function_10, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_global_function_11, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_global_function_12, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_global_function_13, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_global_function_14, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_global_function_15, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_method_id_m2, rb_define_method_id_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_method_id_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_method_id_00, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_method_id_01, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_method_id_02, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_method_id_03, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_method_id_04, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_method_id_05, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_method_id_06, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_method_id_07, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_method_id_08, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_method_id_09, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_method_id_10, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_method_id_11, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_method_id_12, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_method_id_13, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_method_id_14, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_method_id_15, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_method_m2, rb_define_method_m3)
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_method_m2(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_method_m1(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_method_00(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_method_01(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_method_02(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_method_03(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_method_04(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_method_05(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_method_06(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_method_07(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_method_08(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_method_09(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_method_10(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_method_11(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_method_12(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_method_13(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_method_14(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_singleton_method_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_15(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_protected_method_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_15(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_private_method_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_15(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_module_function_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_15(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_global_function_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_15(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_method_id_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_15(n))
# define RBIMPL_ANYARGS_DISPATCH_rb_define_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_method_notimpl, RBIMPL_ANYARGS_DISPATCH_rb_define_method_15(n))
# define RBIMPL_ANYARGS_ATTRSET(sym) RBIMPL_ATTR_MAYBE_UNUSED() RBIMPL_ATTR_NONNULL(()) RBIMPL_ATTR_WEAKREF(sym)
# define RBIMPL_ANYARGS_DECL(sym, ...) \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _notimpl(__VA_ARGS__, VALUE(*)(int, const VALUE *, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m3(__VA_ARGS__, VALUE(*)(ANYARGS), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m2(__VA_ARGS__, VALUE(*)(VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m1(__VA_ARGS__, VALUE(*)(int, union { VALUE *x; const VALUE *y; } __attribute__((__transparent_union__)), VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _00(__VA_ARGS__, VALUE(*)(VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _01(__VA_ARGS__, VALUE(*)(VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _02(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _03(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _04(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _05(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _06(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _07(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _08(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _09(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _10(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _11(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _12(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _13(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _14(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \
RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _15(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int);
RBIMPL_ANYARGS_DECL(rb_define_singleton_method, VALUE, const char *)
RBIMPL_ANYARGS_DECL(rb_define_protected_method, VALUE, const char *)
RBIMPL_ANYARGS_DECL(rb_define_private_method, VALUE, const char *)
RBIMPL_ANYARGS_DECL(rb_define_module_function, VALUE, const char *)
RBIMPL_ANYARGS_DECL(rb_define_global_function, const char *)
RBIMPL_ANYARGS_DECL(rb_define_method_id, VALUE, ID)
RBIMPL_ANYARGS_DECL(rb_define_method, VALUE, const char *)
/** @endcond */
/**
* @brief Defines klass\#mid.
* @see ::rb_define_method
* @param klass Where the method lives.
* @param mid Name of the defining method.
* @param func Implementation of klass\#mid.
* @param arity Arity of klass\#mid.
*/
#define rb_define_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_method((arity), (func))((klass), (mid), (func), (arity))
/**
* @brief Defines klass\#mid.
* @see ::rb_define_method_id
* @param klass Where the method lives.
* @param mid Name of the defining method.
* @param func Implementation of klass\#mid.
* @param arity Arity of klass\#mid.
*/
#define rb_define_method_id(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_method_id((arity), (func))((klass), (mid), (func), (arity))
/**
* @brief Defines obj.mid.
* @see ::rb_define_singleton_method
* @param obj Where the method lives.
* @param mid Name of the defining method.
* @param func Implementation of obj.mid.
* @param arity Arity of obj.mid.
*/
#define rb_define_singleton_method(obj, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method((arity), (func))((obj), (mid), (func), (arity))
/**
* @brief Defines klass\#mid and make it protected.
* @see ::rb_define_protected_method
* @param klass Where the method lives.
* @param mid Name of the defining method.
* @param func Implementation of klass\#mid.
* @param arity Arity of klass\#mid.
*/
#define rb_define_protected_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method((arity), (func))((klass), (mid), (func), (arity))
/**
* @brief Defines klass\#mid and make it private.
* @see ::rb_define_private_method
* @param klass Where the method lives.
* @param mid Name of the defining method.
* @param func Implementation of klass\#mid.
* @param arity Arity of klass\#mid.
*/
#define rb_define_private_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_private_method((arity), (func))((klass), (mid), (func), (arity))
/**
* @brief Defines mod\#mid and make it a module function.
* @see ::rb_define_module_function
* @param mod Where the method lives.
* @param mid Name of the defining method.
* @param func Implementation of mod\#mid.
* @param arity Arity of mod\#mid.
*/
#define rb_define_module_function(mod, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_module_function((arity), (func))((mod), (mid), (func), (arity))
/**
* @brief Defines ::rb_mKerbel \#mid.
* @see ::rb_define_global_function
* @param mid Name of the defining method.
* @param func Implementation of ::rb_mKernel \#mid.
* @param arity Arity of ::rb_mKernel \#mid.
*/
#define rb_define_global_function(mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_global_function((arity), (func))((mid), (func), (arity))
#endif /* __cplusplus */
/**
* This macro is to properly cast a function parameter of *_define_method
* family. It has been around since 1.x era so you can maximise backwards
* compatibility by using it.
*
* ```CXX
* rb_define_method(klass, "method", RUBY_METHOD_FUNC(func), arity);
* ```
*
* @param func A pointer to a function that implements a method.
*/
#if ! defined(RUBY_DEVEL)
# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func))
#elif ! RUBY_DEVEL
# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func))
#elif ! defined(rb_define_method)
# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func))
#else
# define RUBY_METHOD_FUNC(func) (func)
#endif
#endif /* RBIMPL_ANYARGS_H */

39
libs/libruby/ruby/internal/arithmetic.h vendored Normal file
View File

@@ -0,0 +1,39 @@
#ifndef RBIMPL_ARITHMETIC_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Conversion between C's arithmetic types and Ruby's numeric
* types.
*/
#include "ruby/internal/arithmetic/char.h"
#include "ruby/internal/arithmetic/double.h"
#include "ruby/internal/arithmetic/fixnum.h"
#include "ruby/internal/arithmetic/gid_t.h"
#include "ruby/internal/arithmetic/int.h"
#include "ruby/internal/arithmetic/intptr_t.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/arithmetic/long_long.h"
#include "ruby/internal/arithmetic/mode_t.h"
#include "ruby/internal/arithmetic/off_t.h"
#include "ruby/internal/arithmetic/pid_t.h"
#include "ruby/internal/arithmetic/short.h"
#include "ruby/internal/arithmetic/size_t.h"
#include "ruby/internal/arithmetic/st_data_t.h"
#include "ruby/internal/arithmetic/uid_t.h"
#endif /* RBIMPL_ARITHMETIC_H */

View File

@@ -0,0 +1,81 @@
#ifndef RBIMPL_ARITHMETIC_CHAR_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_CHAR_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `char` and Ruby's.
*/
#include "ruby/internal/arithmetic/int.h" /* NUM2INT is here, but */
#include "ruby/internal/arithmetic/long.h" /* INT2FIX is here.*/
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rstring.h"
#include "ruby/internal/value_type.h"
#define RB_NUM2CHR rb_num2char_inline /**< @alias{rb_num2char_inline} */
#define NUM2CHR RB_NUM2CHR /**< @old{RB_NUM2CHR} */
#define CHR2FIX RB_CHR2FIX /**< @old{RB_CHR2FIX} */
/** @cond INTERNAL_MACRO */
#define RB_CHR2FIX RB_CHR2FIX
/** @endcond */
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Converts a C's `unsigned char` into an instance of ::rb_cInteger.
*
* @param[in] c Arbitrary `unsigned char` value.
* @return An instance of ::rb_cInteger.
*
* @internal
*
* Nobody explicitly states this but in Ruby, a char means an unsigned integer
* value of range 0..255. This is a general principle. AFAIK there is no
* single line of code where char is signed.
*/
static inline VALUE
RB_CHR2FIX(unsigned char c)
{
return RB_INT2FIX(c);
}
/**
* Converts an instance of ::rb_cNumeric into C's `char`. At the same time it
* accepts a String of more than one character, and returns its first byte. In
* the early days there was a Ruby level "character" literal `?c`, which
* roughly worked this way.
*
* @param[in] x Either a string or a numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `unsigned int`.
* @return The passed value converted into C's `char`.
*/
static inline char
rb_num2char_inline(VALUE x)
{
if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1))
return RSTRING_PTR(x)[0];
else
return RBIMPL_CAST((char)RB_NUM2INT(x));
}
#endif /* RBIMPL_ARITHMETIC_CHAR_H */

View File

@@ -0,0 +1,72 @@
#ifndef RBIMPL_ARITHMETIC_DOUBLE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_DOUBLE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `double` and Ruby's.
*/
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#define NUM2DBL rb_num2dbl /**< @old{rb_num2dbl} */
#define RFLOAT_VALUE rb_float_value /**< @old{rb_float_value} */
#define DBL2NUM rb_float_new /**< @old{rb_float_new} */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Converts an instance of ::rb_cNumeric into C's `double`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @return The passed value converted into C's `double`.
*/
double rb_num2dbl(VALUE num);
RBIMPL_ATTR_PURE()
/**
* Extracts its double value from an instance of ::rb_cFloat.
*
* @param[in] num An instance of ::rb_cFloat.
* @pre Must not pass anything other than a Fixnum.
* @return The passed value converted into C's `double`.
*/
double rb_float_value(VALUE num);
/**
* Converts a C's `double` into an instance of ::rb_cFloat.
*
* @param[in] d Arbitrary `double` value.
* @return An instance of ::rb_cFloat.
*/
VALUE rb_float_new(double d);
/**
* Identical to rb_float_new(), except it does not generate Flonums.
*
* @param[in] d Arbitrary `double` value.
* @return An instance of ::rb_cFloat.
*
* @internal
*
* @shyouhei has no idea why it is here.
*/
VALUE rb_float_new_in_heap(double d);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_ARITHMETIC_DOUBLE_H */

View File

@@ -0,0 +1,60 @@
#ifndef RBIMPL_ARITHMETIC_FIXNUM_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_FIXNUM_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Handling of integers formerly known as Fixnums.
*/
#include "ruby/backward/2/limits.h"
#define FIXABLE RB_FIXABLE /**< @old{RB_FIXABLE} */
#define FIXNUM_MAX RUBY_FIXNUM_MAX /**< @old{RUBY_FIXNUM_MAX} */
#define FIXNUM_MIN RUBY_FIXNUM_MIN /**< @old{RUBY_FIXNUM_MIN} */
#define NEGFIXABLE RB_NEGFIXABLE /**< @old{RB_NEGFIXABLE} */
#define POSFIXABLE RB_POSFIXABLE /**< @old{RB_POSFIXABLE} */
/**
* Checks if the passed value is in range of fixnum, assuming it is a positive
* number. Can sometimes be useful for C's unsigned integer types.
*
* @internal
*
* FIXABLE can be applied to anything, from double to intmax_t. The problem is
* double. On a 64bit system RUBY_FIXNUM_MAX is 4,611,686,018,427,387,903,
* which is not representable by a double. The nearest value that a double can
* represent is 4,611,686,018,427,387,904, which is not fixable. The
* seemingly-strange "< FIXNUM_MAX + 1" expression below is due to this.
*/
#define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1)
/**
* Checks if the passed value is in range of fixnum, assuming it is a negative
* number. This is an implementation of #RB_FIXABLE. Rarely used stand alone.
*/
#define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN)
/** Checks if the passed value is in range of fixnum */
#define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_))
/** Maximum possible value that a fixnum can represent. */
#define RUBY_FIXNUM_MAX (LONG_MAX / 2)
/** Minimum possible value that a fixnum can represent. */
#define RUBY_FIXNUM_MIN (LONG_MIN / 2)
#endif /* RBIMPL_ARITHMETIC_FIXNUM_H */

View File

@@ -0,0 +1,41 @@
#ifndef RBIMPL_ARITHMETIC_GID_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_GID_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `gid_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/long.h"
/** Converts a C's `gid_t` into an instance of ::rb_cInteger. */
#ifndef GIDT2NUM
# define GIDT2NUM RB_LONG2NUM
#endif
/** Converts an instance of ::rb_cNumeric into C's `gid_t`. */
#ifndef NUM2GIDT
# define NUM2GIDT RB_NUM2LONG
#endif
/** A rb_sprintf() format prefix to be used for a `gid_t` parameter. */
#ifndef PRI_GIDT_PREFIX
# define PRI_GIDT_PREFIX PRI_LONG_PREFIX
#endif
#endif /* RBIMPL_ARITHMETIC_GID_T_H */

View File

@@ -0,0 +1,264 @@
#ifndef RBIMPL_ARITHMETIC_INT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_INT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `int` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/fixnum.h"
#include "ruby/internal/arithmetic/intptr_t.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/compiler_is.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h"
#include "ruby/internal/value.h"
#include "ruby/internal/warning_push.h"
#include "ruby/assert.h"
#define RB_INT2NUM rb_int2num_inline /**< @alias{rb_int2num_inline} */
#define RB_NUM2INT rb_num2int_inline /**< @alias{rb_num2int_inline} */
#define RB_UINT2NUM rb_uint2num_inline /**< @alias{rb_uint2num_inline} */
#define FIX2INT RB_FIX2INT /**< @old{RB_FIX2INT} */
#define FIX2UINT RB_FIX2UINT /**< @old{RB_FIX2UINT} */
#define INT2NUM RB_INT2NUM /**< @old{RB_INT2NUM} */
#define NUM2INT RB_NUM2INT /**< @old{RB_NUM2INT} */
#define NUM2UINT RB_NUM2UINT /**< @old{RB_NUM2UINT} */
#define UINT2NUM RB_UINT2NUM /**< @old{RB_UINT2NUM} */
/** @cond INTERNAL_MACRO */
#define RB_FIX2INT RB_FIX2INT
#define RB_NUM2UINT RB_NUM2UINT
#define RB_FIX2UINT RB_FIX2UINT
/** @endcond */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Converts an instance of ::rb_cNumeric into C's `long`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `int`.
* @return The passed value converted into C's `long`.
*
* @internal
*
* Yes, the API is really strange. It returns `long`, but raises when the
* value is out of `int`. This seems to be due to the fact that Matz favoured
* K&R before, and his machine at that moment was an ILP32 architecture.
*/
long rb_num2int(VALUE num);
/**
* Identical to rb_num2int().
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `int`.
* @return The passed value converted into C's `long`.
*
* @internal
*
* This function seems to be a complete waste of disk space. @shyouhei has no
* idea why this is a different thing from rb_num2short().
*/
long rb_fix2int(VALUE num);
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned long`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `unsigned int`.
* @return The passed value converted into C's `unsigned long`.
*
* @internal
*
* Yes, the API is really strange. It returns `unsigned long`, but raises when
* the value is out of `unsigned int`. This seems to be due to the fact that
* Matz favoured K&R before, and his machine at that moment was an ILP32
* architecture.
*/
unsigned long rb_num2uint(VALUE num);
/**
* Identical to rb_num2uint().
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `unsigned int`.
* @return The passed value converted into C's `unsigned long`.
*
* @internal
*
* This function seems to be a complete waste of disk space. @shyouhei has no
* idea why this is a different thing from rb_num2short().
*/
unsigned long rb_fix2uint(VALUE num);
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Converts a Fixnum into C's `int`.
*
* @param[in] x Some Fixnum.
* @pre Must not pass anything other than a Fixnum.
* @return The passed value converted into C's `int`.
*/
static inline int
RB_FIX2INT(VALUE x)
{
/* "FIX2INT raises a TypeError if passed nil", says rubyspec. Not sure if
* that is a desired behaviour but just preserve backwards compatilibily.
*/
#if 0
RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
#endif
long ret;
if /* constexpr */ (sizeof(int) < sizeof(long)) {
ret = rb_fix2int(x);
}
else {
ret = RB_FIX2LONG(x);
}
return RBIMPL_CAST((int)ret);
}
/**
* Converts an instance of ::rb_cNumeric into C's `int`.
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `int`.
* @return The passed value converted into C's `int`.
*/
static inline int
rb_num2int_inline(VALUE x)
{
long ret;
if /* constexpr */ (sizeof(int) == sizeof(long)) {
ret = RB_NUM2LONG(x);
}
else if (RB_FIXNUM_P(x)) {
ret = rb_fix2int(x);
}
else {
ret = rb_num2int(x);
}
return RBIMPL_CAST((int)ret);
}
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned int`.
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `unsigned int`.
* @return The passed value converted into C's `unsigned int`.
*/
RBIMPL_ATTR_ARTIFICIAL()
static inline unsigned int
RB_NUM2UINT(VALUE x)
{
unsigned long ret;
if /* constexpr */ (sizeof(int) < sizeof(long)) {
ret = rb_num2uint(x);
}
else {
ret = RB_NUM2ULONG(x);
}
return RBIMPL_CAST((unsigned int)ret);
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Converts a Fixnum into C's `int`.
*
* @param[in] x Some Fixnum.
* @pre Must not pass anything other than a Fixnum.
* @return The passed value converted into C's `int`.
*/
static inline unsigned int
RB_FIX2UINT(VALUE x)
{
#if 0 /* Ditto for RB_FIX2INT. */
RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
#endif
unsigned long ret;
if /* constexpr */ (sizeof(int) < sizeof(long)) {
ret = rb_fix2uint(x);
}
else {
ret = RB_FIX2ULONG(x);
}
return RBIMPL_CAST((unsigned int)ret);
}
RBIMPL_WARNING_PUSH()
#if RBIMPL_COMPILER_IS(GCC)
RBIMPL_WARNING_IGNORED(-Wtype-limits) /* We can ignore them here. */
#elif RBIMPL_HAS_WARNING("-Wtautological-constant-out-of-range-compare")
RBIMPL_WARNING_IGNORED(-Wtautological-constant-out-of-range-compare)
#endif
/**
* Converts a C's `int` into an instance of ::rb_cInteger.
*
* @param[in] v Arbitrary `int` value.
* @return An instance of ::rb_cInteger.
*/
static inline VALUE
rb_int2num_inline(int v)
{
if (RB_FIXABLE(v))
return RB_INT2FIX(v);
else
return rb_int2big(v);
}
/**
* Converts a C's `unsigned int` into an instance of ::rb_cInteger.
*
* @param[in] v Arbitrary `unsigned int` value.
* @return An instance of ::rb_cInteger.
*/
static inline VALUE
rb_uint2num_inline(unsigned int v)
{
if (RB_POSFIXABLE(v))
return RB_LONG2FIX(v);
else
return rb_uint2big(v);
}
RBIMPL_WARNING_POP()
#endif /* RBIMPL_ARITHMETIC_INT_H */

View File

@@ -0,0 +1,74 @@
#ifndef RBIMPL_ARITHMETIC_INTPTR_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_INTPTR_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `intptr_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#include "ruby/internal/value.h"
#include "ruby/internal/dllexport.h"
#define rb_int_new rb_int2inum /**< @alias{rb_int2inum} */
#define rb_uint_new rb_uint2inum /**< @alias{rb_uint2inum} */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Converts a C's `intptr_t` into an instance of ::rb_cInteger.
*
* @param[in] i Arbitrary `intptr_t` value.
* @return An instance of ::rb_cInteger.
* @note This function always allocates Bignums, even if the given number
* is small enough to fit into a Fixnum.
*/
VALUE rb_int2big(intptr_t i);
/**
* Converts a C's `intptr_t` into an instance of ::rb_cInteger.
*
* @param[in] i Arbitrary `intptr_t` value.
* @return An instance of ::rb_cInteger.
*/
VALUE rb_int2inum(intptr_t i);
/**
* Converts a C's `intptr_t` into an instance of ::rb_cInteger.
*
* @param[in] i Arbitrary `intptr_t` value.
* @return An instance of ::rb_cInteger.
* @note This function always allocates Bignums, even if the given number
* is small enough to fit into a Fixnum.
*/
VALUE rb_uint2big(uintptr_t i);
/**
* Converts a C's `uintptr_t` into an instance of ::rb_cInteger.
*
* @param[in] i Arbitrary `uintptr_t` value.
* @return An instance of ::rb_cInteger.
*/
VALUE rb_uint2inum(uintptr_t i);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_ARITHMETIC_INTPTR_T_H */

View File

@@ -0,0 +1,356 @@
#ifndef RBIMPL_ARITHMETIC_LONG_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_LONG_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `long` and Ruby's.
*
* ### Q&A ###
*
* - Q: Why are INT2FIX etc. here, not in `int.h`?
*
* - A: Because they are in fact handling `long`. It seems someone did not
* understand the difference of `int` and `long` when they designed those
* macros.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/fixnum.h" /* FIXABLE */
#include "ruby/internal/arithmetic/intptr_t.h" /* rb_int2big etc.*/
#include "ruby/internal/assume.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/cold.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h" /* FIXNUM_FLAG */
#include "ruby/internal/value.h"
#include "ruby/assert.h"
#define FIX2LONG RB_FIX2LONG /**< @old{RB_FIX2LONG} */
#define FIX2ULONG RB_FIX2ULONG /**< @old{RB_FIX2ULONG} */
#define INT2FIX RB_INT2FIX /**< @old{RB_INT2FIX} */
#define LONG2FIX RB_INT2FIX /**< @old{RB_INT2FIX} */
#define LONG2NUM RB_LONG2NUM /**< @old{RB_LONG2NUM} */
#define NUM2LONG RB_NUM2LONG /**< @old{RB_NUM2LONG} */
#define NUM2ULONG RB_NUM2ULONG /**< @old{RB_NUM2ULONG} */
#define RB_FIX2LONG rb_fix2long /**< @alias{rb_fix2long} */
#define RB_FIX2ULONG rb_fix2ulong /**< @alias{rb_fix2ulong} */
#define RB_LONG2FIX RB_INT2FIX /**< @alias{RB_INT2FIX} */
#define RB_LONG2NUM rb_long2num_inline /**< @alias{rb_long2num_inline} */
#define RB_NUM2LONG rb_num2long_inline /**< @alias{rb_num2long_inline} */
#define RB_NUM2ULONG rb_num2ulong_inline /**< @alias{rb_num2ulong_inline} */
#define RB_ULONG2NUM rb_ulong2num_inline /**< @alias{rb_ulong2num_inline} */
#define ULONG2NUM RB_ULONG2NUM /**< @old{RB_ULONG2NUM} */
#define rb_fix_new RB_INT2FIX /**< @alias{RB_INT2FIX} */
#define rb_long2int rb_long2int_inline /**< @alias{rb_long2int_inline} */
/** @cond INTERNAL_MACRO */
#define RB_INT2FIX RB_INT2FIX
/** @endcond */
RBIMPL_SYMBOL_EXPORT_BEGIN()
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_COLD()
/**
* This is an utility function to raise an ::rb_eRangeError.
*
* @param[in] num A signed value about to overflow.
* @exception rb_eRangeError `num` is out of range of `int`.
*/
void rb_out_of_int(SIGNED_VALUE num);
/**
* Converts an instance of ::rb_cNumeric into C's `long`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `long`.
* @return The passed value converted into C's `long`.
*/
long rb_num2long(VALUE num);
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned long`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `unsigned long`.
* @return The passed value converted into C's `unsigned long`.
*/
unsigned long rb_num2ulong(VALUE num);
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Converts a C's `long` into an instance of ::rb_cInteger.
*
* @param[in] i Arbitrary `long` value.
* @return An instance of ::rb_cInteger.
*/
static inline VALUE
RB_INT2FIX(long i)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(i));
/* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully
* defined. Also it can be compiled into a single LEA instruction. */
const unsigned long j = i;
const unsigned long k = (j << 1) + RUBY_FIXNUM_FLAG;
const long l = k;
const SIGNED_VALUE m = l; /* Sign extend */
const VALUE n = m;
RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(n));
return n;
}
/**
* Checks if `int` can hold the given integer.
*
* @param[in] n Arbitrary `long` value.
* @exception rb_eRangeError `n` is out of range of `int`.
* @return Identical value of type `int`
*/
static inline int
rb_long2int_inline(long n)
{
int i = RBIMPL_CAST((int)n);
if /* constexpr */ (sizeof(long) <= sizeof(int)) {
RBIMPL_ASSUME(i == n);
}
if (i != n)
rb_out_of_int(n);
return i;
}
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
/**
* @private
*
* This is an implementation detail of rb_fix2long(). People don't use it
* directly.
*
* @param[in] x A Fixnum.
* @return Identical value of type `long`
* @pre Must not pass anything other than a Fixnum.
*/
static inline long
rbimpl_fix2long_by_idiv(VALUE x)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
/* :NOTE: VALUE can be wider than long. (x-1)/2 never overflows because
* RB_FIXNUM_P(x) holds. Also it has no portability issue like y>>1
* below. */
const SIGNED_VALUE y = x - RUBY_FIXNUM_FLAG;
const SIGNED_VALUE z = y / 2;
const long w = RBIMPL_CAST((long)z);
RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w));
return w;
}
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
/**
* @private
*
* This is an implementation detail of rb_fix2long(). People don't use it
* directly.
*
* @param[in] x A Fixnum.
* @return Identical value of type `long`
* @pre Must not pass anything other than a Fixnum.
*/
static inline long
rbimpl_fix2long_by_shift(VALUE x)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
/* :NOTE: VALUE can be wider than long. If right shift is arithmetic, this
* is noticeably faster than above. */
const SIGNED_VALUE y = x;
const SIGNED_VALUE z = y >> 1;
const long w = RBIMPL_CAST((long)z);
RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w));
return w;
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
/**
* @private
*
* This is an implementation detail of rb_fix2long(). People don't use it
* directly.
*
* @retval true This C compiler's right shift operator is arithmetic.
* @retval false This C compiler's right shift operator is logical.
*/
static inline bool
rbimpl_right_shift_is_arithmetic_p(void)
{
return (-1 >> 1) == -1;
}
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
/**
* Converts a Fixnum into C's `long`.
*
* @param[in] x Some Fixnum.
* @pre Must not pass anything other than a Fixnum.
* @return The passed value converted into C's `long`.
*/
static inline long
rb_fix2long(VALUE x)
{
if /* constexpr */ (rbimpl_right_shift_is_arithmetic_p()) {
return rbimpl_fix2long_by_shift(x);
}
else {
return rbimpl_fix2long_by_idiv(x);
}
}
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
/**
* Converts a Fixnum into C's `unsigned long`.
*
* @param[in] x Some Fixnum.
* @pre Must not pass anything other than a Fixnum.
* @return The passed value converted into C's `unsigned long`.
* @note Negative fixnums will be converted into large unsigned longs.
*/
static inline unsigned long
rb_fix2ulong(VALUE x)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
return rb_fix2long(x);
}
/**
* Converts an instance of ::rb_cNumeric into C's `long`.
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `long`.
* @return The passed value converted into C's `long`.
*/
static inline long
rb_num2long_inline(VALUE x)
{
if (RB_FIXNUM_P(x))
return RB_FIX2LONG(x);
else
return rb_num2long(x);
}
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned long`.
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `unsigned long`.
* @return The passed value converted into C's `unsigned long`.
*
* @internal
*
* This (negative fixnum would become a large unsigned long while negative
* bignum is an exception) has been THE behaviour of NUM2ULONG since the
* beginning. It is strange, but we can no longer change how it works at this
* moment. We have to get by with it.
*
* @see https://bugs.ruby-lang.org/issues/9089
*/
static inline unsigned long
rb_num2ulong_inline(VALUE x)
{
if (RB_FIXNUM_P(x))
return RB_FIX2ULONG(x);
else
return rb_num2ulong(x);
}
/**
* Converts a C's `long` into an instance of ::rb_cInteger.
*
* @param[in] v Arbitrary `long` value.
* @return An instance of ::rb_cInteger.
*/
static inline VALUE
rb_long2num_inline(long v)
{
if (RB_FIXABLE(v))
return RB_LONG2FIX(v);
else
return rb_int2big(v);
}
/**
* Converts a C's `unsigned long` into an instance of ::rb_cInteger.
*
* @param[in] v Arbitrary `unsigned long` value.
* @return An instance of ::rb_cInteger.
*/
static inline VALUE
rb_ulong2num_inline(unsigned long v)
{
if (RB_POSFIXABLE(v))
return RB_LONG2FIX(v);
else
return rb_uint2big(v);
}
/**
* @cond INTERNAL_MACRO
*
* Following overload is necessary because sometimes INT2FIX is used as a enum
* value (e.g. `enum { FOO = INT2FIX(0) };`). THIS IS NG in theory because a
* VALUE does not fit into an enum (which must be a signed int). But we cannot
* break existing codes.
*/
#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14
# /* C++ can write constexpr as enum values. */
#elif ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
# undef INT2FIX
# define INT2FIX(i) (RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG)
#else
# undef INT2FIX
# define INT2FIX(i) \
__builtin_choose_expr( \
__builtin_constant_p(i), \
RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG, \
RB_INT2FIX(i))
#endif
/** @endcond */
#endif /* RBIMPL_ARITHMETIC_LONG_H */

View File

@@ -0,0 +1,135 @@
#ifndef RBIMPL_ARITHMETIC_LONG_LONG_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_LONG_LONG_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `long long` and Ruby's.
*/
#include "ruby/internal/value.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h"
#include "ruby/backward/2/long_long.h"
#define RB_LL2NUM rb_ll2num_inline /**< @alias{rb_ll2num_inline} */
#define RB_ULL2NUM rb_ull2num_inline /**< @alias{rb_ull2num_inline} */
#define LL2NUM RB_LL2NUM /**< @old{RB_LL2NUM} */
#define ULL2NUM RB_ULL2NUM /**< @old{RB_ULL2NUM} */
#define RB_NUM2LL rb_num2ll_inline /**< @alias{rb_num2ll_inline} */
#define RB_NUM2ULL rb_num2ull_inline /**< @alias{rb_num2ull_inline} */
#define NUM2LL RB_NUM2LL /**< @old{RB_NUM2LL} */
#define NUM2ULL RB_NUM2ULL /**< @old{RB_NUM2ULL} */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Converts a C's `long long` into an instance of ::rb_cInteger.
*
* @param[in] num Arbitrary `long long` value.
* @return An instance of ::rb_cInteger.
*/
VALUE rb_ll2inum(LONG_LONG num);
/**
* Converts a C's `unsigned long long` into an instance of ::rb_cInteger.
*
* @param[in] num Arbitrary `unsigned long long` value.
* @return An instance of ::rb_cInteger.
*/
VALUE rb_ull2inum(unsigned LONG_LONG num);
/**
* Converts an instance of ::rb_cNumeric into C's `long long`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `long long`.
* @return The passed value converted into C's `long long`.
*/
LONG_LONG rb_num2ll(VALUE num);
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned long long`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `unsigned long long`.
* @return The passed value converted into C's `unsigned long long`.
*/
unsigned LONG_LONG rb_num2ull(VALUE num);
RBIMPL_SYMBOL_EXPORT_END()
/**
* Converts a C's `long long` into an instance of ::rb_cInteger.
*
* @param[in] n Arbitrary `long long` value.
* @return An instance of ::rb_cInteger
*/
static inline VALUE
rb_ll2num_inline(LONG_LONG n)
{
if (FIXABLE(n)) return LONG2FIX((long)n);
return rb_ll2inum(n);
}
/**
* Converts a C's `unsigned long long` into an instance of ::rb_cInteger.
*
* @param[in] n Arbitrary `unsigned long long` value.
* @return An instance of ::rb_cInteger
*/
static inline VALUE
rb_ull2num_inline(unsigned LONG_LONG n)
{
if (POSFIXABLE(n)) return LONG2FIX((long)n);
return rb_ull2inum(n);
}
/**
* Converts an instance of ::rb_cNumeric into C's `long long`.
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `long long`.
* @return The passed value converted into C's `long long`.
*/
static inline LONG_LONG
rb_num2ll_inline(VALUE x)
{
if (RB_FIXNUM_P(x))
return RB_FIX2LONG(x);
else
return rb_num2ll(x);
}
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned long long`.
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `unsigned long long`.
* @return The passed value converted into C's `unsigned long long`.
*/
static inline unsigned LONG_LONG
rb_num2ull_inline(VALUE x)
{
if (RB_FIXNUM_P(x))
return RB_FIX2LONG(x);
else
return rb_num2ull(x);
}
#endif /* RBIMPL_ARITHMETIC_LONG_LONG_H */

View File

@@ -0,0 +1,41 @@
#ifndef RBIMPL_ARITHMETIC_MODE_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_MODE_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `mode_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/int.h"
/** Converts a C's `mode_t` into an instance of ::rb_cInteger. */
#ifndef NUM2MODET
# define NUM2MODET RB_NUM2INT
#endif
/** Converts an instance of ::rb_cNumeric into C's `mode_t`. */
#ifndef MODET2NUM
# define MODET2NUM RB_INT2NUM
#endif
/** A rb_sprintf() format prefix to be used for a `mode_t` parameter. */
#ifndef PRI_MODET_PREFIX
# define PRI_MODET_PREFIX PRI_INT_PREFIX
#endif
#endif /* RBIMPL_ARITHMETIC_MODE_T_H */

View File

@@ -0,0 +1,62 @@
#ifndef RBIMPL_ARITHMETIC_OFF_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_OFF_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `off_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/int.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/arithmetic/long_long.h"
#include "ruby/backward/2/long_long.h"
/** Converts a C's `off_t` into an instance of ::rb_cInteger. */
#ifdef OFFT2NUM
# /* take that. */
#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
# define OFFT2NUM RB_LL2NUM
#elif SIZEOF_OFF_T == SIZEOF_LONG
# define OFFT2NUM RB_LONG2NUM
#else
# define OFFT2NUM RB_INT2NUM
#endif
/** Converts an instance of ::rb_cNumeric into C's `off_t`. */
#ifdef NUM2OFFT
# /* take that. */
#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
# define NUM2OFFT RB_NUM2LL
#elif SIZEOF_OFF_T == SIZEOF_LONG
# define NUM2OFFT RB_NUM2LONG
#else
# define NUM2OFFT RB_NUM2INT
#endif
/** A rb_sprintf() format prefix to be used for an `off_t` parameter. */
#ifdef PRI_OFFT_PREFIX
# /* take that. */
#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
# define PRI_OFFT_PREFIX PRI_LL_PREFIX
#elif SIZEOF_OFF_T == SIZEOF_LONG
# define PRI_OFFT_PREFIX PRI_LONG_PREFIX
#else
# define PRI_OFFT_PREFIX PRI_INT_PREFIX
#endif
#endif /* RBIMPL_ARITHMETIC_OFF_T_H */

View File

@@ -0,0 +1,41 @@
#ifndef RBIMPL_ARITHMETIC_PID_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_PID_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `pid_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/long.h"
/** Converts a C's `pid_t` into an instance of ::rb_cInteger. */
#ifndef PIDT2NUM
# define PIDT2NUM RB_LONG2NUM
#endif
/** Converts an instance of ::rb_cNumeric into C's `pid_t`. */
#ifndef NUM2PIDT
# define NUM2PIDT RB_NUM2LONG
#endif
/** A rb_sprintf() format prefix to be used for a `pid_t` parameter. */
#ifndef PRI_PIDT_PREFIX
# define PRI_PIDT_PREFIX PRI_LONG_PREFIX
#endif
#endif /* RBIMPL_ARITHMETIC_PID_T_H */

View File

@@ -0,0 +1,113 @@
#ifndef RBIMPL_ARITHMETIC_SHORT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_SHORT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `short` and Ruby's.
*
* Shyouhei wonders: why there is no SHORT2NUM, given there are both
* #USHORT2NUM and #CHR2FIX?
*/
#include "ruby/internal/value.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h"
#define RB_NUM2SHORT rb_num2short_inline /**< @alias{rb_num2short_inline} */
#define RB_NUM2USHORT rb_num2ushort /**< @alias{rb_num2ushort} */
#define NUM2SHORT RB_NUM2SHORT /**< @old{RB_NUM2SHORT} */
#define NUM2USHORT RB_NUM2USHORT /**< @old{RB_NUM2USHORT} */
#define USHORT2NUM RB_INT2FIX /**< @old{RB_INT2FIX} */
#define RB_FIX2SHORT rb_fix2short /**< @alias{rb_fix2ushort} */
#define FIX2SHORT RB_FIX2SHORT /**< @old{RB_FIX2SHORT} */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Converts an instance of ::rb_cNumeric into C's `short`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `short`.
* @return The passed value converted into C's `short`.
*/
short rb_num2short(VALUE num);
/**
* Converts an instance of ::rb_cNumeric into C's `unsigned short`.
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `unsigned short`.
* @return The passed value converted into C's `unsigned short`.
*/
unsigned short rb_num2ushort(VALUE num);
/**
* Identical to rb_num2short().
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `short`.
* @return The passed value converted into C's `short`.
*
* @internal
*
* This function seems to be a complete waste of disk space. @shyouhei has no
* idea why this is a different thing from rb_num2short().
*/
short rb_fix2short(VALUE num);
/**
* Identical to rb_num2ushort().
*
* @param[in] num Something numeric.
* @exception rb_eTypeError `num` is not a numeric.
* @exception rb_eRangeError `num` is out of range of `unsigned short`.
* @return The passed value converted into C's `unsigned short`.
*
* @internal
*
* This function seems to be a complete waste of disk space. @shyouhei has no
* idea why this is a different thing from rb_num2ushort().
*/
unsigned short rb_fix2ushort(VALUE num);
RBIMPL_SYMBOL_EXPORT_END()
/**
* Identical to rb_num2short().
*
* @param[in] x Something numeric.
* @exception rb_eTypeError `x` is not a numeric.
* @exception rb_eRangeError `x` is out of range of `short`.
* @return The passed value converted into C's `short`.
*
* @internal
*
* This function seems to be a complete waste of time. @shyouhei has no idea
* why this is a different thing from rb_num2short().
*/
static inline short
rb_num2short_inline(VALUE x)
{
if (RB_FIXNUM_P(x))
return rb_fix2short(x);
else
return rb_num2short(x);
}
#endif /* RBIMPL_ARITHMETIC_SHORT_H */

View File

@@ -0,0 +1,66 @@
#ifndef RBIMPL_ARITHMETIC_SIZE_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_SIZE_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `size_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/int.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/arithmetic/long_long.h"
#include "ruby/backward/2/long_long.h"
#if defined(__DOXYGEN__)
# /** Converts a C's `size_t` into an instance of ::rb_cInteger. */
# define RB_SIZE2NUM RB_ULONG2NUM
# /** Converts a C's `ssize_t` into an instance of ::rb_cInteger. */
# define RB_SSIZE2NUM RB_LONG2NUM
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
# define RB_SIZE2NUM RB_ULL2NUM
# define RB_SSIZE2NUM RB_LL2NUM
#elif SIZEOF_SIZE_T == SIZEOF_LONG
# define RB_SIZE2NUM RB_ULONG2NUM
# define RB_SSIZE2NUM RB_LONG2NUM
#else
# define RB_SIZE2NUM RB_UINT2NUM
# define RB_SSIZE2NUM RB_INT2NUM
#endif
#if defined(__DOXYGEN__)
# /** Converts an instance of ::rb_cInteger into C's `size_t`. */
# define RB_NUM2SIZE RB_NUM2ULONG
# /** Converts an instance of ::rb_cInteger into C's `ssize_t`. */
# define RB_NUM2SSIZE RB_NUM2LONG
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
# define RB_NUM2SIZE RB_NUM2ULL
# define RB_NUM2SSIZE RB_NUM2LL
#elif SIZEOF_SIZE_T == SIZEOF_LONG
# define RB_NUM2SIZE RB_NUM2ULONG
# define RB_NUM2SSIZE RB_NUM2LONG
#else
# define RB_NUM2SIZE RB_NUM2UINT
# define RB_NUM2SSIZE RB_NUM2INT
#endif
#define NUM2SIZET RB_NUM2SIZE /**< @old{RB_NUM2SIZE} */
#define SIZET2NUM RB_SIZE2NUM /**< @old{RB_SIZE2NUM} */
#define NUM2SSIZET RB_NUM2SSIZE /**< @old{RB_NUM2SSIZE} */
#define SSIZET2NUM RB_SSIZE2NUM /**< @old{RB_SSIZE2NUM} */
#endif /* RBIMPL_ARITHMETIC_SIZE_T_H */

View File

@@ -0,0 +1,75 @@
#ifndef RBIMPL_ARITHMERIC_ST_DATA_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMERIC_ST_DATA_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `st_data_t` and Ruby's.
*/
#include "ruby/internal/arithmetic/fixnum.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/value.h"
#include "ruby/assert.h"
#include "ruby/st.h"
#define ST2FIX RB_ST2FIX /**< @old{RB_ST2FIX} */
/** @cond INTERNAL_MACRO */
#define RB_ST2FIX RB_ST2FIX
/** @endcond */
RBIMPL_ATTR_CONST_UNLESS_DEBUG()
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Converts a C's `st_data_t` into an instance of ::rb_cInteger.
*
* @param[in] i The data in question.
* @return A converted result
* @warning THIS CONVERSION LOSES DATA! Be warned.
* @see https://bugs.ruby-lang.org/issues/13877
* @see https://bugs.ruby-lang.org/issues/14218
*
* @internal
*
* This is needed because of hash functions. Hash functions return
* `st_data_t`, which could theoretically be bigger than Fixnums. However
* allocating Bignums for them every time we calculate hash values is just too
* heavy. To avoid penalty we need to ignore some upper bit(s) and stick to
* Fixnums. This function is used for that purpose.
*/
static inline VALUE
RB_ST2FIX(st_data_t i)
{
SIGNED_VALUE x = i;
if (x >= 0) {
x &= RUBY_FIXNUM_MAX;
}
else {
x |= RUBY_FIXNUM_MIN;
}
RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(x));
unsigned long y = RBIMPL_CAST((unsigned long)x);
return RB_LONG2FIX(y);
}
#endif /* RBIMPL_ARITHMETIC_ST_DATA_T_H */

View File

@@ -0,0 +1,41 @@
#ifndef RBIMPL_ARITHMETIC_UID_T_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ARITHMETIC_UID_T_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Arithmetic conversion between C's `uid_t` and Ruby's.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/long.h"
/** Converts a C's `uid_t` into an instance of ::rb_cInteger. */
#ifndef UIDT2NUM
# define UIDT2NUM RB_LONG2NUM
#endif
/** Converts an instance of ::rb_cNumeric into C's `uid_t`. */
#ifndef NUM2UIDT
# define NUM2UIDT RB_NUM2LONG
#endif
/** A rb_sprintf() format prefix to be used for a `uid_t` parameter. */
#ifndef PRI_UIDT_PREFIX
# define PRI_UIDT_PREFIX PRI_LONG_PREFIX
#endif
#endif /* RBIMPL_ARITHMETIC_UID_T_H */

87
libs/libruby/ruby/internal/assume.h vendored Normal file
View File

@@ -0,0 +1,87 @@
#ifndef RBIMPL_ASSUME_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ASSUME_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ASSUME / #RBIMPL_UNREACHABLE.
*
* These macros must be defined at once because:
*
* - #RBIMPL_ASSUME could fallback to #RBIMPL_UNREACHABLE.
* - #RBIMPL_UNREACHABLE could fallback to #RBIMPL_ASSUME.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/builtin.h"
#include "ruby/internal/warning_push.h"
/** @cond INTERNAL_MACRO */
#if defined(HAVE___ASSUME)
# define RBIMPL_HAVE___ASSUME
#endif
/** @endcond */
/** Wraps (or simulates) `__builtin_unreachable`. */
#if RBIMPL_HAS_BUILTIN(__builtin_unreachable)
# define RBIMPL_UNREACHABLE_RETURN(_) __builtin_unreachable()
#elif defined(RBIMPL_HAVE___ASSUME)
# define RBIMPL_UNREACHABLE_RETURN(_) return (__assume(0), (_))
#else
# define RBIMPL_UNREACHABLE_RETURN(_) return (_)
#endif
/** Wraps (or simulates) `__builtin_unreachable`. */
#if RBIMPL_HAS_BUILTIN(__builtin_unreachable)
# define RBIMPL_UNREACHABLE __builtin_unreachable
#elif defined(RBIMPL_HAVE___ASSUME)
# define RBIMPL_UNREACHABLE() __assume(0)
#endif
/** Wraps (or simulates) `__assume`. */
#if RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0)
# /* icc warnings are false positives. Ignore them. */
# /* "warning #2261: __assume expression with side effects discarded" */
# define RBIMPL_ASSUME(expr) \
RBIMPL_WARNING_PUSH() \
RBIMPL_WARNING_IGNORED(2261) \
__assume(expr) \
RBIMPL_WARNING_POP()
#elif defined(RBIMPL_HAVE___ASSUME)
# define RBIMPL_ASSUME __assume
#elif RBIMPL_HAS_BUILTIN(__builtin_assume)
# define RBIMPL_ASSUME __builtin_assume
#elif ! defined(RBIMPL_UNREACHABLE)
# define RBIMPL_ASSUME(_) RBIMPL_CAST((void)(_))
#else
# define RBIMPL_ASSUME(_) \
(RB_LIKELY(!!(_)) ? RBIMPL_CAST((void)0) : RBIMPL_UNREACHABLE())
#endif
#if ! defined(RBIMPL_UNREACHABLE)
# define RBIMPL_UNREACHABLE() RBIMPL_ASSUME(0)
#endif
#endif /* RBIMPL_ASSUME_H */

View File

@@ -0,0 +1,32 @@
#ifndef RBIMPL_ATTR_ALLOC_SIZE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_ALLOC_SIZE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_ALLOC_SIZE.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((alloc_size))` */
#if RBIMPL_HAS_ATTRIBUTE(alloc_size)
# define RBIMPL_ATTR_ALLOC_SIZE(tuple) __attribute__((__alloc_size__ tuple))
#else
# define RBIMPL_ATTR_ALLOC_SIZE(tuple) /* void */
#endif
#endif /* RBIMPL_ATTR_ALLOC_SIZE_H */

View File

@@ -0,0 +1,46 @@
#ifndef RBIMPL_ATTR_ARTIFICIAL_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_ARTIFICIAL_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_ARTIFICIAL.
*
* ### Q&A ###
*
* - Q: What is this attribute? I don't get what GCC manual is talking about.
*
* - A: In short it is an attribute to manipulate GDB backtraces. The
* attribute makes the best sense when it comes with
* __attribute__((always_inline)). When a function annotated with this
* attribute gets inlined, and when you somehow look at a backtrace which
* includes such inlined call site, then the backtrace shows the caller
* and not the callee. This is handy for instance when an identical
* function is inlined more than once in a single big function. On such
* case it gets vital to know where the inlining happened in the callee.
* See also https://stackoverflow.com/a/21936099
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((artificial))` */
#if RBIMPL_HAS_ATTRIBUTE(artificial)
# define RBIMPL_ATTR_ARTIFICIAL() __attribute__((__artificial__))
#else
# define RBIMPL_ATTR_ARTIFICIAL() /* void */
#endif
#endif /* RBIMPL_ATTR_ARTIFICIAL_H */

37
libs/libruby/ruby/internal/attr/cold.h vendored Normal file
View File

@@ -0,0 +1,37 @@
#ifndef RBIMPL_ATTR_COLD_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_COLD_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_COLD.
*/
#include "ruby/internal/compiler_is.h"
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((cold))` */
#if RBIMPL_COMPILER_IS(SunPro)
# /* Recent SunPro has __has_attribute, and is broken. */
# /* It reports it has attribute cold, reality isn't (warnings issued). */
# define RBIMPL_ATTR_COLD() /* void */
#elif RBIMPL_HAS_ATTRIBUTE(cold)
# define RBIMPL_ATTR_COLD() __attribute__((__cold__))
#else
# define RBIMPL_ATTR_COLD() /* void */
#endif
#endif /* RBIMPL_ATTR_COLD_H */

46
libs/libruby/ruby/internal/attr/const.h vendored Normal file
View File

@@ -0,0 +1,46 @@
#ifndef RBIMPL_ATTR_CONST_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_CONST_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_CONST.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/has/declspec_attribute.h"
/** Wraps (or simulates) `__attribute__((const))` */
#if RBIMPL_HAS_ATTRIBUTE(const)
# define RBIMPL_ATTR_CONST() __attribute__((__const__))
#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias)
# /* If a function can be a const, that is also a noalias. */
# define RBIMPL_ATTR_CONST() __declspec(noalias)
#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
# define RBIMPL_ATTR_CONST() _Pragma("no_side_effect")
#else
# define RBIMPL_ATTR_CONST() /* void */
#endif
/** Enables #RBIMPL_ATTR_CONST if and only if. ! #RUBY_DEBUG. */
#if !defined(RUBY_DEBUG) || !RUBY_DEBUG
# define RBIMPL_ATTR_CONST_UNLESS_DEBUG() RBIMPL_ATTR_CONST()
#else
# define RBIMPL_ATTR_CONST_UNLESS_DEBUG() /* void */
#endif
#endif /* RBIMPL_ATTR_CONST_H */

View File

@@ -0,0 +1,84 @@
#ifndef RBIMPL_ATTR_CONSTEXPR_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_CONSTEXPR_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief #RBIMPL_ATTR_CONSTEXPR.
*/
#include "ruby/internal/has/feature.h"
#include "ruby/internal/compiler_is.h"
/** @cond INTERNAL_MACRO */
#if ! defined(__cplusplus)
# /* Makes no sense. */
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0
#elif defined(__cpp_constexpr)
# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L)
#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 00)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 00)
#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 13, 0)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L)
#elif RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L)
#elif RBIMPL_HAS_FEATURE(cxx_relaxed_constexpr)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 1
#elif RBIMPL_HAS_FEATURE(cxx_constexpr)
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0
#else
# /* :FIXME: icpc must have constexpr but don't know how to detect. */
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0
# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0
#endif
/** @endcond */
/** Wraps (or simulates) C++11 `constexpr`. */
#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14
# define RBIMPL_ATTR_CONSTEXPR(_) constexpr
#elif RBIMPL_HAS_ATTR_CONSTEXPR_CXX11
# define RBIMPL_ATTR_CONSTEXPR(_) RBIMPL_ATTR_CONSTEXPR_ ## _
# define RBIMPL_ATTR_CONSTEXPR_CXX11 constexpr
# define RBIMPL_ATTR_CONSTEXPR_CXX14 /* void */
#else
# define RBIMPL_ATTR_CONSTEXPR(_) /* void */
#endif
/** Enables #RBIMPL_ATTR_CONSTEXPR if and only if. ! #RUBY_DEBUG. */
#if !RUBY_DEBUG
# define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_) RBIMPL_ATTR_CONSTEXPR(_)
#else
# define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_) /* void */
#endif
#endif /* RBIMPL_ATTR_CONSTEXPR_H */

View File

@@ -0,0 +1,75 @@
#ifndef RBIMPL_ATTR_DEPRECATED_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_DEPRECATED_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_DEPRECATED.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/has/c_attribute.h"
#include "ruby/internal/has/cpp_attribute.h"
#include "ruby/internal/has/declspec_attribute.h"
#include "ruby/internal/has/extension.h"
/** Wraps (or simulates) `[[deprecated]]` */
#if defined(__COVERITY__)
/* Coverity Scan emulates gcc but seems not to support this attribute correctly */
# define RBIMPL_ATTR_DEPRECATED(msg)
#elif RBIMPL_HAS_EXTENSION(attribute_deprecated_with_message)
# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
#elif defined(__cplusplus) && RBIMPL_COMPILER_SINCE(GCC, 10, 1, 0) && RBIMPL_COMPILER_BEFORE(GCC, 10, 3, 0)
# /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95302 */
# define RBIMPL_ATTR_DEPRECATED(msg) /* disable until they fix this bug */
#elif RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0)
# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0)
# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
#elif RBIMPL_HAS_ATTRIBUTE(deprecated) /* but not with message. */
# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__))
#elif RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0)
# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated msg)
#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(deprecated)
# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated)
#elif RBIMPL_HAS_CPP_ATTRIBUTE(deprecated)
# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]]
#elif RBIMPL_HAS_C_ATTRIBUTE(deprecated)
# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]]
#else
# define RBIMPL_ATTR_DEPRECATED(msg) /* void */
#endif
/** This is when a function is used internally (for backwards compatibility
* etc.), but extension libraries must consider it deprecated. */
#if defined(RUBY_EXPORT)
# define RBIMPL_ATTR_DEPRECATED_EXT(msg) /* void */
#else
# define RBIMPL_ATTR_DEPRECATED_EXT(msg) RBIMPL_ATTR_DEPRECATED(msg)
#endif
#endif /* RBIMPL_ATTR_DEPRECATED_H */

View File

@@ -0,0 +1,42 @@
#ifndef RBIMPL_ATTR_DIAGNOSE_IF_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_DIAGNOSE_IF_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_DIAGNOSE_IF.
*/
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/warning_push.h"
/** Wraps (or simulates) `__attribute__((diagnose_if))` */
#if RBIMPL_COMPILER_BEFORE(Clang, 5, 0, 0)
# /* https://bugs.llvm.org/show_bug.cgi?id=34319 */
# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */
#elif RBIMPL_HAS_ATTRIBUTE(diagnose_if)
# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) \
RBIMPL_WARNING_PUSH() \
RBIMPL_WARNING_IGNORED(-Wgcc-compat) \
__attribute__((__diagnose_if__(_, __, ___))) \
RBIMPL_WARNING_POP()
#else
# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */
#endif
#endif /* RBIMPL_ATTR_DIAGNOSE_IF_H */

View File

@@ -0,0 +1,32 @@
#ifndef RBIMPL_ATTR_ENUM_EXTENSIBILITY_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_ENUM_EXTENSIBILITY_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief #RBIMPL_ATTR_ENUM_EXTENSIBILITY.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((enum_extensibility))` */
#if RBIMPL_HAS_ATTRIBUTE(enum_extensibility)
# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) __attribute__((__enum_extensibility__(_)))
#else
# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) /* void */
#endif
#endif /* RBIMPL_ATTR_ENUM_EXTENSIBILITY_H */

32
libs/libruby/ruby/internal/attr/error.h vendored Normal file
View File

@@ -0,0 +1,32 @@
#ifndef RBIMPL_ATTR_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_ERROR_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_ERROR.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((error))` */
#if RBIMPL_HAS_ATTRIBUTE(error)
# define RBIMPL_ATTR_ERROR(msg) __attribute__((__error__ msg))
#else
# define RBIMPL_ATTR_ERROR(msg) /* void */
#endif
#endif /* RBIMPL_ATTR_ERROR_H */

View File

@@ -0,0 +1,33 @@
#ifndef RBIMPL_ATTR_FLAG_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_FLAG_ENUM_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_FLAG_ENUM.
* @see https://clang.llvm.org/docs/AttributeReference.html#flag_enum
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((flag_enum)` */
#if RBIMPL_HAS_ATTRIBUTE(flag_enum)
# define RBIMPL_ATTR_FLAG_ENUM() __attribute__((__flag_enum__))
#else
# define RBIMPL_ATTR_FLAG_ENUM() /* void */
#endif
#endif /* RBIMPLATTR_FLAG_ENUM_H */

View File

@@ -0,0 +1,40 @@
#ifndef RBIMPL_ATTR_FORCEINLINE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_FORCEINLINE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_FORCEINLINE.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/attribute.h"
/**
* Wraps (or simulates) `__forceinline`. MSVC complains on declarations like
* `static inline __forceinline void foo()`. It seems MSVC's `inline` and
* `__forceinline` are mutually exclusive. We have to mimic that behaviour for
* non-MSVC compilers.
*/
#if RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0)
# define RBIMPL_ATTR_FORCEINLINE() __forceinline
#elif RBIMPL_HAS_ATTRIBUTE(always_inline)
# define RBIMPL_ATTR_FORCEINLINE() __attribute__((__always_inline__)) inline
#else
# define RBIMPL_ATTR_FORCEINLINE() inline
#endif
#endif /* RBIMPL_ATTR_FORCEINLINE_H */

View File

@@ -0,0 +1,38 @@
#ifndef RBIMPL_ATTR_FORMAT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_FORMAT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_FORMAT.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((format))` */
#if RBIMPL_HAS_ATTRIBUTE(format)
# define RBIMPL_ATTR_FORMAT(x, y, z) __attribute__((__format__(x, y, z)))
#else
# define RBIMPL_ATTR_FORMAT(x, y, z) /* void */
#endif
#if defined(__MINGW_PRINTF_FORMAT)
# define RBIMPL_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
#else
# define RBIMPL_PRINTF_FORMAT __printf__
#endif
#endif /* RBIMPL_ATTR_FORMAT_H */

View File

@@ -0,0 +1,38 @@
#ifndef RBIMPL_ATTR_MAYBE_UNUSED_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_MAYBE_UNUSED_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_MAYBE_UNUSED.
*/
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/has/c_attribute.h"
#include "ruby/internal/has/cpp_attribute.h"
/** Wraps (or simulates) `[[maybe_unused]]` */
#if RBIMPL_HAS_CPP_ATTRIBUTE(maybe_unused)
# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]]
#elif RBIMPL_HAS_C_ATTRIBUTE(maybe_unused)
# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]]
#elif RBIMPL_HAS_ATTRIBUTE(unused)
# define RBIMPL_ATTR_MAYBE_UNUSED() __attribute__((__unused__))
#else
# define RBIMPL_ATTR_MAYBE_UNUSED() /* void */
#endif
#endif /* RBIMPL_ATTR_MAYBE_UNUSED */

View File

@@ -0,0 +1,69 @@
#ifndef RBIMPL_ATTR_NOALIAS_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NOALIAS_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NOALIAS.
*
* ### Q&A ###
*
* - Q: There are seemingly similar attributes named #RBIMPL_ATTR_CONST,
* #RBIMPL_ATTR_PURE, and #RBIMPL_ATTR_NOALIAS. What are the difference?
*
* - A: Allowed operations are different.
*
* - #RBIMPL_ATTR_CONST ... Functions attributed by this are not allowed to
* read/write _any_ pointers at all (there are exceptional situations
* when reading a pointer is possible but forget that; they are too
* exceptional to be useful). Just remember that everything pointer-
* related are NG.
*
* - #RBIMPL_ATTR_PURE ... Functions attributed by this can read any
* nonvolatile pointers, but no writes are allowed at all. The ability
* to read _any_ nonvolatile pointers makes it possible to mark ::VALUE-
* taking functions as being pure, as long as they are read-only.
*
* - #RBIMPL_ATTR_NOALIAS ... Can both read/write, but only through
* pointers passed to the function as parameters. This is a typical
* situation when you create a C++ non-static member function which only
* concerns `this`. No global variables are allowed to read/write. So
* this is not a super-set of being pure. If you want to read something,
* that has to be passed to the function as a pointer. ::VALUE -taking
* functions thus cannot be attributed as such.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/declspec_attribute.h"
/** Wraps (or simulates) `__declspec((noalias))` */
#if RBIMPL_COMPILER_BEFORE(Clang, 12, 0, 0)
# /*
# * `::llvm::Attribute::ArgMemOnly` was buggy before. Maybe because nobody
# * actually seriously used it. It seems they somehow mitigated the situation
# * in LLVM 12. Still not found the exact changeset which fiexed the
# * attribute, though.
# *
# * :FIXME: others (armclang, xlclang, ...) can also be affected?
# */
# define RBIMPL_ATTR_NOALIAS() /* void */
#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias)
# define RBIMPL_ATTR_NOALIAS() __declspec(noalias)
#else
# define RBIMPL_ATTR_NOALIAS() /* void */
#endif
#endif /* RBIMPL_ATTR_NOALIAS_H */

View File

@@ -0,0 +1,45 @@
#ifndef RBIMPL_ATTR_NODISCARD_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NODISCARD_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NODISCARD.
*/
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/has/c_attribute.h"
#include "ruby/internal/has/cpp_attribute.h"
/**
* Wraps (or simulates) `[[nodiscard]]`. In C++ (at least since C++20) a
* nodiscard attribute can have a message why the result shall not be ignored.
* However GCC attribute and SAL annotation cannot take them.
*/
#if RBIMPL_HAS_CPP_ATTRIBUTE(nodiscard)
# define RBIMPL_ATTR_NODISCARD() [[nodiscard]]
#elif RBIMPL_HAS_C_ATTRIBUTE(nodiscard)
# define RBIMPL_ATTR_NODISCARD() [[nodiscard]]
#elif RBIMPL_HAS_ATTRIBUTE(warn_unused_result)
# define RBIMPL_ATTR_NODISCARD() __attribute__((__warn_unused_result__))
#elif defined(_Check_return_)
# /* Take SAL definition. */
# define RBIMPL_ATTR_NODISCARD() _Check_return_
#else
# define RBIMPL_ATTR_NODISCARD() /* void */
#endif
#endif /* RBIMPL_ATTR_NODISCARD_H */

View File

@@ -0,0 +1,91 @@
#ifndef RBIMPL_ATTR_NOEXCEPT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NOEXCEPT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NOEXCEPT.
*
* This isn't actually an attribute in C++ but who cares...
*
* Mainly due to aesthetic reasons, this one is rarely used in the project.
* But can be handy on occasions, especially when a function's noexcept-ness
* depends on its calling functions.
*
* ### Q&A ###
*
* - Q: Can a function that raises Ruby exceptions be attributed `noexcept`?
*
* - A: Yes. `noexcept` is about C++ exceptions, not Ruby's. They don't
* interface each other. You can safely attribute a function that raises
* Ruby exceptions as `noexcept`.
*
* - Q: How, then, can I assert that a function I wrote doesn't raise any Ruby
* exceptions?
*
* - A: `__attribute__((__leaf__))` is for that purpose. A function attributed
* as leaf can still throw C++ exceptions, but not Ruby's. Note however,
* that it's extremely difficult -- if not impossible -- to assert that a
* function doesn't raise any Ruby exceptions at all. Use of that
* attribute is not recommended; mere mortals can't properly use that by
* hand.
*
* - Q: Does it make sense to attribute an inline function `noexcept`?
*
* - A: I thought so before. But no, I don't think they are useful any longer.
*
* - When an inline function attributed `noexcept` actually doesn't throw
* any exceptions at all: these days I don't see any difference in
* generated assembly by adding/removing this attribute. C++ compilers
* get smarter and smarter. Today they can infer if it actually throws
* or not without any annotations by humans (correct me if I'm wrong).
*
* - When an inline function attributed `noexcepr` actually _does_ throw an
* exception: they have to call `std::terminate` then (C++ standard
* mandates so). This means exception handling routines are actually
* enforced, not omitted. This doesn't impact runtime performance (The
* Itanium C++ ABI has zero-cost exception handling), but does impact on
* generated binary size. This is bad.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/feature.h"
/** Wraps (or simulates) C++11 `noexcept` */
#if ! defined(__cplusplus)
# /* Doesn't make sense. */
# define RBIMPL_ATTR_NOEXCEPT(_) /* void */
#elif RBIMPL_HAS_FEATURE(cxx_noexcept)
# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__
# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
#elif defined(__INTEL_CXX11_MODE__)
# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0)
# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
#elif __cplusplus >= 201103L
# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_))
#else
# define RBIMPL_ATTR_NOEXCEPT(_) /* void */
#endif
#endif /* RBIMPL_ATTR_NOEXCEPT_H */

View File

@@ -0,0 +1,35 @@
#ifndef RBIMPL_ATTR_NOINLINE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NOINLINE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NOINLINE.
*/
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/has/declspec_attribute.h"
/** Wraps (or simulates) `__declspec(noinline)` */
#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noinline)
# define RBIMPL_ATTR_NOINLINE() __declspec(noinline)
#elif RBIMPL_HAS_ATTRIBUTE(noinline)
# define RBIMPL_ATTR_NOINLINE() __attribute__((__noinline__))
#else
# define RBIMPL_ATTR_NOINLINE() /* void */
#endif
#endif /* RBIMPL_ATTR_NOINLINE_H */

View File

@@ -0,0 +1,34 @@
#ifndef RBIMPL_ATTR_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NONNULL_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NONNULL.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((nonnull))` */
#if RBIMPL_HAS_ATTRIBUTE(nonnull)
# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list))
# define RBIMPL_NONNULL_ARG(arg) RBIMPL_ASSERT_NOTHING
#else
# define RBIMPL_ATTR_NONNULL(list) /* void */
# define RBIMPL_NONNULL_ARG(arg) RUBY_ASSERT(arg)
#endif
#endif /* RBIMPL_ATTR_NONNULL_H */

View File

@@ -0,0 +1,48 @@
#ifndef RBIMPL_ATTR_NORETURN_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NORETURN_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NORETURN.
*/
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/has/cpp_attribute.h"
#include "ruby/internal/has/declspec_attribute.h"
/** Wraps (or simulates) `[[noreturn]]` */
#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn)
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
#elif RBIMPL_HAS_ATTRIBUTE(noreturn)
# define RBIMPL_ATTR_NORETURN() __attribute__((__noreturn__))
#elif RBIMPL_HAS_CPP_ATTRIBUTE(noreturn)
# define RBIMPL_ATTR_NORETURN() [[noreturn]]
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112)
# define RBIMPL_ATTR_NORETURN() _Noreturn
#elif defined(_Noreturn)
# /* glibc <sys/cdefs.h> has this macro. */
# define RBIMPL_ATTR_NORETURN() _Noreturn
#else
# define RBIMPL_ATTR_NORETURN() /* void */
#endif
#endif /* RBIMPL_ATTR_NORETURN_H */

43
libs/libruby/ruby/internal/attr/pure.h vendored Normal file
View File

@@ -0,0 +1,43 @@
#ifndef RBIMPL_ATTR_PURE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_PURE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_PURE.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/attribute.h"
#include "ruby/assert.h"
/** Wraps (or simulates) `__attribute__((pure))` */
#if RBIMPL_HAS_ATTRIBUTE(pure)
# define RBIMPL_ATTR_PURE() __attribute__((__pure__))
#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
# define RBIMPL_ATTR_PURE() _Pragma("does_not_write_global_data")
#else
# define RBIMPL_ATTR_PURE() /* void */
#endif
/** Enables #RBIMPL_ATTR_PURE if and only if. ! #RUBY_DEBUG. */
#if !RUBY_DEBUG
# define RBIMPL_ATTR_PURE_UNLESS_DEBUG() RBIMPL_ATTR_PURE()
#else
# define RBIMPL_ATTR_PURE_UNLESS_DEBUG() /* void */
#endif
#endif /* RBIMPL_ATTR_PURE_H */

View File

@@ -0,0 +1,44 @@
#ifndef RBIMPL_ATTR_RESTRICT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_RESTRICT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_RESTRICT.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/attribute.h"
/* :FIXME: config.h includes conflicting `#define restrict`. MSVC can be
* detected using `RBIMPL_COMPILER_SINCE()`, but Clang & family cannot use
* `__has_declspec_attribute()` which involves macro substitution. */
/** Wraps (or simulates) `__declspec(restrict)` */
#if RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0)
# define RBIMPL_ATTR_RESTRICT() __declspec(re ## strict)
#elif RBIMPL_HAS_ATTRIBUTE(malloc)
# define RBIMPL_ATTR_RESTRICT() __attribute__((__malloc__))
#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
# define RBIMPL_ATTR_RESTRICT() _Pragma("returns_new_memory")
#else
# define RBIMPL_ATTR_RESTRICT() /* void */
#endif
#endif /* RBIMPL_ATTR_RESTRICT_H */

View File

@@ -0,0 +1,37 @@
#ifndef RBIMPL_ATTR_RETURNS_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_RETURNS_NONNULL_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_RETURNS_NONNULL.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((returns_nonnull))` */
#if defined(_Ret_nonnull_)
# /* Take SAL definition. */
# define RBIMPL_ATTR_RETURNS_NONNULL() _Ret_nonnull_
#elif RBIMPL_HAS_ATTRIBUTE(returns_nonnull)
# define RBIMPL_ATTR_RETURNS_NONNULL() __attribute__((__returns_nonnull__))
#else
# define RBIMPL_ATTR_RETURNS_NONNULL() /* void */
#endif
#endif /* RBIMPL_ATTR_RETURNS_NONNULL_H */

View File

@@ -0,0 +1,32 @@
#ifndef RBIMPL_ATTR_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_WARNING_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_WARNING.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((warning))` */
#if RBIMPL_HAS_ATTRIBUTE(warning)
# define RBIMPL_ATTR_WARNING(msg) __attribute__((__warning__ msg))
#else
# define RBIMPL_ATTR_WARNING(msg) /* void */
#endif
#endif /* RBIMPL_ATTR_WARNING_H */

View File

@@ -0,0 +1,32 @@
#ifndef RBIMPL_ATTR_WEAKREF_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_WEAKREF_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_WEAKREF.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((weakref))` */
#if RBIMPL_HAS_ATTRIBUTE(weakref)
# define RBIMPL_ATTR_WEAKREF(sym) __attribute__((__weakref__(# sym)))
#else
# define RBIMPL_ATTR_WEAKREF(sym) /* void */
#endif
#endif /* RBIMPL_ATTR_WEAKREF_H */

50
libs/libruby/ruby/internal/cast.h vendored Normal file
View File

@@ -0,0 +1,50 @@
#ifndef RBIMPL_CAST_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_CAST_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_CAST.
*
* This casting macro makes sense only inside of other macros that are part of
* public headers. They could be used from C++, and C-style casts could issue
* warnings. Ruby internals are pure C so they should not bother.
*/
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/has/warning.h"
#include "ruby/internal/warning_push.h"
#if ! defined(__cplusplus)
# define RBIMPL_CAST(expr) (expr)
#elif RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0)
# /* g++ has -Wold-style-cast since 1997 or so, but its _Pragma is broken. */
# /* See https://gcc.godbolt.org/z/XWhU6J */
# define RBIMPL_CAST(expr) (expr)
# pragma GCC diagnostic ignored "-Wold-style-cast"
#elif RBIMPL_HAS_WARNING("-Wold-style-cast")
# define RBIMPL_CAST(expr) \
RBIMPL_WARNING_PUSH() \
RBIMPL_WARNING_IGNORED(-Wold-style-cast) \
(expr) \
RBIMPL_WARNING_POP()
#else
# define RBIMPL_CAST(expr) (expr)
#endif
#endif /* RBIMPL_CAST_H */

View File

@@ -0,0 +1,45 @@
#ifndef RBIMPL_COMPILER_IS_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_COMPILER_IS.
*/
/**
* @brief Checks if the compiler is of given brand.
* @param cc Compiler brand, like `MSVC`.
* @retval true It is.
* @retval false It isn't.
*/
#define RBIMPL_COMPILER_IS(cc) RBIMPL_COMPILER_IS_ ## cc
#include "ruby/internal/compiler_is/apple.h"
#include "ruby/internal/compiler_is/clang.h"
#include "ruby/internal/compiler_is/gcc.h"
#include "ruby/internal/compiler_is/intel.h"
#include "ruby/internal/compiler_is/msvc.h"
#include "ruby/internal/compiler_is/sunpro.h"
/* :TODO: Other possible compilers to support:
*
* - IBM XL: recent XL are clang-backended so some tweaks like we do for
* Apple's might be needed.
*
* - ARM's armclang: ditto, it can be clang-backended. */
#endif /* RBIMPL_COMPILER_IS_H */

View File

@@ -0,0 +1,40 @@
#ifndef RBIMPL_COMPILER_IS_APPLE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_APPLE_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_COMPILER_IS_Apple.
*
* Apple ships clang. Problem is, its `__clang_major__` etc. are not the
* upstream LLVM version, but XCode's. We have to think Apple's is distinct
* from LLVM's, when it comes to compiler detection business in this header
* file.
*/
#if ! defined(__clang__)
# define RBIMPL_COMPILER_IS_Apple 0
#elif ! defined(__apple_build_version__)
# define RBIMPL_COMPILER_IS_Apple 0
#else
# define RBIMPL_COMPILER_IS_Apple 1
# define RBIMPL_COMPILER_VERSION_MAJOR __clang_major__
# define RBIMPL_COMPILER_VERSION_MINOR __clang_minor__
# define RBIMPL_COMPILER_VERSION_PATCH __clang_patchlevel__
#endif
#endif /* RBIMPL_COMPILER_IS_APPLE_H */

View File

@@ -0,0 +1,37 @@
#ifndef RBIMPL_COMPILER_IS_CLANG_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_CLANG_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_COMPILER_IS_Clang.
*/
#include "ruby/internal/compiler_is/apple.h"
#if ! defined(__clang__)
# define RBIMPL_COMPILER_IS_Clang 0
#elif RBIMPL_COMPILER_IS(Apple)
# define RBIMPL_COMPILER_IS_Clang 0
#else
# define RBIMPL_COMPILER_IS_Clang 1
# define RBIMPL_COMPILER_VERSION_MAJOR __clang_major__
# define RBIMPL_COMPILER_VERSION_MINOR __clang_minor__
# define RBIMPL_COMPILER_VERSION_PATCH __clang_patchlevel__
#endif
#endif /* RBIMPL_COMPILER_IS_CLANG_H */

View File

@@ -0,0 +1,45 @@
#ifndef RBIMPL_COMPILER_IS_GCC_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_GCC_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_COMPILER_IS_GCC.
*/
#include "ruby/internal/compiler_is/apple.h"
#include "ruby/internal/compiler_is/clang.h"
#include "ruby/internal/compiler_is/intel.h"
#if ! defined(__GNUC__)
# define RBIMPL_COMPILER_IS_GCC 0
#elif RBIMPL_COMPILER_IS(Apple)
# define RBIMPL_COMPILER_IS_GCC 0
#elif RBIMPL_COMPILER_IS(Clang)
# define RBIMPL_COMPILER_IS_GCC 0
#elif RBIMPL_COMPILER_IS(Intel)
# define RBIMPL_COMPILER_IS_GCC 0
#else
# define RBIMPL_COMPILER_IS_GCC 1
# define RBIMPL_COMPILER_VERSION_MAJOR __GNUC__
# define RBIMPL_COMPILER_VERSION_MINOR __GNUC_MINOR__
# define RBIMPL_COMPILER_VERSION_PATCH __GNUC_PATCHLEVEL__
#endif
#endif /* RBIMPL_COMPILER_IS_GCC_H */

View File

@@ -0,0 +1,40 @@
#ifndef RBIMPL_COMPILER_IS_INTEL_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_INTEL_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_COMPILER_IS_Intel.
*/
#if ! defined(__INTEL_COMPILER)
# define RBIMPL_COMPILER_IS_Intel 0
#elif ! defined(__INTEL_COMPILER_UPDATE)
# define RBIMPL_COMPILER_IS_Intel 1
# /* __INTEL_COMPILER = XXYZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (__INTEL_COMPILER / 100)
# define RBIMPL_COMPILER_VERSION_MINOR (__INTEL_COMPILER % 100 / 10)
# define RBIMPL_COMPILER_VERSION_PATCH (__INTEL_COMPILER % 10)
#else
# define RBIMPL_COMPILER_IS_Intel 1
# /* __INTEL_COMPILER = XXYZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (__INTEL_COMPILER / 100)
# define RBIMPL_COMPILER_VERSION_MINOR (__INTEL_COMPILER % 100 / 10)
# define RBIMPL_COMPILER_VERSION_PATCH __INTEL_COMPILER_UPDATE
#endif
#endif /* RBIMPL_COMPILER_IS_INTEL_H */

View File

@@ -0,0 +1,56 @@
#ifndef RBIMPL_COMPILER_IS_MSVC_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_MSVC_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_COMPILER_IS_MSVC.
*/
#include "ruby/internal/compiler_is/clang.h"
#include "ruby/internal/compiler_is/intel.h"
#if ! defined(_MSC_VER)
# define RBIMPL_COMPILER_IS_MSVC 0
#elif RBIMPL_COMPILER_IS(Clang)
# define RBIMPL_COMPILER_IS_MSVC 0
#elif RBIMPL_COMPILER_IS(Intel)
# define RBIMPL_COMPILER_IS_MSVC 0
#elif _MSC_VER >= 1400
# define RBIMPL_COMPILER_IS_MSVC 1
# /* _MSC_FULL_VER = XXYYZZZZZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 10000000)
# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_FULL_VER % 10000000 / 100000)
# define RBIMPL_COMPILER_VERSION_PATCH (_MSC_FULL_VER % 100000)
#elif defined(_MSC_FULL_VER)
# define RBIMPL_COMPILER_IS_MSVC 1
# /* _MSC_FULL_VER = XXYYZZZZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 1000000)
# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_FULL_VER % 1000000 / 10000)
# define RBIMPL_COMPILER_VERSION_PATCH (_MSC_FULL_VER % 10000)
#else
# define RBIMPL_COMPILER_IS_MSVC 1
# /* _MSC_VER = XXYY */
# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_VER / 100)
# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_VER % 100)
# define RBIMPL_COMPILER_VERSION_PATCH 0
#endif
#endif /* RBIMPL_COMPILER_IS_MSVC_H */

View File

@@ -0,0 +1,54 @@
#ifndef RBIMPL_COMPILER_IS_SUNPRO_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_IS_SUNPRO_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines RBIMPL_COMPILER_IS_SunPro.
*/
#if ! (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
# define RBIMPL_COMPILER_IS_SunPro 0
#elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x5100
# define RBIMPL_COMPILER_IS_SunPro 1
# /* __SUNPRO_C = 0xXYYZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_C >> 12)
# define RBIMPL_COMPILER_VERSION_MINOR ((__SUNPRO_C >> 8 & 0xF) * 10 + (__SUNPRO_C >> 4 & 0xF))
# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_C & 0xF)
#elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5100
# define RBIMPL_COMPILER_IS_SunPro 1
# /* __SUNPRO_CC = 0xXYYZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_CC >> 12)
# define RBIMPL_COMPILER_VERSION_MINOR ((__SUNPRO_CC >> 8 & 0xF) * 10 + (__SUNPRO_CC >> 4 & 0xF))
# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_CC & 0xF)
#elif defined(__SUNPRO_C)
# define RBIMPL_COMPILER_IS_SunPro 1
# /* __SUNPRO_C = 0xXYZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_C >> 8)
# define RBIMPL_COMPILER_VERSION_MINOR (__SUNPRO_C >> 4 & 0xF)
# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_C & 0xF)
#else
# define RBIMPL_COMPILER_IS_SunPro 1
# /* __SUNPRO_CC = 0xXYZ */
# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_CC >> 8)
# define RBIMPL_COMPILER_VERSION_MINOR (__SUNPRO_CC >> 4 & 0xF)
# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_CC & 0xF)
#endif
#endif /* RBIMPL_COMPILER_IS_SUNPRO_H */

View File

@@ -0,0 +1,61 @@
#ifndef RBIMPL_COMPILER_SINCE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_COMPILER_SINCE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_COMPILER_SINCE.
*/
#include "ruby/internal/compiler_is.h"
/**
* @brief Checks if the compiler is of given brand and is newer than or equal
* to the passed version.
* @param cc Compiler brand, like `MSVC`.
* @param x Major version.
* @param y Minor version.
* @param z Patchlevel.
* @retval true cc >= x.y.z.
* @retval false otherwise.
*/
#define RBIMPL_COMPILER_SINCE(cc, x, y, z) \
(RBIMPL_COMPILER_IS(cc) && \
((RBIMPL_COMPILER_VERSION_MAJOR > (x)) || \
((RBIMPL_COMPILER_VERSION_MAJOR == (x)) && \
((RBIMPL_COMPILER_VERSION_MINOR > (y)) || \
((RBIMPL_COMPILER_VERSION_MINOR == (y)) && \
(RBIMPL_COMPILER_VERSION_PATCH >= (z)))))))
/**
* @brief Checks if the compiler is of given brand and is older than the
* passed version.
* @param cc Compiler brand, like `MSVC`.
* @param x Major version.
* @param y Minor version.
* @param z Patchlevel.
* @retval true cc < x.y.z.
* @retval false otherwise.
*/
#define RBIMPL_COMPILER_BEFORE(cc, x, y, z) \
(RBIMPL_COMPILER_IS(cc) && \
((RBIMPL_COMPILER_VERSION_MAJOR < (x)) || \
((RBIMPL_COMPILER_VERSION_MAJOR == (x)) && \
((RBIMPL_COMPILER_VERSION_MINOR < (y)) || \
((RBIMPL_COMPILER_VERSION_MINOR == (y)) && \
(RBIMPL_COMPILER_VERSION_PATCH < (z)))))))
#endif /* RBIMPL_COMPILER_SINCE_H */

155
libs/libruby/ruby/internal/config.h vendored Normal file
View File

@@ -0,0 +1,155 @@
#ifndef RBIMPL_CONFIG_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_CONFIG_H
/**
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Thin wrapper to ruby/config.h
*/
#include "ruby/config.h"
#ifdef RUBY_EXTCONF_H
#include RUBY_EXTCONF_H
#endif
#include "ruby/internal/compiler_since.h"
#undef HAVE_PROTOTYPES
#define HAVE_PROTOTYPES 1
#undef HAVE_STDARG_PROTOTYPES
#define HAVE_STDARG_PROTOTYPES 1
#undef TOKEN_PASTE
#define TOKEN_PASTE(x, y) x##y
#if defined(__cplusplus)
#/* __builtin_choose_expr and __builtin_types_compatible aren't available
# * on C++. See https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */
#undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P
#undef HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P
/* HAVE_VA_ARGS_MACRO is for C. C++ situations might be different. */
#undef HAVE_VA_ARGS_MACRO
#if __cplusplus >= 201103L
#define HAVE_VA_ARGS_MACRO
#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__
#define HAVE_VA_ARGS_MACRO
#elif defined(__INTEL_CXX11_MODE__)
#define HAVE_VA_ARGS_MACRO
#elif RBIMPL_COMPILER_SINCE(MSVC, 16, 0, 0)
#define HAVE_VA_ARGS_MACRO
#else
#/* NG, not known. */
#endif
#endif
#if RBIMPL_COMPILER_BEFORE(GCC, 4, 9, 0)
#/* See https://bugs.ruby-lang.org/issues/14221 */
#undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P
#endif
#if RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0)
#/* GCC 4.9.2 reportedly has this feature and is broken. The function is not
# * officially documented below. Seems we should not use it.
# * https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Other-Builtins.html */
#undef HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN
#endif
#if defined(__SUNPRO_CC)
#/* Oracle Developer Studio 12.5: GCC compatibility guide says it supports
# * statement expressions. But to our knowledge they support the extension
# * only for C and not for C++. Prove me wrong. Am happy to support them if
# * there is a way. */
#undef HAVE_STMT_AND_DECL_IN_EXPR
#endif
#ifndef STRINGIZE0
#define STRINGIZE(expr) STRINGIZE0(expr)
#define STRINGIZE0(expr) #expr
#endif
#ifdef AC_APPLE_UNIVERSAL_BUILD
#undef WORDS_BIGENDIAN
#ifdef __BIG_ENDIAN__
#define WORDS_BIGENDIAN
#endif
#endif
#ifndef DLEXT_MAXLEN
#define DLEXT_MAXLEN 4
#endif
#ifndef RUBY_PLATFORM
#define RUBY_PLATFORM "unknown-unknown"
#endif
#ifdef UNALIGNED_WORD_ACCESS
#/* Take that. */
#elif defined(__i386)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__i386__)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(_M_IX86)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__x86_64)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__x86_64__)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(_M_AMD64)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__powerpc64__)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__POWERPC__) // __POWERPC__ is defined for ppc and ppc64 on Darwin
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__aarch64__)
#define UNALIGNED_WORD_ACCESS 1
#elif defined(__mc68020__)
#define UNALIGNED_WORD_ACCESS 1
#else
#define UNALIGNED_WORD_ACCESS 0
#endif
/* Detection of __VA_OPT__ */
#if !defined(HAVE_VA_ARGS_MACRO)
#undef HAVE___VA_OPT__
#elif defined(__cplusplus)
#if __cplusplus > 201703L
#define HAVE___VA_OPT__
#else
#undef HAVE___VA_OPT__
#endif
#else
#/* Idea taken from: https://stackoverflow.com/a/48045656 */
#define RBIMPL_TEST3(q, w, e, ...) e
#define RBIMPL_TEST2(...) RBIMPL_TEST3(__VA_OPT__(, ), 1, 0, 0)
#define RBIMPL_TEST1() RBIMPL_TEST2("ruby")
#if RBIMPL_TEST1()
#define HAVE___VA_OPT__
#else
#undef HAVE___VA_OPT__
#endif
#undef RBIMPL_TEST1
#undef RBIMPL_TEST2
#undef RBIMPL_TEST3
#endif /* HAVE_VA_ARGS_MACRO */
#ifndef USE_RVARGC
#define USE_RVARGC 1
#endif
#endif /* RBIMPL_CONFIG_H */

38
libs/libruby/ruby/internal/constant_p.h vendored Normal file
View File

@@ -0,0 +1,38 @@
#ifndef RBIMPL_CONSTANT_P_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_CONSTANT_P_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_CONSTANT_P.
*
* Note that __builtin_constant_p can be applicable inside of inline functions,
* according to GCC manual. Clang lacks that feature, though.
*
* @see https://bugs.llvm.org/show_bug.cgi?id=4898
* @see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
*/
#include "ruby/internal/has/builtin.h"
/** Wraps (or simulates) `__builtin_constant_p` */
#if RBIMPL_HAS_BUILTIN(__builtin_constant_p)
# define RBIMPL_CONSTANT_P(expr) __builtin_constant_p(expr)
#else
# define RBIMPL_CONSTANT_P(expr) 0
#endif
#endif /* RBIMPL_CONSTANT_P_H */

35
libs/libruby/ruby/internal/core.h vendored Normal file
View File

@@ -0,0 +1,35 @@
#ifndef RBIMPL_CORE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_CORE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Core data structures, definitions and manipulations.
*/
#include "ruby/internal/core/rarray.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/core/rbignum.h"
#include "ruby/internal/core/rclass.h"
#include "ruby/internal/core/rdata.h"
#include "ruby/internal/core/rfile.h"
#include "ruby/internal/core/rhash.h"
#include "ruby/internal/core/robject.h"
#include "ruby/internal/core/rregexp.h"
#include "ruby/internal/core/rstring.h"
#include "ruby/internal/core/rstruct.h"
#include "ruby/internal/core/rtypeddata.h"
#endif /* RBIMPL_CORE_H */

585
libs/libruby/ruby/internal/core/rarray.h vendored Normal file
View File

@@ -0,0 +1,585 @@
#ifndef RBIMPL_RARRAY_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RARRAY_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RArray.
*/
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/maybe_unused.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/rgengc.h"
#include "ruby/internal/stdbool.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/assert.h"
/**
* @private
* @warning Do not touch this macro.
* @warning It is an implementation detail.
* @warning The value of this macro must match for ruby itself and all
* extension libraries, otherwise serious memory corruption shall
* occur.
*/
#ifndef USE_TRANSIENT_HEAP
# define USE_TRANSIENT_HEAP 1
#endif
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RArray.
* @return The passed object casted to ::RArray.
*/
#define RARRAY(obj) RBIMPL_CAST((struct RArray *)(obj))
/** @cond INTERNAL_MACRO */
#define RARRAY_EMBED_FLAG RARRAY_EMBED_FLAG
#define RARRAY_EMBED_LEN_MASK RARRAY_EMBED_LEN_MASK
#define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX
#define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT
#if USE_TRANSIENT_HEAP
# define RARRAY_TRANSIENT_FLAG RARRAY_TRANSIENT_FLAG
#else
# define RARRAY_TRANSIENT_FLAG 0
#endif
/** @endcond */
#define RARRAY_LEN rb_array_len /**< @alias{rb_array_len} */
#define RARRAY_CONST_PTR rb_array_const_ptr /**< @alias{rb_array_const_ptr} */
#define RARRAY_CONST_PTR_TRANSIENT rb_array_const_ptr_transient /**< @alias{rb_array_const_ptr_transient} */
/** @cond INTERNAL_MACRO */
#if defined(__fcc__) || defined(__fcc_version) || \
defined(__FCC__) || defined(__FCC_VERSION)
/* workaround for old version of Fujitsu C Compiler (fcc) */
# define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x))
#else
# define FIX_CONST_VALUE_PTR(x) (x)
#endif
#define RARRAY_EMBED_LEN RARRAY_EMBED_LEN
#define RARRAY_LENINT RARRAY_LENINT
#define RARRAY_TRANSIENT_P RARRAY_TRANSIENT_P
#define RARRAY_ASET RARRAY_ASET
#define RARRAY_PTR RARRAY_PTR
/** @endcond */
/**
* @private
*
* Bits that you can set to ::RBasic::flags.
*
* @warning These enums are not the only bits we use for arrays.
*
* @internal
*
* Unlike strings, flag usages for arrays are scattered across the entire
* source codes. @shyouhei doesn't know the complete list. But what is listed
* here is at least incomplete.
*/
enum ruby_rarray_flags {
/**
* This flag has something to do with memory footprint. If the array is
* "small" enough, ruby tries to be creative to abuse padding bits of
* struct ::RArray for storing its contents. This flag denotes that
* situation.
*
* @warning This bit has to be considered read-only. Setting/clearing
* this bit without corresponding fix up must cause immediate
* SEGV. Also, internal structures of an array change
* dynamically and transparently throughout of its lifetime.
* Don't assume it being persistent.
*
* @internal
*
* 3rd parties must not be aware that there even is more than one way to
* store array elements. It was a bad idea to expose this to them.
*/
RARRAY_EMBED_FLAG = RUBY_FL_USER1,
/* RUBY_FL_USER2 is for ELTS_SHARED */
/**
* When an array employs embedded strategy (see ::RARRAY_EMBED_FLAG), these
* bits are used to store the number of elements actually filled into
* ::RArray::ary.
*
* @internal
*
* 3rd parties must not be aware that there even is more than one way to
* store array elements. It was a bad idea to expose this to them.
*/
#if USE_RVARGC
RARRAY_EMBED_LEN_MASK = RUBY_FL_USER9 | RUBY_FL_USER8 | RUBY_FL_USER7 | RUBY_FL_USER6 |
RUBY_FL_USER5 | RUBY_FL_USER4 | RUBY_FL_USER3
#else
RARRAY_EMBED_LEN_MASK = RUBY_FL_USER4 | RUBY_FL_USER3
#endif
#if USE_TRANSIENT_HEAP
,
/**
* This flag has something to do with an array's "transiency". A transient
* array is an array of young generation (of generational GC), who stores
* its elements inside of dedicated memory pages called a transient heap.
* Not every young generation share that storage scheme, but elder
* generations must no join.
*
* @internal
*
* 3rd parties must not be aware that there even is more than one way to
* store array elements. It was a bad idea to expose this to them.
*/
RARRAY_TRANSIENT_FLAG = RUBY_FL_USER13
#endif
};
/**
* This is an enum because GDB wants it (rather than a macro). People need not
* bother.
*/
enum ruby_rarray_consts {
/** Where ::RARRAY_EMBED_LEN_MASK resides. */
RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3
#if !USE_RVARGC
,
/** Max possible number elements that can be embedded. */
RARRAY_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE)
#endif
};
/** Ruby's array. */
struct RArray {
/** Basic part, including flags and class. */
struct RBasic basic;
/** Array's specific fields. */
union {
/**
* Arrays that use separated memory region for elements use this
* pattern.
*/
struct {
/** Number of elements of the array. */
long len;
/** Auxiliary info. */
union {
/**
* Capacity of `*ptr`. A continuous memory region of at least
* `capa` elements is expected to exist at `*ptr`. This can be
* bigger than `len`.
*/
long capa;
/**
* Parent of the array. Nowadays arrays can share their
* backend memory regions each other, constructing gigantic
* nest of objects. This situation is called "shared", and
* this is the field to control such properties.
*/
#if defined(__clang__) /* <- clang++ is sane */ || \
!defined(__cplusplus) /* <- C99 is sane */ || \
(__cplusplus > 199711L) /* <- C++11 is sane */
const
#endif
VALUE shared_root;
} aux;
/**
* Pointer to the C array that holds the elements of the array. In
* the old days each array had dedicated memory regions. That is
* no longer true today, but there still are arrays of such
* properties. This field could be used to point such things.
*/
const VALUE *ptr;
} heap;
/**
* Embedded elements. When an array is short enough, it uses this area
* to store its elements. In this case the length is encoded into the
* flags.
*/
#if USE_RVARGC
/* This is a length 1 array because:
* 1. GCC has a bug that does not optimize C flexible array members
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
* 2. Zero length arrays are not supported by all compilers
*/
const VALUE ary[1];
#else
const VALUE ary[RARRAY_EMBED_LEN_MAX];
#endif
} as;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* @private
*
* Declares a section of code where raw pointers are used. This is an
* implementation detail of #RARRAY_PTR_USE. People don't use it directly.
*
* @param[in] ary An object of ::RArray.
* @return `ary`'s backend C array.
*/
VALUE *rb_ary_ptr_use_start(VALUE ary);
/**
* @private
*
* Declares an end of a section formerly started by rb_ary_ptr_use_start().
* This is an implementation detail of #RARRAY_PTR_USE. People don't use it
* directly.
*
* @param[in] a An object of ::RArray.
*/
void rb_ary_ptr_use_end(VALUE a);
#if USE_TRANSIENT_HEAP
/**
* Destructively converts an array of transient backend into ordinal one.
*
* @param[out] a An object of ::RArray.
* @pre `a` must be a transient array.
* @post `a` gets out of transient heap, destructively.
*/
void rb_ary_detransient(VALUE a);
#endif
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the length of the array.
*
* @param[in] ary Array in question.
* @return Its number of elements.
* @pre `ary` must be an instance of ::RArray, and must has its
* ::RARRAY_EMBED_FLAG flag set.
*
* @internal
*
* This was a macro before. It was inevitable to be public, since macros are
* global constructs. But should it be forever? Now that it is a function,
* @shyouhei thinks it could just be eliminated, hidden into implementation
* details.
*/
static inline long
RARRAY_EMBED_LEN(VALUE ary)
{
RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
RBIMPL_ASSERT_OR_ASSUME(RB_FL_ANY_RAW(ary, RARRAY_EMBED_FLAG));
VALUE f = RBASIC(ary)->flags;
f &= RARRAY_EMBED_LEN_MASK;
f >>= RARRAY_EMBED_LEN_SHIFT;
return RBIMPL_CAST((long)f);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
/**
* Queries the length of the array.
*
* @param[in] a Array in question.
* @return Its number of elements.
* @pre `a` must be an instance of ::RArray.
*/
static inline long
rb_array_len(VALUE a)
{
RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY);
if (RB_FL_ANY_RAW(a, RARRAY_EMBED_FLAG)) {
return RARRAY_EMBED_LEN(a);
}
else {
return RARRAY(a)->as.heap.len;
}
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Identical to rb_array_len(), except it differs for the return type.
*
* @param[in] ary Array in question.
* @exception rb_eRangeError Too long.
* @return Its number of elements.
* @pre `ary` must be an instance of ::RArray.
*
* @internal
*
* This API seems redundant but has actual usages.
*/
static inline int
RARRAY_LENINT(VALUE ary)
{
return rb_long2int(RARRAY_LEN(ary));
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries if the array is a transient array.
*
* @param[in] ary Array in question.
* @retval true Yes it is.
* @retval false No it isn't.
* @pre `ary` must be an instance of ::RArray.
*
* @internal
*
* @shyouhei doesn't understand the benefit of this function called from
* extension libraries.
*/
static inline bool
RARRAY_TRANSIENT_P(VALUE ary)
{
RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
#if USE_TRANSIENT_HEAP
return RB_FL_ANY_RAW(ary, RARRAY_TRANSIENT_FLAG);
#else
return false;
#endif
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
/**
* @private
*
* This is an implementation detail of RARRAY_PTR(). People do not use it
* directly.
*
* @param[in] a An object of ::RArray.
* @return Its backend storage.
*/
static inline const VALUE *
rb_array_const_ptr_transient(VALUE a)
{
RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY);
if (RB_FL_ANY_RAW(a, RARRAY_EMBED_FLAG)) {
return FIX_CONST_VALUE_PTR(RARRAY(a)->as.ary);
}
else {
return FIX_CONST_VALUE_PTR(RARRAY(a)->as.heap.ptr);
}
}
#if ! USE_TRANSIENT_HEAP
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
#endif
/**
* @private
*
* This is an implementation detail of RARRAY_PTR(). People do not use it
* directly.
*
* @param[in] a An object of ::RArray.
* @return Its backend storage.
* @post `a` is not a transient array.
*/
static inline const VALUE *
rb_array_const_ptr(VALUE a)
{
RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY);
#if USE_TRANSIENT_HEAP
if (RARRAY_TRANSIENT_P(a)) {
rb_ary_detransient(a);
}
#endif
return rb_array_const_ptr_transient(a);
}
/**
* @private
*
* This is an implementation detail of #RARRAY_PTR_USE. People do not use it
* directly.
*
* @param[in] a An object of ::RArray.
* @param[in] allow_transient Whether `a` can be transient or not.
* @return Its backend storage.
* @post `a` is not a transient array unless `allow_transient`.
*/
static inline VALUE *
rb_array_ptr_use_start(VALUE a,
RBIMPL_ATTR_MAYBE_UNUSED()
int allow_transient)
{
RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY);
#if USE_TRANSIENT_HEAP
if (!allow_transient) {
if (RARRAY_TRANSIENT_P(a)) {
rb_ary_detransient(a);
}
}
#endif
return rb_ary_ptr_use_start(a);
}
/**
* @private
*
* This is an implementation detail of #RARRAY_PTR_USE. People do not use it
* directly.
*
* @param[in] a An object of ::RArray.
* @param[in] allow_transient Whether `a` can be transient or not.
*/
static inline void
rb_array_ptr_use_end(VALUE a,
RBIMPL_ATTR_MAYBE_UNUSED()
int allow_transient)
{
RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY);
rb_ary_ptr_use_end(a);
}
/**
* @private
*
* This is an implementation detail of #RARRAY_PTR_USE. People do not use it
* directly.
*/
#define RBIMPL_RARRAY_STMT(flag, ary, var, expr) do { \
RBIMPL_ASSERT_TYPE((ary), RUBY_T_ARRAY); \
const VALUE rbimpl_ary = (ary); \
VALUE *var = rb_array_ptr_use_start(rbimpl_ary, (flag)); \
expr; \
rb_array_ptr_use_end(rbimpl_ary, (flag)); \
} while (0)
/**
* @private
*
* This is an implementation detail of #RARRAY_PTR_USE. People do not use it
* directly.
*/
#define RARRAY_PTR_USE_END(a) rb_array_ptr_use_end(a, 0)
/**
* Declares a section of code where raw pointers are used. In case you need to
* touch the raw C array instead of polite CAPIs, then that operation shall be
* wrapped using this macro.
*
* ```CXX
* const auto ary = rb_eval_string("[...]");
* const auto len = RARRAY_LENINT(ary);
* const auto symwrite = rb_intern("write");
*
* RARRAY_PTR_USE(ary, ptr, {
* rb_funcallv(rb_stdout, symwrite, len, ptr);
* });
* ```
*
* @param ary An object of ::RArray.
* @param ptr_name A variable name which points the C array in `expr`.
* @param expr The expression that touches `ptr_name`.
*
* @internal
*
* For historical reasons use of this macro is not enforced. There are
* extension libraries in the wild which call RARRAY_PTR() without it. We want
* them use it... Maybe some transition path can be implemented later.
*/
#define RARRAY_PTR_USE(ary, ptr_name, expr) \
RBIMPL_RARRAY_STMT(0, ary, ptr_name, expr)
/**
* Identical to #RARRAY_PTR_USE, except the pointer can be a transient one.
*
* @param ary An object of ::RArray.
* @param ptr_name A variable name which points the C array in `expr`.
* @param expr The expression that touches `ptr_name`.
*/
#define RARRAY_PTR_USE_TRANSIENT(ary, ptr_name, expr) \
RBIMPL_RARRAY_STMT(1, ary, ptr_name, expr)
/**
* Wild use of a C pointer. This function accesses the backend storage
* directly. This is slower than #RARRAY_PTR_USE_TRANSIENT. It exercises
* extra manoeuvres to protect our generational GC. Use of this function is
* considered archaic. Use a modern way instead.
*
* @param[in] ary An object of ::RArray.
* @return The backend C array.
*
* @internal
*
* That said... there are extension libraries in the wild who uses it. We
* cannot but continue supporting.
*/
static inline VALUE *
RARRAY_PTR(VALUE ary)
{
RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
VALUE tmp = RB_OBJ_WB_UNPROTECT_FOR(ARRAY, ary);
return RBIMPL_CAST((VALUE *)RARRAY_CONST_PTR(tmp));
}
/**
* Assigns an object in an array.
*
* @param[out] ary Destination array object.
* @param[in] i Index of `ary`.
* @param[in] v Arbitrary ruby object.
* @pre `ary` must be an instance of ::RArray.
* @pre `ary`'s length must be longer than or equal to `i`.
* @pre `i` must be greater than or equal to zero.
* @post `ary`'s `i`th element is set to `v`.
*/
static inline void
RARRAY_ASET(VALUE ary, long i, VALUE v)
{
RARRAY_PTR_USE_TRANSIENT(ary, ptr,
RB_OBJ_WRITE(ary, &ptr[i], v));
}
/**
* @deprecated
*
* :FIXME: we want to convert RARRAY_AREF into an inline function (to add rooms
* for more sanity checks). However there were situations where the address of
* this macro is taken i.e. &RARRAY_AREF(...). They cannot be possible if this
* is not a macro. Such usages are abuse, and we eliminated them internally.
* However we are afraid of similar things to remain in the wild. This macro
* remains as it is due to that. If we could warn such usages we can set a
* transition path, but currently no way is found to do so.
*/
#define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i]
#endif /* RBIMPL_RARRAY_H */

158
libs/libruby/ruby/internal/core/rbasic.h vendored Normal file
View File

@@ -0,0 +1,158 @@
#ifndef RBIMPL_RBASIC_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RBASIC_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RBasic.
*/
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/forceinline.h"
#include "ruby/internal/attr/noalias.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h"
#include "ruby/internal/value.h"
#include "ruby/assert.h"
/**
* Convenient casting macro.
*
* @param obj Arbitrary Ruby object.
* @return The passed object casted to ::RBasic.
*/
#define RBASIC(obj) RBIMPL_CAST((struct RBasic *)(obj))
/** @cond INTERNAL_MACRO */
#define RBASIC_CLASS RBASIC_CLASS
#define RBIMPL_RVALUE_EMBED_LEN_MAX 3
#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX
#define RBIMPL_EMBED_LEN_MAX_OF(T) \
RBIMPL_CAST((int)(sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]) / (sizeof(T))))
/** @endcond */
/**
* This is an enum because GDB wants it (rather than a macro). People need not
* bother.
*/
enum ruby_rvalue_flags {
/** Max possible number of objects that can be embedded. */
RVALUE_EMBED_LEN_MAX = RBIMPL_RVALUE_EMBED_LEN_MAX
};
/**
* Ruby's object's, base components. Every single ruby objects have them in
* common.
*/
struct
RUBY_ALIGNAS(SIZEOF_VALUE)
RBasic {
/**
* Per-object flags. Each ruby objects have their own characteristics
* apart from their classes. For instance whether an object is frozen or
* not is not controlled by its class. This is where such properties are
* stored.
*
* @see enum ::ruby_fl_type
*
* @note This is ::VALUE rather than an enum for alignment purpose. Back
* in the 1990s there were no such thing like `_Alignas` in C.
*/
VALUE flags;
/**
* Class of an object. Every object has its class. Also, everything is an
* object in Ruby. This means classes are also objects. Classes have
* their own classes, classes of classes have their classes, too ... and
* it recursively continues forever.
*
* Also note the `const` qualifier. In ruby an object cannot "change" its
* class.
*/
const VALUE klass;
#ifdef __cplusplus
public:
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_FORCEINLINE()
RBIMPL_ATTR_NOALIAS()
/**
* We need to define this explicit constructor because the field `klass` is
* const-qualified above, which effectively defines the implicit default
* constructor as "deleted" (as of C++11) -- No way but to define one by
* ourselves.
*/
RBasic() :
flags(RBIMPL_VALUE_NULL),
klass(RBIMPL_VALUE_NULL)
{
}
#endif
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Make the object invisible from Ruby code.
*
* It is useful to let Ruby's GC manage your internal data structure -- The
* object keeps being managed by GC, but `ObjectSpace.each_object` never yields
* the object.
*
* Note that the object also lose a way to call a method on it.
*
* @param[out] obj A Ruby object.
* @return The passed object.
* @post The object is destructively modified to be invisible.
* @see rb_obj_reveal
*/
VALUE rb_obj_hide(VALUE obj);
/**
* Make a hidden object visible again.
*
* It is the caller's responsibility to pass the right `klass` which `obj`
* originally used to belong to.
*
* @param[out] obj A Ruby object.
* @param[in] klass Class of `obj`.
* @return Passed `obj`.
* @pre `obj` was previously hidden.
* @post `obj`'s class is `klass`.
* @see rb_obj_hide
*/
VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the class of an object.
*
* @param[in] obj An object.
* @return Its class.
*/
static inline VALUE
RBASIC_CLASS(VALUE obj)
{
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
return RBASIC(obj)->klass;
}
#endif /* RBIMPL_RBASIC_H */

View File

@@ -0,0 +1,80 @@
#ifndef RBIMPL_RBIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RBIGNUM_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate struct RBignum.
* @note The struct RBignum itself is opaque.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/internal/stdbool.h"
#define RBIGNUM_SIGN rb_big_sign /**< @alias{rb_big_sign} */
/** @cond INTERNAL_MACRO */
#define RBIGNUM_POSITIVE_P RBIGNUM_POSITIVE_P
#define RBIGNUM_NEGATIVE_P RBIGNUM_NEGATIVE_P
/** @endcond */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* The "sign" of a bignum.
*
* @param[in] num An object of RBignum.
* @retval 1 It is greater than or equal to zero.
* @retval 0 It is less than zero.
*
* @internal
*
* Implementation wise, unlike fixnums (which are 2's complement), bignums are
* signed magnitude system. Theoretically it could be possible to have
* negative zero instances. But in reality there is no way to create such
* thing. Nobody ever needed that kind of insanity.
*/
int rb_big_sign(VALUE num);
RBIMPL_SYMBOL_EXPORT_END()
/**
* Checks if the bignum is positive.
* @param[in] b An object of RBignum.
* @retval false `b` is less than zero.
* @retval true Otherwise.
*/
static inline bool
RBIGNUM_POSITIVE_P(VALUE b)
{
RBIMPL_ASSERT_TYPE(b, RUBY_T_BIGNUM);
return RBIGNUM_SIGN(b);
}
/**
* Checks if the bignum is negative.
* @param[in] b An object of RBignum.
* @retval true `b` is less than zero.
* @retval false Otherwise.
*/
static inline bool
RBIGNUM_NEGATIVE_P(VALUE b)
{
RBIMPL_ASSERT_TYPE(b, RUBY_T_BIGNUM);
return ! RBIGNUM_POSITIVE_P(b);
}
#endif /* RBIMPL_RBIGNUM_H */

View File

@@ -0,0 +1,93 @@
#ifndef RBIMPL_RCLASS_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RCLASS_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate struct RClass.
* @note The struct RClass itself is opaque.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/cast.h"
/** @cond INTERNAL_MACRO */
#define RMODULE_IS_REFINEMENT RMODULE_IS_REFINEMENT
/** @endcond */
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an RClass.
* @return The passed object casted to RClass.
*/
#define RCLASS(obj) RBIMPL_CAST((struct RClass *)(obj))
/** @alias{RCLASS} */
#define RMODULE RCLASS
/** @alias{rb_class_get_superclass} */
#define RCLASS_SUPER rb_class_get_superclass
/**
* @private
*
* Bits that you can set to ::RBasic::flags.
*
* @internal
*
* Why is it here, given RClass itself is not?
*/
enum ruby_rmodule_flags {
/**
* This flag has something to do with refinements. A module created using
* rb_mod_refine() has this flag set. This is the bit which controls
* difference between normal inclusion versus refinements.
*/
RMODULE_IS_REFINEMENT = RUBY_FL_USER3
};
struct RClass; /* Opaque, declared here for RCLASS() macro. */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Returns the superclass of a class.
* @param[in] klass An object of RClass.
* @retval RUBY_Qfalse `klass` has no super class.
* @retval otherwise Raw superclass of `klass`
* @see rb_class_superclass
*
* ### Q&A ###
*
* - Q: How can a class have no super class?
*
* - A: `klass` could be a module. Or it could be ::rb_cBasicObject.
*
* - Q: What do you mean by "raw" superclass?
*
* - A: This is a really good question. The answer is that this function
* returns something different from what you would normally expect. On
* occasions ruby inserts hidden classes in a hierarchy of class
* inheritance behind-the-scene. Such classes are called "iclass"es and
* distinguished using ::RUBY_T_ICLASS in C level. They are truly
* transparent from Ruby level but can be accessed from C, by using this
* API.
*/
VALUE rb_class_get_superclass(VALUE klass);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_RCLASS_H */

386
libs/libruby/ruby/internal/core/rdata.h vendored Normal file
View File

@@ -0,0 +1,386 @@
#ifndef RBIMPL_RDATA_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RDATA_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RData.
*/
#include "ruby/internal/config.h"
#ifdef STDC_HEADERS
# include <stddef.h>
#endif
#include "ruby/internal/attr/deprecated.h"
#include "ruby/internal/attr/warning.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/defines.h"
/** @cond INTERNAL_MACRO */
#ifdef RUBY_UNTYPED_DATA_WARNING
# /* Take that. */
#elif defined(RUBY_EXPORT)
# define RUBY_UNTYPED_DATA_WARNING 1
#else
# define RUBY_UNTYPED_DATA_WARNING 0
#endif
#define RBIMPL_DATA_FUNC(f) RBIMPL_CAST((void (*)(void *))(f))
#define RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() \
RBIMPL_ATTR_WARNING(("untyped Data is unsafe; use TypedData instead")) \
RBIMPL_ATTR_DEPRECATED(("by TypedData"))
#define RBIMPL_MACRO_SELECT(x, y) x ## y
#define RUBY_MACRO_SELECT(x, y) RBIMPL_MACRO_SELECT(x, y)
/** @endcond */
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RData.
* @return The passed object casted to ::RData.
*/
#define RDATA(obj) RBIMPL_CAST((struct RData *)(obj))
/**
* Convenient getter macro.
*
* @param obj An object, which is in fact an ::RData.
* @return The passed object's ::RData::data field.
*/
#define DATA_PTR(obj) RDATA(obj)->data
/**
* This is a value you can set to ::RData::dfree. Setting this means the data
* was allocated using ::ruby_xmalloc() (or variants), and shall be freed using
* ::ruby_xfree().
*
* @warning Do not use this if you want to use system malloc, because the
* system and Ruby might or might not share the same malloc
* implementation.
*/
#define RUBY_DEFAULT_FREE RBIMPL_DATA_FUNC(-1)
/**
* This is a value you can set to ::RData::dfree. Setting this means the data
* is managed by someone else, like, statically allocated. Of course you are
* on your own then.
*/
#define RUBY_NEVER_FREE RBIMPL_DATA_FUNC(0)
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define RUBY_UNTYPED_DATA_FUNC(f) f RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
/*
#define RUBY_DATA_FUNC(func) ((void (*)(void*))(func))
*/
/**
* This is the type of callbacks registered to ::RData. The argument is the
* `data` field.
*/
typedef void (*RUBY_DATA_FUNC)(void*);
/**
* @deprecated
*
* Old "untyped" user data. It has roughly the same usage as struct
* ::RTypedData, but lacked several features such as support for compaction GC.
* Use of this struct is not recommended any longer. If it is dead necessary,
* please inform the core devs about your usage.
*
* @internal
*
* @shyouhei tried to add RBIMPL_ATTR_DEPRECATED for this type but that yielded
* too many warnings in the core. Maybe we want to retry later... Just add
* deprecated document for now.
*/
struct RData {
/** Basic part, including flags and class. */
struct RBasic basic;
/**
* This function is called when the object is experiencing GC marks. If it
* contains references to other Ruby objects, you need to mark them also.
* Otherwise GC will smash your data.
*
* @see rb_gc_mark()
* @warning This is called during GC runs. Object allocations are
* impossible at that moment (that is why GC runs).
*/
RUBY_DATA_FUNC dmark;
/**
* This function is called when the object is no longer used. You need to
* do whatever necessary to avoid memory leaks.
*
* @warning This is called during GC runs. Object allocations are
* impossible at that moment (that is why GC runs).
*/
RUBY_DATA_FUNC dfree;
/** Pointer to the actual C level struct that you want to wrap. */
void *data;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* This is the primitive way to wrap an existing C struct into ::RData.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] datap Pointer to the target C struct.
* @param[in] dmark Mark function.
* @param[in] dfree Free function.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return An allocated object that wraps `datap`.
*/
VALUE rb_data_object_wrap(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree);
/**
* Identical to rb_data_object_wrap(), except it allocates a new data region
* internally instead of taking an existing one. The allocation is done using
* ruby_calloc(). Hence it makes no sense to pass anything other than
* ::RUBY_DEFAULT_FREE to the last argument.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] size Requested size of memory to allocate.
* @param[in] dmark Mark function.
* @param[in] dfree Free function.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return An allocated object that wraps a new `size` byte region.
*/
VALUE rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree);
/**
* @private
* Documented in include/ruby/internal/globals.h
*/
RUBY_EXTERN VALUE rb_cObject;
RBIMPL_SYMBOL_EXPORT_END()
/**
* Converts sval, a pointer to your struct, into a Ruby object.
*
* @param klass A ruby level class.
* @param mark Mark function.
* @param free Free function.
* @param sval A pointer to your struct.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return A created Ruby object.
*/
#define Data_Wrap_Struct(klass, mark, free, sval) \
rb_data_object_wrap( \
(klass), \
(sval), \
RBIMPL_DATA_FUNC(mark), \
RBIMPL_DATA_FUNC(free))
/**
* @private
*
* This is an implementation detail of #Data_Make_Struct. People don't use it
* directly.
*
* @param result Variable name of created Ruby object.
* @param klass Ruby level class of the object.
* @param type Type name of the C struct.
* @param size Size of the C struct.
* @param mark Mark function.
* @param free Free function.
* @param sval Variable name of created C struct.
*/
#define Data_Make_Struct0(result, klass, type, size, mark, free, sval) \
VALUE result = rb_data_object_zalloc( \
(klass), \
(size), \
RBIMPL_DATA_FUNC(mark), \
RBIMPL_DATA_FUNC(free)); \
(sval) = RBIMPL_CAST((type *)DATA_PTR(result)); \
RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval))
/**
* Identical to #Data_Wrap_Struct, except it allocates a new data region
* internally instead of taking an existing one. The allocation is done using
* ruby_calloc(). Hence it makes no sense to pass anything other than
* ::RUBY_DEFAULT_FREE to the `free` argument.
*
* @param klass Ruby level class of the returning object.
* @param type Type name of the C struct.
* @param mark Mark function.
* @param free Free function.
* @param sval Variable name of created C struct.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return A created Ruby object.
*/
#ifdef HAVE_STMT_AND_DECL_IN_EXPR
#define Data_Make_Struct(klass, type, mark, free, sval) \
RB_GNUC_EXTENSION({ \
Data_Make_Struct0( \
data_struct_obj, \
klass, \
type, \
sizeof(type), \
mark, \
free, \
sval); \
data_struct_obj; \
})
#else
#define Data_Make_Struct(klass, type, mark, free, sval) \
rb_data_object_make( \
(klass), \
RBIMPL_DATA_FUNC(mark), \
RBIMPL_DATA_FUNC(free), \
RBIMPL_CAST((void **)&(sval)), \
sizeof(type))
#endif
/**
* Obtains a C struct from inside of a wrapper Ruby object.
*
* @param obj An instance of ::RData.
* @param type Type name of the C struct.
* @param sval Variable name of obtained C struct.
* @return Unwrapped C struct that `obj` holds.
*/
#define Data_Get_Struct(obj, type, sval) \
((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj)))
RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
/**
* @private
*
* This is an implementation detail of rb_data_object_wrap(). People don't use
* it directly.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] ptr Pointer to the target C struct.
* @param[in] mark Mark function.
* @param[in] free Free function.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return An allocated object that wraps `datap`.
*/
static inline VALUE
rb_data_object_wrap_warning(VALUE klass, void *ptr, RUBY_DATA_FUNC mark, RUBY_DATA_FUNC free)
{
return rb_data_object_wrap(klass, ptr, mark, free);
}
/**
* @private
*
* This is an implementation detail of #Data_Get_Struct. People don't use it
* directly.
*
* @param[in] obj An instance of ::RData.
* @return Unwrapped C struct that `obj` holds.
*/
static inline void *
rb_data_object_get(VALUE obj)
{
Check_Type(obj, RUBY_T_DATA);
return DATA_PTR(obj);
}
RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
/**
* @private
*
* This is an implementation detail of #Data_Get_Struct. People don't use it
* directly.
*
* @param[in] obj An instance of ::RData.
* @return Unwrapped C struct that `obj` holds.
*/
static inline void *
rb_data_object_get_warning(VALUE obj)
{
return rb_data_object_get(obj);
}
#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
# define rb_data_object_wrap_warning(klass, ptr, mark, free) \
RB_GNUC_EXTENSION( \
__builtin_choose_expr( \
__builtin_constant_p(klass) && !(klass), \
rb_data_object_wrap(klass, ptr, mark, free), \
(rb_data_object_wrap_warning)(klass, ptr, mark, free)))
#endif
/**
* This is an implementation detail of #Data_Make_Struct. People don't use it
* directly.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] mark_func Mark function.
* @param[in] free_func Free function.
* @param[in] datap Variable of created C struct.
* @param[in] size Requested size of allocation.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return A created Ruby object.
* @post `*datap` holds the created C struct.
*/
static inline VALUE
rb_data_object_make(VALUE klass, RUBY_DATA_FUNC mark_func, RUBY_DATA_FUNC free_func, void **datap, size_t size)
{
Data_Make_Struct0(result, klass, void, size, mark_func, free_func, *datap);
return result;
}
RBIMPL_ATTR_DEPRECATED(("by: rb_data_object_wrap"))
/** @deprecated This function was renamed to rb_data_object_wrap(). */
static inline VALUE
rb_data_object_alloc(VALUE klass, void *data, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
{
return rb_data_object_wrap(klass, data, dmark, dfree);
}
/** @cond INTERNAL_MACRO */
#define rb_data_object_wrap_0 rb_data_object_wrap
#define rb_data_object_wrap_1 rb_data_object_wrap_warning
#define rb_data_object_wrap_2 rb_data_object_wrap_ /* Used here vvvv */
#define rb_data_object_wrap RUBY_MACRO_SELECT(rb_data_object_wrap_2, RUBY_UNTYPED_DATA_WARNING)
#define rb_data_object_get_0 rb_data_object_get
#define rb_data_object_get_1 rb_data_object_get_warning
#define rb_data_object_get_2 rb_data_object_get_ /* Used here vvvv */
#define rb_data_object_get RUBY_MACRO_SELECT(rb_data_object_get_2, RUBY_UNTYPED_DATA_WARNING)
#define rb_data_object_make_0 rb_data_object_make
#define rb_data_object_make_1 rb_data_object_make_warning
#define rb_data_object_make_2 rb_data_object_make_ /* Used here vvvv */
#define rb_data_object_make RUBY_MACRO_SELECT(rb_data_object_make_2, RUBY_UNTYPED_DATA_WARNING)
/** @endcond */
#endif /* RBIMPL_RDATA_H */

51
libs/libruby/ruby/internal/core/rfile.h vendored Normal file
View File

@@ -0,0 +1,51 @@
#ifndef RBIMPL_RFILE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RFILE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RFile.
*/
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/cast.h"
/* rb_io_t is in ruby/io.h. The header file has historically not been included
* into ruby/ruby.h. We follow that tradition. */
struct rb_io_t;
/**
* Ruby's File and IO. Ruby's IO are not just file descriptors. They have
* buffers. They also have encodings. Various information are controlled
* using this struct.
*/
struct RFile {
/** Basic part, including flags and class. */
struct RBasic basic;
/** IO's specific fields. */
struct rb_io_t *fptr;
};
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RFile.
* @return The passed object casted to ::RFile.
*/
#define RFILE(obj) RBIMPL_CAST((struct RFile *)(obj))
#endif /* RBIMPL_RFILE_H */

144
libs/libruby/ruby/internal/core/rhash.h vendored Normal file
View File

@@ -0,0 +1,144 @@
#ifndef RBIMPL_RHASH_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RHASH_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate struct RHash.
* @note The struct RHash itself is opaque.
*/
#include "ruby/internal/config.h"
#ifdef STDC_HEADERS
# include <stddef.h>
#endif
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
# include "ruby/backward.h"
#endif
/**
* Retrieves the internal table.
*
* @param[in] h An instance of RHash.
* @pre `h` must be of ::RUBY_T_HASH.
* @return A struct st_table which has the contents of this hash.
* @note Nowadays as Ruby evolved over ages, RHash has multiple backend
* storage engines. `h`'s backend is not guaranteed to be a
* st_table. This function creates one when necessary.
*/
#define RHASH_TBL(h) rb_hash_tbl(h, __FILE__, __LINE__)
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*
* @internal
*
* Declaration of rb_hash_iter_lev() is at include/ruby/backward.h.
*/
#define RHASH_ITER_LEV(h) rb_hash_iter_lev(h)
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*
* @internal
*
* Declaration of rb_hash_ifnone() is at include/ruby/backward.h.
*/
#define RHASH_IFNONE(h) rb_hash_ifnone(h)
/**
* Queries the size of the hash. Size here means the number of keys that the
* hash stores.
*
* @param[in] h An instance of RHash.
* @pre `h` must be of ::RUBY_T_HASH.
* @return The size of the hash.
*/
#define RHASH_SIZE(h) rb_hash_size_num(h)
/**
* Checks if the hash is empty.
*
* @param[in] h An instance of RHash.
* @pre `h` must be of ::RUBY_T_HASH.
* @retval true It is.
* @retval false It isn't.
*/
#define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0)
/**
* Destructively updates the default value of the hash.
*
* @param[out] h An instance of RHash.
* @param[in] ifnone Arbitrary default value.
* @pre `h` must be of ::RUBY_T_HASH.
*
* @internal
*
* But why you can set this, given rb_hash_ifnone() doesn't exist?
*/
#define RHASH_SET_IFNONE(h, ifnone) rb_hash_set_ifnone((VALUE)h, ifnone)
struct st_table; /* in ruby/st.h */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* This is the implementation detail of #RHASH_SIZE. People don't call this
* directly.
*
* @param[in] hash An instance of RHash.
* @pre `hash` must be of ::RUBY_T_HASH.
* @return The size of the hash.
*/
size_t rb_hash_size_num(VALUE hash);
/**
* This is the implementation detail of #RHASH_TBL. People don't call this
* directly.
*
* @param[in] hash An instance of RHash.
* @param[in] file The `__FILE__`.
* @param[in] line The `__LINE__`.
* @pre `hash` must be of ::RUBY_T_HASH.
* @return Table that has the contents of the hash.
*/
struct st_table *rb_hash_tbl(VALUE hash, const char *file, int line);
/**
* This is the implementation detail of #RHASH_SET_IFNONE. People don't call
* this directly.
*
* @param[out] hash An instance of RHash.
* @param[in] ifnone Arbitrary default value.
* @pre `hash` must be of ::RUBY_T_HASH.
*/
VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_RHASH_H */

146
libs/libruby/ruby/internal/core/rmatch.h vendored Normal file
View File

@@ -0,0 +1,146 @@
#ifndef RBIMPL_RMATCH_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RMATCH_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RMatch.
*/
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/assert.h"
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RMatch.
* @return The passed object casted to ::RMatch.
*/
#define RMATCH(obj) RBIMPL_CAST((struct RMatch *)(obj))
/** @cond INTERNAL_MACRO */
#define RMATCH_REGS RMATCH_REGS
/** @endcond */
struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
struct re_registers; /* Also in onigmo.h */
/**
* @old{re_pattern_buffer}
*
* @internal
*
* @shyouhei wonders: is anyone actively using this typedef ...?
*/
typedef struct re_pattern_buffer Regexp;
/**
* Represents the region of a capture group. This is basically for caching
* purpose. re_registers have similar concepts (`beg` and `end`) but they are
* in `ptrdiff_t*`. In order for us to implement `MatchData#offset` that info
* has to be converted to offset integers. This is the struct to hold such
* things.
*
* @internal
*
* But why on earth it has to be visible from extension libraries?
*/
struct rmatch_offset {
long beg; /**< Beginning of a group. */
long end; /**< End of a group. */
};
/** Represents a match. */
struct rmatch {
/**
* "Registers" of a match. This is a quasi-opaque struct that holds
* execution result of a match. Roughly resembles `&~`.
*/
struct re_registers regs;
/** Capture group offsets, in C array. */
struct rmatch_offset *char_offset;
/** Number of ::rmatch_offset that ::rmatch::char_offset holds. */
int char_offset_num_allocated;
};
/**
* Regular expression execution context. When a regular expression "matches"
* to a string, it generates capture groups etc. This struct holds that info.
* Visible from Ruby as an instance of `MatchData`.
*
* @note There is no way for extension libraries to manually generate this
* struct except by actually exercising the match operation of a regular
* expression.
*/
struct RMatch {
/** Basic part, including flags and class. */
struct RBasic basic;
/**
* The target string that the match was made against.
*/
VALUE str;
/**
* The result of this match.
*/
struct rmatch *rmatch;
/**
* The expression of this match.
*/
VALUE regexp; /* RRegexp */
};
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the raw ::re_registers.
*
* @param[in] match A match object
* @pre `match` must be of ::RMatch.
* @return Its execution result.
* @note Good. So you are aware of the fact that it could return NULL.
* Yes. It actually does. This is a really bizarre thing. The
* situation is about `String#gsub` and its family. They take
* strings as arguments, like `"foo".sub("bar", "baz")`. On such
* situations, in order to optimise memory allocations, these
* methods do not involve regular expressions at all. They just
* sequentially scan the receiver. Okay. The story begins here.
* Even when they do not kick our regexp engine, there must be
* backref objects e.g. `$&`. But how? You know what? Ruby fakes
* them. It allocates an empty ::RMatch and behaves as if there
* were execution contexts. In reality there weren't. No
* ::re_registers are allocated then. There is no way for this
* function but to return NULL for those fake ::RMatch. This is
* the reason for the nullability of this function.
*/
static inline struct re_registers *
RMATCH_REGS(VALUE match)
{
RBIMPL_ASSERT_TYPE(match, RUBY_T_MATCH);
RBIMPL_ASSERT_OR_ASSUME(RMATCH(match)->rmatch != NULL);
return &RMATCH(match)->rmatch->regs;
}
#endif /* RBIMPL_RMATCH_H */

View File

@@ -0,0 +1,176 @@
#ifndef RBIMPL_ROBJECT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ROBJECT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RObject.
*/
#include "ruby/internal/config.h"
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/deprecated.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RObject.
* @return The passed object casted to ::RObject.
*/
#define ROBJECT(obj) RBIMPL_CAST((struct RObject *)(obj))
/** @cond INTERNAL_MACRO */
#define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX
#define ROBJECT_EMBED ROBJECT_EMBED
#define ROBJECT_IV_CAPACITY ROBJECT_IV_CAPACITY
#define ROBJECT_IVPTR ROBJECT_IVPTR
/** @endcond */
/**
* @private
*
* Bits that you can set to ::RBasic::flags.
*/
enum ruby_robject_flags {
/**
* This flag has something to do with memory footprint. If the object is
* "small" enough, ruby tries to be creative to abuse padding bits of
* struct ::RObject for storing instance variables. This flag denotes that
* situation.
*
* @warning This bit has to be considered read-only. Setting/clearing
* this bit without corresponding fix up must cause immediate
* SEGV. Also, internal structures of an object change
* dynamically and transparently throughout of its lifetime.
* Don't assume it being persistent.
*
* @internal
*
* 3rd parties must not be aware that there even is more than one way to
* store instance variables. Might better be hidden.
*/
ROBJECT_EMBED = RUBY_FL_USER1
};
#if !USE_RVARGC
/**
* This is an enum because GDB wants it (rather than a macro). People need not
* bother.
*/
enum ruby_robject_consts {
/** Max possible number of instance variables that can be embedded. */
ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE)
};
#endif
struct st_table;
/**
* Ruby's ordinal objects. Unless otherwise special cased, all predefined and
* user-defined classes share this struct to hold their instances.
*/
struct RObject {
/** Basic part, including flags and class. */
struct RBasic basic;
/** Object's specific fields. */
union {
/**
* Object that use separated memory region for instance variables use
* this pattern.
*/
struct {
/** Pointer to a C array that holds instance variables. */
VALUE *ivptr;
/**
* This is a table that holds instance variable name to index
* mapping. Used when accessing instance variables using names.
*
* @internal
*
* This is a shortcut for `RCLASS_IV_INDEX_TBL(rb_obj_class(obj))`.
*/
struct rb_id_table *iv_index_tbl;
} heap;
#if USE_RVARGC
/* Embedded instance variables. When an object is small enough, it
* uses this area to store the instance variables.
*
* This is a length 1 array because:
* 1. GCC has a bug that does not optimize C flexible array members
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
* 2. Zero length arrays are not supported by all compilers
*/
VALUE ary[1];
#else
/**
* Embedded instance variables. When an object is small enough, it
* uses this area to store the instance variables.
*/
VALUE ary[ROBJECT_EMBED_LEN_MAX];
#endif
} as;
};
/* Offsets for YJIT */
#ifndef __cplusplus
static const int32_t ROBJECT_OFFSET_AS_HEAP_IVPTR = offsetof(struct RObject, as.heap.ivptr);
static const int32_t ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL = offsetof(struct RObject, as.heap.iv_index_tbl);
static const int32_t ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary);
#endif
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the instance variables.
*
* @param[in] obj Object in question.
* @return Its instance variables, in C array.
* @pre `obj` must be an instance of ::RObject.
*
* @internal
*
* @shyouhei finds no reason for this to be visible from extension libraries.
*/
static inline VALUE *
ROBJECT_IVPTR(VALUE obj)
{
RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
struct RObject *const ptr = ROBJECT(obj);
if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
return ptr->as.ary;
}
else {
return ptr->as.heap.ivptr;
}
}
#endif /* RBIMPL_ROBJECT_H */

View File

@@ -0,0 +1,168 @@
#ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RREGEXP_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RRegexp.
*/
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/core/rstring.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RRegexp.
* @return The passed object casted to ::RRegexp.
*/
#define RREGEXP(obj) RBIMPL_CAST((struct RRegexp *)(obj))
/**
* Convenient accessor macro.
*
* @param obj An object, which is in fact an ::RRegexp.
* @return The passed object's pattern buffer.
*/
#define RREGEXP_PTR(obj) (RREGEXP(obj)->ptr)
/** @cond INTERNAL_MACRO */
#define RREGEXP_SRC RREGEXP_SRC
#define RREGEXP_SRC_PTR RREGEXP_SRC_PTR
#define RREGEXP_SRC_LEN RREGEXP_SRC_LEN
#define RREGEXP_SRC_END RREGEXP_SRC_END
/** @endcond */
struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
/**
* Ruby's regular expression. A regexp is compiled into its own intermediate
* representation. This one holds that info. Regexp "match" operation then
* executes that IR.
*/
struct RRegexp {
/** Basic part, including flags and class. */
struct RBasic basic;
/**
* The pattern buffer. This is a quasi-opaque struct that holds compiled
* intermediate representation of the regular expression.
*
* @note Compilation of a regexp could be delayed until actual match.
*/
struct re_pattern_buffer *ptr;
/** Source code of this expression. */
const VALUE src;
/**
* Reference count. A regexp match can take extraordinarily long time to
* run. Ruby's regular expression is heavily extended and not a regular
* language any longer; runs in NP-time in practice. Now, Ruby also has
* threads and GVL. In order to prevent long GVL lockup, our regexp engine
* can release it on occasions. This means that multiple threads can touch
* a regular expressions at once. That itself is okay. But their cleanup
* phase shall wait for all the concurrent runs, to prevent use-after-free
* situation. This field is used to count such threads that are executing
* this particular pattern buffer.
*
* @warning Of course, touching this field from extension libraries causes
* catastrophic effects. Just leave it.
*/
unsigned long usecnt;
};
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Convenient getter function.
*
* @param[in] rexp The regular expression in question.
* @return The source code of the regular expression.
* @pre `rexp` must be of ::RRegexp.
*/
static inline VALUE
RREGEXP_SRC(VALUE rexp)
{
RBIMPL_ASSERT_TYPE(rexp, RUBY_T_REGEXP);
VALUE ret = RREGEXP(rexp)->src;
RBIMPL_ASSERT_TYPE(ret, RUBY_T_STRING);
return ret;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Convenient getter function.
*
* @param[in] rexp The regular expression in question.
* @return The source code of the regular expression, in C's string.
* @pre `rexp` must be of ::RRegexp.
*
* @internal
*
* It seems nobody uses this function in the wild. Subject to hide?
*/
static inline char *
RREGEXP_SRC_PTR(VALUE rexp)
{
return RSTRING_PTR(RREGEXP_SRC(rexp));
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Convenient getter function.
*
* @param[in] rexp The regular expression in question.
* @return The length of the source code of the regular expression.
* @pre `rexp` must be of ::RRegexp.
*
* @internal
*
* It seems nobody uses this function in the wild. Subject to hide?
*/
static inline long
RREGEXP_SRC_LEN(VALUE rexp)
{
return RSTRING_LEN(RREGEXP_SRC(rexp));
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Convenient getter function.
*
* @param[in] rexp The regular expression in question.
* @return The end of the source code of the regular expression.
* @pre `rexp` must be of ::RRegexp.
*
* @internal
*
* It seems nobody uses this function in the wild. Subject to hide?
*/
static inline char *
RREGEXP_SRC_END(VALUE rexp)
{
return RSTRING_END(RREGEXP_SRC(rexp));
}
#endif /* RBIMPL_RREGEXP_H */

View File

@@ -0,0 +1,578 @@
#ifndef RBIMPL_RSTRING_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RSTRING_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RString.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value_type.h"
#include "ruby/internal/warning_push.h"
#include "ruby/assert.h"
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RString.
* @return The passed object casted to ::RString.
*/
#define RSTRING(obj) RBIMPL_CAST((struct RString *)(obj))
/** @cond INTERNAL_MACRO */
#define RSTRING_NOEMBED RSTRING_NOEMBED
#if !USE_RVARGC
#define RSTRING_EMBED_LEN_MASK RSTRING_EMBED_LEN_MASK
#define RSTRING_EMBED_LEN_SHIFT RSTRING_EMBED_LEN_SHIFT
#define RSTRING_EMBED_LEN_MAX RSTRING_EMBED_LEN_MAX
#endif
#define RSTRING_FSTR RSTRING_FSTR
#define RSTRING_EMBED_LEN RSTRING_EMBED_LEN
#define RSTRING_LEN RSTRING_LEN
#define RSTRING_LENINT RSTRING_LENINT
#define RSTRING_PTR RSTRING_PTR
#define RSTRING_END RSTRING_END
/** @endcond */
/**
* @name Conversion of Ruby strings into C's
*
* @{
*/
/**
* Ensures that the parameter object is a String. This is done by calling its
* `to_str` method.
*
* @param[in,out] v Arbitrary Ruby object.
* @exception rb_eTypeError No implicit conversion defined.
* @post `v` is a String.
*/
#define StringValue(v) rb_string_value(&(v))
/**
* Identical to #StringValue, except it returns a `char*`.
*
* @param[in,out] v Arbitrary Ruby object.
* @exception rb_eTypeError No implicit conversion defined.
* @return Converted Ruby string's backend C string.
* @post `v` is a String.
*/
#define StringValuePtr(v) rb_string_value_ptr(&(v))
/**
* Identical to #StringValuePtr, except it additionally checks for the contents
* for viability as a C string. Ruby can accept wider range of contents as
* strings, compared to C. This function is to check that.
*
* @param[in,out] v Arbitrary Ruby object.
* @exception rb_eTypeError No implicit conversion defined.
* @exception rb_eArgError String is not C-compatible.
* @return Converted Ruby string's backend C string.
* @post `v` is a String.
*/
#define StringValueCStr(v) rb_string_value_cstr(&(v))
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define SafeStringValue(v) StringValue(v)
/**
* Identical to #StringValue, except it additionally converts the string's
* encoding to default external encoding. Ruby has a concept called encodings.
* A string can have different encoding than the environment expects. Someone
* has to make sure its contents be converted to something suitable. This is
* that routine. Call it when necessary.
*
* @param[in,out] v Arbitrary Ruby object.
* @exception rb_eTypeError No implicit conversion defined.
* @return Converted Ruby string's backend C string.
* @post `v` is a String.
*
* @internal
*
* Not sure but it seems this macro does not raise on encoding
* incompatibilities? Doesn't sound right to @shyouhei.
*/
#define ExportStringValue(v) do { \
StringValue(v); \
(v) = rb_str_export(v); \
} while (0)
/** @} */
/**
* @private
*
* Bits that you can set to ::RBasic::flags.
*
* @warning These enums are not the only bits we use for strings.
*
* @internal
*
* Actually all bits through FL_USER1 to FL_USER19 are used for strings. Why
* only this tiny part of them are made public here? @shyouhei can find no
* reason.
*/
enum ruby_rstring_flags {
/**
* This flag has something to do with memory footprint. If the string is
* short enough, ruby tries to be creative to abuse padding bits of struct
* ::RString for storing contents. If this flag is set that string does
* _not_ do that, to resort to good old fashioned external allocation
* strategy instead.
*
* @warning This bit has to be considered read-only. Setting/clearing
* this bit without corresponding fix up must cause immediate
* SEGV. Also, internal structures of a string change
* dynamically and transparently throughout of its lifetime.
* Don't assume it being persistent.
*
* @internal
*
* 3rd parties must not be aware that there even is more than one way to
* store a string. Might better be hidden.
*/
RSTRING_NOEMBED = RUBY_FL_USER1,
#if !USE_RVARGC
/**
* When a string employs embedded strategy (see ::RSTRING_NOEMBED), these
* bits are used to store the number of bytes actually filled into
* ::RString::ary.
*
* @internal
*
* 3rd parties must not be aware that there even is more than one way to
* store a string. Might better be hidden.
*/
RSTRING_EMBED_LEN_MASK = RUBY_FL_USER2 | RUBY_FL_USER3 | RUBY_FL_USER4 |
RUBY_FL_USER5 | RUBY_FL_USER6,
#endif
/* Actually, string encodings are also encoded into the flags, using
* remaining bits.*/
/**
* This flag has something to do with infamous "f"string. What is a
* fstring? Well it is a special subkind of strings that is immutable,
* deduped globally, and managed by our GC. It is much like a Symbol (in
* fact Symbols are dynamic these days and are backended using fstrings).
* This concept has been silently introduced at some point in 2.x era.
* Since then it gained wider acceptance in the core. But extension
* libraries could not know that until very recently. Strings of this flag
* live in a special Limbo deep inside of the interpreter. Never try to
* manipulate it by hand.
*
* @internal
*
* Fstrings are not the only variant strings that we implement today.
* Other things are behind-the-scene. This is the only one that is visible
* from extension library. There is no clear reason why it has to be.
* Given there are more "polite" ways to create fstrings, it seems this bit
* need not be exposed to extension libraries. Might better be hidden.
*/
RSTRING_FSTR = RUBY_FL_USER17
};
#if !USE_RVARGC
/**
* This is an enum because GDB wants it (rather than a macro). People need not
* bother.
*/
enum ruby_rstring_consts {
/** Where ::RSTRING_EMBED_LEN_MASK resides. */
RSTRING_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 2,
/** Max possible number of characters that can be embedded. */
RSTRING_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(char) - 1
};
#endif
/**
* Ruby's String. A string in ruby conceptually has these information:
*
* - Encoding of the string.
* - Length of the string.
* - Contents of the string.
*
* It is worth noting that a string is _not_ an array of characters in ruby.
* It has never been. In 1.x a string was an array of integers. Since 2.x a
* string is no longer an array of anything. A string is a string -- just like
* a Time is not an integer.
*/
struct RString {
/** Basic part, including flags and class. */
struct RBasic basic;
/** String's specific fields. */
union {
/**
* Strings that use separated memory region for contents use this
* pattern.
*/
struct {
/**
* Length of the string, not including terminating NUL character.
*
* @note This is in bytes.
*/
long len;
/**
* Pointer to the contents of the string. In the old days each
* string had dedicated memory regions. That is no longer true
* today, but there still are strings of such properties. This
* field could be used to point such things.
*/
char *ptr;
/** Auxiliary info. */
union {
/**
* Capacity of `*ptr`. A continuous memory region of at least
* `capa` bytes is expected to exist at `*ptr`. This can be
* bigger than `len`.
*/
long capa;
/**
* Parent of the string. Nowadays strings can share their
* contents each other, constructing gigantic nest of objects.
* This situation is called "shared", and this is the field to
* control such properties.
*/
VALUE shared;
} aux;
} heap;
/** Embedded contents. */
struct {
#if USE_RVARGC
long len;
/* This is a length 1 array because:
* 1. GCC has a bug that does not optimize C flexible array members
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
* 2. Zero length arrays are not supported by all compilers
*/
char ary[1];
#else
/**
* When a string is short enough, it uses this area to store the
* contents themselves. This was impractical in the 20th century,
* but these days 64 bit machines can typically hold 24 bytes here.
* Could be sufficiently large. In this case the length is encoded
* into the flags.
*/
char ary[RSTRING_EMBED_LEN_MAX + 1];
#endif
} embed;
} as;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Identical to rb_check_string_type(), except it raises exceptions in case of
* conversion failures.
*
* @param[in] obj Target object.
* @exception rb_eTypeError No implicit conversion to String.
* @return Return value of `obj.to_str`.
* @see rb_io_get_io
* @see rb_ary_to_ary
*/
VALUE rb_str_to_str(VALUE obj);
/**
* Identical to rb_str_to_str(), except it fills the passed pointer with the
* converted object.
*
* @param[in,out] ptr Pointer to a variable of target object.
* @exception rb_eTypeError No implicit conversion to String.
* @return Return value of `obj.to_str`.
* @post `*ptr` is the return value.
*/
VALUE rb_string_value(volatile VALUE *ptr);
/**
* Identical to rb_str_to_str(), except it returns the converted string's
* backend memory region.
*
* @param[in,out] ptr Pointer to a variable of target object.
* @exception rb_eTypeError No implicit conversion to String.
* @post `*ptr` is the return value of `obj.to_str`.
* @return Pointer to the contents of the return value.
*/
char *rb_string_value_ptr(volatile VALUE *ptr);
/**
* Identical to rb_string_value_ptr(), except it additionally checks for the
* contents for viability as a C string. Ruby can accept wider range of
* contents as strings, compared to C. This function is to check that.
*
* @param[in,out] ptr Pointer to a variable of target object.
* @exception rb_eTypeError No implicit conversion to String.
* @exception rb_eArgError String is not C-compatible.
* @post `*ptr` is the return value of `obj.to_str`.
* @return Pointer to the contents of the return value.
*/
char *rb_string_value_cstr(volatile VALUE *ptr);
/**
* Identical to rb_str_to_str(), except it additionally converts the string
* into default external encoding. Ruby has a concept called encodings. A
* string can have different encoding than the environment expects. Someone
* has to make sure its contents be converted to something suitable. This is
* that routine. Call it when necessary.
*
* @param[in] obj Target object.
* @exception rb_eTypeError No implicit conversion to String.
* @return Converted ruby string of default external encoding.
*/
VALUE rb_str_export(VALUE obj);
/**
* Identical to rb_str_export(), except it converts into the locale encoding
* instead.
*
* @param[in] obj Target object.
* @exception rb_eTypeError No implicit conversion to String.
* @return Converted ruby string of locale encoding.
*/
VALUE rb_str_export_locale(VALUE obj);
RBIMPL_ATTR_ERROR(("rb_check_safe_str() and Check_SafeStr() are obsolete; use StringValue() instead"))
/**
* @private
*
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*/
void rb_check_safe_str(VALUE);
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define Check_SafeStr(v) rb_check_safe_str(RBIMPL_CAST((VALUE)(v)))
/**
* @private
*
* Prints diagnostic message to stderr when RSTRING_PTR or RSTRING_END
* is NULL.
*
* @param[in] func The function name where encountered NULL pointer.
*/
void rb_debug_rstring_null_ptr(const char *func);
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the length of the string.
*
* @param[in] str String in question.
* @return Its length, in bytes.
* @pre `str` must be an instance of ::RString, and must has its
* ::RSTRING_NOEMBED flag off.
*
* @internal
*
* This was a macro before. It was inevitable to be public, since macros are
* global constructs. But should it be forever? Now that it is a function,
* @shyouhei thinks it could just be eliminated, hidden into implementation
* details.
*/
static inline long
RSTRING_EMBED_LEN(VALUE str)
{
RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING);
RBIMPL_ASSERT_OR_ASSUME(! RB_FL_ANY_RAW(str, RSTRING_NOEMBED));
#if USE_RVARGC
long f = RSTRING(str)->as.embed.len;
return f;
#else
VALUE f = RBASIC(str)->flags;
f &= RSTRING_EMBED_LEN_MASK;
f >>= RSTRING_EMBED_LEN_SHIFT;
return RBIMPL_CAST((long)f);
#endif
}
RBIMPL_WARNING_PUSH()
#if RBIMPL_COMPILER_IS(Intel)
RBIMPL_WARNING_IGNORED(413)
#endif
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* @private
*
* "Expands" an embedded string into an ordinal one. This is a function that
* returns aggregated type. The returned struct always has its `as.heap.len`
* an `as.heap.ptr` fields set appropriately.
*
* This is an implementation detail that 3rd parties should never bother.
*/
static inline struct RString
rbimpl_rstring_getmem(VALUE str)
{
RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING);
if (RB_FL_ANY_RAW(str, RSTRING_NOEMBED)) {
return *RSTRING(str);
}
else {
/* Expecting compilers to optimize this on-stack struct away. */
struct RString retval;
retval.as.heap.len = RSTRING_EMBED_LEN(str);
retval.as.heap.ptr = RSTRING(str)->as.embed.ary;
return retval;
}
}
RBIMPL_WARNING_POP()
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the length of the string.
*
* @param[in] str String in question.
* @return Its length, in bytes.
* @pre `str` must be an instance of ::RString.
*/
static inline long
RSTRING_LEN(VALUE str)
{
return rbimpl_rstring_getmem(str).as.heap.len;
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the contents pointer of the string.
*
* @param[in] str String in question.
* @return Pointer to its contents.
* @pre `str` must be an instance of ::RString.
*/
static inline char *
RSTRING_PTR(VALUE str)
{
char *ptr = rbimpl_rstring_getmem(str).as.heap.ptr;
if (RB_UNLIKELY(! ptr)) {
/* :BEWARE: @shyouhei thinks that currently, there are rooms for this
* function to return NULL. In the 20th century that was a pointless
* concern. However struct RString can hold fake strings nowadays. It
* seems no check against NULL are exercised around handling of them
* (one of such usages is located in marshal.c, which scares
* @shyouhei). Better check here for maximum safety.
*
* Also, this is not rb_warn() because RSTRING_PTR() can be called
* during GC (see what obj_info() does). rb_warn() needs to allocate
* Ruby objects. That is not possible at this moment. */
rb_debug_rstring_null_ptr("RSTRING_PTR");
}
return ptr;
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Queries the end of the contents pointer of the string.
*
* @param[in] str String in question.
* @return Pointer to its end of contents.
* @pre `str` must be an instance of ::RString.
*/
static inline char *
RSTRING_END(VALUE str)
{
struct RString buf = rbimpl_rstring_getmem(str);
if (RB_UNLIKELY(! buf.as.heap.ptr)) {
/* Ditto. */
rb_debug_rstring_null_ptr("RSTRING_END");
}
return &buf.as.heap.ptr[buf.as.heap.len];
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Identical to RSTRING_LEN(), except it differs for the return type.
*
* @param[in] str String in question.
* @exception rb_eRangeError Too long.
* @return Its length, in bytes.
* @pre `str` must be an instance of ::RString.
*
* @internal
*
* This API seems redundant but has actual usages.
*/
static inline int
RSTRING_LENINT(VALUE str)
{
return rb_long2int(RSTRING_LEN(str));
}
/**
* Convenient macro to obtain the contents and length at once.
*
* @param str String in question.
* @param ptrvar Variable where its contents is stored.
* @param lenvar Variable where its length is stored.
*/
#ifdef HAVE_STMT_AND_DECL_IN_EXPR
# define RSTRING_GETMEM(str, ptrvar, lenvar) \
__extension__ ({ \
struct RString rbimpl_str = rbimpl_rstring_getmem(str); \
(ptrvar) = rbimpl_str.as.heap.ptr; \
(lenvar) = rbimpl_str.as.heap.len; \
})
#else
# define RSTRING_GETMEM(str, ptrvar, lenvar) \
((ptrvar) = RSTRING_PTR(str), \
(lenvar) = RSTRING_LEN(str))
#endif /* HAVE_STMT_AND_DECL_IN_EXPR */
#endif /* RBIMPL_RSTRING_H */

View File

@@ -0,0 +1,121 @@
#ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RSTRUCT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate struct RStruct.
* @note The struct RStruct itself is opaque.
*/
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/arithmetic/int.h"
#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
# include "ruby/backward.h"
#endif
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*
* @internal
*
* Declaration of rb_struct_ptr() is at include/ruby/backward.h.
*/
#define RSTRUCT_PTR(st) rb_struct_ptr(st)
/** @cond INTERNAL_MACRO */
#define RSTRUCT_LEN RSTRUCT_LEN
#define RSTRUCT_SET RSTRUCT_SET
#define RSTRUCT_GET RSTRUCT_GET
/** @endcond */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Returns the number of struct members.
*
* @param[in] st An instance of RStruct.
* @return The number of members of `st`.
* @pre `st` must be of ::RUBY_T_STRUCT.
*/
VALUE rb_struct_size(VALUE st);
/**
* Resembles `Struct#[]`.
*
* @param[in] st An instance of RStruct.
* @param[in] k Index a.k.a. key of the struct.
* @exception rb_eTypeError `k` is neither Numeric, Symbol, nor String.
* @exception rb_eIndexError Numerical index out of range.
* @exception rb_eNameError No such key.
* @return The member stored at `k` in `st`.
* @pre `st` must be of ::RUBY_T_STRUCT.
*/
VALUE rb_struct_aref(VALUE st, VALUE k);
/**
* Resembles `Struct#[]=`.
*
* @param[out] st An instance of RStruct.
* @param[in] k Index a.k.a. key of the struct.
* @param[in] v Value to store.
* @exception rb_eTypeError `k` is neither Numeric, Symbol, nor String.
* @exception rb_eIndexError Numerical index out of range.
* @exception rb_eNameError No such key.
* @return Passed `v`.
* @pre `st` must be of ::RUBY_T_STRUCT.
* @post `v` is stored at `k` in `st`.
*/
VALUE rb_struct_aset(VALUE st, VALUE k, VALUE v);
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_ARTIFICIAL()
/** @copydoc rb_struct_size() */
static inline long
RSTRUCT_LEN(VALUE st)
{
RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
return RB_NUM2LONG(rb_struct_size(st));
}
RBIMPL_ATTR_ARTIFICIAL()
/** @copydoc rb_struct_aset() */
static inline VALUE
RSTRUCT_SET(VALUE st, int k, VALUE v)
{
RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
return rb_struct_aset(st, INT2NUM(k), (v));
}
RBIMPL_ATTR_ARTIFICIAL()
/** @copydoc rb_struct_aref() */
static inline VALUE
RSTRUCT_GET(VALUE st, int k)
{
RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
return rb_struct_aref(st, INT2NUM(k));
}
#endif /* RBIMPL_RSTRUCT_H */

View File

@@ -0,0 +1,604 @@
#ifndef RBIMPL_RTYPEDDATA_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RTYPEDDATA_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RTypedData.
*/
#include "ruby/internal/config.h"
#ifdef STDC_HEADERS
# include <stddef.h>
#endif
#include "ruby/internal/assume.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/flag_enum.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/core/rdata.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/error.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/stdbool.h"
#include "ruby/internal/value_type.h"
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define HAVE_TYPE_RB_DATA_TYPE_T 1
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define HAVE_RB_DATA_TYPE_T_FUNCTION 1
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define HAVE_RB_DATA_TYPE_T_PARENT 1
/**
* This is a value you can set to ::rb_data_type_struct::dfree. Setting this
* means the data was allocated using ::ruby_xmalloc() (or variants), and shall
* be freed using ::ruby_xfree().
*
* @warning Do not use this if you want to use system malloc, because the
* system and Ruby might or might not share the same malloc
* implementation.
*/
#define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
/**
* This is a value you can set to ::rb_data_type_struct::dfree. Setting this
* means the data is managed by someone else, like, statically allocated. Of
* course you are on your own then.
*/
#define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE
/**
* Convenient casting macro.
*
* @param obj An object, which is in fact an ::RTypedData.
* @return The passed object casted to ::RTypedData.
*/
#define RTYPEDDATA(obj) RBIMPL_CAST((struct RTypedData *)(obj))
/**
* Convenient getter macro.
*
* @param v An object, which is in fact an ::RTypedData.
* @return The passed object's ::RTypedData::data field.
*/
#define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data)
/** @old{rb_check_typeddata} */
#define Check_TypedStruct(v, t) \
rb_check_typeddata(RBIMPL_CAST((VALUE)(v)), (t))
/** @cond INTERNAL_MACRO */
#define RTYPEDDATA_P RTYPEDDATA_P
#define RTYPEDDATA_TYPE RTYPEDDATA_TYPE
#define RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY
#define RUBY_TYPED_FROZEN_SHAREABLE RUBY_TYPED_FROZEN_SHAREABLE
#define RUBY_TYPED_WB_PROTECTED RUBY_TYPED_WB_PROTECTED
#define RUBY_TYPED_PROMOTED1 RUBY_TYPED_PROMOTED1
/** @endcond */
/**
* @private
*
* Bits for rb_data_type_struct::flags.
*/
enum
RBIMPL_ATTR_FLAG_ENUM()
rbimpl_typeddata_flags {
/**
* This flag has something to do with Ruby's global interpreter lock. For
* maximum safety, Ruby locks the entire VM during GC. However your
* callback functions could unintentionally unlock it, for instance when
* they try to flush an IO buffer. Such operations are dangerous (threads
* then run alongside of GC). By default, to prevent those scenario,
* callbacks are deferred until the GC engine is 100% sure threads can run.
* This flag skips that; structs with it are deallocated during the sweep
* phase.
*
* Using this flag needs deep understanding of both GC and threads. You
* would better leave it unspecified.
*/
RUBY_TYPED_FREE_IMMEDIATELY = 1,
/**
* This flag has something to do with Ractor. Multiple Ractors run without
* protecting each other. Sharing an object among Ractors is basically
* dangerous, disabled by default. This flag is used to bypass that
* restriction. but setting it is not enough. In addition to do so, an
* object also has to be frozen, and be passed to
* rb_ractor_make_shareable() before being actually shareable. Of course,
* you have to manually prevent race conditions then.
*
* Using this flag needs deep understanding of multithreaded programming.
* You would better leave it unspecified.
*/
RUBY_TYPED_FROZEN_SHAREABLE = RUBY_FL_SHAREABLE,
/**
* This flag has something to do with our garbage collector. These days
* ruby objects are "generational". There are those who are young and
* those who are old. Young objects are prone to die; monitored relatively
* extensively by the garbage collector. OTOH old objects tend to live
* longer. They are relatively rarely considered. This basically works.
* But there is one tweak that has to be exercised. When an elder object
* has reference(s) to younger one(s), that referenced objects must not
* die. In order to detect additions of such references, old generations
* are protected by write barriers. It is a very difficult hack to
* appropriately insert write barriers everywhere. This mechanism is
* disabled by default for 3rd party extensions (they never get aged). By
* specifying this flag you can enable the generational feature to your
* data structure. Of course, you have to manually insert write barriers
* then.
*
* Using this flag needs deep understanding of GC internals, often at the
* level of source code. You would better leave it unspecified.
*/
RUBY_TYPED_WB_PROTECTED = RUBY_FL_WB_PROTECTED, /* THIS FLAG DEPENDS ON Ruby version */
/**
* This flag is mysterious. It seems nobody is currently using it. The
* intention of this flag is also unclear. We need further investigations.
*/
RUBY_TYPED_PROMOTED1 = RUBY_FL_PROMOTED1 /* THIS FLAG DEPENDS ON Ruby version */
};
/**
* This is the struct that holds necessary info for a struct. It roughly
* resembles a Ruby level class; multiple objects can share a ::rb_data_type_t
* instance.
*/
typedef struct rb_data_type_struct rb_data_type_t;
/** @copydoc rb_data_type_t */
struct rb_data_type_struct {
/**
* Name of structs of this kind. This is used for diagnostic purposes.
* This has to be unique in the process, but doesn't has to be a valid
* C/Ruby identifier.
*/
const char *wrap_struct_name;
/** Function pointers. Resembles C++ `vtbl`.*/
struct {
/**
* This function is called when the object is experiencing GC marks.
* If it contains references to other Ruby objects, you need to mark
* them also. Otherwise GC will smash your data.
*
* @see rb_gc_mark()
* @warning This is called during GC runs. Object allocations are
* impossible at that moment (that is why GC runs).
*/
RUBY_DATA_FUNC dmark;
/**
* This function is called when the object is no longer used. You need
* to do whatever necessary to avoid memory leaks.
*
* @warning This is called during GC runs. Object allocations are
* impossible at that moment (that is why GC runs).
*/
RUBY_DATA_FUNC dfree;
/**
* This function is to query the size of the underlying memory regions.
*
* @internal
*
* This function has only one usage, which is form inside of
* `ext/objspace`.
*/
size_t (*dsize)(const void *);
/**
* This function is called when the object is relocated. Like
* ::rb_data_type_struct::dmark, you need to update references to Ruby
* objects inside of your structs.
*
* @see rb_gc_location()
* @warning This is called during GC runs. Object allocations are
* impossible at that moment (that is why GC runs).
*/
RUBY_DATA_FUNC dcompact;
/**
* This field is reserved for future extension. For now, it must be
* filled with zeros.
*/
void *reserved[1]; /* For future extension.
This array *must* be filled with ZERO. */
} function;
/**
* Parent of this class. Sometimes C structs have inheritance-like
* relationships. An example is `struct sockaddr` and its family. If you
* design such things, make ::rb_data_type_t for each of them and connect
* using this field. Ruby can then transparently cast your data back and
* forth when you call #TypedData_Get_Struct().
*
* ```CXX
* struct parent { };
* static inline const rb_data_type_t parent_type = {
* .wrap_struct_name = "parent",
* };
*
* struct child: public parent { };
* static inline const rb_data_type_t child_type = {
* .wrap_struct_name = "child",
* .parent = &parent_type,
* };
*
* // This function can take both parent_class and child_class.
* static inline struct parent *
* get_parent(VALUE v)
* {
* struct parent *p;
* TypedData_Get_Struct(v, parent_type, struct parent, p);
* return p;
* }
* ```
*/
const rb_data_type_t *parent;
/**
* Type-specific static data. This area can be used for any purpose by a
* programmer who define the type. Ruby does not manage this at all.
*/
void *data; /* This area can be used for any purpose
by a programmer who define the type. */
/**
* Type-specific behavioural characteristics. This is a bitfield. It is
* an EXTREMELY WISE IDEA to leave this field blank. It is designed so
* that setting zero is the safest thing to do. If you risk to set any
* bits on, you have to know exactly what you are doing.
*
* @internal
*
* Why it has to be a ::VALUE? @shyouhei doesn't understand the design.
*/
VALUE flags; /* RUBY_FL_WB_PROTECTED */
};
/**
* "Typed" user data. By using this, extension libraries can wrap a C struct
* to make it visible from Ruby. For instance if you have a `struct timeval`,
* and you want users to use it,
*
* ```CXX
* static inline const rb_data_type_t timeval_type = {
* // Note that unspecified fields are 0-filled by default.
* .wrap_struct_name = "timeval",
* .function = {
* .dmark = nullptr, // no need to mark
* .dfree = RUBY_TYPED_DEFAULT_FREE, // use ruby_xfree()
* .dsize = [](auto) {
* return sizeof(struct timeval);
* },
* },
* };
*
* extern "C" void
* Init_timeval(void)
* {
* auto klass = rb_define_class("YourName", rb_cObject);
*
* rb_define_alloc_func(klass, [](auto klass) {
* struct timeval *t;
* auto ret = TypedData_Make_Struct(
* klass, struct timeval, &timeval_type, t);
*
* if (auto i = gettimeofday(t, nullptr); i == -1) {
* rb_sys_fail("gettimeofday(3)");
* }
* else {
* return ret;
* }
* });
* }
* ```
*/
struct RTypedData {
/** The part that all ruby objects have in common. */
struct RBasic basic;
/**
* This field stores various information about how Ruby should handle a
* data. This roughly resembles a Ruby level class (apart from method
* definition etc.)
*/
const rb_data_type_t *type;
/**
* This has to be always 1.
*
* @internal
*
* Why, then, this is not a const ::VALUE?
*/
VALUE typed_flag;
/** Pointer to the actual C level struct that you want to wrap. */
void *data;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
RBIMPL_ATTR_NONNULL((3))
/**
* This is the primitive way to wrap an existing C struct into ::RTypedData.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] datap Pointer to the target C struct.
* @param[in] type The characteristics of the passed data.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return An allocated object that wraps `datap`.
*/
VALUE rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type);
/**
* Identical to rb_data_typed_object_wrap(), except it allocates a new data
* region internally instead of taking an existing one. The allocation is done
* using ruby_calloc(). Hence it makes no sense for `type->function.dfree` to
* be anything other than ::RUBY_TYPED_DEFAULT_FREE.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] size Requested size of memory to allocate.
* @param[in] type The characteristics of the passed data.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return An allocated object that wraps a new `size` byte region.
*/
VALUE rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type);
/**
* Checks for the domestic relationship between the two.
*
* @param[in] child A data type supposed to be a child of `parent`.
* @param[in] parent A data type supposed to be a parent of `child`.
* @retval true `child` is a descendent of `parent`.
* @retval false Otherwise.
*
* @internal
*
* You can path NULL to both arguments, don't know what that means though.
*/
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent);
/**
* Checks if the given object is of given kind.
*
* @param[in] obj An instance of ::RTypedData.
* @param[in] data_type Expected data type of `obj`.
* @retval true `obj` is of `data_type`.
* @retval false Otherwise.
*/
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type);
/**
* Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead
* of returning false.
*
* @param[in] obj An instance of ::RTypedData.
* @param[in] data_type Expected data type of `obj`.
* @exception rb_eTypeError obj is not of `data_type`.
* @return Unwrapped C struct that `obj` holds.
* @post Upon successful return `obj`'s type is guaranteed `data_type`.
*/
void *rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type);
RBIMPL_SYMBOL_EXPORT_END()
/**
* Converts sval, a pointer to your struct, into a Ruby object.
*
* @param klass A ruby level class.
* @param data_type The type of `sval`.
* @param sval A pointer to your struct.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return A created Ruby object.
*/
#define TypedData_Wrap_Struct(klass,data_type,sval)\
rb_data_typed_object_wrap((klass),(sval),(data_type))
/**
* @private
*
* This is an implementation detail of #TypedData_Make_Struct. People don't
* use it directly.
*
* @param result Variable name of created Ruby object.
* @param klass Ruby level class of the object.
* @param type Type name of the C struct.
* @param size Size of the C struct.
* @param data_type The data type describing `type`.
* @param sval Variable name of created C struct.
*/
#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \
VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \
(sval) = RBIMPL_CAST((type *)RTYPEDDATA_DATA(result)); \
RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval))
/**
* Identical to #TypedData_Wrap_Struct, except it allocates a new data region
* internally instead of taking an existing one. The allocation is done using
* ruby_calloc(). Hence it makes no sense for `data_type->function.dfree` to
* be anything other than ::RUBY_TYPED_DEFAULT_FREE.
*
* @param klass Ruby level class of the object.
* @param type Type name of the C struct.
* @param data_type The data type describing `type`.
* @param sval Variable name of created C struct.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return A created Ruby object.
*/
#ifdef HAVE_STMT_AND_DECL_IN_EXPR
#define TypedData_Make_Struct(klass, type, data_type, sval) \
RB_GNUC_EXTENSION({ \
TypedData_Make_Struct0( \
data_struct_obj, \
klass, \
type, \
sizeof(type), \
data_type, \
sval); \
data_struct_obj; \
})
#else
#define TypedData_Make_Struct(klass, type, data_type, sval) \
rb_data_typed_object_make( \
(klass), \
(data_type), \
RBIMPL_CAST((void **)&(sval)), \
sizeof(type))
#endif
/**
* Obtains a C struct from inside of a wrapper Ruby object.
*
* @param obj An instance of ::RTypedData.
* @param type Type name of the C struct.
* @param data_type The data type describing `type`.
* @param sval Variable name of obtained C struct.
* @exception rb_eTypeError `obj` is not a kind of `data_type`.
* @return Unwrapped C struct that `obj` holds.
*/
#define TypedData_Get_Struct(obj,type,data_type,sval) \
((sval) = RBIMPL_CAST((type *)rb_check_typeddata((obj), (data_type))))
RBIMPL_ATTR_PURE()
RBIMPL_ATTR_ARTIFICIAL()
/**
* @private
*
* This is an implementation detail of Check_Type(). People don't use it
* directly.
*
* @param[in] obj Object in question
* @retval true `obj` is an instance of ::RTypedData.
* @retval false `obj` is an instance of ::RData.
* @pre `obj` must be a Ruby object of ::RUBY_T_DATA.
*/
static inline bool
rbimpl_rtypeddata_p(VALUE obj)
{
return RTYPEDDATA(obj)->typed_flag == 1;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Checks whether the passed object is ::RTypedData or ::RData.
*
* @param[in] obj Object in question
* @retval true `obj` is an instance of ::RTypedData.
* @retval false `obj` is an instance of ::RData.
* @pre `obj` must be a Ruby object of ::RUBY_T_DATA.
*/
static inline bool
RTYPEDDATA_P(VALUE obj)
{
#if RUBY_DEBUG
if (RB_UNLIKELY(! RB_TYPE_P(obj, RUBY_T_DATA))) {
Check_Type(obj, RUBY_T_DATA);
RBIMPL_UNREACHABLE_RETURN(false);
}
#endif
return rbimpl_rtypeddata_p(obj);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */
/**
* Queries for the type of given object.
*
* @param[in] obj Object in question
* @return Data type struct that corresponds to `obj`.
* @pre `obj` must be an instance of ::RTypedData.
*/
static inline const struct rb_data_type_struct *
RTYPEDDATA_TYPE(VALUE obj)
{
#if RUBY_DEBUG
if (RB_UNLIKELY(! RTYPEDDATA_P(obj))) {
rb_unexpected_type(obj, RUBY_T_DATA);
RBIMPL_UNREACHABLE_RETURN(NULL);
}
#endif
return RTYPEDDATA(obj)->type;
}
/**
* While we don't stop you from using this function, it seems to be an
* implementation detail of #TypedData_Make_Struct, which is preferred over
* this one.
*
* @param[in] klass Ruby level class of the returning object.
* @param[in] type The data type
* @param[out] datap Return pointer.
* @param[in] size Size of the C struct.
* @exception rb_eTypeError `klass` is not a class.
* @exception rb_eNoMemError Out of memory.
* @return A created Ruby object.
* @post `*datap` points to the C struct wrapped by the returned object.
*/
static inline VALUE
rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)
{
TypedData_Make_Struct0(result, klass, void, size, type, *datap);
return result;
}
RBIMPL_ATTR_DEPRECATED(("by: rb_data_typed_object_wrap"))
/** @deprecated This function was renamed to rb_data_typed_object_wrap(). */
static inline VALUE
rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type)
{
return rb_data_typed_object_wrap(klass, datap, type);
}
#endif /* RBIMPL_RTYPEDDATA_H */

545
libs/libruby/ruby/internal/ctype.h vendored Normal file
View File

@@ -0,0 +1,545 @@
#ifndef RBIMPL_CTYPE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_CTYPE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Our own, locale independent, character handling routines.
*/
#include "ruby/internal/config.h"
#ifdef STDC_HEADERS
# include <ctype.h>
#endif
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
/**
* @name Old character classification macros
*
* What is this #ISPRINT business? Well, according to our VCS and some
* internet surfing, it appears that the initial intent of these macros were to
* mimic codes appear in common in several GNU projects. As far as @shyouhei
* detects they seem to originate GNU regex (that standalone one rather than
* Gnulib or Glibc), and at least date back to 1995.
*
* Let me lawfully quote from a GNU coreutils commit
* https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=49803907f5dbd7646184a8912c9db9b09dcd0f22
*
* > Jim Meyering writes:
* >
* > "... Some ctype macros are valid only for character codes that
* > isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
* > using /bin/cc or gcc but without giving an ansi option). So, all
* > ctype uses should be through macros like ISPRINT... If
* > STDC_HEADERS is defined, then autoconf has verified that the ctype
* > macros don't need to be guarded with references to isascii. ...
* > Defining isascii to 1 should let any compiler worth its salt
* > eliminate the && through constant folding."
* >
* > Bruno Haible adds:
* >
* > "... Furthermore, isupper(c) etc. have an undefined result if c is
* > outside the range -1 <= c <= 255. One is tempted to write isupper(c)
* > with c being of type `char', but this is wrong if c is an 8-bit
* > character >= 128 which gets sign-extended to a negative value.
* > The macro ISUPPER protects against this as well."
*
* So the intent was to reroute old problematic systems that no longer exist.
* At the same time the problems described above no longer hurt us, because we
* decided to completely avoid using system-provided isupper etc. to reinvent
* the wheel. These macros are entirely legacy; please ignore them.
*
* But let me also put stress that GNU people are wise; they use those macros
* only inside of their own implementations and never let them be public. On
* the other hand ruby has thoughtlessly publicised them to 3rd party libraries
* since its beginning, which is a very bad idea. These macros are too easy to
* get conflicted with definitions elsewhere.
*
* New programs should stick to the `rb_` prefixed names.
*
* @note It seems we just mimic the API. We do not share their implementation
* with GPL-ed programs.
*
* @{
*/
#ifndef ISPRINT
# define ISASCII rb_isascii /**< @old{rb_isascii}*/
# define ISPRINT rb_isprint /**< @old{rb_isprint}*/
# define ISGRAPH rb_isgraph /**< @old{rb_isgraph}*/
# define ISSPACE rb_isspace /**< @old{rb_isspace}*/
# define ISUPPER rb_isupper /**< @old{rb_isupper}*/
# define ISLOWER rb_islower /**< @old{rb_islower}*/
# define ISALNUM rb_isalnum /**< @old{rb_isalnum}*/
# define ISALPHA rb_isalpha /**< @old{rb_isalpha}*/
# define ISDIGIT rb_isdigit /**< @old{rb_isdigit}*/
# define ISXDIGIT rb_isxdigit /**< @old{rb_isxdigit}*/
# define ISBLANK rb_isblank /**< @old{rb_isblank}*/
# define ISCNTRL rb_iscntrl /**< @old{rb_iscntrl}*/
# define ISPUNCT rb_ispunct /**< @old{rb_ispunct}*/
#endif
#define TOUPPER rb_toupper /**< @old{rb_toupper}*/
#define TOLOWER rb_tolower /**< @old{rb_tolower}*/
#define STRCASECMP st_locale_insensitive_strcasecmp /**< @old{st_locale_insensitive_strcasecmp}*/
#define STRNCASECMP st_locale_insensitive_strncasecmp /**< @old{st_locale_insensitive_strncasecmp}*/
#define STRTOUL ruby_strtoul /**< @old{ruby_strtoul}*/
/** @} */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/** @name locale insensitive functions
* @{
*/
/* In descriptions below, `the POSIX Locale` and `the "C" locale` are tactfully
* used as to whether the described function mimics POSIX or C99. */
RBIMPL_ATTR_NONNULL(())
/**
* Our own locale-insensitive version of `strcasecmp(3)`. The "case" here
* always means that of the POSIX Locale. It doesn't depend on runtime locale
* settings.
*
* @param[in] s1 Comparison LHS.
* @param[in] s2 Comparison RHS.
* @retval -1 `s1` is "less" than `s2`.
* @retval 0 Both strings converted into lowercase would be identical.
* @retval 1 `s1` is "greater" than `s2`.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
*/
int st_locale_insensitive_strcasecmp(const char *s1, const char *s2);
RBIMPL_ATTR_NONNULL(())
/**
* Our own locale-insensitive version of `strcnasecmp(3)`. The "case" here
* always means that of the POSIX Locale. It doesn't depend on runtime locale
* settings.
*
* @param[in] s1 Comparison LHS.
* @param[in] s2 Comparison RHS.
* @param[in] n Comparison shall stop after first `n` bytes are scanned.
* @retval -1 `s1` is "less" than `s2`.
* @retval 0 Both strings converted into lowercase would be identical.
* @retval 1 `s1` is "greater" than `s2`.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning This function is _not_ timing safe.
*/
int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n);
RBIMPL_ATTR_NONNULL((1))
/**
* Our own locale-insensitive version of `strtoul(3)`. The conversion is done
* as if the current locale is set to the "C" locale, no matter actual runtime
* locale settings.
*
* @note This is needed because `strtoul("i", 0, 36)` would return zero
* if it is locale sensitive and the current locale is `tr_TR`.
* @param[in] str String of digits, optionally preceded with whitespaces
* (ignored) and optionally `+` or `-` sign.
* @param[out] endptr NULL, or an arbitrary pointer (overwritten on return).
* @param[in] base `2` to `36` inclusive for each base, or special case
* `0` to detect the base from the contents of the string.
* @return Converted integer, casted to unsigned long.
* @post If `endptr` is not NULL, it is updated to point the first such
* byte where conversion failed.
* @note This function sets `errno` on failure.
* - `EINVAL`: Passed `base` is out of range.
* - `ERANGE`: Converted integer is out of range of `long`.
* @warning As far as @shyouhei reads ISO/IEC 9899:2018 section 7.22.1.4, a
* conforming `strtoul` implementation shall render `ERANGE`
* whenever it finds the input string represents a negative
* integer. Such thing can never be representable using `unsigned
* long`. However this implementation does not honour that
* language. It just casts such negative value to the return
* type, resulting a very big return value. This behaviour is at
* least questionable. But we can no longer change that at this
* point.
* @note Not only does this function works under the "C" locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
*/
unsigned long ruby_strtoul(const char *str, char **endptr, int base);
RBIMPL_SYMBOL_EXPORT_END()
/*
* We are making the functions below to return `int` instead of `bool`. They
* have been as such since their birth at 5f237d79033b2109afb768bc889611fa9630.
*/
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isascii(3)`.
*
* @param[in] c Byte in question to query.
* @retval false `c` is out of range of ASCII character set.
* @retval true Yes it is.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isascii(int c)
{
return '\0' <= c && c <= '\x7f';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isupper(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "upper".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isupper(int c)
{
return 'A' <= c && c <= 'Z';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `islower(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "lower".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_islower(int c)
{
return 'a' <= c && c <= 'z';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isalpha(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in either IEEE 1003.1 section 7.3.1.1
* "upper" or "lower".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isalpha(int c)
{
return rb_isupper(c) || rb_islower(c);
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isdigit(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "digit".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isdigit(int c)
{
return '0' <= c && c <= '9';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isalnum(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in either IEEE 1003.1 section 7.3.1.1
* "upper", "lower", or "digit".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isalnum(int c)
{
return rb_isalpha(c) || rb_isdigit(c);
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isxdigit(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "xdigit".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isxdigit(int c)
{
return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isblank(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "blank".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isblank(int c)
{
return c == ' ' || c == '\t';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isspace(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "space".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isspace(int c)
{
return c == ' ' || ('\t' <= c && c <= '\r');
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `iscntrl(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "cntrl".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_iscntrl(int c)
{
return ('\0' <= c && c < ' ') || c == '\x7f';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Identical to rb_isgraph(), except it also returns true for `' '`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in either IEEE 1003.1 section 7.3.1.1
* "upper", "lower", "digit", "punct", or a `' '`.
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isprint(int c)
{
return ' ' <= c && c <= '\x7e';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `ispunct(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in IEEE 1003.1 section 7.3.1.1 "punct".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_ispunct(int c)
{
return !rb_isalnum(c);
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `isgraph(3)`.
*
* @param[in] c Byte in question to query.
* @retval true `c` is listed in either IEEE 1003.1 section 7.3.1.1
* "upper", "lower", "digit", or "punct".
* @retval false Anything else.
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_isgraph(int c)
{
return '!' <= c && c <= '\x7e';
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `tolower(3)`.
*
* @param[in] c Byte in question to convert.
* @retval c The byte is not listed in in IEEE 1003.1 section
* 7.3.1.1 "upper".
* @retval otherwise Byte converted using the map defined in IEEE 1003.1
* section 7.3.1 "tolower".
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_tolower(int c)
{
return rb_isupper(c) ? (c|0x20) : c;
}
RBIMPL_ATTR_CONST()
RBIMPL_ATTR_CONSTEXPR(CXX11)
RBIMPL_ATTR_ARTIFICIAL()
/**
* Our own locale-insensitive version of `toupper(3)`.
*
* @param[in] c Byte in question to convert.
* @retval c The byte is not listed in in IEEE 1003.1 section
* 7.3.1.1 "lower".
* @retval otherwise Byte converted using the map defined in IEEE 1003.1
* section 7.3.1 "toupper".
* @note Not only does this function works under the POSIX Locale, but
* also assumes its execution character set be what ruby calls an
* ASCII-compatible character set; which does not include for
* instance EBCDIC or UTF-16LE.
* @warning `c` is an int. This means that when you pass a `char` value
* here, it experiences "integer promotion" as defined in ISO/IEC
* 9899:2018 section 6.3.1.1 paragraph 1.
*/
static inline int
rb_toupper(int c)
{
return rb_islower(c) ? (c&0x5f) : c;
}
/** @} */
#endif /* RBIMPL_CTYPE_H */

112
libs/libruby/ruby/internal/dllexport.h vendored Normal file
View File

@@ -0,0 +1,112 @@
#ifndef RBIMPL_DLLEXPORT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_DLLEXPORT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Tweaking visibility of C variables/functions.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/compiler_is.h"
/**
* Declaration of externally visible global variables. Here "externally" means
* they should be visible from extension libraries. Depending on operating
* systems (dynamic linkers, to be precise), global variables inside of a DLL
* may or may not be visible form outside of that DLL by default. This
* declaration manually tweaks that default and ensures the declared variable
* be truly globally visible.
*
* ```CXX
* extern VALUE foo; // hidden on some OS
* RUBY_EXTERN VALUE foo; // ensure visible
* ```
*/
#undef RUBY_EXTERN
#if defined(MJIT_HEADER) && defined(_WIN32)
# define RUBY_EXTERN extern __declspec(dllimport)
#elif defined(RUBY_EXPORT)
# define RUBY_EXTERN extern
#elif defined(_WIN32)
# define RUBY_EXTERN extern __declspec(dllimport)
#else
# define RUBY_EXTERN extern
#endif
#ifndef RUBY_SYMBOL_EXPORT_BEGIN
# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
#endif
#ifndef RUBY_SYMBOL_EXPORT_END
# define RUBY_SYMBOL_EXPORT_END /* end */
#endif
#ifndef RUBY_FUNC_EXPORTED
# define RUBY_FUNC_EXPORTED /* void */
#endif
/**
* @cond INTERNAL_MACRO
*
* These MJIT related macros are placed here because translate_mjit_header can
* need them. Extension libraries should not touch.
*/
/* These macros are used for functions which are exported only for MJIT
and NOT ensured to be exported in future versions. */
#if ! defined(MJIT_HEADER)
# define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED
#elif ! RBIMPL_COMPILER_IS(MSVC)
# define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED
#else
# define MJIT_FUNC_EXPORTED static
#endif
#define MJIT_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN
#define MJIT_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END
/* On mswin, MJIT header transformation can't be used since cl.exe can't output
preprocessed output preserving macros. So this `MJIT_STATIC` is needed
to force non-static function to static on MJIT header to avoid symbol conflict. */
#ifdef MJIT_HEADER
# define MJIT_STATIC static
#else
# define MJIT_STATIC
#endif
/** @endcond */
/** Shortcut macro equivalent to `RUBY_SYMBOL_EXPORT_BEGIN extern "C" {`.
* \@shyouhei finds it handy. */
#if defined(__DOXYGEN__)
# define RBIMPL_SYMBOL_EXPORT_BEGIN() /* void */
#elif defined(__cplusplus)
# define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN extern "C" {
#else
# define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN
#endif
/** Counterpart of #RBIMPL_SYMBOL_EXPORT_BEGIN */
#if defined(__DOXYGEN__)
# define RBIMPL_SYMBOL_EXPORT_END() /* void */
#elif defined(__cplusplus)
# define RBIMPL_SYMBOL_EXPORT_END() } RUBY_SYMBOL_EXPORT_END
#else
# define RBIMPL_SYMBOL_EXPORT_END() RUBY_SYMBOL_EXPORT_END
#endif
#endif /* RBIMPL_DLLEXPORT_H */

89
libs/libruby/ruby/internal/dosish.h vendored Normal file
View File

@@ -0,0 +1,89 @@
#ifndef RBIMPL_DOSISH_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_DOSISH_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Support for so-called dosish systems.
*/
#ifdef __CYGWIN__
#undef _WIN32
#endif
#if defined(_WIN32)
/*
DOSISH mean MS-Windows style filesystem.
But you should use more precise macros like DOSISH_DRIVE_LETTER, PATH_SEP,
ENV_IGNORECASE or CASEFOLD_FILESYSTEM.
*/
#define DOSISH 1
# define DOSISH_DRIVE_LETTER
#endif
#ifdef _WIN32
#include "ruby/win32.h"
#endif
/** The delimiter of `PATH` environment variable. */
#if defined(DOSISH)
#define PATH_SEP ";"
#else
#define PATH_SEP ":"
#endif
/** Identical to #PATH_SEP, except it is of type `char`. */
#define PATH_SEP_CHAR PATH_SEP[0]
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*
* @internal
*
* For historical interests: there was an operating system called Human68k
* which used an environment variable called `"path"` for this purpose.
*/
#define PATH_ENV "PATH"
#if defined(DOSISH)
#define ENV_IGNORECASE
#endif
/**
* Stone age assumption was that an operating system supports only one file
* system at a moment. This macro was to detect if such (one and only) file
* system has case sensitivity. This assumption is largely not true any
* longer; most operating systems can mount many kinds of file systems side by
* side. Also there are file systems that do or do not ignore cases depending
* on configuration (e.g. EXT4's `casefold` feature).
*
* This macro is still used internally (for instance Ruby level constant
* `File::FNM_SYSCASE` depends on it), but it is basically a wrong idea for you
* to use it today. Please just find another way.
*/
#ifndef CASEFOLD_FILESYSTEM
# if defined DOSISH
# define CASEFOLD_FILESYSTEM 1
# else
# define CASEFOLD_FILESYSTEM 0
# endif
#endif
#endif /* RBIMPL_DOSISH_H */

View File

@@ -0,0 +1,202 @@
#ifndef RUBY_INTERNAL_ENCODING_CODERANGE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_CODERANGE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines for code ranges.
*/
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/** What rb_enc_str_coderange() returns. */
enum ruby_coderange_type {
/** The object's coderange is unclear yet. */
RUBY_ENC_CODERANGE_UNKNOWN = 0,
/** The object holds 0 to 127 inclusive and nothing else. */
RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8),
/** The object's encoding and contents are consistent each other */
RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9),
/** The object holds invalid/malformed/broken character(s). */
RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)),
/** Where the coderange resides. */
RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT|
RUBY_ENC_CODERANGE_VALID|
RUBY_ENC_CODERANGE_BROKEN)
};
RBIMPL_ATTR_CONST()
/**
* @private
*
* This is an implementation detail of #RB_ENC_CODERANGE_CLEAN_P. People don't
* use it directly.
*
* @param[in] cr An enum ::ruby_coderange_type.
* @retval 1 It is.
* @retval 0 It isn't.
*/
static inline int
rb_enc_coderange_clean_p(int cr)
{
return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
}
RBIMPL_ATTR_CONST()
/**
* Queries if a code range is "clean". "Clean" in this context means it is
* known and valid.
*
* @param[in] cr An enum ::ruby_coderange_type.
* @retval 1 It is.
* @retval 0 It isn't.
*/
static inline bool
RB_ENC_CODERANGE_CLEAN_P(enum ruby_coderange_type cr)
{
return rb_enc_coderange_clean_p(cr);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
/**
* Queries the (inline) code range of the passed object. The object must be
* capable of having inline encoding. Using this macro needs deep
* understanding of bit level object binary layout.
*
* @param[in] obj Target object.
* @return An enum ::ruby_coderange_type.
*/
static inline enum ruby_coderange_type
RB_ENC_CODERANGE(VALUE obj)
{
VALUE ret = RB_FL_TEST_RAW(obj, RUBY_ENC_CODERANGE_MASK);
return RBIMPL_CAST((enum ruby_coderange_type)ret);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
/**
* Queries the (inline) code range of the passed object is
* ::RUBY_ENC_CODERANGE_7BIT. The object must be capable of having inline
* encoding. Using this macro needs deep understanding of bit level object
* binary layout.
*
* @param[in] obj Target object.
* @retval 1 It is ascii only.
* @retval 0 Otherwise (including cases when the range is not known).
*/
static inline bool
RB_ENC_CODERANGE_ASCIIONLY(VALUE obj)
{
return RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT;
}
/**
* Destructively modifies the passed object so that its (inline) code range is
* the passed one. The object must be capable of having inline encoding.
* Using this macro needs deep understanding of bit level object binary layout.
*
* @param[out] obj Target object.
* @param[out] cr An enum ::ruby_coderange_type.
* @post `obj`'s code range is `cr`.
*/
static inline void
RB_ENC_CODERANGE_SET(VALUE obj, enum ruby_coderange_type cr)
{
RB_FL_UNSET_RAW(obj, RUBY_ENC_CODERANGE_MASK);
RB_FL_SET_RAW(obj, cr);
}
/**
* Destructively clears the passed object's (inline) code range. The object
* must be capable of having inline encoding. Using this macro needs deep
* understanding of bit level object binary layout.
*
* @param[out] obj Target object.
* @post `obj`'s code range is ::RUBY_ENC_CODERANGE_UNKNOWN.
*/
static inline void
RB_ENC_CODERANGE_CLEAR(VALUE obj)
{
RB_FL_UNSET_RAW(obj, RUBY_ENC_CODERANGE_MASK);
}
RBIMPL_ATTR_CONST()
/* assumed ASCII compatibility */
/**
* "Mix" two code ranges into one. This is handy for instance when you
* concatenate two strings into one. Consider one of then is valid but the
* other isn't. The result must be invalid. This macro computes that kind of
* mixture.
*
* @param[in] a An enum ::ruby_coderange_type.
* @param[in] b Another enum ::ruby_coderange_type.
* @return The `a` "and" `b`.
*/
static inline enum ruby_coderange_type
RB_ENC_CODERANGE_AND(enum ruby_coderange_type a, enum ruby_coderange_type b)
{
if (a == RUBY_ENC_CODERANGE_7BIT) {
return b;
}
else if (a != RUBY_ENC_CODERANGE_VALID) {
return RUBY_ENC_CODERANGE_UNKNOWN;
}
else if (b == RUBY_ENC_CODERANGE_7BIT) {
return RUBY_ENC_CODERANGE_VALID;
}
else {
return b;
}
}
#define ENC_CODERANGE_MASK RUBY_ENC_CODERANGE_MASK /**< @old{RUBY_ENC_CODERANGE_MASK} */
#define ENC_CODERANGE_UNKNOWN RUBY_ENC_CODERANGE_UNKNOWN /**< @old{RUBY_ENC_CODERANGE_UNKNOWN} */
#define ENC_CODERANGE_7BIT RUBY_ENC_CODERANGE_7BIT /**< @old{RUBY_ENC_CODERANGE_7BIT} */
#define ENC_CODERANGE_VALID RUBY_ENC_CODERANGE_VALID /**< @old{RUBY_ENC_CODERANGE_VALID} */
#define ENC_CODERANGE_BROKEN RUBY_ENC_CODERANGE_BROKEN /**< @old{RUBY_ENC_CODERANGE_BROKEN} */
#define ENC_CODERANGE_CLEAN_P(cr) RB_ENC_CODERANGE_CLEAN_P(cr) /**< @old{RB_ENC_CODERANGE_CLEAN_P} */
#define ENC_CODERANGE(obj) RB_ENC_CODERANGE(obj) /**< @old{RB_ENC_CODERANGE} */
#define ENC_CODERANGE_ASCIIONLY(obj) RB_ENC_CODERANGE_ASCIIONLY(obj) /**< @old{RB_ENC_CODERANGE_ASCIIONLY} */
#define ENC_CODERANGE_SET(obj,cr) RB_ENC_CODERANGE_SET(obj,cr) /**< @old{RB_ENC_CODERANGE_SET} */
#define ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_CLEAR(obj) /**< @old{RB_ENC_CODERANGE_CLEAR} */
#define ENC_CODERANGE_AND(a, b) RB_ENC_CODERANGE_AND(a, b) /**< @old{RB_ENC_CODERANGE_AND} */
#define ENCODING_CODERANGE_SET(obj, encindex, cr) RB_ENCODING_CODERANGE_SET(obj, encindex, cr) /**< @old{RB_ENCODING_CODERANGE_SET} */
/** @cond INTERNAL_MACRO */
#define RB_ENC_CODERANGE RB_ENC_CODERANGE
#define RB_ENC_CODERANGE_AND RB_ENC_CODERANGE_AND
#define RB_ENC_CODERANGE_ASCIIONLY RB_ENC_CODERANGE_ASCIIONLY
#define RB_ENC_CODERANGE_CLEAN_P RB_ENC_CODERANGE_CLEAN_P
#define RB_ENC_CODERANGE_CLEAR RB_ENC_CODERANGE_CLEAR
#define RB_ENC_CODERANGE_SET RB_ENC_CODERANGE_SET
/** @endcond */
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_CODERANGE_H */

View File

@@ -0,0 +1,258 @@
#ifndef RUBY_INTERNAL_ENCODING_CTYPE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_CTYPE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to query chacater types.
*/
#include "ruby/onigmo.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Queries if the passed pointer points to a newline character. What is a
* newline and what is not depends on the passed encoding.
*
* @param[in] p Pointer to a possibly-middle of a character.
* @param[in] end End of the string.
* @param[in] enc Encoding.
* @retval false It isn't.
* @retval true It is.
*/
static inline bool
rb_enc_is_newline(const char *p, const char *e, rb_encoding *enc)
{
OnigUChar *up = RBIMPL_CAST((OnigUChar *)p);
OnigUChar *ue = RBIMPL_CAST((OnigUChar *)e);
return ONIGENC_IS_MBC_NEWLINE(enc, up, ue);
}
/**
* Queries if the passed code point is of passed character type in the passed
* encoding. The "character type" here is a set of macros defined in onigmo.h,
* like `ONIGENC_CTYPE_PUNCT`.
*
* @param[in] c An `OnigCodePoint` value.
* @param[in] t An `OnigCtype` value.
* @param[in] enc A `rb_encoding*` value.
* @retval true `c` is of `t` in `enc`.
* @retval false Otherwise.
*/
static inline bool
rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc)
{
return ONIGENC_IS_CODE_CTYPE(enc, c, t);
}
/**
* Identical to rb_isascii(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval false `c` is out of range of ASCII character set in `enc`.
* @retval true Otherwise.
*
* @internal
*
* `enc` is ignored. This is at least an intentional implementation detail
* (not a bug). But there could be rooms for future extensions.
*/
static inline bool
rb_enc_isascii(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_ASCII(c);
}
/**
* Identical to rb_isalpha(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "ALPHA".
* @retval false Otherwise.
*/
static inline bool
rb_enc_isalpha(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_ALPHA(enc, c);
}
/**
* Identical to rb_islower(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "LOWER".
* @retval false Otherwise.
*/
static inline bool
rb_enc_islower(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_LOWER(enc, c);
}
/**
* Identical to rb_isupper(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "UPPER".
* @retval false Otherwise.
*/
static inline bool
rb_enc_isupper(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_UPPER(enc, c);
}
/**
* Identical to rb_iscntrl(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "CNTRL".
* @retval false Otherwise.
*/
static inline bool
rb_enc_iscntrl(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_CNTRL(enc, c);
}
/**
* Identical to rb_ispunct(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "PUNCT".
* @retval false Otherwise.
*/
static inline bool
rb_enc_ispunct(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_PUNCT(enc, c);
}
/**
* Identical to rb_isalnum(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "ANUM".
* @retval false Otherwise.
*/
static inline bool
rb_enc_isalnum(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_ALNUM(enc, c);
}
/**
* Identical to rb_isprint(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "PRINT".
* @retval false Otherwise.
*/
static inline bool
rb_enc_isprint(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_PRINT(enc, c);
}
/**
* Identical to rb_isspace(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "PRINT".
* @retval false Otherwise.
*/
static inline bool
rb_enc_isspace(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_SPACE(enc, c);
}
/**
* Identical to rb_isdigit(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @retval true `enc` classifies `c` as "DIGIT".
* @retval false Otherwise.
*/
static inline bool
rb_enc_isdigit(OnigCodePoint c, rb_encoding *enc)
{
return ONIGENC_IS_CODE_DIGIT(enc, c);
}
RBIMPL_ATTR_CONST()
/**
* Identical to rb_toupper(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @return `c`'s (Ruby's definition of) upper case counterpart.
*
* @internal
*
* As `RBIMPL_ATTR_CONST` implies this function ignores `enc`.
*/
int rb_enc_toupper(int c, rb_encoding *enc);
RBIMPL_ATTR_CONST()
/**
* Identical to rb_tolower(), except it additionally takes an encoding.
*
* @param[in] c A code point.
* @param[in] enc An encoding.
* @return `c`'s (Ruby's definition of) lower case counterpart.
*
* @internal
*
* As `RBIMPL_ATTR_CONST` implies this function ignores `enc`.
*/
int rb_enc_tolower(int c, rb_encoding *enc);
RBIMPL_SYMBOL_EXPORT_END()
/** @cond INTERNAL_MACRO */
#define rb_enc_is_newline rb_enc_is_newline
#define rb_enc_isalnum rb_enc_isalnum
#define rb_enc_isalpha rb_enc_isalpha
#define rb_enc_isascii rb_enc_isascii
#define rb_enc_isctype rb_enc_isctype
#define rb_enc_isdigit rb_enc_isdigit
#define rb_enc_islower rb_enc_islower
#define rb_enc_isprint rb_enc_isprint
#define rb_enc_iscntrl rb_enc_iscntrl
#define rb_enc_ispunct rb_enc_ispunct
#define rb_enc_isspace rb_enc_isspace
#define rb_enc_isupper rb_enc_isupper
/** @endcond */
#endif /* RUBY_INTERNAL_ENCODING_CTYPE_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,184 @@
#ifndef RUBY_INTERNAL_ENCODING_PATHNAME_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_PATHNAME_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate encodings of pathnames.
*/
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
RBIMPL_ATTR_NONNULL(())
/**
* Returns a path component directly adjacent to the passed pointer.
*
* ```
* "/multi/byte/encoded/pathname.txt"
* ^ ^ ^
* | | +--- end
* | +--- @return
* +--- path
* ```
*
* @param[in] path Where to start scanning.
* @param[in] end End of the path string.
* @param[in] enc Encoding of the string.
* @return A pointer in the passed string where the next path component
* resides, or `end` if there is no next path component.
*/
char *rb_enc_path_next(const char *path, const char *end, rb_encoding *enc);
RBIMPL_ATTR_NONNULL(())
/**
* Seeks for non-prefix part of a pathname. This can be a no-op when the OS
* has no such concept like a path prefix. But there are OSes where path
* prefixes do exist.
*
* ```
* "C:\multi\byte\encoded\pathname.txt"
* ^ ^ ^
* | | +--- end
* | +--- @return
* +--- path
* ```
*
* @param[in] path Where to start scanning.
* @param[in] end End of the path string.
* @param[in] enc Encoding of the string.
* @return A pointer in the passed string where non-prefix part starts, or
* `path` if the OS does not have path prefix.
*/
char *rb_enc_path_skip_prefix(const char *path, const char *end, rb_encoding *enc);
RBIMPL_ATTR_NONNULL(())
/**
* Returns the last path component.
*
* ```
* "/multi/byte/encoded/pathname.txt"
* ^ ^ ^
* | | +--- end
* | +--- @return
* +--- path
* ```
*
* @param[in] path Where to start scanning.
* @param[in] end End of the path string.
* @param[in] enc Encoding of the string.
* @return A pointer in the passed string where the last path component
* resides, or `end` if there is no more path component.
*/
char *rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc);
RBIMPL_ATTR_NONNULL(())
/**
* This just returns the passed end basically. It makes difference in case the
* passed string ends with tons of path separators like the following:
*
* ```
* "/path/that/ends/with/lots/of/slashes//////////////"
* ^ ^ ^
* | | +--- end
* | +--- @return
* +--- path
* ```
*
* @param[in] path Where to start scanning.
* @param[in] end End of the path string.
* @param[in] enc Encoding of the string.
* @return A pointer in the passed string where the trailing path
* separators start, or `end` if there is no trailing path
* separators.
*
* @internal
*
* It seems this function was introduced to mimic what POSIX says about
* `basename(3)`.
*/
char *rb_enc_path_end(const char *path, const char *end, rb_encoding *enc);
RBIMPL_ATTR_NONNULL((1, 4))
/**
* Our own encoding-aware version of `basename(3)`. Normally, this function
* returns the last path component of the given name. However in case the
* passed name ends with a path separator, it returns the name of the
* directory, not the last (empty) component. Also if the passed name is a
* root directory, it returns that root directory. Note however that Windows
* filesystem have drive letters, which this function does not return.
*
* @param[in] name Target path.
* @param[out] baselen Return buffer.
* @param[in,out] alllen Number of bytes of `name`.
* @param[enc] enc Encoding of `name`.
* @return The rightmost component of `name`.
* @post `baselen`, if passed, is updated to be the number of bytes
* of the returned basename.
* @post `alllen`, if passed, is updated to be the number of bytes of
* strings not considered as the basename.
*/
const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc);
RBIMPL_ATTR_NONNULL((1, 3))
/**
* Our own encoding-aware version of `extname`. This function first applies
* rb_enc_path_last_separator() to the passed name and only concerns its return
* value (ignores any parent directories). This function returns complicated
* results:
*
* ```CXX
* auto path = "...";
* auto len = strlen(path);
* auto ret = ruby_enc_find_extname(path, &len, rb_ascii8bit_encoding());
*
* switch(len) {
* case 0:
* if (ret == 0) {
* // `path` is a file without extensions.
* }
* else {
* // `path` is a dotfile.
* // `ret` is the file's name.
* }
* break;
*
* case 1:
* // `path` _ends_ with a dot.
* // `ret` is that dot.
* break;
*
* default:
* // `path` has an extension.
* // `ret` is that extension.
* }
* ```
*
* @param[in] name Target path.
* @param[in,out] len Number of bytes of `name`.
* @param[in] enc Encoding of `name`.
* @return See above.
* @post `len`, if passed, is updated (see above).
*/
const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_PATHNAME_H */

View File

@@ -0,0 +1,46 @@
#ifndef RUBY_INTERNAL_ENCODING_RE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_RE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate encodings of symbols.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Identical to rb_reg_new(), except it additionally takes an encoding.
*
* @param[in] ptr A memory region of `len` bytes length.
* @param[in] len Length of `ptr`, in bytes, not including the
* terminating NUL character.
* @param[in] enc Encoding of `ptr`.
* @param[in] opts Options e.g. ONIG_OPTION_MULTILINE.
* @exception rb_eRegexpError Failed to compile `ptr`.
* @return An allocated new instance of ::rb_cRegexp, of `enc` encoding,
* whose expression is compiled according to `ptr`.
*/
VALUE rb_enc_reg_new(const char *ptr, long len, rb_encoding *enc, int opts);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_RE_H */

View File

@@ -0,0 +1,78 @@
#ifndef RUBY_INTERNAL_ENCODING_SPRINTF_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_SPRINTF_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate encodings of symbols.
*/
#include "ruby/internal/config.h"
#include <stdarg.h>
#include "ruby/internal/attr/format.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
/**
* Identical to rb_sprintf(), except it additionally takes an encoding. The
* passed encoding rules both the incoming format specifier and the resulting
* string.
*
* @param[in] enc Encoding of `fmt`.
* @param[in] fmt A `printf`-like format specifier.
* @param[in] ... Variadic number of contents to format.
* @return A rendered new instance of ::rb_cString, of `enc` encoding.
*/
VALUE rb_enc_sprintf(rb_encoding *enc, const char *fmt, ...);
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0)
/**
* Identical to rb_enc_sprintf(), except it takes a `va_list` instead of
* variadic arguments. It can also be seen as a routine identical to
* rb_vsprintf(), except it additionally takes an encoding.
*
* @param[in] enc Encoding of `fmt`.
* @param[in] fmt A `printf`-like format specifier.
* @param[in] ap Contents to format.
* @return A rendered new instance of ::rb_cString, of `enc` encoding.
*/
VALUE rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap);
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL((3))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 4)
/**
* Identical to rb_raise(), except it additionally takes an encoding.
*
* @param[in] enc Encoding of the generating exception.
* @param[in] exc A subclass of ::rb_eException.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
* @param[in] ... Contents of the message.
* @exception exc The specified exception.
* @note It never returns.
*/
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_SPRINTF_H */

View File

@@ -0,0 +1,346 @@
#ifndef RUBY_INTERNAL_ENCODING_STRING_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_STRING_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate encodings of strings.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/intern/string.h" /* rbimpl_strlen */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Identical to rb_enc_str_new(), except it additionally takes an encoding.
*
* @param[in] ptr A memory region of `len` bytes length.
* @param[in] len Length of `ptr`, in bytes, not including the
* terminating NUL character.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eNoMemError Failed to allocate `len+1` bytes.
* @exception rb_eArgError `len` is negative.
* @return An instance of ::rb_cString, of `len` bytes length, of `enc`
* encoding, whose contents are verbatim copy of `ptr`.
* @pre At least `len` bytes of continuous memory region shall be
* accessible via `ptr`.
* @note `enc` can be a null pointer. It can also be seen as a routine
* identical to rb_usascii_str_new() then.
*/
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc);
RBIMPL_ATTR_NONNULL((1))
/**
* Identical to rb_enc_str_new(), except it assumes the passed pointer is a
* pointer to a C string. It can also be seen as a routine identical to
* rb_str_new_cstr(), except it additionally takes an encoding.
*
* @param[in] ptr A C string.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eNoMemError Failed to allocate memory.
* @return An instance of ::rb_cString, of `enc` encoding, whose contents
* are verbatim copy of `ptr`.
* @pre `ptr` must not be a null pointer.
* @pre Because `ptr` is a C string it makes no sense for `enc` to be
* something like UTF-32.
* @note `enc` can be a null pointer. It can also be seen as a routine
* identical to rb_usascii_str_new_cstr() then.
*/
VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc);
/**
* Identical to rb_enc_str_new(), except it takes a C string literal. It can
* also be seen as a routine identical to rb_str_new_static(), except it
* additionally takes an encoding.
*
* @param[in] ptr A C string literal.
* @param[in] len `strlen(ptr)`.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eArgError `len` out of range of `size_t`.
* @pre `ptr` must be a C string constant.
* @return An instance of ::rb_cString, of `enc` encoding, whose backend
* storage is the passed C string literal.
* @warning It is a very bad idea to write to a C string literal (often
* immediate SEGV shall occur). Consider return values of this
* function be read-only.
* @note `enc` can be a null pointer. It can also be seen as a routine
* identical to rb_usascii_str_new_static() then.
*/
VALUE rb_enc_str_new_static(const char *ptr, long len, rb_encoding *enc);
/**
* Identical to rb_enc_str_new(), except it returns a "f"string. It can also
* be seen as a routine identical to rb_interned_str(), except it additionally
* takes an encoding.
*
* @param[in] ptr A memory region of `len` bytes length.
* @param[in] len Length of `ptr`, in bytes, not including the
* terminating NUL character.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eArgError `len` is negative.
* @return A found or created instance of ::rb_cString, of `len` bytes
* length, of `enc` encoding, whose contents are identical to that
* of `ptr`.
* @pre At least `len` bytes of continuous memory region shall be
* accessible via `ptr`.
* @note `enc` can be a null pointer.
*/
VALUE rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc);
RBIMPL_ATTR_NONNULL((1))
/**
* Identical to rb_enc_str_new_cstr(), except it returns a "f"string. It can
* also be seen as a routine identical to rb_interned_str_cstr(), except it
* additionally takes an encoding.
*
* @param[in] ptr A memory region of `len` bytes length.
* @param[in] enc Encoding of `ptr`.
* @return A found or created instance of ::rb_cString of `enc` encoding,
* whose contents are identical to that of `ptr`.
* @pre At least `len` bytes of continuous memory region shall be
* accessible via `ptr`.
* @note `enc` can be a null pointer.
*/
VALUE rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc);
/**
* Counts the number of characters of the passed string, according to the
* passed encoding. This has to be complicated. The passed string could be
* invalid and/or broken. This routine would scan from the beginning til the
* end, byte by byte, to seek out character boundaries. Could be super slow.
*
* @param[in] head Leftmost pointer to the string.
* @param[in] tail Rightmost pointer to the string.
* @param[in] enc Encoding of the string.
* @return Number of characters exist in `head` .. `tail`. The definition
* of "character" depends on the passed `enc`.
*/
long rb_enc_strlen(const char *head, const char *tail, rb_encoding *enc);
/**
* Queries the n-th character. Like rb_enc_strlen() this function can be fast
* or slow depending on the contents. Don't expect characters to be uniformly
* distributed across the entire string.
*
* @param[in] head Leftmost pointer to the string.
* @param[in] tail Rightmost pointer to the string.
* @param[in] nth Requested index of characters.
* @param[in] enc Encoding of the string.
* @return Pointer to the first byte of the character that is `nth`
* character ahead of `head`, or `tail` if there is no such
* character (OOB etc). The definition of "character" depends on
* the passed `enc`.
*/
char *rb_enc_nth(const char *head, const char *tail, long nth, rb_encoding *enc);
/**
* Identical to rb_enc_get_index(), except the return type.
*
* @param[in] obj Object in question.
* @exception rb_eTypeError `obj` is incapable of having an encoding.
* @return `obj`'s encoding.
*/
VALUE rb_obj_encoding(VALUE obj);
/**
* Identical to rb_str_cat(), except it additionally takes an encoding.
*
* @param[out] str Destination object.
* @param[in] ptr Contents to append.
* @param[in] len Length of `src`, in bytes.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eArgError `len` is negative.
* @exception rb_eEncCompatError `enc` is not compatible with `str`.
* @return The passed `dst`.
* @post The contents of `ptr` is copied, transcoded into `dst`'s
* encoding, then pasted into `dst`'s end.
*/
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
/**
* Encodes the passed code point into a series of bytes.
*
* @param[in] code Code point.
* @param[in] enc Target encoding scheme.
* @exception rb_eRangeError `enc` does not glean `code`.
* @return An instance of ::rb_cString, of `enc` encoding, whose sole
* contents is `code` represented in `enc`.
* @note No way to encode code points bigger than UINT_MAX.
*
* @internal
*
* In other languages, APIs like this one could be seen as the primitive
* routines where encodings' "encode" feature are implemented. However in case
* of Ruby this is not the primitive one. We directly manipulate encoded
* strings. Encoding conversion routines transcode an encoded string directly
* to another one; not via a code point array.
*/
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
/**
* Identical to rb_external_str_new(), except it additionally takes an
* encoding. However the whole point of rb_external_str_new() is to encode a
* string into default external encoding. Being able to specify arbitrary
* encoding just ruins the designed purpose the function meseems.
*
* @param[in] ptr A memory region of `len` bytes length.
* @param[in] len Length of `ptr`, in bytes, not including the
* terminating NUL character.
* @param[in] enc Target encoding scheme.
* @exception rb_eArgError `len` is negative.
* @return An instance of ::rb_cString. In case encoding conversion from
* "default internal" to `enc` is fully defined over the given
* contents, then the return value is a string of `enc` encoding,
* whose contents are the converted ones. Otherwise the string is
* a junk.
* @warning It doesn't raise on a conversion failure and silently ends up in
* a corrupted output. You can know the failure by querying
* `valid_encoding?` of the result object.
*
* @internal
*
* @shyouhei has no idea why this one does not follow the naming convention
* that others obey. It seems to him that this should have been called
* `rb_enc_external_str_new`.
*/
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *enc);
/**
* Identical to rb_str_export(), except it additionally takes an encoding.
*
* @param[in] obj Target object.
* @param[in] enc Target encoding.
* @exception rb_eTypeError No implicit conversion to String.
* @return Converted ruby string of `enc` encoding.
*/
VALUE rb_str_export_to_enc(VALUE obj, rb_encoding *enc);
/**
* Encoding conversion main routine.
*
* @param[in] str String to convert.
* @param[in] from Source encoding.
* @param[in] to Destination encoding.
* @return A copy of `str`, with conversion from `from` to `to` applied.
* @note `from` can be a null pointer. `str`'s encoding is taken then.
* @note `to` can be a null pointer. No-op then.
*/
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
/**
* Identical to rb_str_conv_enc(), except it additionally takes IO encoder
* options. The extra arguments can be constructed using io_extract_modeenc()
* etc.
*
* @param[in] str String to convert.
* @param[in] from Source encoding.
* @param[in] to Destination encoding.
* @param[in] ecflags A set of enum ::ruby_econv_flag_type.
* @param[in] ecopts Optional hash.
* @return A copy of `str`, with conversion from `from` to `to` applied.
* @note `from` can be a null pointer. `str`'s encoding is taken then.
* @note `to` can be a null pointer. No-op then.
* @note `ecopts` can be ::RUBY_Qnil, which is equivalent to passing an
* empty hash.
*/
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
/**
* Scans the passed string to collect its code range. Because a Ruby's string
* is mutable, its contents change from time to time; so does its code range.
* A long-lived string tends to fall back to ::RUBY_ENC_CODERANGE_UNKNOWN.
* This API scans it and re-assigns a fine-grained code range constant.
*
* @param[out] str A string.
* @return An enum ::ruby_coderange_type.
*/
int rb_enc_str_coderange(VALUE str);
/**
* Scans the passed string until it finds something odd. Returns the number of
* bytes scanned. As the name implies this is suitable for repeated call. One
* of its application is `IO#readlines`. The method reads from its receiver's
* read buffer, maybe more than once, looking for newlines. But "newline" can
* be different among encodings. This API is used to detect broken contents to
* properly mark them as such.
*
* @param[in] str String to scan.
* @param[in] end End of `str`.
* @param[in] enc `str`'s encoding.
* @param[out] cr Return buffer.
* @return Distance between `str` and first such byte where broken.
* @post `cr` has the code range type.
*/
long rb_str_coderange_scan_restartable(const char *str, const char *end, rb_encoding *enc, int *cr);
/**
* Queries if the passed string is "ASCII only". An ASCII only string is a
* string who doesn't have any non-ASCII characters at all. This doesn't
* necessarily mean the string is in ASCII encoding. For instance a String of
* CP932 encoding can quite much be ASCII only, depending on its contents.
*
* @param[in] str String in question.
* @retval 1 It doesn't have non-ASCII characters.
* @retval 0 It has characters that are out of ASCII.
*/
int rb_enc_str_asciionly_p(VALUE str);
RBIMPL_ATTR_NONNULL(())
/**
* Looks for the passed string in the passed buffer.
*
* @param[in] x Buffer that potentially includes `y`.
* @param[in] m Number of bytes of `x`.
* @param[in] y Query string.
* @param[in] n Number of bytes of `y`.
* @param[in] enc Encoding of both `x` and `y`.
* @retval -1 Not found.
* @retval otherwise Found index in `x`.
* @note This API can match at a non-character-boundary.
*/
long rb_memsearch(const void *x, long m, const void *y, long n, rb_encoding *enc);
/** @cond INTERNAL_MACRO */
RBIMPL_ATTR_NONNULL(())
static inline VALUE
rbimpl_enc_str_new_cstr(const char *str, rb_encoding *enc)
{
long len = rbimpl_strlen(str);
return rb_enc_str_new_static(str, len, enc);
}
#define rb_enc_str_new(str, len, enc) \
((RBIMPL_CONSTANT_P(str) && \
RBIMPL_CONSTANT_P(len) ? \
rb_enc_str_new_static: \
rb_enc_str_new) ((str), (len), (enc)))
#define rb_enc_str_new_cstr(str, enc) \
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_enc_str_new_cstr : \
rb_enc_str_new_cstr) ((str), (enc)))
/** @endcond */
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_STRING_H */

View File

@@ -0,0 +1,100 @@
#ifndef RUBY_INTERNAL_ENCODING_SYMBOL_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_SYMBOL_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate encodings of symbols.
*/
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Identical to rb_intern2(), except it additionally takes an encoding.
*
* @param[in] name The name of the id.
* @param[in] len Length of `name`.
* @param[in] enc `name`'s encoding.
* @exception rb_eRuntimeError Too many symbols.
* @return A (possibly new) id whose value is the given name.
* @note These days Ruby internally has two kinds of symbols
* (static/dynamic). Symbols created using this function would
* become static ones; i.e. would never be garbage collected. It
* is up to you to avoid memory leaks. Think twice before using
* it.
*/
ID rb_intern3(const char *name, long len, rb_encoding *enc);
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_symname_p(), except it additionally takes an encoding.
*
* @param[in] str A C string to check.
* @param[in] enc `str`'s encoding.
* @retval 1 It is a valid symbol name.
* @retval 0 It is invalid as a symbol name.
*/
int rb_enc_symname_p(const char *str, rb_encoding *enc);
/**
* Identical to rb_enc_symname_p(), except it additionally takes the passed
* string's length. This is needed for strings containing NUL bytes, like in
* case of UTF-32.
*
* @param[in] name A C string to check.
* @param[in] len Number of bytes of `str`.
* @param[in] enc `str`'s encoding.
* @retval 1 It is a valid symbol name.
* @retval 0 It is invalid as a symbol name.
*/
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc);
/**
* Identical to rb_check_id(), except it takes a pointer to a memory region
* instead of Ruby's string.
*
* @param[in] ptr A pointer to a memory region.
* @param[in] len Number of bytes of `ptr`.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eEncodingError `ptr` contains non-ASCII according to `enc`.
* @retval 0 No such id ever existed in the history.
* @retval otherwise The id that represents the given name.
*/
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc);
/**
* Identical to rb_check_id_cstr(), except for the return type. It can also be
* seen as a routine identical to rb_check_symbol(), except it takes a pointer
* to a memory region instead of Ruby's string.
*
* @param[in] ptr A pointer to a memory region.
* @param[in] len Number of bytes of `ptr`.
* @param[in] enc Encoding of `ptr`.
* @exception rb_eEncodingError `ptr` contains non-ASCII according to `enc`.
* @retval RUBY_Qnil No such id ever existed in the history.
* @retval otherwise The id that represents the given name.
*/
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_SYMBOL_H */

View File

@@ -0,0 +1,562 @@
#ifndef RUBY_INTERNAL_ENCODING_TRANSCODE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RUBY_INTERNAL_ENCODING_TRANSCODE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief econv stuff
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/** return value of rb_econv_convert() */
typedef enum {
/**
* The conversion stopped when it found an invalid sequence.
*/
econv_invalid_byte_sequence,
/**
* The conversion stopped when it found a character in the input which
* cannot be representable in the output.
*/
econv_undefined_conversion,
/**
* The conversion stopped because there is no destination.
*/
econv_destination_buffer_full,
/**
* The conversion stopped because there is no input.
*/
econv_source_buffer_empty,
/**
* The conversion stopped after converting everything. This is arguably
* the expected normal end of conversion.
*/
econv_finished,
/**
* The conversion stopped after writing something to somewhere, before
* reading everything.
*/
econv_after_output,
/**
* The conversion stopped in middle of reading a character, possibly due to
* a partial read of a socket etc.
*/
econv_incomplete_input
} rb_econv_result_t;
/** An opaque struct that represents a lowest level of encoding conversion. */
typedef struct rb_econv_t rb_econv_t;
/**
* Converts the contents of the passed string from its encoding to the passed
* one.
*
* @param[in] str Target string.
* @param[in] to Destination encoding.
* @param[in] ecflags A set of enum
* ::ruby_econv_flag_type.
* @param[in] ecopts A keyword hash, like
* ::rb_io_t::rb_io_enc_t::ecopts.
* @exception rb_eArgError Not fully converted.
* @exception rb_eInvalidByteSequenceError `str` is malformed.
* @exception rb_eUndefinedConversionError `str` has a character not
* representable using `to`.
* @exception rb_eConversionNotFoundError There is no known conversion from
* `str`'s encoding to `to`.
* @return A string whose encoding is `to`, and whose contents is converted
* contents of `str`.
* @note Use rb_econv_prepare_options() to generate `ecopts`.
*/
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts);
/**
* Queries if there is more than one way to convert between the passed two
* encodings. Encoding conversion are has_and_belongs_to_many relationships.
* There could be no direct conversion defined for the passed pair. Ruby tries
* to find an indirect way to do so then. For instance ISO-8859-1 has no
* direct conversion to ISO-2022-JP. But there is ISO-8859-1 to UTF-8
* conversion; then there is UTF-8 to EUC-JP conversion; finally there also is
* EUC-JP to ISO-2022-JP conversion. So in short ISO-8859-1 can be converted
* to ISO-2022-JP using that path. This function returns true. Obviously not
* everything that can be represented using UTF-8 can also be represented using
* EUC-JP. Conversions in practice can fail depending on the actual input, and
* that renders exceptions in case of rb_str_encode().
*
* @param[in] from_encoding One encoding.
* @param[in] to_encoding Another encoding.
* @retval 0 No way to convert the two.
* @retval 1 At least one way to convert the two.
*
* @internal
*
* Practically @shyouhei knows no way for this function to return 0. It seems
* everything can eventually be converted to/from UTF-8, which connects
* everything.
*/
int rb_econv_has_convpath_p(const char* from_encoding, const char* to_encoding);
/**
* Identical to rb_econv_prepare_opts(), except it additionally takes the
* initial value of flags. The extra bits are bitwise-ORed to the return
* value.
*
* @param[in] opthash Keyword arguments.
* @param[out] ecopts Return buffer.
* @param[in] ecflags Default set of enum ::ruby_econv_flag_type.
* @exception rb_eArgError Unknown/Broken values passed.
* @return Calculated set of enum ::ruby_econv_flag_type.
* @post `ecopts` holds a hash object suitable for
* ::rb_io_t::rb_io_enc_t::ecopts.
*/
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags);
/**
* Splits a keyword arguments hash (that for instance `String#encode` took)
* into a set of enum ::ruby_econv_flag_type and a hash storing replacement
* characters etc.
*
* @param[in] opthash Keyword arguments.
* @param[out] ecopts Return buffer.
* @exception rb_eArgError Unknown/Broken values passed.
* @return Calculated set of enum ::ruby_econv_flag_type.
* @post `ecopts` holds a hash object suitable for
* ::rb_io_t::rb_io_enc_t::ecopts.
*/
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts);
/**
* Creates a new instance of struct ::rb_econv_t.
*
* @param[in] source_encoding Name of an encoding.
* @param[in] destination_encoding Name of another encoding.
* @param[in] ecflags A set of enum ::ruby_econv_flag_type.
* @exception rb_eArgError No such encoding.
* @retval NULL Failed to create a struct ::rb_econv_t.
* @retval otherwise Allocated struct ::rb_econv_t.
* @warning Return value must be passed to rb_econv_close() exactly once.
*/
rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags);
/**
* Identical to rb_econv_open(), except it additionally takes a hash of
* optional strings.
*
*
* @param[in] source_encoding Name of an encoding.
* @param[in] destination_encoding Name of another encoding.
* @param[in] ecflags A set of enum ::ruby_econv_flag_type.
* @param[in] ecopts Optional set of strings.
* @exception rb_eArgError No such encoding.
* @retval NULL Failed to create a struct ::rb_econv_t.
* @retval otherwise Allocated struct ::rb_econv_t.
* @warning Return value must be passed to rb_econv_close() exactly once.
*/
rb_econv_t *rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts);
/**
* Converts a string from an encoding to another.
*
* Possible flags are either ::RUBY_ECONV_PARTIAL_INPUT (means the source
* buffer is a part of much larger one), ::RUBY_ECONV_AFTER_OUTPUT (instructs
* the converter to stop after output before input), or both of them.
*
* @param[in,out] ec Conversion specification/state etc.
* @param[in] source_buffer_ptr Target string.
* @param[in] source_buffer_end End of target string.
* @param[out] destination_buffer_ptr Return buffer.
* @param[out] destination_buffer_end End of return buffer.
* @param[in] flags Flags (see above).
* @return The status of the conversion.
* @post `destination_buffer_ptr` holds conversion results.
*/
rb_econv_result_t rb_econv_convert(rb_econv_t *ec,
const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end,
unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end,
int flags);
/**
* Destructs a converter. Note that a converter can have a buffer, and can be
* non-empty. Calling this would lose your data then.
*
* @param[out] ec The converter to destroy.
* @post `ec` is no longer a valid pointer.
*/
void rb_econv_close(rb_econv_t *ec);
/**
* Assigns the replacement string. The string passed here would appear in
* converted string when it cannot represent its source counterpart. This can
* happen for instance you convert an emoji to ISO-8859-1.
*
* @param[out] ec Target converter.
* @param[in] str Replacement string.
* @param[in] len Number of bytes of `str`.
* @param[in] encname Name of encoding of `str`.
* @retval 0 Success.
* @retval -1 Failure (ENOMEM etc.).
* @post `ec`'s replacement string is set to `str`.
*/
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname);
/**
* "Decorate"s a converter. There are special kind of converters that
* transforms the contents, like replacing CR into CRLF. You can add such
* decorators to a converter using this API. By using this function a
* decorator is prepended at the beginning of a conversion sequence: in case of
* CRLF conversion, newlines are converted before encodings are converted.
*
* @param[out] ec Target converter to decorate.
* @param[in] decorator_name Name of decorator to prepend.
* @retval 0 Success.
* @retval -1 Failure (no such decorator etc.).
* @post Decorator works before encoding conversion happens.
*
* @internal
*
* What is the possible value of the `decorator_name` is not public. You have
* to read through `transcode.c` carefully.
*/
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name);
/**
* Identical to rb_econv_decorate_at_first(), except it adds to the opposite
* direction. For instance CRLF conversion would run _after_ encodings are
* converted.
*
* @param[out] ec Target converter to decorate.
* @param[in] decorator_name Name of decorator to prepend.
* @retval 0 Success.
* @retval -1 Failure (no such decorator etc.).
* @post Decorator works after encoding conversion happens.
*/
int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name);
/**
* Creates a `rb_eConverterNotFoundError` exception object (but does not
* raise).
*
* @param[in] senc Name of source encoding.
* @param[in] denc Name of destination encoding.
* @param[in] ecflags A set of enum ::ruby_econv_flag_type.
* @return An instance of `rb_eConverterNotFoundError`.
*/
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags);
/**
* Appends the passed string to the passed converter's output buffer. This can
* be handy when an encoding needs bytes out of thin air; for instance
* ISO-2022-JP has "shift function" which does not correspond to any
* characters.
*
* @param[out] ec Target converter.
* @param[in] str String to insert.
* @param[in] len Number of bytes of `str`.
* @param[in] str_encoding Encoding of `str`.
* @retval 0 Success.
* @retval -1 Failure (conversion error etc.).
* @note `str_encoding` can be anything, and `str` itself is converted
* when necessary.
*/
int rb_econv_insert_output(rb_econv_t *ec,
const unsigned char *str, size_t len, const char *str_encoding);
/**
* Queries an encoding name which best suits for rb_econv_insert_output()'s
* last parameter. Strings in this encoding need no conversion when inserted;
* can be both time/space efficient.
*
* @param[in] ec Target converter.
* @return Its encoding for insertion.
*/
const char *rb_econv_encoding_to_insert_output(rb_econv_t *ec);
/**
* This is a rb_econv_make_exception() + rb_exc_raise() combo.
*
* @param[in] ec (Possibly failed) conversion.
* @exception rb_eInvalidByteSequenceError Invalid byte sequence.
* @exception rb_eUndefinedConversionError Conversion undefined.
* @note This function can return when no error.
*/
void rb_econv_check_error(rb_econv_t *ec);
/**
* This function makes sense right after rb_econv_convert() returns. As listed
* in ::rb_econv_result_t, rb_econv_convert() can bail out for various reasons.
* This function checks the passed converter's internal state and convert it to
* an appropriate exception object.
*
* @param[in] ec Target converter.
* @retval RUBY_Qnil The converter has no error.
* @retval otherwise Conversion error turned into an exception.
*/
VALUE rb_econv_make_exception(rb_econv_t *ec);
/**
* Queries if rb_econv_putback() makes sense, i.e. there are invalid byte
* sequences remain in the buffer.
*
* @param[in] ec Target converter.
* @return Number of bytes that can be pushed back.
*/
int rb_econv_putbackable(rb_econv_t *ec);
/**
* Puts back the bytes. In case of ::econv_invalid_byte_sequence, some of
* those invalid bytes are discarded and the others are buffered to be
* converted later. The latter bytes can be put back using this API.
*
* @param[out] ec Target converter (invalid byte sequence).
* @param[out] p Return buffer.
* @param[in] n Max number of bytes to put back.
* @post At most `n` bytes of what was put back is written to `p`.
*/
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n);
/**
* Queries the passed encoding's corresponding ASCII compatible encoding. "The
* corresponding ASCII compatible encoding" in this context is an ASCII
* compatible encoding which can represent exactly the same character sets as
* the given ASCII incompatible encoding. For instance that of UTF-16LE is
* UTF-8.
*
* @param[in] encname Name of an ASCII incompatible encoding.
* @retval NULL `encname` is already ASCII compatible.
* @retval otherwise The corresponding ASCII compatible encoding.
*/
const char *rb_econv_asciicompat_encoding(const char *encname);
/**
* Identical to rb_econv_convert(), except it takes Ruby's string instead of
* C's pointer.
*
* @param[in,out] ec Target converter.
* @param[in] src Source string.
* @param[in] flags Flags (see rb_econv_convert).
* @exception rb_eArgError Converted string is too long.
* @exception rb_eInvalidByteSequenceError Invalid byte sequence.
* @exception rb_eUndefinedConversionError Conversion undefined.
* @return The conversion result.
*/
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags);
/**
* Identical to rb_econv_str_convert(), except it converts only a part of the
* passed string. Can be handy when you for instance want to do line-buffered
* conversion.
*
* @param[in,out] ec Target converter.
* @param[in] src Source string.
* @param[in] byteoff Number of bytes to seek.
* @param[in] bytesize Number of bytes to read.
* @param[in] flags Flags (see rb_econv_convert).
* @exception rb_eArgError Converted string is too long.
* @exception rb_eInvalidByteSequenceError Invalid byte sequence.
* @exception rb_eUndefinedConversionError Conversion undefined.
* @return The conversion result.
*/
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags);
/**
* Identical to rb_econv_str_convert(), except it appends the conversion result
* to the additionally passed string instead of creating a new string. It can
* also be seen as a routine identical to rb_econv_append(), except it takes a
* Ruby's string instead of C's pointer.
*
* @param[in,out] ec Target converter.
* @param[in] src Source string.
* @param[in] dst Return buffer.
* @param[in] flags Flags (see rb_econv_convert).
* @exception rb_eArgError Converted string is too long.
* @exception rb_eInvalidByteSequenceError Invalid byte sequence.
* @exception rb_eUndefinedConversionError Conversion undefined.
* @return The conversion result.
*/
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags);
/**
* Identical to rb_econv_str_append(), except it appends only a part of the
* passed string with conversion. It can also be seen as a routine identical
* to rb_econv_substr_convert(), except it appends the conversion result to the
* additionally passed string instead of creating a new string.
*
* @param[in,out] ec Target converter.
* @param[in] src Source string.
* @param[in] byteoff Number of bytes to seek.
* @param[in] bytesize Number of bytes to read.
* @param[in] dst Return buffer.
* @param[in] flags Flags (see rb_econv_convert).
* @exception rb_eArgError Converted string is too long.
* @exception rb_eInvalidByteSequenceError Invalid byte sequence.
* @exception rb_eUndefinedConversionError Conversion undefined.
* @return The conversion result.
*/
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags);
/**
* Converts the passed C's pointer according to the passed converter, then
* append the conversion result to the passed Ruby's string. This way buffer
* overflow is properly avoided to resize the destination properly.
*
* @param[in,out] ec Target converter.
* @param[in] bytesrc Target string.
* @param[in] bytesize Number of bytes of `bytesrc`.
* @param[in] dst Return buffer.
* @param[in] flags Flags (see rb_econv_convert).
* @exception rb_eArgError Converted string is too long.
* @exception rb_eInvalidByteSequenceError Invalid byte sequence.
* @exception rb_eUndefinedConversionError Conversion undefined.
* @return The conversion result.
*/
VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags);
/**
* This badly named function does not set the destination encoding to binary,
* but instead just nullifies newline conversion decorators if any. Other
* ordinal character conversions still happen after this; something non-binary
* would still be generated.
*
* @param[out] ec Target converter to modify.
* @post Any newline conversions, if any, would be killed.
*/
void rb_econv_binmode(rb_econv_t *ec);
/**
* This enum is kind of omnibus. Gathers various constants.
*/
enum ruby_econv_flag_type {
/**
* @name Flags for rb_econv_open()
*
* @{
*/
/** Mask for error handling related bits. */
RUBY_ECONV_ERROR_HANDLER_MASK = 0x000000ff,
/** Special handling of invalid sequences are there. */
RUBY_ECONV_INVALID_MASK = 0x0000000f,
/** Invalid sequences shall be replaced. */
RUBY_ECONV_INVALID_REPLACE = 0x00000002,
/** Special handling of undefined conversion are there. */
RUBY_ECONV_UNDEF_MASK = 0x000000f0,
/** Undefined characters shall be replaced. */
RUBY_ECONV_UNDEF_REPLACE = 0x00000020,
/** Undefined characters shall be escaped. */
RUBY_ECONV_UNDEF_HEX_CHARREF = 0x00000030,
/** Decorators are there. */
RUBY_ECONV_DECORATOR_MASK = 0x0001ff00,
/** Newline converters are there. */
RUBY_ECONV_NEWLINE_DECORATOR_MASK = 0x00007f00,
/** (Unclear; seems unused). */
RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK = 0x00000f00,
/** (Unclear; seems unused). */
RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK = 0x00007000,
/** Universal newline mode. */
RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR = 0x00000100,
/** CR to CRLF conversion shall happen. */
RUBY_ECONV_CRLF_NEWLINE_DECORATOR = 0x00001000,
/** CRLF to CR conversion shall happen. */
RUBY_ECONV_CR_NEWLINE_DECORATOR = 0x00002000,
/** CRLF to LF conversion shall happen. */
RUBY_ECONV_LF_NEWLINE_DECORATOR = 0x00004000,
/** Texts shall be XML-escaped. */
RUBY_ECONV_XML_TEXT_DECORATOR = 0x00008000,
/** Texts shall be AttrValue escaped */
RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR = 0x00010000,
/** (Unclear; seems unused). */
RUBY_ECONV_STATEFUL_DECORATOR_MASK = 0x00f00000,
/** Texts shall be AttrValue escaped. */
RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR = 0x00100000,
/** Newline decorator's default. */
RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR =
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
RUBY_ECONV_CRLF_NEWLINE_DECORATOR,
#else
0,
#endif
#define ECONV_ERROR_HANDLER_MASK RUBY_ECONV_ERROR_HANDLER_MASK /**< @old{RUBY_ECONV_ERROR_HANDLER_MASK} */
#define ECONV_INVALID_MASK RUBY_ECONV_INVALID_MASK /**< @old{RUBY_ECONV_INVALID_MASK} */
#define ECONV_INVALID_REPLACE RUBY_ECONV_INVALID_REPLACE /**< @old{RUBY_ECONV_INVALID_REPLACE} */
#define ECONV_UNDEF_MASK RUBY_ECONV_UNDEF_MASK /**< @old{RUBY_ECONV_UNDEF_MASK} */
#define ECONV_UNDEF_REPLACE RUBY_ECONV_UNDEF_REPLACE /**< @old{RUBY_ECONV_UNDEF_REPLACE} */
#define ECONV_UNDEF_HEX_CHARREF RUBY_ECONV_UNDEF_HEX_CHARREF /**< @old{RUBY_ECONV_UNDEF_HEX_CHARREF} */
#define ECONV_DECORATOR_MASK RUBY_ECONV_DECORATOR_MASK /**< @old{RUBY_ECONV_DECORATOR_MASK} */
#define ECONV_NEWLINE_DECORATOR_MASK RUBY_ECONV_NEWLINE_DECORATOR_MASK /**< @old{RUBY_ECONV_NEWLINE_DECORATOR_MASK} */
#define ECONV_NEWLINE_DECORATOR_READ_MASK RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK /**< @old{RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK} */
#define ECONV_NEWLINE_DECORATOR_WRITE_MASK RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK /**< @old{RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK} */
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR} */
#define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_CRLF_NEWLINE_DECORATOR} */
#define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_CR_NEWLINE_DECORATOR} */
#define ECONV_LF_NEWLINE_DECORATOR RUBY_ECONV_LF_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_LF_NEWLINE_DECORATOR} */
#define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR /**< @old{RUBY_ECONV_XML_TEXT_DECORATOR} */
#define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR /**< @old{RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR} */
#define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK /**< @old{RUBY_ECONV_STATEFUL_DECORATOR_MASK} */
#define ECONV_XML_ATTR_QUOTE_DECORATOR RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR /**< @old{RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR} */
#define ECONV_DEFAULT_NEWLINE_DECORATOR RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR} */
/** @} */
/**
* @name Flags for rb_econv_convert()
*
* @{
*/
/** Indicates the input is a part of much larger one. */
RUBY_ECONV_PARTIAL_INPUT = 0x00020000,
/** Instructs the converter to stop after output. */
RUBY_ECONV_AFTER_OUTPUT = 0x00040000,
#define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT /**< @old{RUBY_ECONV_PARTIAL_INPUT} */
#define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT /**< @old{RUBY_ECONV_AFTER_OUTPUT} */
RUBY_ECONV_FLAGS_PLACEHOLDER /**< Placeholder (not used) */
};
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RUBY_INTERNAL_ENCODING_TRANSCODE_H */

582
libs/libruby/ruby/internal/error.h vendored Normal file
View File

@@ -0,0 +1,582 @@
#ifndef RBIMPL_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ERROR_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Declares ::rb_raise().
*/
#include "ruby/internal/attr/cold.h"
#include "ruby/internal/attr/format.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
/**
* @defgroup exception Exception handlings
* @{
*/
/**
* Warning categories. A warning issued using this API can be selectively
* requested / suppressed by the end-users. For instance passing
* `-W:no-deprecated` to the ruby process would suppress those warnings in
* deprecated category.
*
* @warning There is no way to declare a new category (for now).
*/
typedef enum {
/** Category unspecified. */
RB_WARN_CATEGORY_NONE,
/** Warning is for deprecated features. */
RB_WARN_CATEGORY_DEPRECATED,
/** Warning is for experimental features. */
RB_WARN_CATEGORY_EXPERIMENTAL,
RB_WARN_CATEGORY_ALL_BITS = 0x6 /* no RB_WARN_CATEGORY_NONE bit */
} rb_warning_category_t;
/** for rb_readwrite_sys_fail first argument */
enum rb_io_wait_readwrite {RB_IO_WAIT_READABLE, RB_IO_WAIT_WRITABLE};
/** @cond INTERNAL_MACRO */
#define RB_IO_WAIT_READABLE RB_IO_WAIT_READABLE
#define RB_IO_WAIT_WRITABLE RB_IO_WAIT_WRITABLE
/** @endcond */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* This is the same as `$!` in Ruby.
*
* @retval RUBY_Qnil Not handling exceptions at the moment.
* @retval otherwise The current exception in the current thread.
* @ingroup exception
*/
VALUE rb_errinfo(void);
/**
* Sets the current exception (`$!`) to the given value.
*
* @param[in] err An instance of ::rb_eException, or ::RUBY_Qnil.
* @exception rb_eTypeError What is given was neither ::rb_eException nor
* ::RUBY_Qnil.
* @note Use rb_raise() instead to raise `err`. This function just
* assigns the given object to the global variable.
* @ingroup exception
*/
void rb_set_errinfo(VALUE err);
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
/**
* Exception entry point. By calling this function the execution of your
* program gets interrupted to "raise" an exception up to the callee entities.
* Programs could "rescue" that exception, or could "ensure" some part of them.
* If nobody cares about such things, the raised exception reaches at the top
* of execution. This yields abnormal end of the process.
*
* @param[in] exc A subclass of ::rb_eException.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
* @exception exc The specified exception.
* @note It never returns.
*/
void rb_raise(VALUE exc, const char *fmt, ...);
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL((1))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
/**
* Raises the unsung "fatal" exception. This is considered severe. Nobody can
* rescue the exception. Once raised, process termination is inevitable.
* However ensure clauses still run, so that resources are properly cleaned up.
*
* @param[in] fmt Format specifier string compatible with rb_sprintf().
* @exception rb_eFatal An exception that you cannot rescue.
* @note It never returns.
*/
void rb_fatal(const char *fmt, ...);
RBIMPL_ATTR_COLD()
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL((1))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
/**
* Interpreter panic switch. Immediate process termination without any
* synchronisations shall occur. LOTS of internal states, stack traces, and
* even machine registers are displayed if possible for debugging purposes
* then.
*
* @warning Do not use this API.
* @warning You are not expected to use this API.
* @warning Why not just fix your code instead of calling this API?
* @warning It was a bad idea to expose this API to extension libraries at
* the first place. We just cannot delete it at this point for
* backwards compatibility. That doesn't mean everyone are
* welcomed to call this function at will.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
* @note It never returns.
*/
void rb_bug(const char *fmt, ...);
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL(())
/**
* This is a wrapper of rb_bug() which automatically constructs appropriate
* message from the passed errno.
*
* @param[in] msg Additional message to display.
* @exception err C level errno.
* @note It never returns.
*/
void rb_bug_errno(const char *msg, int err);
RBIMPL_ATTR_NORETURN()
/**
* Converts a C errno into a Ruby exception, then raises it. For instance:
*
* ```CXX
* static VALUE
* foo(VALUE argv)
* {
* const auto cmd = StringValueCStr(argv);
* const auto waitr = system(cmd);
* if (waitr == -1) {
* rb_sys_fail("system(3posix)"); // <-------------- this
* }
* else {
* return INT2FIX(fd);
* }
* }
* ```
*
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing errno.
* @note It never returns.
*/
void rb_sys_fail(const char *msg);
RBIMPL_ATTR_NORETURN()
/**
* Identical to rb_sys_fail(), except it takes the message in Ruby's String
* instead of C's.
*
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing errno.
* @note It never returns.
*/
void rb_sys_fail_str(VALUE msg);
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL((2))
/**
* Identical to rb_sys_fail(), except it takes additional module to extend the
* exception object before raising.
*
* @param[in] mod A ::rb_cModule instance.
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing errno.
* @note It never returns.
*
* @internal
*
* Does anybody use it?
*/
void rb_mod_sys_fail(VALUE mod, const char *msg);
RBIMPL_ATTR_NORETURN()
/**
* Identical to rb_mod_sys_fail(), except it takes the message in Ruby's String
* instead of C's.
*
* @param[in] mod A ::rb_cModule instance.
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing errno.
* @note It never returns.
*/
void rb_mod_sys_fail_str(VALUE mod, VALUE msg);
RBIMPL_ATTR_NORETURN()
/**
* Raises appropriate exception using the parameters.
*
* In Ruby level there are rb_eEAGAINWaitReadable etc. This function maps the
* given parameter to an appropriate exception class, then raises it.
*
* @param[in] waiting Reason for the IO to wait.
* @param[in] msg Additional message to raise.
* @exception rb_eEAGAINWaitWritable
* @exception rb_eEWOULDBLOCKWaitWritable
* @exception rb_eEINPROGRESSWaitWritable
* @exception rb_eEAGAINWaitReadable
* @exception rb_eEWOULDBLOCKWaitReadable
* @exception rb_eEINPROGRESSWaitReadable
* @exception rb_eSystemCallError
* @note It never returns.
*/
void rb_readwrite_sys_fail(enum rb_io_wait_readwrite waiting, const char *msg);
RBIMPL_ATTR_NORETURN()
/**
* Breaks from a block. Because you are using a CAPI this is not as intuitive
* as it sounds. In order for this function to properly work, make a
* ::rb_block_call_func_t function that calls it internally, and pass that
* function to rb_block_call().
*
* @exception rb_eLocalJumpError Called from outside of a block.
* @note It never returns.
*/
void rb_iter_break(void);
RBIMPL_ATTR_NORETURN()
/**
* Identical to rb_iter_break(), except it additionally takes the "value" of
* this breakage. It will be the evaluation result of the iterator. This is
* kind of complicated; you cannot see this as a "return from a block"
* behaviour. Take a look at this example:
*
* ```ruby
* def foo(q)
* puts(w = yield(q))
* puts(e = yield(w))
* puts(r = yield(e))
* puts(t = yield(r))
* puts(y = yield(t))
* return "howdy!"
* end
*
* x = foo(0) {|i|
* if i > 2
* break "hello!"
* else
* next i + 1
* end
* }
*
* puts x
* ```
*
* This script outputs 1, 2, 3, and hello. Note that the value passed to break
* becomes the return value of foo method, not the value of yield. This is
* confusing, but can be handy on occasions e.g. when you want to bring a
* local variable out of a block.
*
* @param[in] val The value of the iterator.
* @exception rb_eLocalJumpError Called from outside of a block.
* @note It never returns.
*/
void rb_iter_break_value(VALUE val);
RBIMPL_ATTR_NORETURN()
/**
* Terminates the current execution context. This API is the entry point of a
* "well-mannered" termination sequence. When called from an extension
* library, it raises ::rb_eSystemExit exception. Programs could rescue that
* exception. Can cancel process exit then. Otherwise, that exception results
* in a process termination with the status passed to this function.
*
* @param[in] status Exit status, see also exit(3).
* @exception rb_eSystemExit Exception representing the exit status.
* @note It never returns.
*
* @internal
*
* "When called from an extension library"? You might wonder. In fact there
* are chances for this function to be called from outside of it, for instance
* when dlopen(3) failed. In case it is not possible for this function to
* raise an exception, it does not (silently enters to process cleanup). But
* that is a kind of implementation detail which extension library authors
* should not bother.
*/
void rb_exit(int status);
RBIMPL_ATTR_NORETURN()
/**
* @exception rb_eNotImpError
* @note It never returns.
*/
void rb_notimplement(void);
/**
* Creates an exception object that represents the given C errno.
*
* @param[in] err C level errno.
* @param[in] msg Additional message.
* @retval rb_eSystemCallError An exception for the errno.
*/
VALUE rb_syserr_new(int err, const char * msg);
/**
* Identical to rb_syserr_new(), except it takes the message in Ruby's String
* instead of C's.
*
* @param[in] n C level errno.
* @param[in] arg Additional message.
* @retval rb_eSystemCallError An exception for the errno.
*/
VALUE rb_syserr_new_str(int n, VALUE arg);
RBIMPL_ATTR_NORETURN()
/**
* Raises appropriate exception that represents a C errno.
*
* @param[in] err C level errno.
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing `err`.
* @note It never returns.
*/
void rb_syserr_fail(int err, const char *msg);
RBIMPL_ATTR_NORETURN()
/**
* Identical to rb_syserr_fail(), except it takes the message in Ruby's String
* instead of C's.
*
* @param[in] err C level errno.
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing `err`.
* @note It never returns.
*/
void rb_syserr_fail_str(int err, VALUE msg);
RBIMPL_ATTR_NORETURN()
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_mod_sys_fail(), except it does not depend on C global
* variable errno. Pass it explicitly.
*
* @param[in] mod A ::rb_cModule instance.
* @param[in] err C level errno.
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing `err`.
* @note It never returns.
*/
void rb_mod_syserr_fail(VALUE mod, int err, const char *msg);
RBIMPL_ATTR_NORETURN()
/**
* Identical to rb_mod_syserr_fail(), except it takes the message in Ruby's
* String instead of C's.
*
* @param[in] mod A ::rb_cModule instance.
* @param[in] err C level errno.
* @param[in] msg Additional message to raise.
* @exception rb_eSystemCallError An exception representing `err`.
* @note It never returns.
*/
void rb_mod_syserr_fail_str(VALUE mod, int err, VALUE msg);
RBIMPL_ATTR_NORETURN()
/**
* Identical to rb_readwrite_sys_fail(), except it does not depend on C global
* variable errno. Pass it explicitly.
*
* @param[in] waiting Reason for the IO to wait.
* @param[in] err C level errno.
* @param[in] msg Additional message to raise.
* @exception rb_eEAGAINWaitWritable
* @exception rb_eEWOULDBLOCKWaitWritable
* @exception rb_eEINPROGRESSWaitWritable
* @exception rb_eEAGAINWaitReadable
* @exception rb_eEWOULDBLOCKWaitReadable
* @exception rb_eEINPROGRESSWaitReadable
* @exception rb_eSystemCallError
* @note It never returns.
*/
void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite waiting, int err, const char *msg);
RBIMPL_ATTR_COLD()
RBIMPL_ATTR_NORETURN()
/**
* Fails with the given object's type incompatibility to the type.
*
* It seems this function is visible from extension libraries only because
* RTYPEDDATA_TYPE() uses it on RUBY_DEBUG. So you can basically ignore it;
* use some other fine-grained method instead.
*
* @param[in] self The object in question.
* @param[in] t Expected type of the object.
* @exception rb_eTypeError `self` not in type `t`.
* @note It never returns.
* @note The second argument must have been an enum ::ruby_value_type,
* but for historical reasons it remains to be an int (in other
* words we see no benefits fixing this bug).
*/
void rb_unexpected_type(VALUE self, int t);
/**
* @private
*
* This is an implementation detail of #ruby_verbose. Please don't use it
* directly.
*
* @retval Qnil Interpreter is quiet.
* @retval Qfalse Interpreter is kind of chatty.
* @retval otherwise Interpreter is very verbose.
*/
VALUE *rb_ruby_verbose_ptr(void);
/**
* @private
*
* This is an implementation detail of #ruby_debug. Please don't use it
* directly.
*
* @retval Qnil Interpreter not in debug mode.
* @retval Qfalse Interpreter not in debug mode.
* @retval otherwise Interpreter is in debug mode.
*/
VALUE *rb_ruby_debug_ptr(void);
/**
* This variable controls whether the interpreter is in debug mode. Setting
* this to some truthy value is equivalent to passing `-W` flag to the
* interpreter. Setting this to ::Qfalse is equivalent to passing `-W1` flag
* to the interpreter. Setting this to ::Qnil is equivalent to passing `-W0`
* flag to the interpreter.
*
* @retval Qnil Interpreter is quiet.
* @retval Qfalse Interpreter is kind of chatty.
* @retval otherwise Interpreter is very verbose.
*/
#define ruby_verbose (*rb_ruby_verbose_ptr())
/**
* This variable controls whether the interpreter is in debug mode. Setting
* this to some truthy value is equivalent to passing `-d` flag to the
* interpreter.
*
* @retval Qnil Interpreter not in debug mode.
* @retval Qfalse Interpreter not in debug mode.
* @retval otherwise Interpreter is in debug mode.
*/
#define ruby_debug (*rb_ruby_debug_ptr())
/* reports if `-W' specified */
RBIMPL_ATTR_NONNULL((1))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
/**
* Issues a warning.
*
* In ruby, warnings these days are tightly coupled with the rb_mWarning
* constant and its `warn` singleton method. This CAPI is just a thin wrapper
* of it; everything passed are formatted like what rb_sprintf() does, then
* passed through to the method. Programs can have their own `def
* Warning.warn` at will to do whatever they want, from ignoring the warnings
* at all to sinking them to some BigQuery data set via a Fluentd cluster. By
* default, the method just emits its passed contents to ::rb_stderr using
* rb_io_write().
*
* @note This function is affected by the `-W` flag.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*
* @internal
*
* Above description is in fact inaccurate. This API interfaces with Ractors.
*/
void rb_warning(const char *fmt, ...);
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
/**
* Identical to rb_warning(), except it takes additional "category" parameter.
*
* @param[in] cat Name of a known category.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_category_warning(rb_warning_category_t cat, const char *fmt, ...);
RBIMPL_ATTR_NONNULL((1, 3))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 4)
/**
* Issues a compile-time warning that happens at `__file__:__line__`. Purpose
* of this function being exposed to CAPI is unclear.
*
* @note This function is affected by the `-W` flag.
* @param[in] file The path corresponding to Ruby level `__FILE__`.
* @param[in] line The number corresponding to Ruby level `__LINE__`.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_compile_warning(const char *file, int line, const char *fmt, ...);
RBIMPL_ATTR_NONNULL((1))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
/**
* Identical to rb_sys_fail(), except it does not raise an exception to render
* a warning instead.
*
* @note This function is affected by the `-W` flag.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_sys_warning(const char *fmt, ...);
/* reports always */
RBIMPL_ATTR_COLD()
RBIMPL_ATTR_NONNULL((1))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
/**
* Identical to rb_warning(), except it reports always regardless of runtime
* `-W` flag.
*
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_warn(const char *fmt, ...);
RBIMPL_ATTR_COLD()
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
/**
* Identical to rb_category_warning(), except it reports always regardless of
* runtime `-W` flag.
*
* @param[in] cat Category e.g. deprecated.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_category_warn(rb_warning_category_t cat, const char *fmt, ...);
RBIMPL_ATTR_NONNULL((1, 3))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 3, 4)
/**
* Identical to rb_compile_warning(), except it reports always regardless of
* runtime `-W` flag.
*
* @param[in] file The path corresponding to Ruby level `__FILE__`.
* @param[in] line The number corresponding to Ruby level `__LINE__`.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_compile_warn(const char *file, int line, const char *fmt, ...);
RBIMPL_ATTR_NONNULL((2, 4))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 4, 5)
/**
* Identical to rb_compile_warn(), except it also accepts category.
*
* @param[in] cat Category e.g. deprecated.
* @param[in] file The path corresponding to Ruby level `__FILE__`.
* @param[in] line The number corresponding to Ruby level `__LINE__`.
* @param[in] fmt Format specifier string compatible with rb_sprintf().
*/
void rb_category_compile_warn(rb_warning_category_t cat, const char *file, int line, const char *fmt, ...);
/** @} */
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_ERROR_H */

400
libs/libruby/ruby/internal/eval.h vendored Normal file
View File

@@ -0,0 +1,400 @@
#ifndef RBIMPL_EVAL_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_EVAL_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Declares ::rb_eval_string().
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
RBIMPL_ATTR_NONNULL(())
/**
* Evaluates the given string.
*
* In case it is called from within a C-backended method, the evaluation is
* done under the current binding. However there can be no method. On such
* situation this function evaluates in an isolated binding, like `require`
* runs in a separate one.
*
* `__FILE__` will be `"(eval)"`, and `__LINE__` starts from 1 in the
* evaluation.
*
* @param[in] str Ruby code to evaluate.
* @exception rb_eException Raises an exception on error.
* @return The evaluated result.
*
* @internal
*
* @shyouhei's old tale about the birth and growth of this function:
*
* At the beginning, there was no rb_eval_string(). @shyouhei heard that
* @shugo, author of Apache httpd's mod_ruby module, requested @matz for this
* API. He wanted a way so that mod_ruby can evaluate ruby scripts one by one,
* separately, in each different contexts. So this function was made. It was
* designed to be a global interpreter entry point like ruby_run_node().
*
* The way it is implemented however allows extension libraries (not just
* programs like Apache httpd) to call this function. Because its name says
* nothing about the initial design, people started to think of it as an
* orthodox way to call ruby level `eval` method from their extension
* libraries. Even our `extension.rdoc` has had a description of this function
* basically according to this understanding.
*
* The old (mod_ruby like) usage still works. But over time, usages of this
* function from extension libraries got popular, while mod_ruby faded out; is
* no longer maintained now. Devs decided to actively support both. This
* function now auto-detects how it is called, and switches how it works
* depending on it.
*
* @see https://bugs.ruby-lang.org/issues/18780
*/
VALUE rb_eval_string(const char *str);
RBIMPL_ATTR_NONNULL((1))
/**
* Identical to rb_eval_string(), except it avoids potential global escapes.
* Such global escapes include exceptions, `throw`, `break`, for example.
*
* It first evaluates the given string as rb_eval_string() does. If no global
* escape occurred during the evaluation, it returns the result and `*state` is
* zero. Otherwise, it returns some undefined value and sets `*state` to
* nonzero. If state is `NULL`, it is not set in both cases.
*
* @param[in] str Ruby code to evaluate.
* @param[out] state State of execution.
* @return The evaluated result if succeeded, an undefined value if
* otherwise.
* @post `*state` is set to zero if succeeded. Nonzero otherwise.
* @warning You have to clear the error info with `rb_set_errinfo(Qnil)` if
* you decide to ignore the caught exception.
* @see rb_eval_string
* @see rb_protect
*
* @internal
*
* The "undefined value" described above is in fact ::RUBY_Qnil for now. But
* @shyouhei doesn't think that we would never change that.
*
* Though not a part of our public API, `state` is in fact an
* enum ruby_tag_type. You can see the potential "nonzero" values by looking
* at vm_core.h.
*/
VALUE rb_eval_string_protect(const char *str, int *state);
RBIMPL_ATTR_NONNULL((1))
/**
* Identical to rb_eval_string_protect(), except it evaluates the given string
* under a module binding in an isolated binding. This is the same as a
* binding for loaded libraries on `rb_load(something, true)`.
*
* @param[in] str Ruby code to evaluate.
* @param[out] state State of execution.
* @return The evaluated result if succeeded, an undefined value if
* otherwise.
* @post `*state` is set to zero if succeeded. Nonzero otherwise.
* @warning You have to clear the error info with `rb_set_errinfo(Qnil)` if
* you decide to ignore the caught exception.
* @see rb_eval_string
*/
VALUE rb_eval_string_wrap(const char *str, int *state);
/**
* Calls a method. Can call both public and private methods.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] n Number of arguments that follow.
* @param[in] ... Arbitrary number of method arguments.
* @exception rb_eNoMethodError No such method.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcall(VALUE recv, ID mid, int n, ...);
/**
* Identical to rb_funcall(), except it takes the method arguments as a C
* array.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @exception rb_eNoMethodError No such method.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv);
/**
* Identical to rb_funcallv(), except you can specify how to handle the last
* element of the given array.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @param[in] kw_splat Handling of keyword parameters:
* - RB_NO_KEYWORDS `argv`'s last is not a keyword argument.
* - RB_PASS_KEYWORDS `argv`'s last is a keyword argument.
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
* @exception rb_eNoMethodError No such method.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat);
/**
* Identical to rb_funcallv(), except it only takes public methods into
* account. This is roughly Ruby's `Object#public_send`.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @exception rb_eNoMethodError No such method.
* @exception rb_eNoMethodError The method is private or protected.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcallv_public(VALUE recv, ID mid, int argc, const VALUE *argv);
/**
* Identical to rb_funcallv_public(), except you can specify how to handle the
* last element of the given array. It can also be seen as a routine identical
* to rb_funcallv_kw(), except it only takes public methods into account.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @param[in] kw_splat Handling of keyword parameters:
* - RB_NO_KEYWORDS `argv`'s last is not a keyword argument.
* - RB_PASS_KEYWORDS `argv`'s last is a keyword argument.
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
* @exception rb_eNoMethodError No such method.
* @exception rb_eNoMethodError The method is private or protected.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcallv_public_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat);
/**
* @deprecated This is an old name of rb_funcallv(). Provided here for
* backwards compatibility to 2.x programs (introduced in 2.1).
* It is not a good name. Please don't use it any longer.
*/
#define rb_funcall2 rb_funcallv
/**
* @deprecated This is an old name of rb_funcallv_public(). Provided here
* for backwards compatibility to 2.x programs (introduced in
* 2.1). It is not a good name. Please don't use it any longer.
*/
#define rb_funcall3 rb_funcallv_public
/**
* Identical to rb_funcallv_public(), except you can pass the passed block.
*
* Sometimes you want to "pass" a block parameter form one method to another.
* Suppose you have this Ruby method `foo`:
*
* ```ruby
* def foo(x, y, &z)
* x.open(y, &z)
* end
* ```
*
* And suppose you want to translate this into C. Then
* rb_funcall_passing_block() function is usable in this situation.
*
* ```CXX
* VALUE
* foo_translated_into_C(VALUE self, VALUE x, VALUE y)
* {
* const auto open = rb_intern("open");
*
* return rb_funcall_passing_block(x, open, 1, &y);
* }
* ```
*
* @see rb_yield_block
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @exception rb_eNoMethodError No such method.
* @exception rb_eNoMethodError The method is private or protected.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv);
/**
* Identical to rb_funcallv_passing_block(), except you can specify how to
* handle the last element of the given array. It can also be seen as a
* routine identical to rb_funcallv_public_kw(), except you can pass the passed
* block.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @param[in] kw_splat Handling of keyword parameters:
* - RB_NO_KEYWORDS `argv`'s last is not a keyword argument.
* - RB_PASS_KEYWORDS `argv`'s last is a keyword argument.
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
* @exception rb_eNoMethodError No such method.
* @exception rb_eNoMethodError The method is private or protected.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcall_passing_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat);
/**
* Identical to rb_funcallv_public(), except you can pass a block. A block
* here basically is an instance of ::rb_cProc. If you want to exercise
* `to_proc` conversion, do so before passing it here. However nil and symbols
* are special-case allowed.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @param[in] procval An instance of Proc, Symbol, or NilClass.
* @exception rb_eNoMethodError No such method.
* @exception rb_eNoMethodError The method is private or protected.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*
* @internal
*
* Implementation-wise, `procval` is in fact a "block handler" object. You
* could also pass an IFUNC (block_handler_ifunc) here to say precise. --- But
* AFAIK there is no 3rd party way to even know that there are objects called
* IFUNC behind-the-scene.
*/
VALUE rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE procval);
/**
* Identical to rb_funcallv_with_block(), except you can specify how to handle
* the last element of the given array. It can also be seen as a routine
* identical to rb_funcallv_public_kw(), except you can pass a block.
*
* @param[in,out] recv Receiver of the method.
* @param[in] mid Name of the method to call.
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @param[in] procval An instance of Proc, Symbol, or NilClass.
* @param[in] kw_splat Handling of keyword parameters:
* - RB_NO_KEYWORDS `argv`'s last is not a keyword argument.
* - RB_PASS_KEYWORDS `argv`'s last is a keyword argument.
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
* @exception rb_eNoMethodError No such method.
* @exception rb_eNoMethodError The method is private or protected.
* @exception rb_eException Any exceptions happen inside.
* @return What the method evaluates to.
*/
VALUE rb_funcall_with_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE procval, int kw_splat);
/**
* This resembles ruby's `super`.
*
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @exception rb_eNoMethodError No super method are there.
* @exception rb_eException Any exceptions happen inside.
* @return What the super method evaluates to.
*/
VALUE rb_call_super(int argc, const VALUE *argv);
/**
* Identical to rb_call_super(), except you can specify how to handle the last
* element of the given array.
*
* @param[in] argc Number of arguments.
* @param[in] argv Arbitrary number of method arguments.
* @param[in] kw_splat Handling of keyword parameters:
* - RB_NO_KEYWORDS `argv`'s last is not a keyword argument.
* - RB_PASS_KEYWORDS `argv`'s last is a keyword argument.
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
* @exception rb_eNoMethodError No super method are there.
* @exception rb_eException Any exceptions happen inside.
* @return What the super method evaluates to.
*/
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat);
/**
* This resembles ruby's `self`.
*
* @exception rb_eRuntimeError Called from outside of method context.
* @return Current receiver.
*/
VALUE rb_current_receiver(void);
RBIMPL_ATTR_NONNULL((2))
/**
* Keyword argument deconstructor.
*
* Retrieves argument values bound to keywords, which directed by `table` into
* `values`, deleting retrieved entries from `keyword_hash` along the way.
* First `required` number of IDs referred by `table` are mandatory, and
* succeeding `optional` (`-optional-1` if `optional` is negative) number of
* IDs are optional. If a mandatory key is not contained in `keyword_hash`,
* raises ::rb_eArgError. If an optional key is not present in `keyword_hash`,
* the corresponding element in `values` is set to ::RUBY_Qundef. If
* `optional` is negative, rest of `keyword_hash` are ignored, otherwise raises
* ::rb_eArgError.
*
* @warning Handling keyword arguments in the C API is less efficient than
* handling them in Ruby. Consider using a Ruby wrapper method
* around a non-keyword C function.
* @see https://bugs.ruby-lang.org/issues/11339
* @param[out] keyword_hash Target hash to deconstruct.
* @param[in] table List of keywords that you are interested in.
* @param[in] required Number of mandatory keywords.
* @param[in] optional Number of optional keywords (can be negative).
* @param[out] values Buffer to be filled.
* @exception rb_eArgError Absence of a mandatory keyword.
* @exception rb_eArgError Found an unknown keyword.
* @return Number of found values that are stored into `values`.
*/
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values);
RBIMPL_ATTR_NONNULL(())
/**
* Splits a hash into two.
*
* Takes a hash of various keys, and split it into symbol-keyed parts and
* others. Symbol-keyed part becomes the return value. What remains are
* returned as a new hash object stored at the argument pointer.
*
* @param[in,out] orighash Pointer to a target hash to split.
* @return An extracted keyword hash.
* @post Upon successful return `orighash` points to another hash
* object, whose contents are the remainder of the operation.
* @note The argument hash object is not modified.
*/
VALUE rb_extract_keywords(VALUE *orighash);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_EVAL_H */

154
libs/libruby/ruby/internal/event.h vendored Normal file
View File

@@ -0,0 +1,154 @@
#ifndef RBIMPL_EVENT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_EVENT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Debugging and tracing APIs.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
/* These macros are not enums because they are wider than int.*/
/**
* @name Traditional set_trace_func events
*
* @{
*/
#define RUBY_EVENT_NONE 0x0000 /**< No events. */
#define RUBY_EVENT_LINE 0x0001 /**< Encountered a new line. */
#define RUBY_EVENT_CLASS 0x0002 /**< Encountered a new class. */
#define RUBY_EVENT_END 0x0004 /**< Encountered an end of a class clause. */
#define RUBY_EVENT_CALL 0x0008 /**< A method, written in Ruby, is called. */
#define RUBY_EVENT_RETURN 0x0010 /**< Encountered a `return` statement. */
#define RUBY_EVENT_C_CALL 0x0020 /**< A method, written in C, is called. */
#define RUBY_EVENT_C_RETURN 0x0040 /**< Return from a method, written in C. */
#define RUBY_EVENT_RAISE 0x0080 /**< Encountered a `raise` statement. */
#define RUBY_EVENT_ALL 0x00ff /**< Bitmask of traditional events. */
/** @} */
/**
* @name TracePoint extended events
*
* @{
*/
#define RUBY_EVENT_B_CALL 0x0100 /**< Encountered an `yield` statement. */
#define RUBY_EVENT_B_RETURN 0x0200 /**< Encountered a `next` statement. */
#define RUBY_EVENT_THREAD_BEGIN 0x0400 /**< Encountered a new thread. */
#define RUBY_EVENT_THREAD_END 0x0800 /**< Encountered an end of a thread. */
#define RUBY_EVENT_FIBER_SWITCH 0x1000 /**< Encountered a `Fiber#yield`. */
#define RUBY_EVENT_SCRIPT_COMPILED 0x2000 /**< Encountered an `eval`. */
#define RUBY_EVENT_TRACEPOINT_ALL 0xffff /**< Bitmask of extended events. */
/** @} */
/**
* @name Special events
*
* @internal
*
* These bits are actually used internally. See vm_core.h if you are curious.
*
* @endinternal
*
* @{
*/
#define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 /**< Opaque bits. */
/** @} */
/**
* @name Internal events
*
* @shyouhei's understanding is that some of them are visible from extension
* libraries because of `ext/objspace`. But it seems that doesn't describe
* everything? The ultimate reason why they are here remains unclear.
*
* @{
*/
#define RUBY_INTERNAL_EVENT_SWITCH 0x040000 /**< Thread switched. */
#define RUBY_EVENT_SWITCH 0x040000 /**< @old{RUBY_INTERNAL_EVENT_SWITCH} */
/* 0x080000 */
#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 /**< Object allocated. */
#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 /**< Object swept. */
#define RUBY_INTERNAL_EVENT_GC_START 0x400000 /**< GC started. */
#define RUBY_INTERNAL_EVENT_GC_END_MARK 0x800000 /**< GC ended mark phase. */
#define RUBY_INTERNAL_EVENT_GC_END_SWEEP 0x1000000 /**< GC ended sweep phase. */
#define RUBY_INTERNAL_EVENT_GC_ENTER 0x2000000 /**< `gc_enter()` is called. */
#define RUBY_INTERNAL_EVENT_GC_EXIT 0x4000000 /**< `gc_exit()` is called. */
#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x7f00000 /**< Bitmask of GC events. */
#define RUBY_INTERNAL_EVENT_MASK 0xffff0000 /**< Bitmask of internal events. */
/** @} */
/**
* Represents event(s). As the name implies events are bit flags.
*/
typedef uint32_t rb_event_flag_t;
/**
* Type of event hooks. When an event happens registered functions are kicked
* with appropriate parameters.
*
* @param[in] evflag The kind of event that happened.
* @param[in] data The `data` passed to rb_add_event_hook().
* @param[in] self Current receiver.
* @param[in] mid Name of the current method.
* @param[in] klass Current class.
*/
typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass);
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Registers an event hook function.
*
* @param[in] func A callback.
* @param[in] events A set of events that `func` should run.
* @param[in] data Passed as-is to `func`.
*/
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data);
/**
* Removes the passed function from the list of event hooks.
*
* @param[in] func A callback.
* @return Number of deleted event hooks.
* @note As multiple events can share the same `func` it is quite
* possible for the return value to become more than one.
*
* @internal
*
* @shyouhei doesn't know if this is an Easter egg or an official feature, but
* you can pass 0 to the argument. That effectively swipes everything out from
* the hook list.
*/
int rb_remove_event_hook(rb_event_hook_func_t func);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_EVENT_H */

948
libs/libruby/ruby/internal/fl_type.h vendored Normal file
View File

@@ -0,0 +1,948 @@
#ifndef RBIMPL_FL_TYPE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_FL_TYPE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines enum ::ruby_fl_type.
*/
#include "ruby/internal/config.h" /* for ENUM_OVER_INT */
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/deprecated.h"
#include "ruby/internal/attr/flag_enum.h"
#include "ruby/internal/attr/forceinline.h"
#include "ruby/internal/attr/noalias.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/compiler_since.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/has/extension.h"
#include "ruby/internal/special_consts.h"
#include "ruby/internal/stdbool.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/assert.h"
#include "ruby/defines.h"
/** @cond INTERNAL_MACRO */
#if RBIMPL_HAS_EXTENSION(enumerator_attributes)
# define RBIMPL_HAVE_ENUM_ATTRIBUTE 1
#elif RBIMPL_COMPILER_SINCE(GCC, 6, 0, 0)
# define RBIMPL_HAVE_ENUM_ATTRIBUTE 1
#endif
#ifdef ENUM_OVER_INT
# define RBIMPL_WIDER_ENUM 1
#elif SIZEOF_INT * CHAR_BIT > 12+19+1
# define RBIMPL_WIDER_ENUM 1
#else
# define RBIMPL_WIDER_ENUM 0
#endif
/** @endcond */
#define FL_SINGLETON RBIMPL_CAST((VALUE)RUBY_FL_SINGLETON) /**< @old{RUBY_FL_SINGLETON} */
#define FL_WB_PROTECTED RBIMPL_CAST((VALUE)RUBY_FL_WB_PROTECTED) /**< @old{RUBY_FL_WB_PROTECTED} */
#define FL_PROMOTED0 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED0) /**< @old{RUBY_FL_PROMOTED0} */
#define FL_PROMOTED1 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED1) /**< @old{RUBY_FL_PROMOTED1} */
#define FL_FINALIZE RBIMPL_CAST((VALUE)RUBY_FL_FINALIZE) /**< @old{RUBY_FL_FINALIZE} */
#define FL_TAINT RBIMPL_CAST((VALUE)RUBY_FL_TAINT) /**< @old{RUBY_FL_TAINT} */
#define FL_SHAREABLE RBIMPL_CAST((VALUE)RUBY_FL_SHAREABLE) /**< @old{RUBY_FL_SHAREABLE} */
#define FL_UNTRUSTED RBIMPL_CAST((VALUE)RUBY_FL_UNTRUSTED) /**< @old{RUBY_FL_UNTRUSTED} */
#define FL_SEEN_OBJ_ID RBIMPL_CAST((VALUE)RUBY_FL_SEEN_OBJ_ID) /**< @old{RUBY_FL_SEEN_OBJ_ID} */
#define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR) /**< @old{RUBY_FL_EXIVAR} */
#define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE) /**< @old{RUBY_FL_FREEZE} */
#define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT) /**< @old{RUBY_FL_USHIFT} */
#define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0) /**< @old{RUBY_FL_USER0} */
#define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1) /**< @old{RUBY_FL_USER1} */
#define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2) /**< @old{RUBY_FL_USER2} */
#define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3) /**< @old{RUBY_FL_USER3} */
#define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4) /**< @old{RUBY_FL_USER4} */
#define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5) /**< @old{RUBY_FL_USER5} */
#define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6) /**< @old{RUBY_FL_USER6} */
#define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7) /**< @old{RUBY_FL_USER7} */
#define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8) /**< @old{RUBY_FL_USER8} */
#define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9) /**< @old{RUBY_FL_USER9} */
#define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10) /**< @old{RUBY_FL_USER10} */
#define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11) /**< @old{RUBY_FL_USER11} */
#define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12) /**< @old{RUBY_FL_USER12} */
#define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13) /**< @old{RUBY_FL_USER13} */
#define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14) /**< @old{RUBY_FL_USER14} */
#define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15) /**< @old{RUBY_FL_USER15} */
#define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16) /**< @old{RUBY_FL_USER16} */
#define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17) /**< @old{RUBY_FL_USER17} */
#define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18) /**< @old{RUBY_FL_USER18} */
#define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19) /**< @old{RUBY_FL_USER19} */
#define ELTS_SHARED RUBY_ELTS_SHARED /**< @old{RUBY_ELTS_SHARED} */
#define RB_OBJ_FREEZE rb_obj_freeze_inline /**< @alias{rb_obj_freeze_inline} */
/** @cond INTERNAL_MACRO */
#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED
#define RB_FL_ABLE RB_FL_ABLE
#define RB_FL_ALL RB_FL_ALL
#define RB_FL_ALL_RAW RB_FL_ALL_RAW
#define RB_FL_ANY RB_FL_ANY
#define RB_FL_ANY_RAW RB_FL_ANY_RAW
#define RB_FL_REVERSE RB_FL_REVERSE
#define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW
#define RB_FL_SET RB_FL_SET
#define RB_FL_SET_RAW RB_FL_SET_RAW
#define RB_FL_TEST RB_FL_TEST
#define RB_FL_TEST_RAW RB_FL_TEST_RAW
#define RB_FL_UNSET RB_FL_UNSET
#define RB_FL_UNSET_RAW RB_FL_UNSET_RAW
#define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
#define RB_OBJ_FROZEN RB_OBJ_FROZEN
#define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
#define RB_OBJ_INFECT RB_OBJ_INFECT
#define RB_OBJ_INFECT_RAW RB_OBJ_INFECT_RAW
#define RB_OBJ_TAINT RB_OBJ_TAINT
#define RB_OBJ_TAINTABLE RB_OBJ_TAINTABLE
#define RB_OBJ_TAINTED RB_OBJ_TAINTED
#define RB_OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW
#define RB_OBJ_TAINT_RAW RB_OBJ_TAINT_RAW
#define RB_OBJ_UNTRUST RB_OBJ_TAINT
#define RB_OBJ_UNTRUSTED RB_OBJ_TAINTED
/** @endcond */
/**
* @defgroup deprecated_macros Deprecated macro APIs
* @{
* These macros are deprecated. Prefer their `RB_`-prefixed versions.
*/
#define FL_ABLE RB_FL_ABLE /**< @old{RB_FL_ABLE} */
#define FL_ALL RB_FL_ALL /**< @old{RB_FL_ALL} */
#define FL_ALL_RAW RB_FL_ALL_RAW /**< @old{RB_FL_ALL_RAW} */
#define FL_ANY RB_FL_ANY /**< @old{RB_FL_ANY} */
#define FL_ANY_RAW RB_FL_ANY_RAW /**< @old{RB_FL_ANY_RAW} */
#define FL_REVERSE RB_FL_REVERSE /**< @old{RB_FL_REVERSE} */
#define FL_REVERSE_RAW RB_FL_REVERSE_RAW /**< @old{RB_FL_REVERSE_RAW} */
#define FL_SET RB_FL_SET /**< @old{RB_FL_SET} */
#define FL_SET_RAW RB_FL_SET_RAW /**< @old{RB_FL_SET_RAW} */
#define FL_TEST RB_FL_TEST /**< @old{RB_FL_TEST} */
#define FL_TEST_RAW RB_FL_TEST_RAW /**< @old{RB_FL_TEST_RAW} */
#define FL_UNSET RB_FL_UNSET /**< @old{RB_FL_UNSET} */
#define FL_UNSET_RAW RB_FL_UNSET_RAW /**< @old{RB_FL_UNSET_RAW} */
#define OBJ_FREEZE RB_OBJ_FREEZE /**< @old{RB_OBJ_FREEZE} */
#define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW /**< @old{RB_OBJ_FREEZE_RAW} */
#define OBJ_FROZEN RB_OBJ_FROZEN /**< @old{RB_OBJ_FROZEN} */
#define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW /**< @old{RB_OBJ_FROZEN_RAW} */
#define OBJ_INFECT RB_OBJ_INFECT /**< @old{RB_OBJ_INFECT} */
#define OBJ_INFECT_RAW RB_OBJ_INFECT_RAW /**< @old{RB_OBJ_INFECT_RAW} */
#define OBJ_TAINT RB_OBJ_TAINT /**< @old{RB_OBJ_TAINT} */
#define OBJ_TAINTABLE RB_OBJ_TAINTABLE /**< @old{RB_OBJ_TAINT_RAW} */
#define OBJ_TAINTED RB_OBJ_TAINTED /**< @old{RB_OBJ_TAINTED} */
#define OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW /**< @old{RB_OBJ_TAINTED_RAW} */
#define OBJ_TAINT_RAW RB_OBJ_TAINT_RAW /**< @old{RB_OBJ_TAINT_RAW} */
#define OBJ_UNTRUST RB_OBJ_UNTRUST /**< @old{RB_OBJ_TAINT} */
#define OBJ_UNTRUSTED RB_OBJ_UNTRUSTED /**< @old{RB_OBJ_TAINTED} */
/** @} */
/**
* This is an enum because GDB wants it (rather than a macro). People need not
* bother.
*/
enum ruby_fl_ushift {
/**
* Number of bits in ::ruby_fl_type that are _not_ open to users. This is
* an implementation detail. Please ignore.
*/
RUBY_FL_USHIFT = 12
};
/* > The expression that defines the value of an enumeration constant shall be
* > an integer constant expression that has a value representable as an `int`.
*
* -- ISO/IEC 9899:2018 section 6.7.2.2
*
* So ENUM_OVER_INT situation is an extension to the standard. Note however
* that we do not support 16 bit `int` environment. */
RB_GNUC_EXTENSION
/**
* The flags. Each ruby objects have their own characteristics apart from
* their classes. For instance whether an object is frozen or not is not
* controlled by its class. This is the type that represents such properties.
*
* @note About the `FL_USER` terminology: the "user" here does not necessarily
* mean only you. For instance struct ::RString instances use these
* bits to cache their encodings etc. Devs discussed about this topic,
* reached their consensus that ::RUBY_T_DATA is the only valid data
* structure that can use these bits; other data structures including
* ::RUBY_T_OBJECT use these bits for their own purpose. See also
* https://bugs.ruby-lang.org/issues/18059
*/
enum
RBIMPL_ATTR_FLAG_ENUM()
ruby_fl_type {
/**
* @deprecated This flag once was a thing back in the old days, but makes
* no sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @internal
*
* The reality is our GC no longer remembers write barriers inside of each
* objects, to use dedicated bitmap instead. But this flag is still used
* internally. The current usages of this flag should be something
* different, which is unclear to @shyouhei.
*/
RUBY_FL_WB_PROTECTED = (1<<5),
/**
* This flag has something to do with our garbage collector. These days
* ruby objects are "generational". There are those who are young and
* those who are old. Young objects are prone to die; monitored relatively
* extensively by the garbage collector. OTOH old objects tend to live
* longer. They are relatively rarely considered. This flag is set when a
* object experienced promotion i.e. survived a garbage collection.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_FL_PROMOTED0 = (1<<5),
/**
* This flag has something to do with our garbage collector. These days
* ruby objects are "generational". There are those who are young and
* those who are old. Young objects are prone to die; monitored relatively
* extensively by the garbage collector. OTOH old objects tend to live
* longer. They are relatively rarely considered. This flag is set when a
* object experienced two promotions i.e. survived garbage collections
* twice.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_FL_PROMOTED1 = (1<<6),
/**
* This flag has something to do with our garbage collector. These days
* ruby objects are "generational". There are those who are young and
* those who are old. Young objects are prone to die; monitored relatively
* extensively by the garbage collector. OTOH old objects tend to live
* longer. They are relatively rarely considered. This flag is set when a
* object experienced promotions i.e. survived more than one garbage
* collections.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_FL_PROMOTED = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1,
/**
* This flag has something to do with finalisers. A ruby object can have
* its finaliser, which is another object that evaluates when the target
* object is about to die. This flag is used to denote that there is an
* attached finaliser.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_FL_FINALIZE = (1<<7),
/**
* @deprecated This flag once was a thing back in the old days, but makes
* no sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*/
RUBY_FL_TAINT
#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
#elif defined(_MSC_VER)
# pragma deprecated(RUBY_FL_TAINT)
#endif
= (1<<8),
/**
* This flag has something to do with Ractor. Multiple Ractors run without
* protecting each other. Sharing an object among Ractors are basically
* dangerous, disabled by default. This flag is used to bypass that
* restriction. Of course, you have to manually prevent race conditions
* then.
*
* This flag needs deep understanding of multithreaded programming. You
* would better not use it.
*/
RUBY_FL_SHAREABLE = (1<<8),
/**
* @deprecated This flag once was a thing back in the old days, but makes
* no sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*/
RUBY_FL_UNTRUSTED
#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
RBIMPL_ATTR_DEPRECATED(("trustedness turned out to be a wrong idea."))
#elif defined(_MSC_VER)
# pragma deprecated(RUBY_FL_UNTRUSTED)
#endif
= (1<<8),
/**
* This flag has something to do with object IDs. Unlike in the old days,
* an object's object ID (that a user can query using `Object#object_id`)
* is no longer its physical address represented using Ruby level integers.
* It is now a monotonic-increasing integer unrelated to the underlying
* memory arrangement. Object IDs are assigned when necessary; objects are
* born without one, and will eventually have such property when queried.
* The interpreter has to manage which one is which. This is the flag that
* helps the management. Objects with this flag set are the ones with
* object IDs assigned.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_FL_SEEN_OBJ_ID = (1<<9),
/**
* This flag has something to do with instance variables. 3rd parties need
* not know, but there are several ways to store an object's instance
* variables. Objects with this flag use so-called "generic" backend
* storage. This distinction is purely an implementation detail. People
* need not be aware of this working behind-the-scene.
*
* @internal
*
* As of writing everything except ::RObject and RModule use this scheme.
*/
RUBY_FL_EXIVAR = (1<<10),
/**
* This flag has something to do with data immutability. When this flag is
* set an object is considered "frozen". No modification are expected to
* happen beyond that point for the particular object. Immutability is
* basically considered to be a good property these days. Library authors
* are expected to obey. Test this bit before you touch a data structure.
*
* @see rb_check_frozen()
*/
RUBY_FL_FREEZE = (1<<11),
/** (@shyouhei doesn't know how to excude this macro from doxygen). */
#define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n))
RBIMPL_FL_USER_N(0), /**< User-defined flag. */
RBIMPL_FL_USER_N(1), /**< User-defined flag. */
RBIMPL_FL_USER_N(2), /**< User-defined flag. */
RBIMPL_FL_USER_N(3), /**< User-defined flag. */
RBIMPL_FL_USER_N(4), /**< User-defined flag. */
RBIMPL_FL_USER_N(5), /**< User-defined flag. */
RBIMPL_FL_USER_N(6), /**< User-defined flag. */
RBIMPL_FL_USER_N(7), /**< User-defined flag. */
RBIMPL_FL_USER_N(8), /**< User-defined flag. */
RBIMPL_FL_USER_N(9), /**< User-defined flag. */
RBIMPL_FL_USER_N(10), /**< User-defined flag. */
RBIMPL_FL_USER_N(11), /**< User-defined flag. */
RBIMPL_FL_USER_N(12), /**< User-defined flag. */
RBIMPL_FL_USER_N(13), /**< User-defined flag. */
RBIMPL_FL_USER_N(14), /**< User-defined flag. */
RBIMPL_FL_USER_N(15), /**< User-defined flag. */
RBIMPL_FL_USER_N(16), /**< User-defined flag. */
RBIMPL_FL_USER_N(17), /**< User-defined flag. */
RBIMPL_FL_USER_N(18), /**< User-defined flag. */
#ifdef ENUM_OVER_INT
RBIMPL_FL_USER_N(19), /**< User-defined flag. */
#else
# define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19))
#endif
#undef RBIMPL_FL_USER_N
#undef RBIMPL_WIDER_ENUM
/**
* This flag has something to do with data structures. Over time, ruby
* evolved to reduce memory footprints. One of such attempt is so-called
* copy-on-write, which delays duplication of resources until ultimately
* necessary. Some data structures share this scheme. For example
* multiple instances of struct ::RArray could point identical memory
* region in common, as long as they don't differ. As people favour
* immutable style of programming than before, this situation is getting
* more and more common. Because such "shared" memory regions have nuanced
* ownership by nature, each structures need special care for them. This
* flag is used to distinguish such shared constructs.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_ELTS_SHARED = RUBY_FL_USER2,
/**
* This flag has something to do with an object's class. There are kind of
* classes called "singleton class", each of which have exactly one
* instance. What is interesting about singleton classes is that they are
* created _after_ their instance were instantiated, like this:
*
* ```ruby
* foo = Object.new # foo is an instance of Object...
* bar = foo.singleton_class # foo is now an instance of bar.
* ```
*
* Here as you see `bar` is a singleton class of `foo`, which is injected
* into `foo`'s inheritance tree in a different statement (== distinct
* sequence point). In order to achieve this property singleton classes
* are special-cased in the interpreter. There is one bit flag that
* distinguishes if a class is a singleton class or not, and this is it.
*
* @internal
*
* But honestly, @shyouhei doesn't think this flag should be visible from
* 3rd parties. It must be an implementation detail that they should never
* know. Might better be hidden.
*/
RUBY_FL_SINGLETON = RUBY_FL_USER0,
};
enum {
/**
* @deprecated This flag once was a thing back in the old days, but makes
* no sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*/
RUBY_FL_DUPPED
#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
RBIMPL_ATTR_DEPRECATED(("It seems there is no actual usage of this enum."))
#elif defined(_MSC_VER)
# pragma deprecated(RUBY_FL_DUPPED)
#endif
= (int)RUBY_T_MASK | (int)RUBY_FL_EXIVAR
};
#undef RBIMPL_HAVE_ENUM_ATTRIBUTE
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* This is an implementation detail of #RB_OBJ_FREEZE(). People don't use it
* directly.
*
* @param[out] klass A singleton class.
* @post `klass` gets frozen.
*/
void rb_freeze_singleton_class(VALUE klass);
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_FORCEINLINE()
/**
* Checks if the object is flaggable. There are some special cases (most
* notably ::RUBY_Qfalse) where appending a flag to an object is not possible.
* This function can detect that.
*
* @param[in] obj Object in question
* @retval true It is flaggable.
* @retval false No it isn't.
*/
static bool
RB_FL_ABLE(VALUE obj)
{
if (RB_SPECIAL_CONST_P(obj)) {
return false;
}
else if (RB_TYPE_P(obj, RUBY_T_NODE)) {
return false;
}
else {
return true;
}
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_FL_TEST(). 3rd parties need not use
* this. Just always use RB_FL_TEST().
*
* @param[in] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @pre The object must not be an enum ::ruby_special_consts.
* @return `obj`'s flags, masked by `flags`.
*/
static inline VALUE
RB_FL_TEST_RAW(VALUE obj, VALUE flags)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
return RBASIC(obj)->flags & flags;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Tests if the given flag(s) are set or not. You can pass multiple flags at
* once:
*
* ```CXX
* auto obj = rb_eval_string("...");
* if (RB_FL_TEST(obj, RUBY_FL_FREEZE | RUBY_FL_SHAREABLE)) {
* printf("Ractor ready!\n");
* }
* ```
*
* @param[in] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @return `obj`'s flags, masked by `flags`.
* @note It is intentional for this function to return ::VALUE. The
* return value could be passed to RB_FL_STE() etc.
*/
static inline VALUE
RB_FL_TEST(VALUE obj, VALUE flags)
{
if (RB_FL_ABLE(obj)) {
return RB_FL_TEST_RAW(obj, flags);
}
else {
return RBIMPL_VALUE_NULL;
}
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_FL_ANY(). 3rd parties need not use
* this. Just always use RB_FL_ANY().
*
* @param[in] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @retval true The object has any of the flags set.
* @retval false No it doesn't at all.
* @pre The object must not be an enum ::ruby_special_consts.
*/
static inline bool
RB_FL_ANY_RAW(VALUE obj, VALUE flags)
{
return RB_FL_TEST_RAW(obj, flags);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Identical to RB_FL_TEST(), except it returns bool.
*
* @param[in] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @retval true The object has any of the flags set.
* @retval false No it doesn't at all.
*/
static inline bool
RB_FL_ANY(VALUE obj, VALUE flags)
{
return RB_FL_TEST(obj, flags);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_FL_ALL(). 3rd parties need not use
* this. Just always use RB_FL_ALL().
*
* @param[in] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @retval true The object has all of the flags set.
* @retval false The object lacks any of the flags.
* @pre The object must not be an enum ::ruby_special_consts.
*/
static inline bool
RB_FL_ALL_RAW(VALUE obj, VALUE flags)
{
return RB_FL_TEST_RAW(obj, flags) == flags;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Identical to RB_FL_ANY(), except it mandates all passed flags be set.
*
* @param[in] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @retval true The object has all of the flags set.
* @retval false The object lacks any of the flags.
*/
static inline bool
RB_FL_ALL(VALUE obj, VALUE flags)
{
return RB_FL_TEST(obj, flags) == flags;
}
RBIMPL_ATTR_NOALIAS()
RBIMPL_ATTR_ARTIFICIAL()
/**
* @private
*
* This is an implenentation detail of RB_FL_SET(). 3rd parties need not use
* this. Just always use RB_FL_SET().
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` set.
*
* @internal
*
* This is function is here to annotate a part of RB_FL_SET_RAW() as
* `__declspec(noalias)`.
*/
static inline void
rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
{
obj->flags |= flags;
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_FL_SET(). 3rd parties need not use
* this. Just always use RB_FL_SET().
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` set.
*/
static inline void
RB_FL_SET_RAW(VALUE obj, VALUE flags)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
rbimpl_fl_set_raw_raw(RBASIC(obj), flags);
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Sets the given flag(s).
*
* ```CXX
* auto v = rb_eval_string("...");
* RB_FL_SET(v, RUBY_FL_FREEZE);
* ```
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` set.
*/
static inline void
RB_FL_SET(VALUE obj, VALUE flags)
{
if (RB_FL_ABLE(obj)) {
RB_FL_SET_RAW(obj, flags);
}
}
RBIMPL_ATTR_NOALIAS()
RBIMPL_ATTR_ARTIFICIAL()
/**
* @private
*
* This is an implenentation detail of RB_FL_UNSET(). 3rd parties need not use
* this. Just always use RB_FL_UNSET().
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` cleared.
*
* @internal
*
* This is function is here to annotate a part of RB_FL_UNSET_RAW() as
* `__declspec(noalias)`.
*/
static inline void
rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
{
obj->flags &= ~flags;
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_FL_UNSET(). 3rd parties need not use
* this. Just always use RB_FL_UNSET().
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` cleared.
*/
static inline void
RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
rbimpl_fl_unset_raw_raw(RBASIC(obj), flags);
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Clears the given flag(s).
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` cleard.
*/
static inline void
RB_FL_UNSET(VALUE obj, VALUE flags)
{
if (RB_FL_ABLE(obj)) {
RB_FL_UNSET_RAW(obj, flags);
}
}
RBIMPL_ATTR_NOALIAS()
RBIMPL_ATTR_ARTIFICIAL()
/**
* @private
*
* This is an implenentation detail of RB_FL_REVERSE(). 3rd parties need not
* use this. Just always use RB_FL_REVERSE().
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` reversed.
*
* @internal
*
* This is function is here to annotate a part of RB_FL_REVERSE_RAW() as
* `__declspec(noalias)`.
*/
static inline void
rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
{
obj->flags ^= flags;
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_FL_REVERSE(). 3rd parties need not
* use this. Just always use RB_FL_REVERSE().
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` cleared.
*/
static inline void
RB_FL_REVERSE_RAW(VALUE obj, VALUE flags)
{
RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags);
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* Reverses the flags. This function is here mainly for symmetry on set/unset.
* Rarely used in practice.
*
* @param[out] obj Object in question.
* @param[in] flags A set of enum ::ruby_fl_type.
* @post `obj` has `flags` reversed.
*/
static inline void
RB_FL_REVERSE(VALUE obj, VALUE flags)
{
if (RB_FL_ABLE(obj)) {
RB_FL_REVERSE_RAW(obj, flags);
}
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] obj Object in question.
* @return false always.
*/
static inline bool
RB_OBJ_TAINTABLE(VALUE obj)
{
return false;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] obj Object in question.
* @return false always.
*/
static inline VALUE
RB_OBJ_TAINTED_RAW(VALUE obj)
{
return false;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] obj Object in question.
* @return false always.
*/
static inline bool
RB_OBJ_TAINTED(VALUE obj)
{
return false;
}
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] obj Object in question.
*/
static inline void
RB_OBJ_TAINT_RAW(VALUE obj)
{
return;
}
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] obj Object in question.
*/
static inline void
RB_OBJ_TAINT(VALUE obj)
{
return;
}
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] dst Victim object.
* @param[in] src Infectant object.
*/
static inline void
RB_OBJ_INFECT_RAW(VALUE dst, VALUE src)
{
return;
}
RBIMPL_ATTR_ARTIFICIAL()
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
/**
* @deprecated This function once was a thing in the old days, but makes no
* sense any longer today. Exists here for backwards
* compatibility only. You can safely forget about it.
*
* @param[in] dst Victim object.
* @param[in] src Infectant object.
*/
static inline void
RB_OBJ_INFECT(VALUE dst, VALUE src)
{
return;
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_OBJ_FROZEN(). 3rd parties need not
* use this. Just always use RB_OBJ_FROZEN().
*
* @param[in] obj Object in question.
* @retval RUBY_FL_FREEZE Yes it is.
* @retval 0 No it isn't.
*
* @internal
*
* It is intentional not to return bool here. There is a place in ruby core
* (namely `class.c:singleton_class_of()`) where return value of this function
* is passed to RB_FL_SET_RAW().
*/
static inline VALUE
RB_OBJ_FROZEN_RAW(VALUE obj)
{
return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE);
}
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
* Checks if an object is frozen.
*
* @param[in] obj Object in question.
* @retval true Yes it is.
* @retval false No it isn't.
*/
static inline bool
RB_OBJ_FROZEN(VALUE obj)
{
if (! RB_FL_ABLE(obj)) {
return true;
}
else {
return RB_OBJ_FROZEN_RAW(obj);
}
}
RBIMPL_ATTR_ARTIFICIAL()
/**
* This is an implenentation detail of RB_OBJ_FREEZE(). 3rd parties need not
* use this. Just always use RB_OBJ_FREEZE().
*
* @param[out] obj Object in question.
*/
static inline void
RB_OBJ_FREEZE_RAW(VALUE obj)
{
RB_FL_SET_RAW(obj, RUBY_FL_FREEZE);
}
RUBY_SYMBOL_EXPORT_BEGIN
void rb_obj_freeze_inline(VALUE obj);
RUBY_SYMBOL_EXPORT_END
#endif /* RBIMPL_FL_TYPE_H */

57
libs/libruby/ruby/internal/gc.h vendored Normal file
View File

@@ -0,0 +1,57 @@
#ifndef RBIMPL_GC_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_GC_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Registering values to the GC.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Inform the garbage collector that `valptr` points to a live Ruby object that
* should not be moved. Note that extensions should use this API on global
* constants instead of assuming constants defined in Ruby are always alive.
* Ruby code can remove global constants.
*/
void rb_gc_register_address(VALUE *valptr);
/**
* An alias for `rb_gc_register_address()`.
*/
void rb_global_variable(VALUE *);
/**
* Inform the garbage collector that a pointer previously passed to
* `rb_gc_register_address()` no longer points to a live Ruby object.
*/
void rb_gc_unregister_address(VALUE *valptr);
/**
* Inform the garbage collector that `object` is a live Ruby object that should
* not be moved.
*
* See also: rb_gc_register_address()
*/
void rb_gc_register_mark_object(VALUE object);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_GC_H */

113
libs/libruby/ruby/internal/glob.h vendored Normal file
View File

@@ -0,0 +1,113 @@
#ifndef RBIMPL_GLOB_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_GLOB_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Declares ::rb_glob().
*/
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* Type of a glob callback function. Called every time glob scans a path.
*
* @param[in] path The path in question.
* @param[in] arg The argument passed to rb_glob().
* @param[in] enc Encoding of the path.
* @retval -1 Not enough memory to do the operation.
* @retval 0 Operation successful.
* @retval otherwise Opaque exception state.
* @note You can use rb_protect() to generate the return value.
*
* @internal
*
* This is a wrong design. Type of `enc` should have been `rb_encoding*`
* instead of just `void*`. But we cannot change the API any longer.
*
* Though not a part of our public API, the "opaque exception state" is in fact
* an enum ruby_tag_type. You can see the potential "otherwise" values by
* looking at vm_core.h.
*/
typedef int ruby_glob_func(const char *path, VALUE arg, void *enc);
RBIMPL_ATTR_NONNULL(())
/**
* The "glob" operator. Expands the given pattern against the actual local
* filesystem, then iterates over the expanded filenames by calling the
* callback function.
*
* @param[in] pattern A glob pattern.
* @param[in] func Identical to ruby_glob_func, except it can raise
* exceptions instead of returning opaque state.
* @param[in] arg Extra argument passed to func.
* @exception rb_eException Can propagate what `func` raises.
* @note The language accepted as the pattern is not a regular
* expression. It resembles shell's glob.
*/
void rb_glob(const char *pattern, void (*func)(const char *path, VALUE arg, void *enc), VALUE arg);
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_glob(), except it returns opaque exception states instead of
* raising exceptions.
*
* @param[in] pattern A glob pattern.
* @param[in] flags No, you are not allowed to use this. Just pass 0.
* @param[in] func A callback function.
* @param[in] arg Extra argument passed to func.
* @return Return value of `func`.
*
* @internal
*
* This function is completely broken by design... Not only is there no sane
* way to pass flags, but there also is no sane way to know what a return value
* is meant to be.
*
* Though not a part of our public API, and @shyouhei thinks it's a failure not
* to be a public API, the flags can be `FNM_EXTGLOB`, `FNM_DOTMATCH` etc.
* Look at dir.c for the list.
*
* Though not a part of our public API, the return value is in fact an
* enum ruby_tag_type. You can see the potential values by looking at
* vm_core.h.
*/
int ruby_glob(const char *pattern, int flags, ruby_glob_func *func, VALUE arg);
RBIMPL_ATTR_NONNULL(())
/**
* Identical to ruby_glob(), @shyouhei currently suspects. Historically you
* had to call this function instead of ruby_glob() if the pattern included
* "{x,y,...}" syntax. However since commit 0f63d961169989a7f6dcf7c0487fe29da,
* ruby_glob() also supports that syntax. It seems as of writing these two
* functions provide basically the same functionality in a different
* implementation. Is this analysis right? Correct me! :FIXME:
*
* @param[in] pattern A glob pattern.
* @param[in] flags No, you are not allowed to use this. Just pass 0.
* @param[in] func A callback function.
* @param[in] arg Extra argument passed to func.
* @return Return value of `func`.
*/
int ruby_brace_glob(const char *pattern, int flags, ruby_glob_func *func, VALUE arg);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_GLOB_H */

209
libs/libruby/ruby/internal/globals.h vendored Normal file
View File

@@ -0,0 +1,209 @@
#ifndef RBIMPL_GLOBALS_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_GLOBALS_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Ruby-level global variables / constants, visible from C.
*/
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/special_consts.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
/**
* @defgroup object Core objects and their operations
*
* @internal
*
* There are several questionable constants listed in this header file. They
* are intentionally left untouched for purely academic backwards compatibility
* concerns. But for instance do any one of 3rd party extension libraries even
* need to know that there is NameError::Message?
*
* @endinternal
*
* @{
*/
RBIMPL_SYMBOL_EXPORT_BEGIN()
/**
* @private
*
* @deprecated This macro once was a thing in the old days, but makes no sense
* any longer today. Exists here for backwards compatibility
* only. You can safely forget about it.
*/
#define RUBY_INTEGER_UNIFICATION 1
RUBY_EXTERN VALUE rb_mKernel; /**< `Kernel` module. */
RUBY_EXTERN VALUE rb_mComparable; /**< `Comparable` module. */
RUBY_EXTERN VALUE rb_mEnumerable; /**< `Enumerable` module. */
RUBY_EXTERN VALUE rb_mErrno; /**< `Errno` module. */
RUBY_EXTERN VALUE rb_mFileTest; /**< `FileTest` module. */
RUBY_EXTERN VALUE rb_mGC; /**< `GC` module. */
RUBY_EXTERN VALUE rb_mMath; /**< `Math` module. */
RUBY_EXTERN VALUE rb_mProcess; /**< `Process` module. */
RUBY_EXTERN VALUE rb_mWaitReadable; /**< `IO::WaitReadable` module. */
RUBY_EXTERN VALUE rb_mWaitWritable; /**< `IO::WaitReadable` module. */
RUBY_EXTERN VALUE rb_cBasicObject; /**< `BasicObject` class. */
RUBY_EXTERN VALUE rb_cObject; /**< `Object` class. */
RUBY_EXTERN VALUE rb_cArray; /**< `Array` class. */
RUBY_EXTERN VALUE rb_cBinding; /**< `Binding` class. */
RUBY_EXTERN VALUE rb_cClass; /**< `Class` class. */
RUBY_EXTERN VALUE rb_cDir; /**< `Dir` class. */
RUBY_EXTERN VALUE rb_cEncoding; /**< `Encoding` class. */
RUBY_EXTERN VALUE rb_cEnumerator; /**< `Enumerator` class. */
RUBY_EXTERN VALUE rb_cFalseClass; /**< `FalseClass` class. */
RUBY_EXTERN VALUE rb_cFile; /**< `File` class. */
RUBY_EXTERN VALUE rb_cComplex; /**< `Complex` class. */
RUBY_EXTERN VALUE rb_cFloat; /**< `Float` class. */
RUBY_EXTERN VALUE rb_cHash; /**< `Hash` class. */
RUBY_EXTERN VALUE rb_cIO; /**< `IO` class. */
RUBY_EXTERN VALUE rb_cInteger; /**< `Module` class. */
RUBY_EXTERN VALUE rb_cMatch; /**< `MatchData` class. */
RUBY_EXTERN VALUE rb_cMethod; /**< `Method` class. */
RUBY_EXTERN VALUE rb_cModule; /**< `Module` class. */
RUBY_EXTERN VALUE rb_cRefinement; /**< `Refinement` class. */
RUBY_EXTERN VALUE rb_cNameErrorMesg; /**< `NameError::Message` class. */
RUBY_EXTERN VALUE rb_cNilClass; /**< `NilClass` class. */
RUBY_EXTERN VALUE rb_cNumeric; /**< `Numeric` class. */
RUBY_EXTERN VALUE rb_cProc; /**< `Proc` class. */
RUBY_EXTERN VALUE rb_cRandom; /**< `Random` class. */
RUBY_EXTERN VALUE rb_cRange; /**< `Range` class. */
RUBY_EXTERN VALUE rb_cRational; /**< `Rational` class. */
RUBY_EXTERN VALUE rb_cRegexp; /**< `Regexp` class. */
RUBY_EXTERN VALUE rb_cStat; /**< `File::Stat` class. */
RUBY_EXTERN VALUE rb_cString; /**< `String` class. */
RUBY_EXTERN VALUE rb_cStruct; /**< `Struct` class. */
RUBY_EXTERN VALUE rb_cSymbol; /**< `Sumbol` class. */
RUBY_EXTERN VALUE rb_cThread; /**< `Thread` class. */
RUBY_EXTERN VALUE rb_cTime; /**< `Time` class. */
RUBY_EXTERN VALUE rb_cTrueClass; /**< `TrueClass` class. */
RUBY_EXTERN VALUE rb_cUnboundMethod; /**< `UnboundMethod` class. */
/**
* @}
* @addtogroup exception
* @{
*/
RUBY_EXTERN VALUE rb_eException; /**< Mother of all exceptions. */
RUBY_EXTERN VALUE rb_eStandardError; /**< `StandardError` exception. */
RUBY_EXTERN VALUE rb_eSystemExit; /**< `SystemExit` exception. */
RUBY_EXTERN VALUE rb_eInterrupt; /**< `Interrupt` exception. */
RUBY_EXTERN VALUE rb_eSignal; /**< `SignalException` exception. */
RUBY_EXTERN VALUE rb_eFatal; /**< `fatal` exception. */
RUBY_EXTERN VALUE rb_eArgError; /**< `ArgumentError` exception. */
RUBY_EXTERN VALUE rb_eEOFError; /**< `EOFError` exception. */
RUBY_EXTERN VALUE rb_eIndexError; /**< `IndexError` exception. */
RUBY_EXTERN VALUE rb_eStopIteration; /**< `StopIteration` exception. */
RUBY_EXTERN VALUE rb_eKeyError; /**< `KeyError` exception. */
RUBY_EXTERN VALUE rb_eRangeError; /**< `RangeError` exception. */
RUBY_EXTERN VALUE rb_eIOError; /**< `IOError` exception. */
RUBY_EXTERN VALUE rb_eRuntimeError; /**< `RuntimeError` exception. */
RUBY_EXTERN VALUE rb_eFrozenError; /**< `FrozenError` exception. */
RUBY_EXTERN VALUE rb_eSecurityError; /**< `SecurityError` exception. */
RUBY_EXTERN VALUE rb_eSystemCallError; /**< `SystemCallError` exception. */
RUBY_EXTERN VALUE rb_eThreadError; /**< `ThreadError` exception. */
RUBY_EXTERN VALUE rb_eTypeError; /**< `TypeError` exception. */
RUBY_EXTERN VALUE rb_eZeroDivError; /**< `ZeroDivisionError` exception. */
RUBY_EXTERN VALUE rb_eNotImpError; /**< `NotImplementedError` exception. */
RUBY_EXTERN VALUE rb_eNoMemError; /**< `NoMemoryError` exception. */
RUBY_EXTERN VALUE rb_eNoMethodError; /**< `NoMethodError` exception. */
RUBY_EXTERN VALUE rb_eFloatDomainError; /**< `FloatDomainError` exception. */
RUBY_EXTERN VALUE rb_eLocalJumpError; /**< `LocalJumpError` exception. */
RUBY_EXTERN VALUE rb_eSysStackError; /**< `SystemStackError` exception. */
RUBY_EXTERN VALUE rb_eRegexpError; /**< `RegexpError` exception. */
RUBY_EXTERN VALUE rb_eEncodingError; /**< `EncodingError` exception. */
RUBY_EXTERN VALUE rb_eEncCompatError; /**< `Encoding::CompatibilityError` exception. */
RUBY_EXTERN VALUE rb_eNoMatchingPatternError; /**< `NoMatchingPatternError` exception. */
RUBY_EXTERN VALUE rb_eNoMatchingPatternKeyError; /**< `NoMatchingPatternKeyError` exception. */
RUBY_EXTERN VALUE rb_eScriptError; /**< `ScriptError` exception. */
RUBY_EXTERN VALUE rb_eNameError; /**< `NameError` exception. */
RUBY_EXTERN VALUE rb_eSyntaxError; /**< `SyntaxError` exception. */
RUBY_EXTERN VALUE rb_eLoadError; /**< `LoadError` exception. */
RUBY_EXTERN VALUE rb_eMathDomainError; /**< `Math::DomainError` exception. */
/**
* @}
* @addtogroup object
* @{
*/
RUBY_EXTERN VALUE rb_stdin; /**< `STDIN` constant. */
RUBY_EXTERN VALUE rb_stdout; /**< `STDOUT` constant. */
RUBY_EXTERN VALUE rb_stderr; /**< `STDERR` constant. */
RBIMPL_ATTR_PURE()
/**
* Object to class mapping function. Every object have its class. This
* function obtains that.
*
* @param[in] obj Target object to query.
* @return The class of the given object.
*
* @internal
*
* This function is a super-duper hot path. Optimised targeting modern C
* compilers and x86_64 architecture.
*/
static inline VALUE
rb_class_of(VALUE obj)
{
if (! RB_SPECIAL_CONST_P(obj)) {
return RBASIC_CLASS(obj);
}
else if (obj == RUBY_Qfalse) {
return rb_cFalseClass;
}
else if (obj == RUBY_Qnil) {
return rb_cNilClass;
}
else if (obj == RUBY_Qtrue) {
return rb_cTrueClass;
}
else if (RB_FIXNUM_P(obj)) {
return rb_cInteger;
}
else if (RB_STATIC_SYM_P(obj)) {
return rb_cSymbol;
}
else if (RB_FLONUM_P(obj)) {
return rb_cFloat;
}
#if !RUBY_DEBUG
RBIMPL_UNREACHABLE_RETURN(Qfalse);
#else
RUBY_ASSERT_FAIL("unexpected type");
#endif
}
#define CLASS_OF rb_class_of /**< @old{rb_class_of} */
RBIMPL_SYMBOL_EXPORT_END()
/** @} */
#endif /* RBIMPL_GLOBALS_H */

View File

@@ -0,0 +1,163 @@
#ifndef RBIMPL_HAS_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_ATTRIBUTE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_ATTRIBUTE.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/compiler_since.h"
#if defined(__has_attribute)
# if __has_attribute(pure) || RBIMPL_COMPILER_IS(GCC)
# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
# * __has_attribute. Cygwin copied that content to be a victim of the
# * broken-ness. We don't take them into account. */
# define RBIMPL_HAVE___HAS_ATTRIBUTE 1
# endif
#endif
/** Wraps (or simulates) `__has_attribute`. */
#if defined(RBIMPL_HAVE___HAS_ATTRIBUTE)
# define RBIMPL_HAS_ATTRIBUTE(_) __has_attribute(_)
#elif RBIMPL_COMPILER_IS(GCC)
# /* GCC <= 4 lack __has_attribute predefined macro, while have attributes
# * themselves. We can simulate the macro like the following: */
# define RBIMPL_HAS_ATTRIBUTE(_) (RBIMPL_HAS_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_alloc_size RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_artificial RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0)
# define RBIMPL_HAS_ATTRIBUTE_cdecl RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_cold RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(GCC, 2, 6, 0)
# define RBIMPL_HAS_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0)
# define RBIMPL_HAS_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_error RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_format RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_hot RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_leaf RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0)
# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_undefined RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0)
# define RBIMPL_HAS_ATTRIBUTE_nonnull RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(GCC, 2, 5, 0)
# define RBIMPL_HAS_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(GCC, 2,96, 0)
# define RBIMPL_HAS_ATTRIBUTE_returns_nonnull RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(GCC, 4, 1, 0)
# define RBIMPL_HAS_ATTRIBUTE_stdcall RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_unused RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result RBIMPL_COMPILER_SINCE(GCC, 3, 4, 0)
# define RBIMPL_HAS_ATTRIBUTE_warning RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0)
# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# /* Note that "0, 0, 0" might be inaccurate. */
#elif RBIMPL_COMPILER_IS(SunPro)
# /* Oracle Solaris Studio 12.4 (cc version 5.11) introduced __has_attribute.
# * Before that, following attributes were available. */
# /* See https://docs.oracle.com/cd/F24633_01/index.html */
# define RBIMPL_HAS_ATTRIBUTE(_) (RBIMPL_HAS_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_ATTRIBUTE_alias RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_constructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_destructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_packed RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
# define RBIMPL_HAS_ATTRIBUTE_vector_size RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0)
# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0)
#elif defined (_MSC_VER)
# define RBIMPL_HAS_ATTRIBUTE(_) 0
# /* Fallback below doesn't work: see win32/Makefile.sub */
#else
# /* Take config.h definition when available. */
# define RBIMPL_HAS_ATTRIBUTE(_) ((RBIMPL_HAS_ATTRIBUTE_ ## _)+0)
# ifdef ALWAYS_INLINE
# define RBIMPL_HAS_ATTRIBUTE_always_inline 1
# endif
# ifdef FUNC_CDECL
# define RBIMPL_HAS_ATTRIBUTE_cdecl 1
# endif
# ifdef CONSTFUNC
# define RBIMPL_HAS_ATTRIBUTE_const 1
# endif
# ifdef DEPRECATED
# define RBIMPL_HAS_ATTRIBUTE_deprecated 1
# endif
# ifdef ERRORFUNC
# define RBIMPL_HAS_ATTRIBUTE_error 1
# endif
# ifdef FUNC_FASTCALL
# define RBIMPL_HAS_ATTRIBUTE_fastcall 1
# endif
# ifdef PUREFUNC
# define RBIMPL_HAS_ATTRIBUTE_pure 1
# endif
# ifdef NO_ADDRESS_SAFETY_ANALYSIS
# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis 1
# endif
# ifdef NO_SANITIZE
# define RBIMPL_HAS_ATTRIBUTE_no_sanitize 1
# endif
# ifdef NO_SANITIZE_ADDRESS
# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address 1
# endif
# ifdef NOINLINE
# define RBIMPL_HAS_ATTRIBUTE_noinline 1
# endif
# ifdef RBIMPL_FUNC_NONNULL
# define RBIMPL_HAS_ATTRIBUTE_nonnull 1
# endif
# ifdef NORETURN
# define RBIMPL_HAS_ATTRIBUTE_noreturn 1
# endif
# ifdef FUNC_OPTIMIZED
# define RBIMPL_HAS_ATTRIBUTE_optimize 1
# endif
# ifdef FUNC_STDCALL
# define RBIMPL_HAS_ATTRIBUTE_stdcall 1
# endif
# ifdef MAYBE_UNUSED
# define RBIMPL_HAS_ATTRIBUTE_unused 1
# endif
# ifdef WARN_UNUSED_RESULT
# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result 1
# endif
# ifdef WARNINGFUNC
# define RBIMPL_HAS_ATTRIBUTE_warning 1
# endif
# ifdef WEAK
# define RBIMPL_HAS_ATTRIBUTE_weak 1
# endif
#endif
#endif /* RBIMPL_HAS_ATTRIBUTE_H */

117
libs/libruby/ruby/internal/has/builtin.h vendored Normal file
View File

@@ -0,0 +1,117 @@
#ifndef RBIMPL_HAS_BUILTIN_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_BUILTIN_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_BUILTIN.
*/
#include "ruby/internal/config.h"
#include "ruby/internal/compiler_since.h"
#if defined(__has_builtin)
# if RBIMPL_COMPILER_IS(Intel)
# /* :TODO: Intel C Compiler has __has_builtin (since 19.1 maybe?), and is
# * reportedly broken. We have to skip them. However the situation can
# * change. They might improve someday. We need to revisit here later. */
# elif RBIMPL_COMPILER_IS(GCC) && ! __has_builtin(__builtin_alloca)
# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
# * __has_builtin. Cygwin copied that content to be a victim of the
# * broken-ness. We don't take them into account. */
# else
# define RBIMPL_HAVE___HAS_BUILTIN 1
# endif
#endif
/** Wraps (or simulates) `__has_builtin`. */
#if defined(RBIMPL_HAVE___HAS_BUILTIN)
# define RBIMPL_HAS_BUILTIN(_) __has_builtin(_)
#elif RBIMPL_COMPILER_IS(GCC)
# /* :FIXME: Historically GCC has had tons of builtins, but it implemented
# * __has_builtin only since GCC 10. This section can be made more
# * granular. */
# /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970 */
# define RBIMPL_HAS_BUILTIN(_) (RBIMPL_HAS_BUILTIN_ ## _)
# define RBIMPL_HAS_BUILTIN___builtin_add_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
# define RBIMPL_HAS_BUILTIN___builtin_alloca RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align RBIMPL_COMPILER_SINCE(GCC, 6, 1, 0)
# define RBIMPL_HAS_BUILTIN___builtin_assume 0
# /* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 for bswap16. */
# define RBIMPL_HAS_BUILTIN___builtin_bswap16 RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
#ifndef __OpenBSD__
# define RBIMPL_HAS_BUILTIN___builtin_bswap32 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_bswap64 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
#endif
# define RBIMPL_HAS_BUILTIN___builtin_clz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_clzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_clzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_constant_p RBIMPL_COMPILER_SINCE(GCC, 2,95, 3)
# define RBIMPL_HAS_BUILTIN___builtin_ctz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_ctzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_ctzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_expect RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0)
# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0)
# define RBIMPL_HAS_BUILTIN___builtin_popcount RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_popcountl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_popcountll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
# define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0
# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
# define RBIMPL_HAS_BUILTIN___builtin_unreachable RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0)
# /* Note that "0, 0, 0" might be inaccurate. */
#else
# /* Take config.h definition when available */
# define RBIMPL_HAS_BUILTIN(_) ((RBIMPL_HAS_BUILTIN_ ## _)+0)
# define RBIMPL_HAS_BUILTIN___builtin_add_overflow HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW
# define RBIMPL_HAS_BUILTIN___builtin_alloca 0
# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN
# define RBIMPL_HAS_BUILTIN___builtin_assume 0
# define RBIMPL_HAS_BUILTIN___builtin_assume_aligned HAVE_BUILTIN___BUILTIN_ASSUME_ALIGNED
# define RBIMPL_HAS_BUILTIN___builtin_bswap16 HAVE_BUILTIN___BUILTIN_BSWAP16
# define RBIMPL_HAS_BUILTIN___builtin_bswap32 HAVE_BUILTIN___BUILTIN_BSWAP32
# define RBIMPL_HAS_BUILTIN___builtin_bswap64 HAVE_BUILTIN___BUILTIN_BSWAP64
# define RBIMPL_HAS_BUILTIN___builtin_clz HAVE_BUILTIN___BUILTIN_CLZ
# define RBIMPL_HAS_BUILTIN___builtin_clzl HAVE_BUILTIN___BUILTIN_CLZL
# define RBIMPL_HAS_BUILTIN___builtin_clzll HAVE_BUILTIN___BUILTIN_CLZLL
# define RBIMPL_HAS_BUILTIN___builtin_constant_p HAVE_BUILTIN___BUILTIN_CONSTANT_P
# define RBIMPL_HAS_BUILTIN___builtin_ctz HAVE_BUILTIN___BUILTIN_CTZ
# define RBIMPL_HAS_BUILTIN___builtin_ctzl 0
# define RBIMPL_HAS_BUILTIN___builtin_ctzll HAVE_BUILTIN___BUILTIN_CTZLL
# define RBIMPL_HAS_BUILTIN___builtin_expect HAVE_BUILTIN___BUILTIN_EXPECT
# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P
# define RBIMPL_HAS_BUILTIN___builtin_popcount HAVE_BUILTIN___BUILTIN_POPCOUNT
# define RBIMPL_HAS_BUILTIN___builtin_popcountl 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0
# define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0
# define RBIMPL_HAS_BUILTIN___builtin_popcountll HAVE_BUILTIN___BUILTIN_POPCOUNTLL
# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW
# if defined(HAVE___BUILTIN_UNREACHABLE)
# define RBIMPL_HAS_BUILTIN___builtin_unreachable 1
# else
# define RBIMPL_HAS_BUILTIN___builtin_unreachable 0
# endif
#endif
#endif /* RBIMPL_HAS_BUILTIN_H */

View File

@@ -0,0 +1,38 @@
#ifndef RBIMPL_HAS_C_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_C_ATTRIBUTE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_C_ATTRIBUTE.
*/
/** Wraps (or simulates) `__has_c_attribute`. */
#if defined(__cplusplus)
# /* Makes no sense. */
# define RBIMPL_HAS_C_ATTRIBUTE(_) 0
#elif defined(__has_c_attribute)
# define RBIMPL_HAS_C_ATTRIBUTE(_) __has_c_attribute(_)
#else
# /* As of writing everything that lacks __has_c_attribute also completely
# * lacks C2x attributes as well. Might change in future? */
# define RBIMPL_HAS_C_ATTRIBUTE(_) 0
#endif
#endif /* RBIMPL_HAS_C_ATTRIBUTE_H */

View File

@@ -0,0 +1,86 @@
#ifndef RBIMPL_HAS_CPP_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_CPP_ATTRIBUTE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_CPP_ATTRIBUTE.
*/
#include "ruby/internal/compiler_is.h"
#include "ruby/internal/compiler_since.h"
/** @cond INTERNAL_MACRO */
#if RBIMPL_COMPILER_IS(SunPro)
# /* Oracle Developer Studio 12.5's C++ preprocessor is reportedly broken. We
# * could simulate __has_cpp_attribute like below, but don't know the exact
# * list of which version supported which attribute. Just kill everything for
# * now. If you can please :FIXME: */
# /* https://unicode-org.atlassian.net/browse/ICU-12893 */
# /* https://github.com/boostorg/config/pull/95 */
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) 0
#elif defined(__has_cpp_attribute)
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) __has_cpp_attribute(_)
#elif RBIMPL_COMPILER_IS(MSVC)
# /* MSVC has never updated its __cplusplus since forever (unless specified
# * explicitly by a compiler flag). They also lack __has_cpp_attribute until
# * 2019. However, they do have attributes since 2015 or so. */
# /* https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance */
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_carries_dependency 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_fallthrough 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_maybe_unused 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_nodiscard 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0)
#elif RBIMPL_COMPILER_BEFORE(Clang, 3, 6, 0)
# /* Clang 3.6.0 introduced __has_cpp_attribute. Prior to that following
# * attributes were already there. */
# /* https://clang.llvm.org/cxx_status.html */
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(Clang, 3, 3, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(Clang, 3, 4, 0)
#elif RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0)
# /* GCC 5+ have __has_cpp_attribute, while 4.x had following attributes. */
# /* https://gcc.gnu.org/projects/cxx-status.html */
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) (RBIMPL_HAS_CPP_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0)
#else
# /* :FIXME:
# * Candidate compilers to list here:
# * - icpc: They have __INTEL_CXX11_MODE__.
# */
# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) 0
#endif
/** @endcond */
/** Wraps (or simulates) `__has_cpp_attribute`. */
#if ! defined(__cplusplus)
# /* Makes no sense. */
# define RBIMPL_HAS_CPP_ATTRIBUTE(_) 0
#else
# /* GCC needs workarounds. See https://gcc.godbolt.org/z/jdz3pa */
# define RBIMPL_HAS_CPP_ATTRIBUTE(_) \
((RBIMPL_HAS_CPP_ATTRIBUTE0(_) <= __cplusplus) ? RBIMPL_HAS_CPP_ATTRIBUTE0(_) : 0)
#endif
#endif /* RBIMPL_HAS_CPP_ATTRIBUTE_H */

View File

@@ -0,0 +1,47 @@
#ifndef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_DECLSPEC_ATTRIBUTE.
*/
#include "ruby/internal/compiler_since.h"
/** Wraps (or simulates) `__has_declspec_attribute`. */
#if defined(__has_declspec_attribute)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) __has_declspec_attribute(_)
#else
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) (RBIMPL_HAS_DECLSPEC_ATTRIBUTE_ ## _)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_align RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_empty_bases RBIMPL_COMPILER_SINCE(MSVC,19, 0, 23918)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noalias RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(MSVC,11, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0)
# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_restrict RBIMPL_COMPILER_SINCE(MSVC,14, 0, 0)
# /* Note that "8, 0, 0" might be inaccurate. */
# if ! defined(__cplusplus)
# /* Clang has this in both C/C++, but MSVC has this in C++ only.*/
# undef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow
# endif
#endif
#endif /* RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H */

View File

@@ -0,0 +1,33 @@
#ifndef RBIMPL_HAS_EXTENSION_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_EXTENSION_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_EXTENSION.
*/
#include "ruby/internal/has/feature.h"
/** Wraps (or simulates) `__has_extension`. */
#if defined(__has_extension)
# define RBIMPL_HAS_EXTENSION(_) __has_extension(_)
#else
# /* Pre-3.0 clang had __has_feature but not __has_extension. */
# define RBIMPL_HAS_EXTENSION(_) RBIMPL_HAS_FEATURE(_)
#endif
#endif /* RBIMPL_HAS_EXTENSION_H */

View File

@@ -0,0 +1,31 @@
#ifndef RBIMPL_HAS_FEATURE_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_FEATURE_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_FEATURE.
*/
/** Wraps (or simulates) `__has_feature`. */
#if defined(__has_feature)
# define RBIMPL_HAS_FEATURE(_) __has_feature(_)
#else
# define RBIMPL_HAS_FEATURE(_) 0
#endif
#endif /* RBIMPL_HAS_FEATURE_H */

View File

@@ -0,0 +1,31 @@
#ifndef RBIMPL_HAS_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_HAS_WARNING_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_HAS_WARNING.
*/
/** Wraps (or simulates) `__has_warning`. */
#if defined(__has_warning)
# define RBIMPL_HAS_WARNING(_) __has_warning(_)
#else
# define RBIMPL_HAS_WARNING(_) 0
#endif
#endif /* RBIMPL_HAS_WARNING_H */

View File

@@ -0,0 +1,657 @@
#ifndef RBIMPL_INTERN_ARRAY_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_INTERN_ARRAY_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Public APIs related to ::rb_cArray.
*/
#include "ruby/internal/attr/noalias.h"
#include "ruby/internal/attr/noexcept.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/* array.c */
RBIMPL_ATTR_NONNULL(())
RBIMPL_ATTR_NOALIAS()
/**
* Fills the memory region with a series of ::RUBY_Qnil.
*
* @param[out] buf Buffer to squash.
* @param[in] len Number of objects of `buf`.
* @post `buf` is filled with ::RUBY_Qnil.
*/
void rb_mem_clear(VALUE *buf, long len)
RBIMPL_ATTR_NOEXCEPT(true)
;
/**
* Identical to rb_ary_new_from_values(), except it expects exactly two
* parameters.
*
* @param[in] car Arbitrary ruby object.
* @param[in] cdr Arbitrary ruby object.
* @return An allocated new array, of length 2, whose contents are the
* passed objects.
*/
VALUE rb_assoc_new(VALUE car, VALUE cdr);
/**
* Try converting an object to its array representation using its `to_ary`
* method, if any. If there is no such thing, returns ::RUBY_Qnil.
*
* @param[in] obj Arbitrary ruby object to convert.
* @exception rb_eTypeError `obj.to_ary` returned something non-Array.
* @retval RUBY_Qnil No conversion from `obj` to array defined.
* @retval otherwise Converted array representation of `obj`.
* @see rb_io_check_io
* @see rb_check_string_type
* @see rb_check_hash_type
*/
VALUE rb_check_array_type(VALUE obj);
/**
* Allocates a new, empty array.
*
* @return An allocated new array, whose length is 0.
*/
VALUE rb_ary_new(void);
/**
* Identical to rb_ary_new(), except it additionally specifies how many rooms
* of objects it should allocate. This way you can create an array whose
* capacity is bigger than the length of it. If you can say that an array
* grows to a specific amount, this could be effective than resizing an array
* over and over again and again.
*
* @param[in] capa Designed capacity of the generating array.
* @return An empty array, whose capacity is `capa`.
*/
VALUE rb_ary_new_capa(long capa);
/**
* Constructs an array from the passed objects.
*
* @param[in] n Number of passed objects.
* @param[in] ... Arbitrary ruby objects, filled into the returning array.
* @return An array of size `n`, whose contents are the passed objects.
*/
VALUE rb_ary_new_from_args(long n, ...);
/**
* Identical to rb_ary_new_from_args(), except how objects are passed.
*
* @param[in] n Number of objects of `elts`.
* @param[in] elts Arbitrary ruby objects, filled into the returning array.
* @return An array of size `n`, whose contents are the passed objects.
*/
VALUE rb_ary_new_from_values(long n, const VALUE *elts);
/**
* Allocates a hidden (no class) empty array.
*
* @param[in] capa Designed capacity of the array.
* @return A hidden, empty array.
* @see rb_obj_hide()
*/
VALUE rb_ary_hidden_new(long capa);
#define rb_ary_tmp_new rb_ary_hidden_new
/**
* Destroys the given array for no reason.
*
* @warning DO NOT USE IT.
* @warning Leave this task to our GC.
* @warning It was a wrong indea at the first place to let you know about it.
*
* @param[out] ary The array to be executed.
* @post The given array no longer exists.
* @note Maybe `Array#clear` could be what you want.
*
* @internal
*
* Should have moved this to `internal/array.h`.
*/
void rb_ary_free(VALUE ary);
/**
* Declares that the array is about to be modified. This for instance let the
* array have a dedicated backend storage.
*
* @param[out] ary Array about to be modified.
* @exception rb_eFrozenError `ary` is frozen.
* @post Upon successful return the passed array is eligible to be
* modified.
*/
void rb_ary_modify(VALUE ary);
/** @alias{rb_obj_freeze} */
VALUE rb_ary_freeze(VALUE obj);
RBIMPL_ATTR_PURE()
/**
* Queries if the passed two arrays share the same backend storage. A use-case
* for knowing such property is to take a snapshot of an array (using
* e.g. rb_ary_replace()), then check later if that snapshot still shares the
* storage with the original. Taking a snapshot is ultra-cheap. If nothing
* happens the impact shall be minimal. But if someone modifies the original,
* that entity shall pay the cost of copy-on-write. You can detect that using
* this API.
*
* @param[in] lhs Comparison LHS.
* @param[in] rhs Comparison RHS.
* @retval RUBY_Qtrue They share the same backend storage.
* @retval RUBY_Qfalse They are distinct.
* @pre Both arguments must be of ::RUBY_T_ARRAY.
*/
VALUE rb_ary_shared_with_p(VALUE lhs, VALUE rhs);
/**
* Queries element(s) of an array. This is complicated! Refer `Array#slice`
* document for the complete description of how it behaves.
*
* @param[in] argc Number of objects of `argv`.
* @param[in] argv Up to 2 objects.
* @param[in] ary Target array.
* @exception rb_eTypeError `argv` (or its part) includes non-Integer.
* @exception rb_eRangeError rb_cArithSeq is passed, and is OOB.
* @return An element (if requested), or an array of elements (if
* requested), or ::RUBY_Qnil (if index OOB).
*
* @internal
*
* ```rbs
* # "int" is ::Integer or `#to_int`, defined in builtin.rbs
*
* class ::Array[unchecked out T]
* def slice
* : (int i) -> T?
* | (int beg, int len) -> ::Array[T]?
* | (Range[int] r) -> ::Array[T]?
* | (ArithmeticSequence as) -> ::Array[T]? # This also raises RagneError.
* end
* ```
*/
VALUE rb_ary_aref(int argc, const VALUE *argv, VALUE ary);
/**
* Obtains a part of the passed array.
*
* @param[in] ary Target array.
* @param[in] beg Subpart index.
* @param[in] len Requested length of returning array.
* @retval RUBY_Qnil Requested range out of bounds of `ary`.
* @retval otherwise An allocated new array whose contents are `ary`'s
* `beg` to `len`.
* @note Return array can be shorter than `len` when for instance
* `[0, 1, 2, 3]`'s 4th to 1,000,000,000th is requested.
*/
VALUE rb_ary_subseq(VALUE ary, long beg, long len);
/**
* Destructively stores the passed value to the passed array's passed index.
* It also resizes the array's backend storage so that the requested index is
* not out of bounds.
*
* @param[out] ary Target array to modify.
* @param[in] key Where to store `val`.
* @param[in] val What to store at `key`.
* @exception rb_eFrozenError `ary` is frozen.
* @exception rb_eIndexError `key` is negative.
* @post `ary`'s `key`th position is occupied with `val`.
* @post Depending on `key` and previous length of `ary` this operation
* can also create a series of "hole" positions inside of the
* backend storage. They are filled with ::RUBY_Qnil.
*/
void rb_ary_store(VALUE ary, long key, VALUE val);
/**
* Duplicates an array.
*
* @param[in] ary Target to duplicate.
* @return An allocated new array whose contents are identical to `ary`.
*
* @internal
*
* Not sure why this has to be something different from `ary_make_shared_copy`,
* which seems much efficient.
*/
VALUE rb_ary_dup(VALUE ary);
/**
* I guess there is no use case of this function in extension libraries, but
* this is a routine identical to rb_ary_dup(). This makes the most sense when
* the passed array is formerly hidden by rb_obj_hide().
*
* @param[in] ary An array, possibly hidden.
* @return A duplicated new instance of ::rb_cArray.
*/
VALUE rb_ary_resurrect(VALUE ary);
/**
* Force converts an object to an array. It first tries its `#to_ary` method.
* Takes the result if any. Otherwise creates an array of size 1 whose sole
* element is the passed object.
*
* @param[in] obj Arbitrary ruby object.
* @return An array representation of `obj`.
* @note Unlike rb_str_to_str() which is a variant of
* rb_check_string_type(), rb_ary_to_ary() is not a variant of
* rb_check_array_type().
*/
VALUE rb_ary_to_ary(VALUE obj);
/**
* Converts an array into a human-readable string. Historically its behaviour
* changed over time. Currently it is identical to calling `inspect` method.
* This behaviour is from that of python (!!) circa 2006.
*
* @param[in] ary Array to inspect.
* @return Recursively inspected representation of `ary`.
* @see `[ruby-dev:29520]`
*/
VALUE rb_ary_to_s(VALUE ary);
/**
* Destructively appends multiple elements at the end of the array.
*
* @param[out] ary Where to push `train`.
* @param[in] train Arbitrary ruby objects to push to `ary`.
* @param[in] len Number of objects of `train`.
* @exception rb_eIndexError `len` too large.
* @exception rb_eFrozenError `ary` is frozen.
* @return The passed `ary`.
* @post `ary` has contents from `train` appended at its end.
*/
VALUE rb_ary_cat(VALUE ary, const VALUE *train, long len);
/**
* Special case of rb_ary_cat() that it adds only one element.
*
* @param[out] ary Where to push `elem`.
* @param[in] elem Arbitrary ruby object to push.
* @exception rb_eFrozenError `ary` is frozen.
* @return The passed `ary`.
* @post `ary` has `elem` appended at its end.
*/
VALUE rb_ary_push(VALUE ary, VALUE elem);
/**
* Destructively deletes an element from the end of the passed array and
* returns what was deleted.
*
* @param[out] ary Target array to modify.
* @exception rb_eFrozenError `ary` is frozen.
* @return What was at the end of `ary`, or ::RUBY_Qnil if there is
* nothing to remove.
* @post `ary`'s last element, if any, is removed.
* @note There is no way to distinguish whether `ary` was an 1-element
* array whose content was ::RUBY_Qnil, or was empty.
*/
VALUE rb_ary_pop(VALUE ary);
/**
* Destructively deletes an element from the beginning of the passed array and
* returns what was deleted. It can also be seen as a routine identical to
* rb_ary_pop(), except which side of the array to scrub.
*
* @param[out] ary Target array to modify.
* @exception rb_eFrozenError `ary` is frozen.
* @return What was at the beginning of `ary`, or ::RUBY_Qnil if there is
* nothing to remove.
* @post `ary`'s first element, if any, is removed. As the name implies
* everything else remaining in `ary` gets moved towards `ary`'s
* beginning.
* @note There is no way to distinguish whether `ary` was an 1-element
* array whose content was ::RUBY_Qnil, or was empty.
*/
VALUE rb_ary_shift(VALUE ary);
/**
* Destructively prepends the passed item at the beginning of the passed array.
* It can also be seen as a routine identical to rb_ary_push(), except which
* side of the array to modify.
*
* @param[out] ary Target array to modify.
* @param[in] elem Arbitrary ruby object to unshift.
* @exception rb_eFrozenError `ary` is frozen.
* @return The passed `ary`.
* @post `ary` has `elem` prepended at this beginning.
*/
VALUE rb_ary_unshift(VALUE ary, VALUE elem);
RBIMPL_ATTR_PURE()
/**
* Queries an element of an array. When passed offset is negative it counts
* backwards.
*
* @param[in] ary An array to look into.
* @param[in] off Offset (can be negative).
* @return ::RUBY_Qnil when `off` is out of bounds of `ary`. Otherwise
* what is stored at `off`-th position of `ary`.
* @note `ary`'s `off`-th element can happen to be ::RUBY_Qnil.
*/
VALUE rb_ary_entry(VALUE ary, long off);
/**
* Iteratively yields each element of the passed array to the implicitly passed
* block if any. In case there is no block given, an enumerator that does the
* thing is generated instead.
*
* @param[in] ary Array to iterate over.
* @retval ary Passed block was evaluated.
* @retval otherwise An instance of ::rb_cEnumerator for `Array#each`.
*/
VALUE rb_ary_each(VALUE ary);
/**
* Recursively stringises the elements of the passed array, flattens that
* result, then joins the sequence using the passed separator.
*
* @param[in] ary Target array to convert.
* @param[in] sep Separator. Either a string, or ::RUBY_Qnil
* if you want no separator.
* @exception rb_eArgError Infinite recursion in `ary`.
* @exception rb_eTypeError `sep` is not a string.
* @exception rb_eEncCompatError Strings do not agree with their encodings.
* @return An instance of ::rb_cString which concatenates stringised
* contents of `ary`, using `sep` as separator.
*/
VALUE rb_ary_join(VALUE ary, VALUE sep);
/**
* _Destructively_ reverses the passed array in-place.
*
* @warning This is `Array#reverse!`, not `Array#reverse`.
* @param[out] ary Target array to modify.
* @exception rb_eFrozenError `ary` is frozen.
* @return Passed `ary`.
* @post `ary` is reversed.
*/
VALUE rb_ary_reverse(VALUE ary);
/**
* _Destructively_ rotates the passed array in-place to towards its end. The
* amount can be negative. Would rotate to the opposite direction then.
*
* @warning This is `Array#rotate!`, not `Array#rotate`.
* @param[out] ary Target array to modify.
* @param[in] rot Amount of rotation.
* @exception rb_eFrozenError `ary` is frozen.
* @retval RUBY_Qnil Not rotated.
* @retval ary Rotated.
* @post `ary` is rotated.
*/
VALUE rb_ary_rotate(VALUE ary, long rot);
/**
* Creates a copy of the passed array, whose elements are sorted according to
* their `<=>` result.
*
* @param[in] ary Array to sort.
* @exception rb_eArgError Comparison not defined among elements.
* @exception rb_eRuntimeError Infinite recursion in `<=>`.
* @return A copy of `ary`, sorted.
* @note As of writing this function uses `qsort` as backend algorithm,
* which means the result is unstable (in terms of sort stability).
*/
VALUE rb_ary_sort(VALUE ary);
/**
* Destructively sorts the passed array in-place, according to each elements'
* `<=>` result.
*
* @param[in] ary Target array to modify.
* @exception rb_eArgError Comparison not defined among elements.
* @exception rb_eRuntimeError Infinite recursion in `<=>`.
* @return Passed `ary`.
* @post `ary` is sorted.
* @note As of writing this function uses `qsort` as backend algorithm,
* which means the result is unstable (in terms of sort stability).
*/
VALUE rb_ary_sort_bang(VALUE ary);
/**
* Destructively removes elements from the passed array, so that there would be
* no elements inside that satisfy `==` relationship with the passed object.
* Returns the last deleted element if any. But in case there was nothing to
* delete it gets complicated. It checks for the implicitly passed block. If
* there is a block the return value would be what the block evaluates to.
* Otherwise it resorts to ::RUBY_Qnil.
*
* @param[out] ary Target array to modify.
* @param[in] elem Template object to match against each element.
* @exception rb_eFrozenError `ary` is frozen.
* @return What was deleted, or what was the block returned, or
* ::RUBY_Qnil (see above).
* @post All elements that have `==` relationship with `elem` are purged
* from `ary`. Elements shift their positions so that `ary` gets
* compact.
*
* @internal
*
* Internally there also is `rb_ary_delete_same`, which compares by identity.
*/
VALUE rb_ary_delete(VALUE ary, VALUE elem);
/**
* Destructively removes an element which resides at the specific index of the
* passed array. Unlike rb_ary_stre() the index can be negative, which means
* the index counts backwards from the array's tail.
*
* @param[out] ary Target array to modify.
* @param[in] pos Position (can be negative).
* @exception rb_eFrozenError `ary` is frozen.
* @return What was deleted, or ::RUBY_Qnil in case of OOB.
* @post `ary`'s `pos`-th element is deleted if any.
* @note There is no way to distinguish whether `pos` is out of bound,
* or `pos` did exist but stored ::RUBY_Qnil as an ordinal value.
*/
VALUE rb_ary_delete_at(VALUE ary, long pos);
/**
* Destructively removes everything form an array.
*
* @param[out] ary Target array to modify.
* @exception rb_eFrozenError `ary` is frozen.
* @return The passed `ary`.
* @post `ary` is an empty array.
*/
VALUE rb_ary_clear(VALUE ary);
/**
* Creates a new array, concatenating the former to the latter.
*
* @param[in] lhs Source array #1.
* @param[in] rhs Source array #2.
* @exception rb_eIndexError Result array too big.
* @return A new array containing `rhs` concatenated to `lhs`.
* @note This operation doesn't commute. Don't get confused by the
* "plus" terminology. For historical reasons there are some
* noncommutative `+`s in Ruby. This is one of such things. There
* has been a long discussion around `+`s in programming languages.
*
* @internal
*
* rb_ary_concat() is not a destructive version of rb_ary_plus(). They raise
* different exceptions. Don't know why though.
*/
VALUE rb_ary_plus(VALUE lhs, VALUE rhs);
/**
* Destructively appends the contents of latter into the end of former.
*
* @param[out] lhs Destination array.
* @param[in] rhs Source array.
* @exception rb_eFrozenError `lhs` is frozen.
* @exception rb_eIndexError Result array too big.
* @exception rb_eTypeError `rhs` doesn't respond to `#to_ary`.
* @return The passed `lhs`.
* @post `lhs` has contents of `rhs` appended to its end.
*/
VALUE rb_ary_concat(VALUE lhs, VALUE rhs);
/**
* Looks up the passed key, assuming the passed array is an alist. An "alist"
* here is a list of "association"s, much like that of Emacs. Emacs has
* `assoc` function that behaves exactly the same as this one.
*
* ```ruby
* # This is an example of aliist.
* auto_mode_alist = [
* [ /\.[ch]\z/, :"c-mode" ],
* [ /\.[ch]pp\z/, :"c++-mode" ],
* [ /\.awk\z/, :"awk-mode" ],
* [ /\.cs\z/, :"csharp-mode" ],
* [ /\.go\z/, :"go-mode" ],
* [ /\.java\z/, :"java-mode" ],
* [ /\.pas\z/, :"pascal-mode" ],
* [ /\.rs\z/, :"rust-mode" ],
* [ /\.txt\z/, :"text-mode" ],
* ]
* ```
*
* This function scans the passed array looking for an element, which itself is
* an array, whose first element is the passed key. If no such element is
* found, returns ::RUBY_Qnil.
*
* Although this function expects the passed array be an array of arrays, it
* can happily accept non-array elements; it just ignores such things.
*
* @param[in] alist An array of arrays.
* @param[in] key Needle.
* @retval RUBY_Qnil Nothing was found.
* @retval otherwise An element in `alist` whose first element is in `==`
* relationship with `key`.
*/
VALUE rb_ary_assoc(VALUE alist, VALUE key);
/**
* Identical to rb_ary_assoc(), except it scans the passed array from the
* opposite direction.
*
* @param[in] alist An array of arrays.
* @param[in] key Needle.
* @retval RUBY_Qnil Nothing was found.
* @retval otherwise An element in `alist` whose first element is in `==`
* relationship with `key`.
*/
VALUE rb_ary_rassoc(VALUE alist, VALUE key);
/**
* Queries if the passed array has the passed entry.
*
* @param[in] ary Target array to scan.
* @param[in] elem Target array to find.
* @retval RUBY_Qfalse No element in `ary` is in `==` relationship with
* `elem`.
* @retval RUBY_Qtrue There is at least one element in `ary` which is in
* `==` relationship with `elem`.
*
* @internal
*
* This is the only function in the entire C API that is named using third
* person singular form of a verb (except #ISASCII etc., which are not our
* naming). The counterpart Ruby API of this function is `Array#include?`.
*/
VALUE rb_ary_includes(VALUE ary, VALUE elem);
/**
* Recursively compares each elements of the two arrays one-by-one using `<=>`.
*
* @param[in] lhs Comparison LHS.
* @param[in] rhs Comparison RHS.
* @retval RUBY_Qnil `lhs` and `rhs` are not comparable.
* @retval -1 `lhs` is less than `rhs`.
* @retval 0 They are equal.
* @retval 1 `rhs` is less then `lhs`.
*/
VALUE rb_ary_cmp(VALUE lhs, VALUE rhs);
/**
* Replaces the contents of the former object with the contents of the latter.
*
* @param[out] copy Destination object.
* @param[in] orig Source object.
* @exception rb_eTypeError `orig` has no implicit conversion to Array.
* @exception rb_eFrozenError `copy` is frozen.
* @return The passed `copy`.
* @post `copy`'s former components are abandoned. It now has the
* identical length and contents to `orig`.
*/
VALUE rb_ary_replace(VALUE copy, VALUE orig);
/**
* This _was_ a generalisation of `Array#values_at`, `Struct#values_at`, and
* `MatchData#values_at`. It begun its life as a refactoring effort. However
* as Ruby evolves over time, as of writing none of aforementioned methods
* share their implementations at all. This function is not deprecated; still
* works as it has been. But it is now kind of like a rudimentum.
*
* This function takes an object, which is a receiver, and a series of
* "indices", which are either integers, or ranges of integers. Calls the
* passed callback for each of those indices, along with the receiver. This
* callback is expected to do something like rb_ary_aref(), rb_struct_aref(),
* etc. In case of a range index rb_range_beg_len() expands the range.
* Finally return values of the callback are gathered as an array, then
* returned.
*
* @param[in] obj Arbitrary ruby object.
* @param[in] olen "Length" of `obj`.
* @param[in] argc Number of objects of `argv`.
* @param[in] argv List of "indices", described above.
* @param[in] func Callback function.
* @return A new instance of ::rb_cArray gathering `func`outputs.
*
* @internal
*
* `Array#values_at` no longer uses this function. There is no reason apart
* from historical ones to list this function here.
*/
VALUE rb_get_values_at(VALUE obj, long olen, int argc, const VALUE *argv, VALUE (*func)(VALUE obj, long oidx));
/**
* Expands or shrinks the passed array to the passed length.
*
* @param[out] ary An array to modify.
* @param[in] len Desired length of `ary`.
* @exception rb_eFrozenError `ary` is frozen.
* @exception rb_eIndexError `len` too long.
* @return The passed `ary`.
* @post `ary`'s length is `len`.
* @post Depending on `len` and previous length of `ary` this operation
* can also create a series of "hole" positions inside of the
* backend storage. They are filled with ::RUBY_Qnil.
*
* @internal
*
* `len` is signed. Intentional or...?
*/
VALUE rb_ary_resize(VALUE ary, long len);
#define rb_ary_new2 rb_ary_new_capa /**< @old{rb_ary_new_capa} */
#define rb_ary_new3 rb_ary_new_from_args /**< @old{rb_ary_new_from_args} */
#define rb_ary_new4 rb_ary_new_from_values /**< @old{rb_ary_new_from_values} */
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_INTERN_ARRAY_H */

View File

@@ -0,0 +1,846 @@
#ifndef RBIMPL_INTERN_BIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_INTERN_BIGNUM_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Public APIs related to so-called rb_cBignum.
*/
#include "ruby/internal/config.h"
#ifdef STDC_HEADERS
# include <stddef.h>
#endif
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/backward/2/long_long.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/* bignum.c */
/**
* Allocates a bignum object.
*
* @param[in] len Length of the bignum's backend storage, in words.
* @param[in] sign Sign of the bignum.
* @return An allocated new bignum instance.
* @note This only allocates an object, doesn't fill its value in.
*
* @internal
*
* @shyouhei finds it hard to use from extension libraries. `len` is per
* `BDIGIT` but its definition is hidden.
*/
VALUE rb_big_new(size_t len, int sign);
/**
* Queries if the passed bignum instance is a "bigzro". What is a bigzero?
* Well, bignums are for very big integers, but can also represent tiny ones
* like -1, 0, 1. Bigzero are instances of bignums whose values are zero.
* Knowing if a bignum is bigzero can be handy on occasions, like for instance
* detecting division by zero situation.
*
* @param[in] x A bignum.
* @retval 1 It is a bigzero.
* @retval 0 Otherwise.
*/
int rb_bigzero_p(VALUE x);
/**
* Duplicates the given bignum.
*
* @param[in] num A bignum.
* @return An allocated bignum, who is equivalent to `num`.
*/
VALUE rb_big_clone(VALUE num);
/**
* Destructively modify the passed bignum into 2's complement representation.
*
* @note By default bignums are in signed magnitude system.
*
* @param[out] num A bignum to modify.
*/
void rb_big_2comp(VALUE num);
/**
* Normalises the passed bignum. It for instance returns a fixnum of the same
* value if fixnum can represent that number.
*
* @param[out] x Target bignum (can be destructively modified).
* @return An integer of the identical value (can be `x` itself).
*/
VALUE rb_big_norm(VALUE x);
/**
* Destructively resizes the backend storage of the passed bignum.
*
* @param[out] big A bignum.
* @param[in] len New length of `big`'s backend, in words.
*/
void rb_big_resize(VALUE big, size_t len);
RBIMPL_ATTR_NONNULL(())
/**
* Parses C's string to convert into a Ruby's integer. It understands prefixes
* (e.g. `0x`) and underscores.
*
* @param[in] str Stringised representation of the return value.
* @param[in] base Base of conversion. Must be `-36..36` inclusive,
* except `1`. `2..36` means the conversion is done
* according to it, with unmatched prefix understood
* as a part of the result. `-36..-2` means the
* conversion honours prefix when present, or use
* `-base` when absent. `0` is equivalent to `-10`.
* `-1` mandates a prefix. `1` is an error.
* @param[in] badcheck Whether to raise ::rb_eArgError on failure. If
* `0` is passed here this function can return
* `INT2FIX(0)` for parse errors.
* @exception rb_eArgError Failed to parse (and `badcheck` is truthy).
* @return An instance of ::rb_cInteger, which is a numeric interpretation
* of what is written in `str`.
*
* @internal
*
* Not sure if it intentionally accepts `base == -1` or is just buggy. Nobody
* practically uses negative bases these days.
*/
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck);
/**
* Identical to rb_cstr2inum(), except it takes Ruby's strings instead of C's.
*
* @param[in] str Stringised representation of the return
* value.
* @param[in] base Base of conversion. Must be `-36..36`
* inclusive, except `1`. `2..36` means the
* conversion is done according to it, with
* unmatched prefix understood as a part of the
* result. `-36..-2` means the conversion
* honours prefix when present, or use `-base`
* when absent. `0` is equivalent to `-10`.
* `-1` mandates a prefix. `1` is an error.
* @param[in] badcheck Whether to raise ::rb_eArgError on failure.
* If `0` is passed here this function can
* return `INT2FIX(0)` for parse errors.
* @exception rb_eArgError Failed to parse (and `badcheck` is truthy).
* @exception rb_eTypeError `str` is not a string.
* @exception rb_eEncCompatError `str` is not ASCII compatible.
* @return An instance of ::rb_cInteger, which is a numeric interpretation
* of what is written in `str`.
*/
VALUE rb_str_to_inum(VALUE str, int base, int badcheck);
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_cstr_to_inum(), except the second argument controls the base
* and badcheck at once. It basically doesn't raise for parse errors, unless
* the base is zero.
*
* This is an older API. New codes might prefer rb_cstr_to_inum().
*
* @param[in] str Stringised representation of the return value.
* @param[in] base Base of conversion. Must be `-36..36` inclusive,
* except `1`. `2..36` means the conversion is done
* according to it, with unmatched prefix understood
* as a part of the result. `-36..-2` means the
* conversion honours prefix when present, or use
* `-base` when absent. `0` is equivalent to `-10`.
* `-1` mandates a prefix. `1` is an error.
* @exception rb_eArgError Failed to parse (and `base` is zero).
* @return An instance of ::rb_cInteger, which is a numeric interpretation
* of what is written in `str`.
*/
VALUE rb_cstr2inum(const char *str, int base);
/**
* Identical to rb_str_to_inum(), except the second argument controls the base
* and badcheck at once. It can also be seen as a routine identical to
* rb_cstr2inum(), except it takes Ruby's strings instead of C's.
*
* This is an older API. New codes might prefer rb_cstr_to_inum().
*
* @param[in] str Stringised representation of the return
* value.
* @param[in] base Base of conversion. Must be `-36..36`
* inclusive, except `1`. `2..36` means the
* conversion is done according to it, with
* unmatched prefix understood as a part of the
* result. `-36..-2` means the conversion
* honours prefix when present, or use `-base`
* when absent. `0` is equivalent to `-10`.
* `-1` mandates a prefix. `1` is an error.
* @exception rb_eArgError Failed to parse (and `base` is zero).
* @exception rb_eTypeError `str` is not a string.
* @exception rb_eEncCompatError `str` is not ASCII compatible.
* @return An instance of ::rb_cInteger, which is a numeric interpretation
* of what is written in `str`.
*/
VALUE rb_str2inum(VALUE str, int base);
/**
* Generates a place-value representation of the passed integer.
*
* @param[in] x An integer to stringify.
* @param[in] base `2` to `36` inclusive for each radix.
* @exception rb_eArgError `base` is out of range.
* @exception rb_eRangeError `x` is too big, cannot represent in string.
* @return An instance of ::rb_cString which represents `x`.
*/
VALUE rb_big2str(VALUE x, int base);
/**
* Converts a bignum into C's `long`.
*
* @param[in] x A bignum.
* @exception rb_eRangeError `x` is out of range of `long`.
* @return The passed value converted into C's `long`.
*/
long rb_big2long(VALUE x);
/** @alias{rb_big2long} */
#define rb_big2int(x) rb_big2long(x)
/**
* Converts a bignum into C's `unsigned long`.
*
* @param[in] x A bignum.
* @exception rb_eRangeError `x` is out of range of `unsigned long`.
* @return The passed value converted into C's `unsigned long`.
*
* @internal
*
* This function can generate a very large positive integer for a negative
* input. For instance applying Ruby's -4,611,686,018,427,387,905 to this
* function yields C's 13,835,058,055,282,163,711 on my machine. This is how
* it has been. Cannot change any longer.
*/
unsigned long rb_big2ulong(VALUE x);
/** @alias{rb_big2long} */
#define rb_big2uint(x) rb_big2ulong(x)
#if HAVE_LONG_LONG
/**
* Converts a bignum into C's `long long`.
*
* @param[in] x A bignum.
* @exception rb_eRangeError `x` is out of range of `long long`.
* @return The passed value converted into C's `long long`.
*/
LONG_LONG rb_big2ll(VALUE);
/**
* Converts a bignum into C's `unsigned long long`.
*
* @param[in] x A bignum.
* @exception rb_eRangeError `x` is out of range of `unsigned long long`.
* @return The passed value converted into C's `unsigned long long`.
*
* @internal
*
* This function can generate a very large positive integer for a negative
* input. For instance applying Ruby's -4,611,686,018,427,387,905 to this
* function yields C's 13,835,058,055,282,163,711 on my machine. This is how
* it has been. Cannot change any longer.
*/
unsigned LONG_LONG rb_big2ull(VALUE);
#endif /* HAVE_LONG_LONG */
RBIMPL_ATTR_NONNULL(())
/**
* Converts a bignum into a series of its parts.
*
* @param[in] val An integer.
* @param[out] buf Return buffer.
* @param[in] num_longs Number of words of `buf`.
* @exception rb_eTypeError `val` doesn't respond to `#to_int`.
* @post `buf` is filled with `val`'s 2's complement representation, in
* the host CPU's native byte order, from least significant word
* towards the most significant one, for `num_longs` words.
* @note The "pack" terminology comes from `Array#pack`.
*/
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);
RBIMPL_ATTR_NONNULL(())
/**
* Constructs a (possibly very big) bignum from a series of integers. `buf[0]`
* would be the return value's least significant word; `buf[num_longs-1]` would
* be that of most significant.
*
* @param[in] buf A series of integers.
* @param[in] num_longs Number of words of `buf`.
* @exception rb_eArgError Result would be too big.
* @return An instance of ::rb_cInteger which is an "unpack"-ed value of
* the parameters.
* @note The "unpack" terminology comes from `String#pack`.
*/
VALUE rb_big_unpack(unsigned long *buf, long num_longs);
/* pack.c */
RBIMPL_ATTR_NONNULL(())
/**
* Encodes a Unicode codepoint into its UTF-8 representation.
*
* @param[out] buf Return buffer, must at least be 6 bytes width.
* @param[in] uv An Unicode codepoint.
* @exception rb_eRangeError `uv` is out of Unicode.
* @return Number of bytes written to `buf`
* @post `buf` holds a UTF-8 representation of `uv`.
*/
int rb_uv_to_utf8(char buf[6], unsigned long uv);
/* bignum.c */
/**
* Converts a C's `double` into a bignum.
*
* @param[in] d A value to convert.
* @exception rb_eFloatDomainError `d` is Inf/NaN.
* @return An instance of ::rb_cInteger whose value is approximately `d`.
*
* @internal
*
* @shyouhei is not sure if the result is guaranteed to be the nearest integer
* of `d`.
*/
VALUE rb_dbl2big(double d);
/**
* Converts a bignum into C's `double`.
*
* @param[in] x A bignum.
* @return The passed value converted into C's `double`.
*
* @internal
*
* @shyouhei is not sure if the result is guaranteed to be `x`'s nearest value
* that a `double` can represent.
*/
double rb_big2dbl(VALUE x);
/**
* Compares the passed two bignums.
*
* @param[in] lhs Comparison LHS.
* @param[in] rhs Comparison RHS.
* @retval -1 `rhs` is bigger than `lhs`.
* @retval 0 They are identical.
* @retval 1 `lhs` is bigger than `rhs`.
* @see rb_num_coerce_cmp()
*/
VALUE rb_big_cmp(VALUE lhs, VALUE rhs);
/**
* Equality, in terms of `==`. This checks if the _value_ is the same, not the
* identity. For instance `1 == 1.0` must hold.
*
* @param[in] lhs Comparison LHS.
* @param[in] rhs Comparison RHS.
* @retval RUBY_Qtrue They are the same.
* @retval RUBY_Qfalse They are different.
*/
VALUE rb_big_eq(VALUE lhs, VALUE rhs);
/**
* Equality, in terms of `eql?`. Unlike rb_big_eq() it does not convert
* ::rb_cFloat etc. This function returns ::RUBY_Qtrue if and only if both
* parameters are bignums, which represent the identical numerical value.
*
* @param[in] lhs Comparison LHS.
* @param[in] rhs Comparison RHS.
* @retval RUBY_Qtrue They are identical.
* @retval RUBY_Qfalse They are distinct.
*/
VALUE rb_big_eql(VALUE lhs, VALUE rhs);
/**
* Performs addition of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x + y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_big_plus(VALUE x, VALUE y);
/**
* Performs subtraction of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x - y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_big_minus(VALUE x, VALUE y);
/**
* Performs multiplication of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x * y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_big_mul(VALUE x, VALUE y);
/**
* Performs division of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x / y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_big_div(VALUE x, VALUE y);
/**
* Performs "integer division". This is different from rb_big_div().
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x.div y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_big_idiv(VALUE x, VALUE y);
/**
* Performs modulo of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x % y` evaluates to.
* @see rb_num_coerce_bin()
*
* @internal
*
* There also is `rb_big_remainder()` internally, which is different from this
* one.
*/
VALUE rb_big_modulo(VALUE x, VALUE y);
/**
* Performs "divmod" operation. The operation in bignum's context is that it
* calculates rb_big_idiv() and rb_big_modulo() at once.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x.divmod y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_big_divmod(VALUE x, VALUE y);
/**
* Raises `x` to the powerof `y`.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x ** y` evaluates to.
* @see rb_num_coerce_bin()
* @note This can return an instance of ::rb_cFloat, even when both `x`
* and `y` are bignums. Or an instance of ::rb_cRational, when for
* instance `y` is negative.
*/
VALUE rb_big_pow(VALUE x, VALUE y);
/**
* Performs bitwise and of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x & y` evaluates to.
* @see rb_num_coerce_bit()
*/
VALUE rb_big_and(VALUE x, VALUE y);
/**
* Performs bitwise or of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x | y` evaluates to.
* @see rb_num_coerce_bit()
*/
VALUE rb_big_or(VALUE x, VALUE y);
/**
* Performs exclusive or of the passed two objects.
*
* @param[in] x A bignum.
* @param[in] y Arbitrary ruby object.
* @return What `x ^ y` evaluates to.
* @see rb_num_coerce_bit()
*/
VALUE rb_big_xor(VALUE x, VALUE y);
/**
* Performs shift left.
*
* @param[in] x A bignum.
* @param[in] y Shift amount.
* @exception rb_eTypeError `y` is not an integer.
* @exception rb_eArgError `y` is too big.
* @return `x` shifted left to `y` bits.
* @note `y` can be negative. Shifts right then.
*/
VALUE rb_big_lshift(VALUE x, VALUE y);
/**
* Performs shift right.
*
* @param[in] x A bignum.
* @param[in] y Shift amount.
* @exception rb_eTypeError `y` is not an integer.
* @return `x` shifted right to `y` bits.
* @note This is arithmetic. Because bignums are not bitfields there is
* no shift right logical operator.
*/
VALUE rb_big_rshift(VALUE x, VALUE y);
/**
* @name Flags for rb_integer_pack()/rb_integer_unpack()
* @{
*/
/** Stores/interprets the most significant word as the first word. */
#define INTEGER_PACK_MSWORD_FIRST 0x01
/** Stores/interprets the least significant word as the first word. */
#define INTEGER_PACK_LSWORD_FIRST 0x02
/**
* Stores/interprets the most significant byte in a word as the first byte in
* the word.
*/
#define INTEGER_PACK_MSBYTE_FIRST 0x10
/**
* Stores/interprets the least significant byte in a word as the first byte in
* the word.
*/
#define INTEGER_PACK_LSBYTE_FIRST 0x20
/**
* Means either #INTEGER_PACK_MSBYTE_FIRST or #INTEGER_PACK_LSBYTE_FIRST,
* depending on the host processor's endian.
*/
#define INTEGER_PACK_NATIVE_BYTE_ORDER 0x40
/** Uses 2's complement representation. */
#define INTEGER_PACK_2COMP 0x80
/** Uses "generic" implementation (handy on test). */
#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION 0x400
/**
* Always generates a bignum object even if the integer can be representable
* using fixnum scheme (unpack only)
*/
#define INTEGER_PACK_FORCE_BIGNUM 0x100
/**
* Interprets the input as a signed negative number (unpack only). If not
* specified returns a positive number.
*/
#define INTEGER_PACK_NEGATIVE 0x200
/** Little endian combination. */
#define INTEGER_PACK_LITTLE_ENDIAN \
(INTEGER_PACK_LSWORD_FIRST | \
INTEGER_PACK_LSBYTE_FIRST)
/** Big endian combination */
#define INTEGER_PACK_BIG_ENDIAN \
(INTEGER_PACK_MSWORD_FIRST | \
INTEGER_PACK_MSBYTE_FIRST)
/** @} */
RBIMPL_ATTR_NONNULL(())
/**
* Exports an integer into a buffer. This function fills the buffer specified
* by `words` and `numwords` as `val` in the format specified by `wordsize`,
* `nails` and `flags`.
*
* @param[in] val Integer or integer-like object which has
* `#to_int` method.
* @param[out] words Return buffer.
* @param[in] numwords Number of words of `words`.
* @param[in] wordsize Number of bytes per word.
* @param[in] nails Number of padding bits in a word. Most
* significant nails bits of each word are filled
* by zero.
* @param[in] flags Bitwise or of constants whose name starts
* "INTEGER_PACK_".
* @exception rb_eTypeError `val` doesn't respond to `#to_int`.
*
* Possible flags are:
*
* - #INTEGER_PACK_MSWORD_FIRST:
* Stores the most significant word as the first word.
*
* - #INTEGER_PACK_LSWORD_FIRST:
* Stores the least significant word as the first word.
*
* - #INTEGER_PACK_MSBYTE_FIRST:
* Stores the most significant byte in a word as the first byte in the
* word.
*
* - #INTEGER_PACK_LSBYTE_FIRST:
* Stores the least significant byte in a word as the first byte in the
* word.
*
* - #INTEGER_PACK_NATIVE_BYTE_ORDER:
* Either #INTEGER_PACK_MSBYTE_FIRST or #INTEGER_PACK_LSBYTE_FIRST
* corresponding to the host's endian.
*
* - #INTEGER_PACK_2COMP:
* Uses 2's complement representation.
*
* - #INTEGER_PACK_LITTLE_ENDIAN: Shorthand of
* `INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_LSBYTE_FIRST`.
*
* - #INTEGER_PACK_BIG_ENDIAN: Shorthand of
* `INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_MSBYTE_FIRST`.
*
* - #INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION:
* Uses generic implementation (for test and debug).
*
* This function fills the buffer specified by `words` as `val`'s 2's
* complement representation if #INTEGER_PACK_2COMP is specified in `flags`.
* Otherwise it fills `words` as `abs(val)` and signedness is returned via the
* return value.
*
* @return The signedness and overflow condition. The overflow condition
* depends on #INTEGER_PACK_2COMP.
*
* When #INTEGER_PACK_2COMP is not specified:
*
* - `-2` :
* Negative overflow. `val <= -2**(numwords*(wordsize*CHAR_BIT-nails))`
*
* - `-1` :
* Negative without overflow.
* `-2**(numwords*(wordsize*CHAR_BIT-nails)) < val < 0`
*
* - `0` : zero. `val == 0`
*
* - `1` :
* Positive without overflow.
* `0 < val < 2**(numwords*(wordsize*CHAR_BIT-nails))`
*
* - `2` :
* Positive overflow. `2**(numwords*(wordsize*CHAR_BIT-nails)) <= val`
*
* When #INTEGER_PACK_2COMP is specified:
*
* - `-2` :
* Negative overflow. `val < -2**(numwords*(wordsize*CHAR_BIT-nails))`
*
* - `-1` :
* Negative without overflow.
* `-2**(numwords*(wordsize*CHAR_BIT-nails)) <= val < 0`
*
* - `0` : zero. `val == 0`
*
* - `1` :
* Positive without overflow.
* `0 < val < 2**(numwords*(wordsize*CHAR_BIT-nails))`
*
* - `2` :
* Positive overflow. `2**(numwords*(wordsize*CHAR_BIT-nails)) <= val`
*
* The value, `-2**(numwords*(wordsize*CHAR_BIT-nails))`, is representable in
* 2's complement representation but not representable in absolute value. So
* `-1` is returned for the value if #INTEGER_PACK_2COMP is specified but
* returns `-2` if #INTEGER_PACK_2COMP is not specified.
*
* The least significant words are filled in the buffer when overflow occur.
*/
int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
RBIMPL_ATTR_NONNULL(())
/**
* Import an integer from a buffer.
*
* @param[in] words Buffer to import.
* @param[in] numwords Number of words of `words`.
* @param[in] wordsize Number of bytes per word.
* @param[in] nails Number of padding bits in a word. Most
* significant nails bits of each word are ignored.
* @param[in] flags Bitwise or of constants whose name starts
* "INTEGER_PACK_".
* @exception rb_eArgError `numwords * wordsize` too big.
*
* Possible flags are:
*
* - #INTEGER_PACK_MSWORD_FIRST:
* Interpret the first word as the most significant word.
*
* - #INTEGER_PACK_LSWORD_FIRST:
* Interpret the first word as the least significant word.
*
* - #INTEGER_PACK_MSBYTE_FIRST:
* Interpret the first byte in a word as the most significant byte in the
* word.
*
* - #INTEGER_PACK_LSBYTE_FIRST:
* Interpret the first byte in a word as the least significant byte in
* the word.
*
* - #INTEGER_PACK_NATIVE_BYTE_ORDER:
* Either #INTEGER_PACK_MSBYTE_FIRST or #INTEGER_PACK_LSBYTE_FIRST
* corresponding to the host's endian.
*
* - #INTEGER_PACK_2COMP:
* Uses 2's complement representation.
*
* - #INTEGER_PACK_LITTLE_ENDIAN: Shorthand of
* `INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_LSBYTE_FIRST`
*
* - #INTEGER_PACK_BIG_ENDIAN: Shorthand of
* `INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_MSBYTE_FIRST`
*
* - #INTEGER_PACK_FORCE_BIGNUM:
* Returns a bignum even if its value is representable as a fixnum.
*
* - #INTEGER_PACK_NEGATIVE:
* Returns a non-positive value. (Returns a non-negative value if not
* specified.)
*
* - #INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION:
* Uses generic implementation (for test and debug).
*
* @return An instance of ::rb_cInteger whose value is the interpreted
* `words`. The range of the result value depends on
* #INTEGER_PACK_2COMP and #INTEGER_PACK_NEGATIVE.
*
* When #INTEGER_PACK_2COMP is not set:
*
* - `0 <= val < 2**(numwords*(wordsize*CHAR_BIT-nails))` if
* `!INTEGER_PACK_NEGATIVE`
*
* - `-2**(numwords*(wordsize*CHAR_BIT-nails)) < val <= 0` if
* `INTEGER_PACK_NEGATIVE`
*
* When #INTEGER_PACK_2COMP is set:
*
* - `-2**(numwords*(wordsize*CHAR_BIT-nails)-1)` `<= val <=`
* `2**(numwords*(wordsize*CHAR_BIT-nails)-1)-1` if
* `!INTEGER_PACK_NEGATIVE`
*
* - `-2**(numwords*(wordsize*CHAR_BIT-nails)) <= val <= -1` if
* `INTEGER_PACK_NEGATIVE`
*
* Passing #INTEGER_PACK_2COMP without #INTEGER_PACK_NEGATIVE means sign
* extension. #INTEGER_PACK_2COMP with #INTEGER_PACK_NEGATIVE means assuming
* the higher bits are `1`.
*
* Note that this function returns 0 when `numwords` is zero and
* #INTEGER_PACK_2COMP is set but #INTEGER_PACK_NEGATIVE is not set.
*/
VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
/**
* Calculates the number of bytes needed to represent the absolute value of the
* passed integer.
*
* @param[in] val Integer or integer-like object which has
* `#to_int` method.
* @param[out] nlz_bits_ret Number of leading zero bits in the most
* significant byte is returned if not `NULL`.
* @exception rb_eTypeError `val` doesn't respond to `#to_int`.
* @return `((val_numbits * CHAR_BIT + CHAR_BIT - 1) / CHAR_BIT)`, where
* val_numbits is the number of bits of `abs(val)`.
* @post If `nlz_bits_ret` is not `NULL`,
* `(return_value * CHAR_BIT - val_numbits)` is stored in
* `*nlz_bits_ret`. In this case,
* `0 <= *nlz_bits_ret < CHAR_BIT`.
*
* This function should not overflow.
*/
size_t rb_absint_size(VALUE val, int *nlz_bits_ret);
/**
* Calculates the number of words needed represent the absolute value of the
* passed integer. Unlike rb_absint_size() this function can overflow. It
* returns `(size_t)-1` then.
*
* @param[in] val Integer or integer-like object which has
* `#to_int` method.
* @param[in] word_numbits Number of bits per word.
* @param[out] nlz_bits_ret Number of leading zero bits in the most
* significant word is returned if not `NULL`.
* @exception rb_eTypeError `val` doesn't respond to `#to_int`.
* @retval (size_t)-1 Overflowed.
* @retval otherwise
`((val_numbits * CHAR_BIT + word_numbits - 1) / word_numbits)`,
* where val_numbits is the number of bits of `abs(val)`.
* @post If `nlz_bits_ret` is not `NULL` and there is no overflow,
* `(return_value * word_numbits - val_numbits)` is stored in
* `*nlz_bits_ret`. In this case,
* `0 <= *nlz_bits_ret < word_numbits.`
*
*/
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret);
/**
* Tests `abs(val)` consists only of a bit or not.
*
* @param[in] val Integer or integer-like object which has
* `#to_int` method.
* @exception rb_eTypeError `val` doesn't respond to `#to_int`.
* @retval 1 `abs(val) == 1 << n` for some `n >= 0`.
* @retval 0 Otherwise.
*
* rb_absint_singlebit_p() can be used to determine required buffer size for
* rb_integer_pack() used with #INTEGER_PACK_2COMP (two's complement).
*
* Following example calculates number of bits required to represent val in
* two's complement number, without sign bit.
*
* ```CXX
* size_t size;
* int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
* size = rb_absint_numwords(val, 1, NULL)
* if (size == (size_t)-1) ...overflow...
* if (neg && rb_absint_singlebit_p(val))
* size--;
* ```
*
* Following example calculates number of bytes required to represent val in
* two's complement number, with sign bit.
*
* ```CXX
* size_t size;
* int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
* int nlz_bits;
* size = rb_absint_size(val, &nlz_bits);
* if (nlz_bits == 0 && !(neg && rb_absint_singlebit_p(val)))
* size++;
* ```
*/
int rb_absint_singlebit_p(VALUE val);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_INTERN_BIGNUM_H */

View File

@@ -0,0 +1,394 @@
#ifndef RBIMPL_INTERN_CLASS_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_INTERN_CLASS_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Public APIs related to ::rb_cClass/::rb_cModule.
*/
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/backward/2/stdarg.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/* class.c */
/**
* Creates a new, anonymous class.
*
* @param[in] super What would become a parent class.
* @exception rb_eTypeError `super` is not something inheritable.
* @return An anonymous class that inherits `super`.
*/
VALUE rb_class_new(VALUE super);
/**
* The comment that comes with this function says `:nodoc:`. Not sure what
* that means though.
*
* @param[out] clone Destination object.
* @param[in] orig Source object.
* @exception rb_eTypeError Cannot copy `orig`.
* @return The passed `clone`.
*/
VALUE rb_mod_init_copy(VALUE clone, VALUE orig);
/**
* Asserts that the given class can derive a child class. A class might or
* might not be able to do so; for instance a singleton class cannot.
*
* @param[in] super Possible super class.
* @exception rb_eTypeError No it cannot.
* @post Upon successful return `super` can derive.
*/
void rb_check_inheritable(VALUE super);
/**
* This is a very badly designed API that creates an anonymous class.
*
* @param[in] id Discarded for no reason (why...).
* @param[in] super What would become a parent class. 0 means
* ::rb_cObject.
* @exception rb_eTypeError `super` is not something inheritable.
* @return An anonymous class that inherits `super`.
* @warning You must explicitly name the return value.
*/
VALUE rb_define_class_id(ID id, VALUE super);
/**
* Identical to rb_define_class_under(), except it takes the name in ::ID
* instead of C's string.
*
* @param[out] outer A class which contains the new class.
* @param[in] id Name of the new class
* @param[in] super A class from which the new class will derive.
* 0 means ::rb_cObject.
* @exception rb_eTypeError The constant name `id` is already taken but the
* constant is not a class.
* @exception rb_eTypeError The class is already defined but the class can
* not be reopened because its superclass is not
* `super`.
* @exception rb_eArgError `super` is NULL.
* @return The created class.
* @post `outer::id` refers the returned class.
* @note If a class named `id` is already defined and its superclass is
* `super`, the function just returns the defined class.
* @note The compaction GC does not move classes returned by this
* function.
*/
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super);
/**
* Creates a new, anonymous module.
*
* @return An anonymous module.
*/
VALUE rb_module_new(void);
/**
* Creates a new, anonymous refinement.
*
* @return An anonymous refinement.
*/
VALUE rb_refinement_new(void);
/**
* This is a very badly designed API that creates an anonymous module.
*
* @param[in] id Discarded for no reason (why...).
* @return An anonymous module.
* @warning You must explicitly name the return value.
*/
VALUE rb_define_module_id(ID id);
/**
* Identical to rb_define_module_under(), except it takes the name in ::ID
* instead of C's string.
*
* @param[out] outer A class which contains the new module.
* @param[in] id Name of the new module
* @exception rb_eTypeError The constant name `id` is already taken but the
* constant is not a module.
* @return The created module.
* @post `outer::id` refers the returned module.
* @note The compaction GC does not move classes returned by this
* function.
*/
VALUE rb_define_module_id_under(VALUE outer, ID id);
/**
* Queries the list of included modules. It can also be seen as a routine to
* first call rb_mod_ancestors(), then rejects non-modules from the return
* value.
*
* @param[in] mod Class or Module.
* @return An array of modules that are either included or prepended in any
* of `mod`'s ancestry tree (including itself).
*/
VALUE rb_mod_included_modules(VALUE mod);
/**
* Queries if the passed module is included by the module. It can also be seen
* as a routine to first call rb_mod_included_modules(), then see if the return
* value contains the passed module.
*
* @param[in] child A Module.
* @param[in] parent Another Module.
* @exception rb_eTypeError `child` is not an instance of ::rb_cModule.
* @retval RUBY_Qtrue `parent` is either included or prepended in any
* of `child`'s ancestry tree (including itself).
* @return RUBY_Qfalse Otherwise.
*/
VALUE rb_mod_include_p(VALUE child, VALUE parent);
/**
* Queries the module's ancestors. This routine gathers classes and modules
* that the passed module either inherits, includes, or prepends, then
* recursively applies that routine again and again to the collected entries
* until the list doesn't grow up.
*
* @param[in] mod A module or a class.
* @return An array of classes or modules that `mod` possibly recursively
* inherits, includes, or prepends.
*
* @internal
*
* Above description is written in a recursive language but in practice it
* computes the return value iteratively.
*/
VALUE rb_mod_ancestors(VALUE mod);
/**
* Queries the class's descendants. This routine gathers classes that are
* subclasses of the given class (or subclasses of those subclasses, etc.),
* returning an array of classes that have the given class as an ancestor.
* The returned array does not include the given class or singleton classes.
*
* @param[in] klass A class.
* @return An array of classes where `klass` is an ancestor.
*
* @internal
*/
VALUE rb_class_descendants(VALUE klass);
/**
* Queries the class's direct descendants. This routine gathers classes that are
* direct subclasses of the given class,
* returning an array of classes that have the given class as a superclass.
* The returned array does not include singleton classes.
*
* @param[in] klass A class.
* @return An array of classes where `klass` is the `superclass`.
*
* @internal
*/
VALUE rb_class_subclasses(VALUE klass);
/**
* Returns the attached object for a singleton class.
* If the given class is not a singleton class, raises a TypeError.
*
* @param[in] klass A class.
* @return The object which has the singleton class `klass`.
*
* @internal
*/
VALUE rb_class_attached_object(VALUE klass);
/**
* Generates an array of symbols, which are the list of method names defined in
* the passed class.
*
* @param[in] argc Number of objects of `argv`.
* @param[in] argv Array of at most one object, which controls (if
* any) whether the return array includes the names
* of methods defined in ancestors or not.
* @param[in] mod A module or a class.
* @exception rb_eArgError `argc` out of range.
* @return An array of symbols collecting names of instance methods that
* are not private, defined at `mod`.
*/
VALUE rb_class_instance_methods(int argc, const VALUE *argv, VALUE mod);
/**
* Identical to rb_class_instance_methods(), except it returns names of methods
* that are public only.
*
* @param[in] argc Number of objects of `argv`.
* @param[in] argv Array of at most one object, which controls (if
* any) whether the return array includes the names
* of methods defined in ancestors or not.
* @param[in] mod A module or a class.
* @exception rb_eArgError `argc` out of range.
* @return An array of symbols collecting names of instance methods that
* are public, defined at `mod`.
*/
VALUE rb_class_public_instance_methods(int argc, const VALUE *argv, VALUE mod);
/**
* Identical to rb_class_instance_methods(), except it returns names of methods
* that are protected only.
*
* @param[in] argc Number of objects of `argv`.
* @param[in] argv Array of at most one object, which controls (if
* any) whether the return array includes the names
* of methods defined in ancestors or not.
* @param[in] mod A module or a class.
* @exception rb_eArgError `argc` out of range.
* @return An array of symbols collecting names of instance methods that
* are protected, defined at `mod`.
*/
VALUE rb_class_protected_instance_methods(int argc, const VALUE *argv, VALUE mod);
/**
* Identical to rb_class_instance_methods(), except it returns names of methods
* that are private only.
*
* @param[in] argc Number of objects of `argv`.
* @param[in] argv Array of at most one object, which controls (if
* any) whether the return array includes the names
* of methods defined in ancestors or not.
* @param[in] mod A module or a class.
* @exception rb_eArgError `argc` out of range.
* @return An array of symbols collecting names of instance methods that
* are protected, defined at `mod`.
*/
VALUE rb_class_private_instance_methods(int argc, const VALUE *argv, VALUE mod);
/**
* Identical to rb_class_instance_methods(), except it returns names of
* singleton methods instead of instance methods.
*
* @param[in] argc Number of objects of `argv`.
* @param[in] argv Array of at most one object, which controls (if
* any) whether the return array includes the names
* of methods defined in ancestors or not.
* @param[in] obj Arbitrary ruby object.
* @exception rb_eArgError `argc` out of range.
* @return An array of symbols collecting names of instance methods that
* are not private, defined at the singleton class of `obj`.
*/
VALUE rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj);
/**
* Identical to rb_define_method(), except it takes the name of the method in
* ::ID instead of C's string.
*
* @param[out] klass A module or a class.
* @param[in] mid Name of the function.
* @param[in] func The method body.
* @param[in] arity The number of parameters. See @ref defmethod.
* @note There are in fact 18 different prototypes for func.
* @see ::ruby::backward::cxxanyargs::define_method::rb_define_method_id
*/
void rb_define_method_id(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int arity);
/* vm_method.c */
/**
* Inserts a method entry that hides previous method definition of the given
* name. This is not a deletion of a method. Method of the same name defined
* in a parent class is kept invisible in this way.
*
* @param[out] mod The module to insert an undef.
* @param[in] mid Name of the undef.
* @exception rb_eTypeError `klass` is a non-module.
* @exception rb_eFrozenError `klass` is frozen.
* @exception rb_eNameError No such method named `klass#name`.
* @post `klass#name` is undefined.
* @see rb_undef_method
*
* @internal
*
* @shyouhei doesn't understand why this is not the ::ID -taking variant of
* rb_undef_method(), given rb_remove_method() has its ::ID -taking counterpart
* named rb_remove_method_id().
*/
void rb_undef(VALUE mod, ID mid);
/* class.c */
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_define_method(), except it defines a protected method.
*
* @param[out] klass A module or a class.
* @param[in] mid Name of the function.
* @param[in] func The method body.
* @param[in] arity The number of parameters. See @ref defmethod.
* @note There are in fact 18 different prototypes for func.
* @see ::ruby::backward::cxxanyargs::define_method::rb_define_protected_method
*/
void rb_define_protected_method(VALUE klass, const char *mid, VALUE (*func)(ANYARGS), int arity);
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_define_method(), except it defines a private method.
*
* @param[out] klass A module or a class.
* @param[in] mid Name of the function.
* @param[in] func The method body.
* @param[in] arity The number of parameters. See @ref defmethod.
* @note There are in fact 18 different prototypes for func.
* @see ::ruby::backward::cxxanyargs::define_method::rb_define_protected_method
*/
void rb_define_private_method(VALUE klass, const char *mid, VALUE (*func)(ANYARGS), int arity);
RBIMPL_ATTR_NONNULL(())
/**
* Identical to rb_define_method(), except it defines a singleton method.
*
* @param[out] obj Arbitrary ruby object.
* @param[in] mid Name of the function.
* @param[in] func The method body.
* @param[in] arity The number of parameters. See @ref defmethod.
* @note There are in fact 18 different prototypes for func.
* @see ::ruby::backward::cxxanyargs::define_method::rb_define_singleton_method
*/
void rb_define_singleton_method(VALUE obj, const char *mid, VALUE(*func)(ANYARGS), int arity);
/**
* Finds or creates the singleton class of the passed object.
*
* @param[out] obj Arbitrary ruby object.
* @exception rb_eTypeError `obj` cannot have its singleton class.
* @return A (possibly newly allocated) instance of ::rb_cClass.
* @post `obj` has its singleton class, which is the return value.
* @post In case `obj` is a class, the returned singleton class also has
* its own singleton class in order to keep consistency of the
* inheritance structure of metaclasses.
* @note A new singleton class will be created if `obj` did not have
* one.
* @note The singleton classes for ::RUBY_Qnil, ::RUBY_Qtrue, and
* ::RUBY_Qfalse are ::rb_cNilClass, ::rb_cTrueClass, and
* ::rb_cFalseClass respectively.
*
* @internal
*
* You can _create_ a singleton class of a frozen object. Intentional or ...?
*
* Nowadays there are wider range of objects who cannot have singleton classes
* than before. For instance some string instances cannot for some reason.
*/
VALUE rb_singleton_class(VALUE obj);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_INTERN_CLASS_H */

View File

@@ -0,0 +1,62 @@
#ifndef RBIMPL_INTERN_COMPAR_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_INTERN_COMPAR_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Public APIs related to ::rb_mComparable.
*/
#include "ruby/internal/attr/cold.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
RBIMPL_SYMBOL_EXPORT_BEGIN()
/* bignum.c */
/**
* Canonicalises the passed `val`, which is the return value of `a <=> b`, into
* C's `{-1, 0, 1}`. This can be handy when you implement a callback function
* to pass to `qsort(3)` etc.
*
* @param[in] val Return value of a space ship operator.
* @param[in] a Comparison LHS.
* @param[in] b Comparison RHS.
* @exception rb_eArgError `a` and `b` are not comparable each other.
* @retval -1 `val` is less than zero.
* @retval 0 `val` is equal to zero.
* @retval 1 `val` is greater than zero.
*/
int rb_cmpint(VALUE val, VALUE a, VALUE b);
/* compar.c */
RBIMPL_ATTR_COLD()
RBIMPL_ATTR_NORETURN()
/**
* Raises "comparison failed" error.
*
* @param[in] a Comparison LHS.
* @param[in] b Comparison RHS.
* @exception rb_eArgError `a` and `b` are not comparable each other.
*/
void rb_cmperr(VALUE a, VALUE b);
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_INTERN_COMPAR_H */

View File

@@ -0,0 +1,253 @@
#ifndef RBIMPL_INTERN_COMPLEX_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_INTERN_COMPLEX_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Public APIs related to ::rb_cComplex.
*/
#include "ruby/internal/attr/deprecated.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/arithmetic/long.h" /* INT2FIX is here. */
RBIMPL_SYMBOL_EXPORT_BEGIN()
/* complex.c */
/**
* Identical to rb_complex_new(), except it assumes both arguments are not
* instances of ::rb_cComplex. It is thus dangerous for extension libraries.
*
* @param[in] real Real part, in any numeric except Complex.
* @param[in] imag Imaginary part, in any numeric except Complex.
* @return An instance of ::rb_cComplex whose value is `real + (imag)i`.
*/
VALUE rb_complex_raw(VALUE real, VALUE imag);
/**
* Shorthand of `x+0i`. It practically converts `x` into a Complex of the
* identical value.
*
* @param[in] x Any numeric except Complex.
* @return An instance of ::rb_cComplex, whose value is `x + 0i`.
*/
#define rb_complex_raw1(x) rb_complex_raw((x), INT2FIX(0))
/** @alias{rb_complex_raw} */
#define rb_complex_raw2(x,y) rb_complex_raw((x), (y))
/**
* Constructs a Complex, by first multiplying the imaginary part with `1i` then
* adds it to the real part. This definition doesn't need both arguments be
* real numbers. It can happily combine two instances of ::rb_cComplex (with
* rotating the latter one).
*
* @param[in] real An instance of ::rb_cNumeric.
* @param[in] imag Another instance of ::rb_cNumeric.
* @return An instance of ::rb_cComplex whose value is `imag * 1i + real`.
*/
VALUE rb_complex_new(VALUE real, VALUE imag);
/**
* Shorthand of `x+0i`. It practically converts `x` into a Complex of the
* identical value.
*
* @param[in] x Any numeric value.
* @return An instance of ::rb_cComplex, whose value is `x + 0i`.
*/
#define rb_complex_new1(x) rb_complex_new((x), INT2FIX(0))
/** @alias{rb_complex_new} */
#define rb_complex_new2(x,y) rb_complex_new((x), (y))
/**
* Constructs a Complex using polar representations. Unlike rb_complex_new()
* it makes no sense to pass non-real instances to this function.
*
* @param[in] abs Magnitude, in any numeric except Complex.
* @param[in] arg Angle, in radians, in any numeric except Complex.
* @return An instance of ::rb_cComplex which denotes the given polar
* coordinates.
*/
VALUE rb_complex_new_polar(VALUE abs, VALUE arg);
RBIMPL_ATTR_DEPRECATED(("by: rb_complex_new_polar"))
/** @old{rb_complex_new_polar} */
VALUE rb_complex_polar(VALUE abs, VALUE arg);
RBIMPL_ATTR_PURE()
/**
* Queries the real part of the passed Complex.
*
* @param[in] z An instance of ::rb_cComplex.
* @return Its real part, which is an instance of ::rb_cNumeric.
*/
VALUE rb_complex_real(VALUE z);
RBIMPL_ATTR_PURE()
/**
* Queries the imaginary part of the passed Complex.
*
* @param[in] z An instance of ::rb_cComplex.
* @return Its imaginary part, which is an instance of ::rb_cNumeric.
*/
VALUE rb_complex_imag(VALUE z);
/**
* Performs addition of the passed two objects.
*
* @param[in] x An instance of ::rb_cComplex.
* @param[in] y Arbitrary ruby object.
* @return What `x + y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_complex_plus(VALUE x, VALUE y);
/**
* Performs subtraction of the passed two objects.
*
* @param[in] x An instance of ::rb_cComplex.
* @param[in] y Arbitrary ruby object.
* @return What `x - y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_complex_minus(VALUE x, VALUE y);
/**
* Performs multiplication of the passed two objects.
*
* @param[in] x An instance of ::rb_cComplex.
* @param[in] y Arbitrary ruby object.
* @return What `x * y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_complex_mul(VALUE x, VALUE y);
/**
* Performs division of the passed two objects.
*
* @param[in] x An instance of ::rb_cComplex.
* @param[in] y Arbitrary ruby object.
* @return What `x / y` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_complex_div(VALUE x, VALUE y);
/**
* Performs negation of the passed object.
*
* @param[in] z An instance of ::rb_cComplex.
* @return What `-z` evaluates to.
*/
VALUE rb_complex_uminus(VALUE z);
/**
* Performs complex conjugation of the passed object.
*
* @param[in] z An instance of ::rb_cComplex.
* @return Its complex conjugate, in ::rb_cComplex.
*/
VALUE rb_complex_conjugate(VALUE z);
/**
* Queries the absolute (or the magnitude) of the passed object.
*
* @param[in] z An instance of ::rb_cComplex.
* @return Its magnitude, in ::rb_cFloat.
*/
VALUE rb_complex_abs(VALUE z);
/**
* Queries the argument (or the angle) of the passed object.
*
* @param[in] z An instance of ::rb_cComplex.
* @return Its magnitude, in ::rb_cFloat.
*/
VALUE rb_complex_arg(VALUE z);
/**
* Performs exponentiation of the passed two objects.
*
* @param[in] base An instance of ::rb_cComplex.
* @param[in] exp Arbitrary ruby object.
* @return What `base ** exp` evaluates to.
* @see rb_num_coerce_bin()
*/
VALUE rb_complex_pow(VALUE base, VALUE exp);
/**
* Identical to rb_complex_new(), except it takes the arguments as C's double
* instead of Ruby's object.
*
* @param[in] real Real part.
* @param[in] imag Imaginary part.
* @return An instance of ::rb_cComplex whose value is `real + (imag)i`.
*/
VALUE rb_dbl_complex_new(double real, double imag);
/** @alias{rb_complex_plus} */
#define rb_complex_add rb_complex_plus
/** @alias{rb_complex_minus} */
#define rb_complex_sub rb_complex_minus
/** @alias{rb_complex_uminus} */
#define rb_complex_nagate rb_complex_uminus
/**
* Converts various values into a Complex. This function accepts:
*
* - Instances of ::rb_cComplex (taken as-is),
* - Instances of ::rb_cNumeric (adds `0i`),
* - Instances of ::rb_cString (parses),
* - Other objects that respond to `#to_c`.
*
* It (possibly recursively) applies `#to_c` until both sides become a Complex
* value, then computes `imag * 1i + real`.
*
* As a special case, passing ::RUBY_Qundef to `imag` is the same as passing
* `RB_INT2NUM(0)`.
*
* @param[in] real Real part (see above).
* @param[in] imag Imaginary part (see above).
* @exception rb_eTypeError Passed something not described above.
* @return An instance of ::rb_cComplex whose value is `1i * imag + real`.
*
* @internal
*
* This was the implementation of `Kernel#Complex` before, but they diverged.
*/
VALUE rb_Complex(VALUE real, VALUE imag);
/**
* Shorthand of `x+0i`. It practically converts `x` into a Complex of the
* identical value.
*
* @param[in] x ::rb_cNumeric, ::rb_cString, or something that responds to
* `#to_c`.
* @return An instance of ::rb_cComplex, whose value is `x + 0i`.
*/
#define rb_Complex1(x) rb_Complex((x), INT2FIX(0))
/** @alias{rb_Complex} */
#define rb_Complex2(x,y) rb_Complex((x), (y))
RBIMPL_SYMBOL_EXPORT_END()
#endif /* RBIMPL_INTERN_COMPLEX_H */

Some files were not shown because too many files have changed in this diff Show More