diff options
Diffstat (limited to 'include/ruby')
| -rw-r--r-- | include/ruby/assert.h | 54 | ||||
| -rw-r--r-- | include/ruby/backward.h | 79 | ||||
| -rw-r--r-- | include/ruby/backward/classext.h | 18 | ||||
| -rw-r--r-- | include/ruby/backward/cxxanyargs.hpp | 439 | ||||
| -rw-r--r-- | include/ruby/backward/rubyio.h | 6 | ||||
| -rw-r--r-- | include/ruby/backward/rubysig.h | 47 | ||||
| -rw-r--r-- | include/ruby/backward/st.h | 6 | ||||
| -rw-r--r-- | include/ruby/backward/util.h | 6 | ||||
| -rw-r--r-- | include/ruby/debug.h | 115 | ||||
| -rw-r--r-- | include/ruby/defines.h | 541 | ||||
| -rw-r--r-- | include/ruby/encoding.h | 429 | ||||
| -rw-r--r-- | include/ruby/intern.h | 1230 | ||||
| -rw-r--r-- | include/ruby/io.h | 185 | ||||
| -rw-r--r-- | include/ruby/missing.h | 278 | ||||
| -rw-r--r-- | include/ruby/onigmo.h | 941 | ||||
| -rw-r--r-- | include/ruby/oniguruma.h | 8 | ||||
| -rw-r--r-- | include/ruby/re.h | 71 | ||||
| -rw-r--r-- | include/ruby/regex.h | 46 | ||||
| -rw-r--r-- | include/ruby/ruby.h | 2873 | ||||
| -rw-r--r-- | include/ruby/st.h | 197 | ||||
| -rw-r--r-- | include/ruby/subst.h | 19 | ||||
| -rw-r--r-- | include/ruby/thread.h | 57 | ||||
| -rw-r--r-- | include/ruby/thread_native.h | 56 | ||||
| -rw-r--r-- | include/ruby/util.h | 89 | ||||
| -rw-r--r-- | include/ruby/version.h | 74 | ||||
| -rw-r--r-- | include/ruby/vm.h | 63 | ||||
| -rw-r--r-- | include/ruby/win32.h | 825 |
27 files changed, 8752 insertions, 0 deletions
diff --git a/include/ruby/assert.h b/include/ruby/assert.h new file mode 100644 index 0000000000..d19d8e4e32 --- /dev/null +++ b/include/ruby/assert.h @@ -0,0 +1,54 @@ +#ifndef RUBY_ASSERT_H +#define RUBY_ASSERT_H + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +NORETURN(void rb_assert_failure(const char *, int, const char *, const char *)); +#ifdef RUBY_FUNCTION_NAME_STRING +# define RUBY_ASSERT_FAIL(expr) \ + rb_assert_failure(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, expr) +#else +# define RUBY_ASSERT_FAIL(expr) \ + rb_assert_failure(__FILE__, __LINE__, NULL, expr) +#endif +#define RUBY_ASSERT_MESG(expr, mesg) \ + ((expr) ? (void)0 : RUBY_ASSERT_FAIL(mesg)) +#ifdef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P +# define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \ + ((RUBY_DEBUG+0) ? RUBY_ASSERT_MESG((expr), mesg) : \ + __builtin_choose_expr( \ + __builtin_constant_p(cond), \ + __builtin_choose_expr(cond, RUBY_ASSERT_MESG(expr, mesg), (void)0), \ + RUBY_ASSERT_MESG(!(cond) || (expr), mesg))) +#else +# define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \ + RUBY_ASSERT_MESG(!((RUBY_DEBUG+0) || (cond)) || (expr), mesg) +#endif +#define RUBY_ASSERT(expr) RUBY_ASSERT_MESG_WHEN((!RUBY_NDEBUG+0), expr, #expr) +#define RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN(cond, expr, #expr) +#define RUBY_ASSERT_ALWAYS(expr) RUBY_ASSERT_MESG_WHEN(TRUE, expr, #expr) + +#ifndef RUBY_DEBUG +# define RUBY_DEBUG 0 +#endif +#ifndef RUBY_NDEBUG +# ifdef NDEBUG +# define RUBY_NDEBUG 1 +# else +# define RUBY_NDEBUG 0 +# endif +#endif + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif diff --git a/include/ruby/backward.h b/include/ruby/backward.h new file mode 100644 index 0000000000..863edf0ed5 --- /dev/null +++ b/include/ruby/backward.h @@ -0,0 +1,79 @@ +#ifndef RUBY_RUBY_BACKWARD_H +#define RUBY_RUBY_BACKWARD_H 1 + +#define RClass RClassDeprecated +#ifndef __cplusplus +DEPRECATED_TYPE(("RClass is internal use only"), +struct RClass { + struct RBasic basic; +}); +#endif + +#define DECLARE_DEPRECATED_FEATURE(ver, func) \ + NORETURN(ERRORFUNC(("deprecated since "#ver), DEPRECATED(void func(void)))) + +/* eval.c */ +DECLARE_DEPRECATED_FEATURE(2.2, rb_disable_super); +DECLARE_DEPRECATED_FEATURE(2.2, rb_enable_super); + +/* hash.c */ +DECLARE_DEPRECATED_FEATURE(2.2, rb_hash_iter_lev); +DECLARE_DEPRECATED_FEATURE(2.2, rb_hash_ifnone); + +/* string.c */ +DECLARE_DEPRECATED_FEATURE(2.2, rb_str_associate); +DECLARE_DEPRECATED_FEATURE(2.2, rb_str_associated); + +/* variable.c */ +DEPRECATED(void rb_autoload(VALUE, ID, const char*)); + +/* vm.c */ +DECLARE_DEPRECATED_FEATURE(2.2, rb_clear_cache); +DECLARE_DEPRECATED_FEATURE(2.2, rb_frame_pop); + +#define DECLARE_DEPRECATED_INTERNAL_FEATURE(func) \ + NORETURN(ERRORFUNC(("deprecated internal function"), DEPRECATED(void func(void)))) + +/* eval.c */ +NORETURN(ERRORFUNC(("internal function"), void rb_frozen_class_p(VALUE))); +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_exec_end_proc); + +/* error.c */ +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error); +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error_with_enc); +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error_append); + +/* gc.c */ +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_gc_call_finalizer_at_exit); + +/* signal.c */ +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_trap_exit); + +/* struct.c */ +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_struct_ptr); + +/* thread.c */ +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_clear_trace_func); + +/* variable.c */ +DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_generic_ivar_table); +NORETURN(ERRORFUNC(("internal function"), VALUE rb_mod_const_missing(VALUE, VALUE))); + +/* from version.c */ +#ifndef RUBY_SHOW_COPYRIGHT_TO_DIE +# define RUBY_SHOW_COPYRIGHT_TO_DIE 1 +#endif +#if RUBY_SHOW_COPYRIGHT_TO_DIE +/* for source code backward compatibility */ +DEPRECATED(static inline int ruby_show_copyright_to_die(int)); +static inline int +ruby_show_copyright_to_die(int exitcode) +{ + ruby_show_copyright(); + return exitcode; +} +#define ruby_show_copyright() /* defer EXIT_SUCCESS */ \ + (exit(ruby_show_copyright_to_die(EXIT_SUCCESS))) +#endif + +#endif /* RUBY_RUBY_BACKWARD_H */ diff --git a/include/ruby/backward/classext.h b/include/ruby/backward/classext.h new file mode 100644 index 0000000000..9d5747316a --- /dev/null +++ b/include/ruby/backward/classext.h @@ -0,0 +1,18 @@ +#if defined __GNUC__ +#warning use of RClass internals is deprecated +#elif defined _MSC_VER +#pragma message("warning: use of RClass internals is deprecated") +#endif + +#ifndef RUBY_BACKWARD_CLASSEXT_H +#define RUBY_BACKWARD_CLASSEXT_H 1 + +typedef struct rb_deprecated_classext_struct { + VALUE super; +} rb_deprecated_classext_t; + +#undef RCLASS_SUPER(c) +#define RCLASS_EXT(c) ((rb_deprecated_classext_t *)RCLASS(c)->ptr) +#define RCLASS_SUPER(c) (RCLASS(c)->super) + +#endif /* RUBY_BACKWARD_CLASSEXT_H */ diff --git a/include/ruby/backward/cxxanyargs.hpp b/include/ruby/backward/cxxanyargs.hpp new file mode 100644 index 0000000000..3585f678b8 --- /dev/null +++ b/include/ruby/backward/cxxanyargs.hpp @@ -0,0 +1,439 @@ +#ifndef RUBY_BACKWARD_CXXANYARGS_HPP // -*- C++ -*- +#define RUBY_BACKWARD_CXXANYARGS_HPP +/// @file +/// @brief Provides old prototypes for C++ programs. +/// @author \@shyouhei +/// @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. +/// @note DO NOT MODERNIZE THIS FILE! As the file name implies it is +/// meant to be a backwards compatibility shim. Please stick to +/// C++ 98 and never use newer features, like `constexpr`. + +/// @brief The main namespace. +/// @note The name "ruby" might already be taken, but that must not be a +/// problem because namespaces are allowed to reopen. +namespace ruby { + +/// @brief Backwards compatibility layer. +namespace backward { + +/// @brief Provides ANYARGS deprecation warnings. +/// +/// In C, ANYARGS means there is no function prototype. Literally anything, +/// even including nothing, can be a valid ANYARGS. So passing a correctly +/// prototyped function pointer to an ANYARGS-ed function parameter is valid, +/// at the same time passing an ANYARGS-ed function pointer to a granular typed +/// function parameter is also valid. However on the other hand in C++, +/// ANYARGS doesn't actually mean any number of arguments. C++'s ANYARGS means +/// _variadic_ number of arguments. This is incompatible with ordinal, correct +/// function prototypes. +/// +/// Luckily, function prototypes being distinct each other means they can be +/// overloaded. We can provide a compatibility layer for older Ruby APIs which +/// used to have ANYARGS. This namespace includes such attempts. +namespace cxxanyargs { + +/// @brief ANYARGS-ed function type. +typedef VALUE type(ANYARGS); + +/// @brief ANYARGS-ed function type, void variant. +typedef void void_type(ANYARGS); + +/// @brief ANYARGS-ed function type, int variant. +typedef int int_type(ANYARGS); + +/// @name Hooking global variables +/// @{ + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Define a function-backended global variable. +/// @param[in] q Name of the variable. +/// @param[in] w Getter function. +/// @param[in] e Setter function. +/// @note Both functions can be nullptr. +/// @see rb_define_hooked_variable() +/// @deprecated Use glanular typed overload instead. +inline void +rb_define_virtual_variable(const char *q, type *w, void_type *e) +{ + rb_gvar_getter_t *r = reinterpret_cast<rb_gvar_getter_t*>(w); + rb_gvar_setter_t *t = reinterpret_cast<rb_gvar_setter_t*>(e); + ::rb_define_virtual_variable(q, r, t); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Define a function-backended global variable. +/// @param[in] q Name of the variable. +/// @param[in] w Getter function. +/// @param[in] e Setter function. +/// @note Both functions can be nullptr. +/// @see rb_define_hooked_variable() +/// @deprecated Use glanular typed overload instead. +inline void +rb_define_virtual_variable(const char *q, rb_gvar_getter_t *w, void_type *e) +{ + rb_gvar_setter_t *t = reinterpret_cast<rb_gvar_setter_t*>(e); + ::rb_define_virtual_variable(q, w, t); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Define a function-backended global variable. +/// @param[in] q Name of the variable. +/// @param[in] w Getter function. +/// @param[in] e Setter function. +/// @note Both functions can be nullptr. +/// @see rb_define_hooked_variable() +/// @deprecated Use glanular typed overload instead. +inline void +rb_define_virtual_variable(const char *q, type *w, rb_gvar_setter_t *e) +{ + rb_gvar_getter_t *r = reinterpret_cast<rb_gvar_getter_t*>(w); + ::rb_define_virtual_variable(q, r, e); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Define a function-backended global variable. +/// @param[in] q Name of the variable. +/// @param[in] w Variable storage. +/// @param[in] e Getter function. +/// @param[in] r Setter function. +/// @note Both functions can be nullptr. +/// @see rb_define_virtual_variable() +/// @deprecated Use glanular typed overload instead. +inline void +rb_define_hooked_variable(const char *q, VALUE *w, type *e, void_type *r) +{ + rb_gvar_getter_t *t = reinterpret_cast<rb_gvar_getter_t*>(e); + rb_gvar_setter_t *y = reinterpret_cast<rb_gvar_setter_t*>(r); + ::rb_define_hooked_variable(q, w, t, y); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Define a function-backended global variable. +/// @param[in] q Name of the variable. +/// @param[in] w Variable storage. +/// @param[in] e Getter function. +/// @param[in] r Setter function. +/// @note Both functions can be nullptr. +/// @see rb_define_virtual_variable() +/// @deprecated Use glanular typed overload instead. +inline void +rb_define_hooked_variable(const char *q, VALUE *w, rb_gvar_getter_t *e, void_type *r) +{ + rb_gvar_setter_t *y = reinterpret_cast<rb_gvar_setter_t*>(r); + ::rb_define_hooked_variable(q, w, e, y); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Define a function-backended global variable. +/// @param[in] q Name of the variable. +/// @param[in] w Variable storage. +/// @param[in] e Getter function. +/// @param[in] r Setter function. +/// @note Both functions can be nullptr. +/// @see rb_define_virtual_variable() +/// @deprecated Use glanular typed overload instead. +inline void +rb_define_hooked_variable(const char *q, VALUE *w, type *e, rb_gvar_setter_t *r) +{ + rb_gvar_getter_t *t = reinterpret_cast<rb_gvar_getter_t*>(e); + ::rb_define_hooked_variable(q, w, t, r); +} + +/// @} +/// @name Exceptions and tag jumps +/// @{ + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Old way to implement iterators. +/// @param[in] q A function that can yield. +/// @param[in] w Passed to `q`. +/// @param[in] e What is to be yielded. +/// @param[in] r Passed to `e`. +/// @return The return value of `q`. +/// @note `e` can be nullptr. +/// @deprecated This function is obsolated since long before 2.x era. Do not +/// use it any longer. rb_block_call() is provided instead. +inline VALUE +rb_iterate(VALUE(*q)(VALUE), VALUE w, type *e, VALUE r) +{ + rb_block_call_func_t t = reinterpret_cast<rb_block_call_func_t>(e); + return ::rb_iterate(q, w, t, r); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Call a method with a block. +/// @param[in] q The self. +/// @param[in] w The method. +/// @param[in] e The # of elems of `r` +/// @param[in] r The arguments. +/// @param[in] t What is to be yielded. +/// @param[in] y Passed to `t` +/// @return Return value of `q#w(*r,&t)` +/// @note 't' can be nullptr. +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y) +{ + rb_block_call_func_t u = reinterpret_cast<rb_block_call_func_t>(t); + return ::rb_block_call(q, w, e, r, u, y); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief An equivalent of `rescue` clause. +/// @param[in] q A function that can raise. +/// @param[in] w Passed to `q`. +/// @param[in] e A function that cleans-up. +/// @param[in] r Passed to `e`. +/// @return The return value of `q` if no exception occurs, or the return +/// value of `e` if otherwise. +/// @note `e` can be nullptr. +/// @see rb_ensure() +/// @see rb_rescue2() +/// @see rb_protect() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_rescue(type *q, VALUE w, type *e, VALUE r) +{ + typedef VALUE func1_t(VALUE); + typedef VALUE func2_t(VALUE, VALUE); + func1_t *t = reinterpret_cast<func1_t*>(q); + func2_t *y = reinterpret_cast<func2_t*>(e); + return ::rb_rescue(t, w, y, r); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief An equivalent of `rescue` clause. +/// @param[in] q A function that can raise. +/// @param[in] w Passed to `q`. +/// @param[in] e A function that cleans-up. +/// @param[in] r Passed to `e`. +/// @param[in] ... 0-terminated list of subclass of @ref rb_eException. +/// @return The return value of `q` if no exception occurs, or the return +/// value of `e` if otherwise. +/// @note `e` can be nullptr. +/// @see rb_ensure() +/// @see rb_rescue() +/// @see rb_protect() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_rescue2(type *q, VALUE w, type *e, VALUE r, ...) +{ + typedef VALUE func1_t(VALUE); + typedef VALUE func2_t(VALUE, VALUE); + func1_t *t = reinterpret_cast<func1_t*>(q); + func2_t *y = reinterpret_cast<func2_t*>(e); + va_list ap; + va_start(ap, r); + VALUE ret = ::rb_vrescue2(t, w, y, r, ap); + va_end(ap); + return ret; +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief An equivalent of `ensure` clause. +/// @param[in] q A function that can raise. +/// @param[in] w Passed to `q`. +/// @param[in] e A function that ensures. +/// @param[in] r Passed to `e`. +/// @return The return value of `q`. +/// @note It makes no sense to pass nullptr to `e`. +/// @see rb_rescue() +/// @see rb_rescue2() +/// @see rb_protect() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_ensure(type *q, VALUE w, type *e, VALUE r) +{ + typedef VALUE func1_t(VALUE); + func1_t *t = reinterpret_cast<func1_t*>(q); + func1_t *y = reinterpret_cast<func1_t*>(e); + return ::rb_ensure(t, w, y, r); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief An equivalent of `Kernel#catch`. +/// @param[in] q The "tag" string. +/// @param[in] w A function that can throw. +/// @param[in] e Passed to `w`. +/// @return What was thrown. +/// @note `q` can be a nullptr but makes no sense to pass nullptr to`w`. +/// @see rb_block_call() +/// @see rb_protect() +/// @see rb_rb_catch_obj() +/// @see rb_rescue() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_catch(const char *q, type *w, VALUE e) +{ + rb_block_call_func_t r = reinterpret_cast<rb_block_call_func_t>(w); + return ::rb_catch(q, r, e); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief An equivalent of `Kernel#catch`. +/// @param[in] q The "tag" object. +/// @param[in] w A function that can throw. +/// @param[in] e Passed to `w`. +/// @return What was thrown. +/// @note It makes no sense to pass nullptr to`w`. +/// @see rb_block_call() +/// @see rb_protect() +/// @see rb_rb_catch_obj() +/// @see rb_rescue() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_catch_obj(VALUE q, type *w, VALUE e) +{ + rb_block_call_func_t r = reinterpret_cast<rb_block_call_func_t>(w); + return ::rb_catch_obj(q, r, e); +} + +/// @} +/// @name Procs, Fibers and Threads +/// @{ + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Creates a @ref rb_cFiber instance. +/// @param[in] q The fiber body. +/// @param[in] w Passed to `q`. +/// @return What was allocated. +/// @note It makes no sense to pass nullptr to`q`. +/// @see rb_proc_new() +/// @see rb_thread_creatr() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_fiber_new(type *q, VALUE w) +{ + rb_block_call_func_t e = reinterpret_cast<rb_block_call_func_t>(q); + return ::rb_fiber_new(e, w); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Creates a @ref rb_cProc instance. +/// @param[in] q The proc body. +/// @param[in] w Passed to `q`. +/// @return What was allocated. +/// @note It makes no sense to pass nullptr to`q`. +/// @see rb_fiber_new() +/// @see rb_thread_creatr() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_proc_new(type *q, VALUE w) +{ + rb_block_call_func_t e = reinterpret_cast<rb_block_call_func_t>(q); + return ::rb_proc_new(e, w); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Creates a @ref rb_cThread instance. +/// @param[in] q The thread body. +/// @param[in] w Passed to `q`. +/// @return What was allocated. +/// @note It makes no sense to pass nullptr to`q`. +/// @see rb_proc_new() +/// @see rb_fiber_new() +/// @deprecated Use glanular typed overload instead. +inline VALUE +rb_thread_create(type *q, void *w) +{ + typedef VALUE ptr_t(void*); + ptr_t *e = reinterpret_cast<ptr_t*>(q); + return ::rb_thread_create(e, w); +} + +/// @} +/// @name Hash and st_table +/// @{ + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Iteration over the given table. +/// @param[in] q A table to scan. +/// @param[in] w A function to iterate. +/// @param[in] e Passed to `w`. +/// @retval 0 Always returns 0. +/// @note It makes no sense to pass nullptr to`w`. +/// @see st_foreach_check() +/// @see rb_hash_foreach() +/// @deprecated Use glanular typed overload instead. +inline int +st_foreach(st_table *q, int_type *w, st_data_t e) +{ + st_foreach_callback_func *r = + reinterpret_cast<st_foreach_callback_func*>(w); + return ::st_foreach(q, r, e); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Iteration over the given table. +/// @param[in] q A table to scan. +/// @param[in] w A function to iterate. +/// @param[in] e Passed to `w`. +/// @retval 0 Successful end of iteration. +/// @retval 1 Element removed during traversing. +/// @note It makes no sense to pass nullptr to`w`. +/// @see st_foreach() +/// @deprecated Use glanular typed overload instead. +inline int +st_foreach_check(st_table *q, int_type *w, st_data_t e, st_data_t) +{ + st_foreach_check_callback_func *t = + reinterpret_cast<st_foreach_check_callback_func*>(w); + return ::st_foreach_check(q, t, e, 0); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Iteration over the given table. +/// @param[in] q A table to scan. +/// @param[in] w A function to iterate. +/// @param[in] e Passed to `w`. +/// @note It makes no sense to pass nullptr to`w`. +/// @see st_foreach_check() +/// @deprecated Use glanular typed overload instead. +inline void +st_foreach_safe(st_table *q, int_type *w, st_data_t e) +{ + st_foreach_callback_func *r = + reinterpret_cast<st_foreach_callback_func*>(w); + ::st_foreach_safe(q, r, e); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Iteration over the given hash. +/// @param[in] q A hash to scan. +/// @param[in] w A function to iterate. +/// @param[in] e Passed to `w`. +/// @note It makes no sense to pass nullptr to`w`. +/// @see st_foreach() +/// @deprecated Use glanular typed overload instead. +inline void +rb_hash_foreach(VALUE q, int_type *w, VALUE e) +{ + st_foreach_callback_func *r = + reinterpret_cast<st_foreach_callback_func*>(w); + ::rb_hash_foreach(q, r, e); +} + +RUBY_CXX_DEPRECATED("Use of ANYARGS in this function is deprecated") +/// @brief Iteration over each instance variable of the object. +/// @param[in] q An object. +/// @param[in] w A function to iterate. +/// @param[in] e Passed to `w`. +/// @note It makes no sense to pass nullptr to`w`. +/// @see st_foreach() +/// @deprecated Use glanular typed overload instead. +inline void +rb_ivar_foreach(VALUE q, int_type *w, VALUE e) +{ + st_foreach_callback_func *r = + reinterpret_cast<st_foreach_callback_func*>(w); + ::rb_ivar_foreach(q, r, e); +} + +/// @} +}}} + +using namespace ruby::backward::cxxanyargs; +#endif // RUBY_BACKWARD_CXXANYARGS_HPP diff --git a/include/ruby/backward/rubyio.h b/include/ruby/backward/rubyio.h new file mode 100644 index 0000000000..a6e3a7c78b --- /dev/null +++ b/include/ruby/backward/rubyio.h @@ -0,0 +1,6 @@ +#if defined __GNUC__ +#warning use "ruby/io.h" instead of "rubyio.h" +#elif defined _MSC_VER +#pragma message("warning: use \"ruby/io.h\" instead of \"rubyio.h\"") +#endif +#include "ruby/io.h" diff --git a/include/ruby/backward/rubysig.h b/include/ruby/backward/rubysig.h new file mode 100644 index 0000000000..58b13cab1c --- /dev/null +++ b/include/ruby/backward/rubysig.h @@ -0,0 +1,47 @@ +/********************************************************************** + + rubysig.h - + + $Author$ + $Date$ + created at: Wed Aug 16 01:15:38 JST 1995 + + Copyright (C) 1993-2008 Yukihiro Matsumoto + +**********************************************************************/ + +#if defined __GNUC__ +#warning rubysig.h is obsolete +#elif defined _MSC_VER +#pragma message("warning: rubysig.h is obsolete") +#endif + +#ifndef RUBYSIG_H +#define RUBYSIG_H +#include "ruby/ruby.h" + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +#define RUBY_CRITICAL(statements) do {statements;} while (0) +#define DEFER_INTS (0) +#define ENABLE_INTS (1) +#define ALLOW_INTS do {CHECK_INTS;} while (0) +#define CHECK_INTS rb_thread_check_ints() + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif diff --git a/include/ruby/backward/st.h b/include/ruby/backward/st.h new file mode 100644 index 0000000000..3e36d44cf8 --- /dev/null +++ b/include/ruby/backward/st.h @@ -0,0 +1,6 @@ +#if defined __GNUC__ +#warning use "ruby/st.h" instead of bare "st.h" +#elif defined _MSC_VER +#pragma message("warning: use \"ruby/st.h\" instead of bare \"st.h\"") +#endif +#include "ruby/st.h" diff --git a/include/ruby/backward/util.h b/include/ruby/backward/util.h new file mode 100644 index 0000000000..11d32a2da8 --- /dev/null +++ b/include/ruby/backward/util.h @@ -0,0 +1,6 @@ +#if defined __GNUC__ +#warning use "ruby/util.h" instead of bare "util.h" +#elif defined _MSC_VER +#pragma message("warning: use \"ruby/util.h\" instead of bare \"util.h\"") +#endif +#include "ruby/util.h" diff --git a/include/ruby/debug.h b/include/ruby/debug.h new file mode 100644 index 0000000000..8a831e61ab --- /dev/null +++ b/include/ruby/debug.h @@ -0,0 +1,115 @@ +/********************************************************************** + + ruby/debug.h - + + $Author: ko1 $ + created at: Tue Nov 20 20:35:08 2012 + + Copyright (C) 2012 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RB_DEBUG_H +#define RB_DEBUG_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +/* Note: This file contains experimental APIs. */ +/* APIs can be replaced at Ruby 2.0.1 or later */ + + +/* profile frames APIs */ +int rb_profile_frames(int start, int limit, VALUE *buff, int *lines); +VALUE rb_profile_frame_path(VALUE frame); +VALUE rb_profile_frame_absolute_path(VALUE frame); +VALUE rb_profile_frame_label(VALUE frame); +VALUE rb_profile_frame_base_label(VALUE frame); +VALUE rb_profile_frame_full_label(VALUE frame); +VALUE rb_profile_frame_first_lineno(VALUE frame); +VALUE rb_profile_frame_classpath(VALUE frame); +VALUE rb_profile_frame_singleton_method_p(VALUE frame); +VALUE rb_profile_frame_method_name(VALUE frame); +VALUE rb_profile_frame_qualified_method_name(VALUE frame); + +/* debug inspector APIs */ +typedef struct rb_debug_inspector_struct rb_debug_inspector_t; +typedef VALUE (*rb_debug_inspector_func_t)(const rb_debug_inspector_t *, void *); + +VALUE rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data); +VALUE rb_debug_inspector_frame_self_get(const rb_debug_inspector_t *dc, long index); +VALUE rb_debug_inspector_frame_class_get(const rb_debug_inspector_t *dc, long index); +VALUE rb_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, long index); +VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, long index); +VALUE rb_debug_inspector_backtrace_locations(const rb_debug_inspector_t *dc); + +/* Old style set_trace_func APIs */ + +/* duplicated def of include/ruby/ruby.h */ +void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); +int rb_remove_event_hook(rb_event_hook_func_t func); + +int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data); +void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); +int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func); +int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data); + +/* TracePoint APIs */ + +VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data); +VALUE rb_tracepoint_enable(VALUE tpval); +VALUE rb_tracepoint_disable(VALUE tpval); +VALUE rb_tracepoint_enabled_p(VALUE tpval); + +typedef struct rb_trace_arg_struct rb_trace_arg_t; +rb_trace_arg_t *rb_tracearg_from_tracepoint(VALUE tpval); + +rb_event_flag_t rb_tracearg_event_flag(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_event(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_lineno(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_path(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_method_id(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_callee_id(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_binding(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_self(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg); +VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg); + +/* + * Postponed Job API + * rb_postponed_job_register and rb_postponed_job_register_one are + * async-signal-safe and used via SIGPROF by the "stackprof" RubyGem + */ +typedef void (*rb_postponed_job_func_t)(void *arg); +int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data); +int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data); + +/* undocumented advanced tracing APIs */ + +typedef enum { + RUBY_EVENT_HOOK_FLAG_SAFE = 0x01, + RUBY_EVENT_HOOK_FLAG_DELETED = 0x02, + RUBY_EVENT_HOOK_FLAG_RAW_ARG = 0x04 +} rb_event_hook_flag_t; + +void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag); +void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag); + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_DEBUG_H */ diff --git a/include/ruby/defines.h b/include/ruby/defines.h new file mode 100644 index 0000000000..dc71d65100 --- /dev/null +++ b/include/ruby/defines.h @@ -0,0 +1,541 @@ +/************************************************ + + defines.h - + + $Author$ + created at: Wed May 18 00:21:44 JST 1994 + +************************************************/ + +#ifndef RUBY_DEFINES_H +#define RUBY_DEFINES_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/config.h" +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif + +/* function attributes */ +#ifndef CONSTFUNC +# define CONSTFUNC(x) x +#endif +#ifndef PUREFUNC +# define PUREFUNC(x) x +#endif +#ifndef DEPRECATED +# define DEPRECATED(x) x +#endif +#ifndef DEPRECATED_BY +# define DEPRECATED_BY(n,x) DEPRECATED(x) +#endif +#ifndef DEPRECATED_TYPE +# define DEPRECATED_TYPE(mesg, decl) decl +#endif +#ifndef RUBY_CXX_DEPRECATED +# define RUBY_CXX_DEPRECATED(mesg) /* nothing */ +#endif +#ifndef NOINLINE +# define NOINLINE(x) x +#endif +#ifndef ALWAYS_INLINE +# define ALWAYS_INLINE(x) x +#endif +#ifndef ERRORFUNC +# define HAVE_ATTRIBUTE_ERRORFUNC 0 +# define ERRORFUNC(mesg, x) x +#else +# define HAVE_ATTRIBUTE_ERRORFUNC 1 +#endif +#ifndef WARNINGFUNC +# define HAVE_ATTRIBUTE_WARNINGFUNC 0 +# define WARNINGFUNC(mesg, x) x +#else +# define HAVE_ATTRIBUTE_WARNINGFUNC 1 +#endif + +#ifndef GCC_VERSION_SINCE +# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) +# define GCC_VERSION_SINCE(major, minor, patchlevel) \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major) && \ + ((__GNUC_MINOR__ > (minor)) || \ + (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))))) +# else +# define GCC_VERSION_SINCE(major, minor, patchlevel) 0 +# endif +#endif +#ifndef GCC_VERSION_BEFORE +# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) +# define GCC_VERSION_BEFORE(major, minor, patchlevel) \ + ((__GNUC__ < (major)) || \ + ((__GNUC__ == (major) && \ + ((__GNUC_MINOR__ < (minor)) || \ + (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ <= (patchlevel)))))) +# else +# define GCC_VERSION_BEFORE(major, minor, patchlevel) 0 +# endif +#endif + +/* likely */ +#if __GNUC__ >= 3 +#define RB_LIKELY(x) (__builtin_expect(!!(x), 1)) +#define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0)) +#else /* __GNUC__ >= 3 */ +#define RB_LIKELY(x) (x) +#define RB_UNLIKELY(x) (x) +#endif /* __GNUC__ >= 3 */ + +/* + cold attribute for code layout improvements + RUBY_FUNC_ATTRIBUTE not used because MSVC does not like nested func macros + */ +#if defined(__clang__) || GCC_VERSION_SINCE(4, 3, 0) +#define COLDFUNC __attribute__((cold)) +#else +#define COLDFUNC +#endif + +#ifdef __GNUC__ +#if defined __MINGW_PRINTF_FORMAT +#define PRINTF_ARGS(decl, string_index, first_to_check) \ + decl __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) +#else +#define PRINTF_ARGS(decl, string_index, first_to_check) \ + decl __attribute__((format(printf, string_index, first_to_check))) +#endif +#else +#define PRINTF_ARGS(decl, string_index, first_to_check) decl +#endif + +#ifdef __GNUC__ +#define RB_GNUC_EXTENSION __extension__ +#define RB_GNUC_EXTENSION_BLOCK(x) __extension__ ({ x; }) +#else +#define RB_GNUC_EXTENSION +#define RB_GNUC_EXTENSION_BLOCK(x) (x) +#endif + +/* AC_INCLUDES_DEFAULT */ +#include <stdio.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif +#ifdef STDC_HEADERS +# include <stdlib.h> +# include <stddef.h> +#else +# ifdef HAVE_STDLIB_H +# include <stdlib.h> +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include <memory.h> +# endif +# include <string.h> +#endif +#ifdef HAVE_STRINGS_H +# include <strings.h> +#endif +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif +#ifdef HAVE_STDINT_H +# include <stdint.h> +#endif +#ifdef HAVE_STDALIGN_H +# include <stdalign.h> +#endif +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#ifdef HAVE_SYS_SELECT_H +# include <sys/select.h> +#endif + +#ifdef RUBY_USE_SETJMPEX +#include <setjmpex.h> +#endif + +#include "ruby/missing.h" + +#define RUBY + +#ifdef __cplusplus +# ifndef HAVE_PROTOTYPES +# define HAVE_PROTOTYPES 1 +# endif +# ifndef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 +# endif +#endif + +#undef _ +#ifdef HAVE_PROTOTYPES +# define _(args) args +#else +# define _(args) () +#endif + +#undef __ +#ifdef HAVE_STDARG_PROTOTYPES +# define __(args) args +#else +# define __(args) () +#endif + +#ifdef __cplusplus +#define ANYARGS ... +#else +#define ANYARGS +#endif + +#ifndef RUBY_SYMBOL_EXPORT_BEGIN +# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */ +# define RUBY_SYMBOL_EXPORT_END /* end */ +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +#define xmalloc ruby_xmalloc +#define xmalloc2 ruby_xmalloc2 +#define xcalloc ruby_xcalloc +#define xrealloc ruby_xrealloc +#define xrealloc2 ruby_xrealloc2 +#define xfree ruby_xfree + +#if GCC_VERSION_SINCE(4,3,0) +# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((alloc_size params)) +#elif defined(__has_attribute) +# if __has_attribute(alloc_size) +# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__((__alloc_size__ params)) +# endif +#endif +#ifndef RUBY_ATTR_ALLOC_SIZE +# define RUBY_ATTR_ALLOC_SIZE(params) +#endif + +#ifdef __has_attribute +# if __has_attribute(malloc) +# define RUBY_ATTR_MALLOC __attribute__((__malloc__)) +# endif +#endif +#ifndef RUBY_ATTR_MALLOC +# define RUBY_ATTR_MALLOC +#endif + +#ifdef __has_attribute +# if __has_attribute(returns_nonnull) +# define RUBY_ATTR_RETURNS_NONNULL __attribute__((__returns_nonnull__)) +# endif +#endif +#ifndef RUBY_ATTR_RETURNS_NONNULL +# define RUBY_ATTR_RETURNS_NONNULL +#endif + +void *ruby_xmalloc(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1)); +void *ruby_xmalloc2(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2)); +void *ruby_xcalloc(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2)); +void *ruby_xrealloc(void*,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2)); +void *ruby_xrealloc2(void*,size_t,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2,3)); +void ruby_xfree(void*); + +#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS +#define USE_GC_MALLOC_OBJ_INFO_DETAILS 0 +#endif + +#if USE_GC_MALLOC_OBJ_INFO_DETAILS + +void *ruby_xmalloc_body(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1)); +void *ruby_xmalloc2_body(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2)); +void *ruby_xcalloc_body(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2)); +void *ruby_xrealloc_body(void*,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2)); +void *ruby_xrealloc2_body(void*,size_t,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2,3)); + +#define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__) +#define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__) +#define ruby_xcalloc(s1, s2) ruby_xcalloc_with_location(s1, s2, __FILE__, __LINE__) +#define ruby_xrealloc(ptr, s1) ruby_xrealloc_with_location(ptr, s1, __FILE__, __LINE__) +#define ruby_xrealloc2(ptr, s1, s2) ruby_xrealloc2_with_location(ptr, s1, s2, __FILE__, __LINE__) + +extern const char *ruby_malloc_info_file; +extern int ruby_malloc_info_line; + +static inline void * +ruby_xmalloc_with_location(size_t s, const char *file, int line) +{ + void *ptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + ptr = ruby_xmalloc_body(s); + ruby_malloc_info_file = NULL; + return ptr; +} + +static inline void * +ruby_xmalloc2_with_location(size_t s1, size_t s2, const char *file, int line) +{ + void *ptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + ptr = ruby_xmalloc2_body(s1, s2); + ruby_malloc_info_file = NULL; + return ptr; +} + +static inline void * +ruby_xcalloc_with_location(size_t s1, size_t s2, const char *file, int line) +{ + void *ptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + ptr = ruby_xcalloc_body(s1, s2); + ruby_malloc_info_file = NULL; + return ptr; +} + +static inline void * +ruby_xrealloc_with_location(void *ptr, size_t s, const char *file, int line) +{ + void *rptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + rptr = ruby_xrealloc_body(ptr, s); + ruby_malloc_info_file = NULL; + return rptr; +} + +static inline void * +ruby_xrealloc2_with_location(void *ptr, size_t s1, size_t s2, const char *file, int line) +{ + void *rptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + rptr = ruby_xrealloc2_body(ptr, s1, s2); + ruby_malloc_info_file = NULL; + return rptr; +} +#endif + +#define STRINGIZE(expr) STRINGIZE0(expr) +#ifndef STRINGIZE0 +#define STRINGIZE0(expr) #expr +#endif + +#ifdef HAVE_LONG_LONG +# define HAVE_TRUE_LONG_LONG 1 +#endif + +#if SIZEOF_LONG_LONG > 0 +# define LONG_LONG long long +#elif SIZEOF___INT64 > 0 +# define HAVE_LONG_LONG 1 +# define LONG_LONG __int64 +# undef SIZEOF_LONG_LONG +# define SIZEOF_LONG_LONG SIZEOF___INT64 +#endif + +#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 AC_APPLE_UNIVERSAL_BUILD +#undef WORDS_BIGENDIAN +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN +#endif +#endif + +#ifdef _WIN32 +#include "ruby/win32.h" +#endif + +#ifdef RUBY_EXPORT +#undef RUBY_EXTERN + +#ifndef FALSE +# define FALSE 0 +#elif FALSE +# error FALSE must be false +#endif +#ifndef TRUE +# define TRUE 1 +#elif !TRUE +# error TRUE must be true +#endif + +#endif + +#ifndef RUBY_FUNC_EXPORTED +#define RUBY_FUNC_EXPORTED +#endif + +/* These macros are used for functions which are exported only for MJIT + and NOT ensured to be exported in future versions. */ +#define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED +#define MJIT_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN +#define MJIT_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END + +#if defined(MJIT_HEADER) && defined(_MSC_VER) +# undef MJIT_FUNC_EXPORTED +# define MJIT_FUNC_EXPORTED static +#endif + +#ifndef RUBY_EXTERN +#define RUBY_EXTERN extern +#endif + +#ifndef EXTERN +# if defined __GNUC__ +# define EXTERN _Pragma("message \"EXTERN is deprecated, use RUBY_EXTERN instead\""); \ + RUBY_EXTERN +# elif defined _MSC_VER +# define EXTERN __pragma(message(__FILE__"("STRINGIZE(__LINE__)"): warning: "\ + "EXTERN is deprecated, use RUBY_EXTERN instead")); \ + RUBY_EXTERN +# else +# define EXTERN <-<-"EXTERN is deprecated, use RUBY_EXTERN instead"->-> +# endif +#endif + +#ifndef RUBY_MBCHAR_MAXSIZE +#define RUBY_MBCHAR_MAXSIZE INT_MAX + /* MB_CUR_MAX will not work well in C locale */ +#endif + +#if defined(__sparc) +void rb_sparc_flush_register_windows(void); +# define FLUSH_REGISTER_WINDOWS rb_sparc_flush_register_windows() +#else +# define FLUSH_REGISTER_WINDOWS ((void)0) +#endif + +#if defined(DOSISH) +#define PATH_SEP ";" +#else +#define PATH_SEP ":" +#endif +#define PATH_SEP_CHAR PATH_SEP[0] + +#define PATH_ENV "PATH" + +#if defined(DOSISH) +#define ENV_IGNORECASE +#endif + +#ifndef CASEFOLD_FILESYSTEM +# if defined DOSISH +# define CASEFOLD_FILESYSTEM 1 +# else +# define CASEFOLD_FILESYSTEM 0 +# endif +#endif + +#ifndef DLEXT_MAXLEN +#define DLEXT_MAXLEN 4 +#endif + +#ifndef RUBY_PLATFORM +#define RUBY_PLATFORM "unknown-unknown" +#endif + +#ifndef FUNC_MINIMIZED +#define FUNC_MINIMIZED(x) x +#endif +#ifndef FUNC_UNOPTIMIZED +#define FUNC_UNOPTIMIZED(x) x +#endif +#ifndef RUBY_ALIAS_FUNCTION_TYPE +#define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) \ + FUNC_MINIMIZED(type prot) {return (type)name args;} +#endif +#ifndef RUBY_ALIAS_FUNCTION_VOID +#define RUBY_ALIAS_FUNCTION_VOID(prot, name, args) \ + FUNC_MINIMIZED(void prot) {name args;} +#endif +#ifndef RUBY_ALIAS_FUNCTION +#define RUBY_ALIAS_FUNCTION(prot, name, args) \ + RUBY_ALIAS_FUNCTION_TYPE(VALUE, prot, name, args) +#endif +#ifndef RUBY_FUNC_NONNULL +#define RUBY_FUNC_NONNULL(n, x) x +#endif + +#ifndef UNALIGNED_WORD_ACCESS +# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ + defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \ + defined(__powerpc64__) || \ + defined(__aarch64__) || \ + defined(__mc68020__) +# define UNALIGNED_WORD_ACCESS 1 +# else +# define UNALIGNED_WORD_ACCESS 0 +# endif +#endif +#ifndef PACKED_STRUCT +# define PACKED_STRUCT(x) x +#endif +#ifndef PACKED_STRUCT_UNALIGNED +# if UNALIGNED_WORD_ACCESS +# define PACKED_STRUCT_UNALIGNED(x) PACKED_STRUCT(x) +# else +# define PACKED_STRUCT_UNALIGNED(x) x +# endif +#endif + +#ifndef RUBY_ALIGNAS +#define RUBY_ALIGNAS(x) /* x */ +#endif + +#ifdef RUBY_ALIGNOF +/* OK, take that definition */ +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +#define RUBY_ALIGNOF alignof +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#define RUBY_ALIGNOF _Alignof +#else +#define RUBY_ALIGNOF(type) ((size_t)offsetof(struct { char f1; type f2; }, f2)) +#endif + +#define NORETURN_STYLE_NEW 1 +#ifdef NORETURN +/* OK, take that definition */ +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +#define NORETURN(x) [[ noreturn ]] x +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#define NORETURN(x) _Noreturn x +#else +#define NORETURN(x) x +#endif + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_DEFINES_H */ diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h new file mode 100644 index 0000000000..93939ee7db --- /dev/null +++ b/include/ruby/encoding.h @@ -0,0 +1,429 @@ +/********************************************************************** + + encoding.h - + + $Author: matz $ + created at: Thu May 24 11:49:41 JST 2007 + + Copyright (C) 2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_ENCODING_H +#define RUBY_ENCODING_H 1 + +#ifdef RUBY_INTERNAL_H +#error "Include this file before internal.h" +#endif + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include <stdarg.h> +#include "ruby/ruby.h" +#include "ruby/oniguruma.h" + +RUBY_SYMBOL_EXPORT_BEGIN + +enum ruby_encoding_consts { + RUBY_ENCODING_INLINE_MAX = 127, + RUBY_ENCODING_SHIFT = (RUBY_FL_USHIFT+10), + RUBY_ENCODING_MASK = (RUBY_ENCODING_INLINE_MAX<<RUBY_ENCODING_SHIFT + /* RUBY_FL_USER10..RUBY_FL_USER16 */), + RUBY_ENCODING_MAXNAMELEN = 42 +}; + +#define ENCODING_INLINE_MAX RUBY_ENCODING_INLINE_MAX +#define ENCODING_SHIFT RUBY_ENCODING_SHIFT +#define ENCODING_MASK RUBY_ENCODING_MASK + +#define RB_ENCODING_SET_INLINED(obj,i) do {\ + RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\ + RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\ +} while (0) +#define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i)) + +#define RB_ENCODING_GET_INLINED(obj) \ + (int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT) +#define RB_ENCODING_GET(obj) \ + (RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \ + RB_ENCODING_GET_INLINED(obj) : \ + rb_enc_get_index(obj)) + +#define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0) + +#define ENCODING_SET_INLINED(obj,i) RB_ENCODING_SET_INLINED(obj,i) +#define ENCODING_SET(obj,i) RB_ENCODING_SET(obj,i) +#define ENCODING_GET_INLINED(obj) RB_ENCODING_GET_INLINED(obj) +#define ENCODING_GET(obj) RB_ENCODING_GET(obj) +#define ENCODING_IS_ASCII8BIT(obj) RB_ENCODING_IS_ASCII8BIT(obj) +#define ENCODING_MAXNAMELEN RUBY_ENCODING_MAXNAMELEN + +enum ruby_coderange_type { + RUBY_ENC_CODERANGE_UNKNOWN = 0, + RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8), + RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9), + RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)), + RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT| + RUBY_ENC_CODERANGE_VALID| + RUBY_ENC_CODERANGE_BROKEN) +}; + +static inline int +rb_enc_coderange_clean_p(int cr) +{ + return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT; +} +#define RB_ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr) +#define RB_ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK) +#define RB_ENC_CODERANGE_ASCIIONLY(obj) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT) +#define RB_ENC_CODERANGE_SET(obj,cr) (\ + RBASIC(obj)->flags = \ + (RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr)) +#define RB_ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_SET((obj),0) + +/* assumed ASCII compatibility */ +#define RB_ENC_CODERANGE_AND(a, b) \ + ((a) == RUBY_ENC_CODERANGE_7BIT ? (b) : \ + (a) != RUBY_ENC_CODERANGE_VALID ? RUBY_ENC_CODERANGE_UNKNOWN : \ + (b) == RUBY_ENC_CODERANGE_7BIT ? RUBY_ENC_CODERANGE_VALID : (b)) + +#define RB_ENCODING_CODERANGE_SET(obj, encindex, cr) \ + do { \ + VALUE rb_encoding_coderange_obj = (obj); \ + RB_ENCODING_SET(rb_encoding_coderange_obj, (encindex)); \ + RB_ENC_CODERANGE_SET(rb_encoding_coderange_obj, (cr)); \ + } while (0) + +#define ENC_CODERANGE_MASK RUBY_ENC_CODERANGE_MASK +#define ENC_CODERANGE_UNKNOWN RUBY_ENC_CODERANGE_UNKNOWN +#define ENC_CODERANGE_7BIT RUBY_ENC_CODERANGE_7BIT +#define ENC_CODERANGE_VALID RUBY_ENC_CODERANGE_VALID +#define ENC_CODERANGE_BROKEN RUBY_ENC_CODERANGE_BROKEN +#define ENC_CODERANGE_CLEAN_P(cr) RB_ENC_CODERANGE_CLEAN_P(cr) +#define ENC_CODERANGE(obj) RB_ENC_CODERANGE(obj) +#define ENC_CODERANGE_ASCIIONLY(obj) RB_ENC_CODERANGE_ASCIIONLY(obj) +#define ENC_CODERANGE_SET(obj,cr) RB_ENC_CODERANGE_SET(obj,cr) +#define ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_CLEAR(obj) +#define ENC_CODERANGE_AND(a, b) RB_ENC_CODERANGE_AND(a, b) +#define ENCODING_CODERANGE_SET(obj, encindex, cr) RB_ENCODING_CODERANGE_SET(obj, encindex, cr) + +typedef const OnigEncodingType rb_encoding; + +int rb_char_to_option_kcode(int c, int *option, int *kcode); + +int rb_enc_replicate(const char *, rb_encoding *); +int rb_define_dummy_encoding(const char *); +PUREFUNC(int rb_enc_dummy_p(rb_encoding *enc)); +PUREFUNC(int rb_enc_to_index(rb_encoding *enc)); +int rb_enc_get_index(VALUE obj); +void rb_enc_set_index(VALUE obj, int encindex); +int rb_enc_capable(VALUE obj); +int rb_enc_find_index(const char *name); +int rb_enc_alias(const char *alias, const char *orig); +int rb_to_encoding_index(VALUE); +rb_encoding *rb_to_encoding(VALUE); +rb_encoding *rb_find_encoding(VALUE); +rb_encoding *rb_enc_get(VALUE); +rb_encoding *rb_enc_compatible(VALUE,VALUE); +rb_encoding *rb_enc_check(VALUE,VALUE); +VALUE rb_enc_associate_index(VALUE, int); +VALUE rb_enc_associate(VALUE, rb_encoding*); +void rb_enc_copy(VALUE dst, VALUE src); + +VALUE rb_enc_str_new(const char*, long, rb_encoding*); +VALUE rb_enc_str_new_cstr(const char*, rb_encoding*); +VALUE rb_enc_str_new_static(const char*, long, rb_encoding*); +VALUE rb_enc_reg_new(const char*, long, rb_encoding*, int); +PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3); +VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list); +long rb_enc_strlen(const char*, const char*, rb_encoding*); +char* rb_enc_nth(const char*, const char*, long, rb_encoding*); +VALUE rb_obj_encoding(VALUE); +VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc); +VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc); + +VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *); +VALUE rb_str_export_to_enc(VALUE, rb_encoding *); +VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to); +VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts); + +#ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P +#define rb_enc_str_new(str, len, enc) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_enc_str_new_static((str), (len), (enc)) : \ + rb_enc_str_new((str), (len), (enc)) \ +) +#define rb_enc_str_new_cstr(str, enc) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_enc_str_new_static((str), (long)strlen(str), (enc)) : \ + rb_enc_str_new_cstr((str), (enc)) \ +) +#endif + +PRINTF_ARGS(NORETURN(void rb_enc_raise(rb_encoding *, VALUE, const char*, ...)), 3, 4); + +/* index -> rb_encoding */ +rb_encoding *rb_enc_from_index(int idx); + +/* name -> rb_encoding */ +rb_encoding *rb_enc_find(const char *name); + +/* rb_encoding * -> name */ +#define rb_enc_name(enc) (enc)->name + +/* rb_encoding * -> minlen/maxlen */ +#define rb_enc_mbminlen(enc) (enc)->min_enc_len +#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len + +/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */ +int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc); + +/* -> mbclen (only for valid encoding) */ +int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc); + +/* -> chlen, invalid or needmore */ +int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc); +#define MBCLEN_CHARFOUND_P(ret) ONIGENC_MBCLEN_CHARFOUND_P(ret) +#define MBCLEN_CHARFOUND_LEN(ret) ONIGENC_MBCLEN_CHARFOUND_LEN(ret) +#define MBCLEN_INVALID_P(ret) ONIGENC_MBCLEN_INVALID_P(ret) +#define MBCLEN_NEEDMORE_P(ret) ONIGENC_MBCLEN_NEEDMORE_P(ret) +#define MBCLEN_NEEDMORE_LEN(ret) ONIGENC_MBCLEN_NEEDMORE_LEN(ret) + +/* -> 0x00..0x7f, -1 */ +int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc); + + +/* -> code (and len) or raise exception */ +unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc); + +/* prototype for obsolete function */ +unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc); +/* overriding macro */ +#define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc)) +#define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e)) + +/* -> codelen>0 or raise exception */ +int rb_enc_codelen(int code, rb_encoding *enc); +/* -> 0 for invalid codepoint */ +int rb_enc_code_to_mbclen(int code, rb_encoding *enc); +#define rb_enc_code_to_mbclen(c, enc) ONIGENC_CODE_TO_MBCLEN((enc), (c)); + +/* code,ptr,encoding -> write buf */ +#define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC((enc),(c),(UChar*)(buf)) + +/* start, ptr, end, encoding -> prev_char */ +#define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e))) +/* start, ptr, end, encoding -> next_char */ +#define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e))) +#define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e))) +#define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n))) + +/* ptr, ptr, encoding -> newline_or_not */ +#define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE((enc),(UChar*)(p),(UChar*)(end)) + +#define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE((enc),(c),(t)) +#define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c) +#define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA((enc),(c)) +#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c)) +#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c)) +#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c)) +#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c)) +#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c)) +#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c)) +#define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c)) + +static inline int +rb_enc_asciicompat_inline(rb_encoding *enc) +{ + return rb_enc_mbminlen(enc)==1 && !rb_enc_dummy_p(enc); +} +#define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc) + +int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc); +CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc)); +CONSTFUNC(int rb_enc_tolower(int c, rb_encoding *enc)); +ID rb_intern3(const char*, long, rb_encoding*); +ID rb_interned_id_p(const char *, long, rb_encoding *); +int rb_enc_symname_p(const char*, rb_encoding*); +int rb_enc_symname2_p(const char*, long, rb_encoding*); +int rb_enc_str_coderange(VALUE); +long rb_str_coderange_scan_restartable(const char*, const char*, rb_encoding*, int*); +int rb_enc_str_asciionly_p(VALUE); +#define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str)) +VALUE rb_enc_from_encoding(rb_encoding *enc); +PUREFUNC(int rb_enc_unicode_p(rb_encoding *enc)); +rb_encoding *rb_ascii8bit_encoding(void); +rb_encoding *rb_utf8_encoding(void); +rb_encoding *rb_usascii_encoding(void); +rb_encoding *rb_locale_encoding(void); +rb_encoding *rb_filesystem_encoding(void); +rb_encoding *rb_default_external_encoding(void); +rb_encoding *rb_default_internal_encoding(void); +#ifndef rb_ascii8bit_encindex +CONSTFUNC(int rb_ascii8bit_encindex(void)); +#endif +#ifndef rb_utf8_encindex +CONSTFUNC(int rb_utf8_encindex(void)); +#endif +#ifndef rb_usascii_encindex +CONSTFUNC(int rb_usascii_encindex(void)); +#endif +int rb_locale_encindex(void); +int rb_filesystem_encindex(void); +VALUE rb_enc_default_external(void); +VALUE rb_enc_default_internal(void); +void rb_enc_set_default_external(VALUE encoding); +void rb_enc_set_default_internal(VALUE encoding); +VALUE rb_locale_charmap(VALUE klass); +long rb_memsearch(const void*,long,const void*,long,rb_encoding*); +char *rb_enc_path_next(const char *,const char *,rb_encoding*); +char *rb_enc_path_skip_prefix(const char *,const char *,rb_encoding*); +char *rb_enc_path_last_separator(const char *,const char *,rb_encoding*); +char *rb_enc_path_end(const char *,const char *,rb_encoding*); +const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc); +const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc); +ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc); +VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc); + +RUBY_EXTERN VALUE rb_cEncoding; + +/* econv stuff */ + +typedef enum { + econv_invalid_byte_sequence, + econv_undefined_conversion, + econv_destination_buffer_full, + econv_source_buffer_empty, + econv_finished, + econv_after_output, + econv_incomplete_input +} rb_econv_result_t; + +typedef struct rb_econv_t rb_econv_t; + +VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts); +int rb_econv_has_convpath_p(const char* from_encoding, const char* to_encoding); + +int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags); +int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts); + +rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags); +rb_econv_t *rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts); + +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); +void rb_econv_close(rb_econv_t *ec); + +/* result: 0:success -1:failure */ +int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname); + +/* result: 0:success -1:failure */ +int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name); +int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name); + +VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags); + +/* result: 0:success -1:failure */ +int rb_econv_insert_output(rb_econv_t *ec, + const unsigned char *str, size_t len, const char *str_encoding); + +/* encoding that rb_econv_insert_output doesn't need conversion */ +const char *rb_econv_encoding_to_insert_output(rb_econv_t *ec); + +/* raise an error if the last rb_econv_convert is error */ +void rb_econv_check_error(rb_econv_t *ec); + +/* returns an exception object or nil */ +VALUE rb_econv_make_exception(rb_econv_t *ec); + +int rb_econv_putbackable(rb_econv_t *ec); +void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n); + +/* returns the corresponding ASCII compatible encoding for encname, + * or NULL if encname is not ASCII incompatible encoding. */ +const char *rb_econv_asciicompat_encoding(const char *encname); + +VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags); +VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags); +VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags); +VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags); +VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags); + +void rb_econv_binmode(rb_econv_t *ec); + +enum ruby_econv_flag_type { +/* flags for rb_econv_open */ + RUBY_ECONV_ERROR_HANDLER_MASK = 0x000000ff, + + RUBY_ECONV_INVALID_MASK = 0x0000000f, + RUBY_ECONV_INVALID_REPLACE = 0x00000002, + + RUBY_ECONV_UNDEF_MASK = 0x000000f0, + RUBY_ECONV_UNDEF_REPLACE = 0x00000020, + RUBY_ECONV_UNDEF_HEX_CHARREF = 0x00000030, + + RUBY_ECONV_DECORATOR_MASK = 0x0000ff00, + RUBY_ECONV_NEWLINE_DECORATOR_MASK = 0x00003f00, + RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK = 0x00000f00, + RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK = 0x00003000, + + RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR = 0x00000100, + RUBY_ECONV_CRLF_NEWLINE_DECORATOR = 0x00001000, + RUBY_ECONV_CR_NEWLINE_DECORATOR = 0x00002000, + RUBY_ECONV_XML_TEXT_DECORATOR = 0x00004000, + RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR = 0x00008000, + + RUBY_ECONV_STATEFUL_DECORATOR_MASK = 0x00f00000, + RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR = 0x00100000, + + 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 +#define ECONV_INVALID_MASK RUBY_ECONV_INVALID_MASK +#define ECONV_INVALID_REPLACE RUBY_ECONV_INVALID_REPLACE +#define ECONV_UNDEF_MASK RUBY_ECONV_UNDEF_MASK +#define ECONV_UNDEF_REPLACE RUBY_ECONV_UNDEF_REPLACE +#define ECONV_UNDEF_HEX_CHARREF RUBY_ECONV_UNDEF_HEX_CHARREF +#define ECONV_DECORATOR_MASK RUBY_ECONV_DECORATOR_MASK +#define ECONV_NEWLINE_DECORATOR_MASK RUBY_ECONV_NEWLINE_DECORATOR_MASK +#define ECONV_NEWLINE_DECORATOR_READ_MASK RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK +#define ECONV_NEWLINE_DECORATOR_WRITE_MASK RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK +#define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR +#define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR +#define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR +#define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR +#define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR +#define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK +#define ECONV_XML_ATTR_QUOTE_DECORATOR RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR +#define ECONV_DEFAULT_NEWLINE_DECORATOR RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR +/* end of flags for rb_econv_open */ + +/* flags for rb_econv_convert */ + RUBY_ECONV_PARTIAL_INPUT = 0x00010000, + RUBY_ECONV_AFTER_OUTPUT = 0x00020000, +#define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT +#define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT +/* end of flags for rb_econv_convert */ +RUBY_ECONV_FLAGS_PLACEHOLDER}; + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_ENCODING_H */ diff --git a/include/ruby/intern.h b/include/ruby/intern.h new file mode 100644 index 0000000000..2f60fb569e --- /dev/null +++ b/include/ruby/intern.h @@ -0,0 +1,1230 @@ +/********************************************************************** + + intern.h - + + $Author$ + created at: Thu Jun 10 14:22:17 JST 1993 + + Copyright (C) 1993-2007 Yukihiro Matsumoto + Copyright (C) 2000 Network Applied Communication Laboratory, Inc. + Copyright (C) 2000 Information-technology Promotion Agency, Japan + +**********************************************************************/ + +#ifndef RUBY_INTERN_H +#define RUBY_INTERN_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#if !defined(__has_attribute) +#define __has_attribute(x) 0 +#endif + +#include "ruby/defines.h" +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif + +#ifdef HAVE_STDARG_PROTOTYPES +# include <stdarg.h> +#else +# include <varargs.h> +#endif + +#include "ruby/st.h" + +/* 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 + +RUBY_SYMBOL_EXPORT_BEGIN + +/* + * Functions and variables that are used by more than one source file of + * the kernel. + */ + +#define UNLIMITED_ARGUMENTS (-1) + +/* array.c */ +void rb_mem_clear(VALUE*, long); +VALUE rb_assoc_new(VALUE, VALUE); +VALUE rb_check_array_type(VALUE); +VALUE rb_ary_new(void); +VALUE rb_ary_new_capa(long capa); +VALUE rb_ary_new_from_args(long n, ...); +VALUE rb_ary_new_from_values(long n, const VALUE *elts); +VALUE rb_ary_tmp_new(long); +void rb_ary_free(VALUE); +void rb_ary_modify(VALUE); +VALUE rb_ary_freeze(VALUE); +VALUE rb_ary_shared_with_p(VALUE, VALUE); +VALUE rb_ary_aref(int, const VALUE*, VALUE); +VALUE rb_ary_subseq(VALUE, long, long); +void rb_ary_store(VALUE, long, VALUE); +VALUE rb_ary_dup(VALUE); +VALUE rb_ary_resurrect(VALUE ary); +VALUE rb_ary_to_ary(VALUE); +VALUE rb_ary_to_s(VALUE); +VALUE rb_ary_cat(VALUE, const VALUE *, long); +VALUE rb_ary_push(VALUE, VALUE); +VALUE rb_ary_pop(VALUE); +VALUE rb_ary_shift(VALUE); +VALUE rb_ary_unshift(VALUE, VALUE); +VALUE rb_ary_entry(VALUE, long); +VALUE rb_ary_each(VALUE); +VALUE rb_ary_join(VALUE, VALUE); +VALUE rb_ary_reverse(VALUE); +VALUE rb_ary_rotate(VALUE, long); +VALUE rb_ary_sort(VALUE); +VALUE rb_ary_sort_bang(VALUE); +VALUE rb_ary_delete(VALUE, VALUE); +VALUE rb_ary_delete_at(VALUE, long); +VALUE rb_ary_clear(VALUE); +VALUE rb_ary_plus(VALUE, VALUE); +VALUE rb_ary_concat(VALUE, VALUE); +VALUE rb_ary_assoc(VALUE, VALUE); +VALUE rb_ary_rassoc(VALUE, VALUE); +VALUE rb_ary_includes(VALUE, VALUE); +VALUE rb_ary_cmp(VALUE, VALUE); +VALUE rb_ary_replace(VALUE copy, VALUE orig); +VALUE rb_get_values_at(VALUE, long, int, const VALUE*, VALUE(*)(VALUE,long)); +VALUE rb_ary_resize(VALUE ary, long len); +#define rb_ary_new2 rb_ary_new_capa +#define rb_ary_new3 rb_ary_new_from_args +#define rb_ary_new4 rb_ary_new_from_values +/* bignum.c */ +VALUE rb_big_new(size_t, int); +int rb_bigzero_p(VALUE x); +VALUE rb_big_clone(VALUE); +void rb_big_2comp(VALUE); +VALUE rb_big_norm(VALUE); +void rb_big_resize(VALUE big, size_t len); +VALUE rb_cstr_to_inum(const char*, int, int); +VALUE rb_str_to_inum(VALUE, int, int); +VALUE rb_cstr2inum(const char*, int); +VALUE rb_str2inum(VALUE, int); +VALUE rb_big2str(VALUE, int); +long rb_big2long(VALUE); +#define rb_big2int(x) rb_big2long(x) +unsigned long rb_big2ulong(VALUE); +#define rb_big2uint(x) rb_big2ulong(x) +#if HAVE_LONG_LONG +LONG_LONG rb_big2ll(VALUE); +unsigned LONG_LONG rb_big2ull(VALUE); +#endif /* HAVE_LONG_LONG */ +void rb_big_pack(VALUE val, unsigned long *buf, long num_longs); +VALUE rb_big_unpack(unsigned long *buf, long num_longs); +int rb_uv_to_utf8(char[6],unsigned long); +VALUE rb_dbl2big(double); +double rb_big2dbl(VALUE); +VALUE rb_big_cmp(VALUE, VALUE); +VALUE rb_big_eq(VALUE, VALUE); +VALUE rb_big_eql(VALUE, VALUE); +VALUE rb_big_plus(VALUE, VALUE); +VALUE rb_big_minus(VALUE, VALUE); +VALUE rb_big_mul(VALUE, VALUE); +VALUE rb_big_div(VALUE, VALUE); +VALUE rb_big_idiv(VALUE, VALUE); +VALUE rb_big_modulo(VALUE, VALUE); +VALUE rb_big_divmod(VALUE, VALUE); +VALUE rb_big_pow(VALUE, VALUE); +VALUE rb_big_and(VALUE, VALUE); +VALUE rb_big_or(VALUE, VALUE); +VALUE rb_big_xor(VALUE, VALUE); +VALUE rb_big_lshift(VALUE, VALUE); +VALUE rb_big_rshift(VALUE, VALUE); + +/* For rb_integer_pack and rb_integer_unpack: */ +/* "MS" in MSWORD and MSBYTE means "most significant" */ +/* "LS" in LSWORD and LSBYTE means "least significant" */ +#define INTEGER_PACK_MSWORD_FIRST 0x01 +#define INTEGER_PACK_LSWORD_FIRST 0x02 +#define INTEGER_PACK_MSBYTE_FIRST 0x10 +#define INTEGER_PACK_LSBYTE_FIRST 0x20 +#define INTEGER_PACK_NATIVE_BYTE_ORDER 0x40 +#define INTEGER_PACK_2COMP 0x80 +#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION 0x400 +/* For rb_integer_unpack: */ +#define INTEGER_PACK_FORCE_BIGNUM 0x100 +#define INTEGER_PACK_NEGATIVE 0x200 +/* Combinations: */ +#define INTEGER_PACK_LITTLE_ENDIAN \ + (INTEGER_PACK_LSWORD_FIRST | \ + INTEGER_PACK_LSBYTE_FIRST) +#define INTEGER_PACK_BIG_ENDIAN \ + (INTEGER_PACK_MSWORD_FIRST | \ + INTEGER_PACK_MSBYTE_FIRST) +int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags); +VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags); +size_t rb_absint_size(VALUE val, int *nlz_bits_ret); +size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret); +int rb_absint_singlebit_p(VALUE val); + +/* rational.c */ +VALUE rb_rational_raw(VALUE, VALUE); +#define rb_rational_raw1(x) rb_rational_raw((x), INT2FIX(1)) +#define rb_rational_raw2(x,y) rb_rational_raw((x), (y)) +VALUE rb_rational_new(VALUE, VALUE); +#define rb_rational_new1(x) rb_rational_new((x), INT2FIX(1)) +#define rb_rational_new2(x,y) rb_rational_new((x), (y)) +VALUE rb_Rational(VALUE, VALUE); +#define rb_Rational1(x) rb_Rational((x), INT2FIX(1)) +#define rb_Rational2(x,y) rb_Rational((x), (y)) +VALUE rb_rational_num(VALUE rat); +VALUE rb_rational_den(VALUE rat); +VALUE rb_flt_rationalize_with_prec(VALUE, VALUE); +VALUE rb_flt_rationalize(VALUE); +/* complex.c */ +VALUE rb_complex_raw(VALUE, VALUE); +#define rb_complex_raw1(x) rb_complex_raw((x), INT2FIX(0)) +#define rb_complex_raw2(x,y) rb_complex_raw((x), (y)) +VALUE rb_complex_new(VALUE, VALUE); +#define rb_complex_new1(x) rb_complex_new((x), INT2FIX(0)) +#define rb_complex_new2(x,y) rb_complex_new((x), (y)) +VALUE rb_complex_new_polar(VALUE abs, VALUE arg); +DEPRECATED_BY(rb_complex_new_polar, VALUE rb_complex_polar(VALUE abs, VALUE arg)); +VALUE rb_complex_real(VALUE z); +VALUE rb_complex_imag(VALUE z); +VALUE rb_complex_plus(VALUE x, VALUE y); +VALUE rb_complex_minus(VALUE x, VALUE y); +VALUE rb_complex_mul(VALUE x, VALUE y); +VALUE rb_complex_div(VALUE x, VALUE y); +VALUE rb_complex_uminus(VALUE z); +VALUE rb_complex_conjugate(VALUE z); +VALUE rb_complex_abs(VALUE z); +VALUE rb_complex_arg(VALUE z); +VALUE rb_complex_pow(VALUE base, VALUE exp); +VALUE rb_dbl_complex_new(double real, double imag); +#define rb_complex_add rb_complex_plus +#define rb_complex_sub rb_complex_minus +#define rb_complex_nagate rb_complex_uminus + +VALUE rb_Complex(VALUE, VALUE); +#define rb_Complex1(x) rb_Complex((x), INT2FIX(0)) +#define rb_Complex2(x,y) rb_Complex((x), (y)) +/* class.c */ +VALUE rb_class_new(VALUE); +VALUE rb_mod_init_copy(VALUE, VALUE); +VALUE rb_singleton_class_clone(VALUE); +void rb_singleton_class_attached(VALUE,VALUE); +void rb_check_inheritable(VALUE); +VALUE rb_define_class_id(ID, VALUE); +VALUE rb_define_class_id_under(VALUE, ID, VALUE); +VALUE rb_module_new(void); +VALUE rb_define_module_id(ID); +VALUE rb_define_module_id_under(VALUE, ID); +VALUE rb_mod_included_modules(VALUE); +VALUE rb_mod_include_p(VALUE, VALUE); +VALUE rb_mod_ancestors(VALUE); +VALUE rb_class_instance_methods(int, const VALUE*, VALUE); +VALUE rb_class_public_instance_methods(int, const VALUE*, VALUE); +VALUE rb_class_protected_instance_methods(int, const VALUE*, VALUE); +VALUE rb_class_private_instance_methods(int, const VALUE*, VALUE); +VALUE rb_obj_singleton_methods(int, const VALUE*, VALUE); +void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int); +void rb_undef(VALUE, ID); +void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int); +void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int); +void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int); +VALUE rb_singleton_class(VALUE); +/* compar.c */ +int rb_cmpint(VALUE, VALUE, VALUE); +NORETURN(void rb_cmperr(VALUE, VALUE)); +/* cont.c */ +VALUE rb_fiber_new(rb_block_call_func_t, VALUE); +VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv); +VALUE rb_fiber_resume_kw(VALUE fib, int argc, const VALUE *argv, int kw_splat); +VALUE rb_fiber_yield(int argc, const VALUE *argv); +VALUE rb_fiber_yield_kw(int argc, const VALUE *argv, int kw_splat); +VALUE rb_fiber_current(void); +VALUE rb_fiber_alive_p(VALUE); +/* enum.c */ +VALUE rb_enum_values_pack(int, const VALUE*); +/* enumerator.c */ +VALUE rb_enumeratorize(VALUE, VALUE, int, const VALUE *); +typedef VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE); +VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *); +VALUE rb_enumeratorize_with_size_kw(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *, int); +#ifndef RUBY_EXPORT +#define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \ + rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn)) +#define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat) \ + rb_enumeratorize_with_size_kw(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn), kw_splat) +#endif +#define SIZED_ENUMERATOR(obj, argc, argv, size_fn) \ + rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()), \ + (argc), (argv), (size_fn)) +#define SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) \ + rb_enumeratorize_with_size_kw((obj), ID2SYM(rb_frame_this_func()), \ + (argc), (argv), (size_fn), (kw_splat)) +#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \ + if (!rb_block_given_p()) \ + return SIZED_ENUMERATOR(obj, argc, argv, size_fn); \ + } while (0) +#define RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) do { \ + if (!rb_block_given_p()) \ + return SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat); \ + } while (0) +#define RETURN_ENUMERATOR(obj, argc, argv) RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0) +#define RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat) +typedef struct { + VALUE begin; + VALUE end; + VALUE step; + int exclude_end; +} rb_arithmetic_sequence_components_t; +int rb_arithmetic_sequence_extract(VALUE, rb_arithmetic_sequence_components_t *); +/* error.c */ +VALUE rb_exc_new(VALUE, const char*, long); +VALUE rb_exc_new_cstr(VALUE, const char*); +VALUE rb_exc_new_str(VALUE, VALUE); +#define rb_exc_new2 rb_exc_new_cstr +#define rb_exc_new3 rb_exc_new_str +PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2); +PRINTF_ARGS(NORETURN(void rb_loaderror_with_path(VALUE path, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_name_error_str(VALUE, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_frozen_error_raise(VALUE, const char*, ...)), 2, 3); +NORETURN(void rb_invalid_str(const char*, const char*)); +NORETURN(void rb_error_frozen(const char*)); +NORETURN(void rb_error_frozen_object(VALUE)); +void rb_error_untrusted(VALUE); +void rb_check_frozen(VALUE); +void rb_check_trusted(VALUE); +#define rb_check_frozen_internal(obj) do { \ + VALUE frozen_obj = (obj); \ + if (RB_UNLIKELY(RB_OBJ_FROZEN(frozen_obj))) { \ + rb_error_frozen_object(frozen_obj); \ + } \ + } while (0) +#ifdef __GNUC__ +#define rb_check_frozen(obj) __extension__({rb_check_frozen_internal(obj);}) +#else +static inline void +rb_check_frozen_inline(VALUE obj) +{ + rb_check_frozen_internal(obj); +} +#define rb_check_frozen(obj) rb_check_frozen_inline(obj) +static inline void +rb_check_trusted_inline(VALUE obj) +{ + rb_check_trusted(obj); +} +#define rb_check_trusted(obj) rb_check_trusted_inline(obj) +#endif +void rb_check_copyable(VALUE obj, VALUE orig); + +#define RB_OBJ_INIT_COPY(obj, orig) \ + ((obj) != (orig) && (rb_obj_init_copy((obj), (orig)), 1)) +#define OBJ_INIT_COPY(obj, orig) RB_OBJ_INIT_COPY(obj, orig) + +/* eval.c */ +int rb_sourceline(void); +const char *rb_sourcefile(void); +VALUE rb_check_funcall(VALUE, ID, int, const VALUE*); +VALUE rb_check_funcall_kw(VALUE, ID, int, const VALUE*, int); + +NORETURN(MJIT_STATIC void rb_error_arity(int, int, int)); +static inline int +rb_check_arity(int argc, int min, int max) +{ + if ((argc < min) || (max != UNLIMITED_ARGUMENTS && argc > max)) + rb_error_arity(argc, min, max); + return argc; +} +#define rb_check_arity rb_check_arity /* for ifdef */ + +#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT) +typedef struct { + int maxfd; + fd_set *fdset; +} rb_fdset_t; + +void rb_fd_init(rb_fdset_t *); +void rb_fd_term(rb_fdset_t *); +void rb_fd_zero(rb_fdset_t *); +void rb_fd_set(int, rb_fdset_t *); +void rb_fd_clr(int, rb_fdset_t *); +int rb_fd_isset(int, const rb_fdset_t *); +void rb_fd_copy(rb_fdset_t *, const fd_set *, int); +void rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src); + +struct timeval; +int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); + +#define rb_fd_ptr(f) ((f)->fdset) +#define rb_fd_max(f) ((f)->maxfd) + +#elif defined(_WIN32) + +typedef struct { + int capa; + fd_set *fdset; +} rb_fdset_t; + +void rb_fd_init(rb_fdset_t *); +void rb_fd_term(rb_fdset_t *); +#define rb_fd_zero(f) ((f)->fdset->fd_count = 0) +void rb_fd_set(int, rb_fdset_t *); +#define rb_fd_clr(n, f) rb_w32_fdclr((n), (f)->fdset) +#define rb_fd_isset(n, f) rb_w32_fdisset((n), (f)->fdset) +#define rb_fd_copy(d, s, n) rb_w32_fd_copy((d), (s), (n)) +void rb_w32_fd_copy(rb_fdset_t *, const fd_set *, int); +#define rb_fd_dup(d, s) rb_w32_fd_dup((d), (s)) +void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src); +static inline int +rb_fd_select(int n, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout) +{ + return rb_w32_select(n, + rfds ? rfds->fdset : NULL, + wfds ? wfds->fdset : NULL, + efds ? efds->fdset : NULL, + timeout); +} +#define rb_fd_resize(n, f) ((void)(f)) + +#define rb_fd_ptr(f) ((f)->fdset) +#define rb_fd_max(f) ((f)->fdset->fd_count) + +#else + +typedef fd_set rb_fdset_t; +#define rb_fd_zero(f) FD_ZERO(f) +#define rb_fd_set(n, f) FD_SET((n), (f)) +#define rb_fd_clr(n, f) FD_CLR((n), (f)) +#define rb_fd_isset(n, f) FD_ISSET((n), (f)) +#define rb_fd_copy(d, s, n) (*(d) = *(s)) +#define rb_fd_dup(d, s) (*(d) = *(s)) +#define rb_fd_resize(n, f) ((void)(f)) +#define rb_fd_ptr(f) (f) +#define rb_fd_init(f) FD_ZERO(f) +#define rb_fd_init_copy(d, s) (*(d) = *(s)) +#define rb_fd_term(f) ((void)(f)) +#define rb_fd_max(f) FD_SETSIZE +#define rb_fd_select(n, rfds, wfds, efds, timeout) select((n), (rfds), (wfds), (efds), (timeout)) + +#endif + +NORETURN(void rb_exc_raise(VALUE)); +NORETURN(void rb_exc_fatal(VALUE)); +NORETURN(VALUE rb_f_exit(int, const VALUE*)); +NORETURN(VALUE rb_f_abort(int, const VALUE*)); +void rb_remove_method(VALUE, const char*); +void rb_remove_method_id(VALUE, ID); +#define HAVE_RB_DEFINE_ALLOC_FUNC 1 +typedef VALUE (*rb_alloc_func_t)(VALUE); +void rb_define_alloc_func(VALUE, rb_alloc_func_t); +void rb_undef_alloc_func(VALUE); +rb_alloc_func_t rb_get_alloc_func(VALUE); +void rb_clear_constant_cache(void); +void rb_clear_method_cache_by_class(VALUE); +void rb_alias(VALUE, ID, ID); +void rb_attr(VALUE,ID,int,int,int); +int rb_method_boundp(VALUE, ID, int); +int rb_method_basic_definition_p(VALUE, ID); +VALUE rb_eval_cmd(VALUE, VALUE, int); +VALUE rb_eval_cmd_kw(VALUE, VALUE, int); +int rb_obj_respond_to(VALUE, ID, int); +int rb_respond_to(VALUE, ID); +NORETURN(VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker)); +#if !defined(RUBY_EXPORT) && defined(_WIN32) +RUBY_EXTERN VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE, VALUE marker); +#define rb_f_notimplement (*rb_f_notimplement_) +#endif +NORETURN(void rb_interrupt(void)); +VALUE rb_apply(VALUE, ID, VALUE); +void rb_backtrace(void); +ID rb_frame_this_func(void); +VALUE rb_obj_instance_eval(int, const VALUE*, VALUE); +VALUE rb_obj_instance_exec(int, const VALUE*, VALUE); +VALUE rb_mod_module_eval(int, const VALUE*, VALUE); +VALUE rb_mod_module_exec(int, const VALUE*, VALUE); +void rb_load(VALUE, int); +void rb_load_protect(VALUE, int, int*); +NORETURN(void rb_jump_tag(int)); +int rb_provided(const char*); +int rb_feature_provided(const char *, const char **); +void rb_provide(const char*); +VALUE rb_f_require(VALUE, VALUE); +VALUE rb_require_safe(VALUE, int); /* Remove in 3.0 */ +VALUE rb_require_string(VALUE); +void rb_obj_call_init(VALUE, int, const VALUE*); +void rb_obj_call_init_kw(VALUE, int, const VALUE*, int); +VALUE rb_class_new_instance(int, const VALUE*, VALUE); +VALUE rb_class_new_instance_kw(int, const VALUE*, VALUE, int); +VALUE rb_block_proc(void); +VALUE rb_block_lambda(void); +VALUE rb_proc_new(rb_block_call_func_t, VALUE); +VALUE rb_obj_is_proc(VALUE); +VALUE rb_proc_call(VALUE, VALUE); +VALUE rb_proc_call_kw(VALUE, VALUE, int); +VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE); +VALUE rb_proc_call_with_block_kw(VALUE, int argc, const VALUE *argv, VALUE, int); +int rb_proc_arity(VALUE); +VALUE rb_proc_lambda_p(VALUE); +VALUE rb_binding_new(void); +VALUE rb_obj_method(VALUE, VALUE); +VALUE rb_obj_is_method(VALUE); +VALUE rb_method_call(int, const VALUE*, VALUE); +VALUE rb_method_call_kw(int, const VALUE*, VALUE, int); +VALUE rb_method_call_with_block(int, const VALUE *, VALUE, VALUE); +VALUE rb_method_call_with_block_kw(int, const VALUE *, VALUE, VALUE, int); +int rb_mod_method_arity(VALUE, ID); +int rb_obj_method_arity(VALUE, ID); +VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); +void rb_set_end_proc(void (*)(VALUE), VALUE); +void rb_thread_schedule(void); +void rb_thread_wait_fd(int); +int rb_thread_fd_writable(int); +void rb_thread_fd_close(int); +int rb_thread_alone(void); +void rb_thread_sleep(int); +void rb_thread_sleep_forever(void); +void rb_thread_sleep_deadly(void); +VALUE rb_thread_stop(void); +VALUE rb_thread_wakeup(VALUE); +VALUE rb_thread_wakeup_alive(VALUE); +VALUE rb_thread_run(VALUE); +VALUE rb_thread_kill(VALUE); +VALUE rb_thread_create(VALUE (*)(void *), void*); +int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); +void rb_thread_wait_for(struct timeval); +VALUE rb_thread_current(void); +VALUE rb_thread_main(void); +VALUE rb_thread_local_aref(VALUE, ID); +VALUE rb_thread_local_aset(VALUE, ID, VALUE); +void rb_thread_atfork(void); +void rb_thread_atfork_before_exec(void); +VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); +VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE); +VALUE rb_exec_recursive_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); +VALUE rb_exec_recursive_paired_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE); +/* dir.c */ +VALUE rb_dir_getwd(void); +/* file.c */ +VALUE rb_file_s_expand_path(int, const VALUE *); +VALUE rb_file_expand_path(VALUE, VALUE); +VALUE rb_file_s_absolute_path(int, const VALUE *); +VALUE rb_file_absolute_path(VALUE, VALUE); +VALUE rb_file_dirname(VALUE fname); +int rb_find_file_ext_safe(VALUE*, const char* const*, int); /* Remove in 3.0 */ +VALUE rb_find_file_safe(VALUE, int); /* Remove in 3.0 */ +int rb_find_file_ext(VALUE*, const char* const*); +VALUE rb_find_file(VALUE); +VALUE rb_file_directory_p(VALUE,VALUE); +VALUE rb_str_encode_ospath(VALUE); +int rb_is_absolute_path(const char *); +/* gc.c */ +COLDFUNC NORETURN(void rb_memerror(void)); +PUREFUNC(int rb_during_gc(void)); +void rb_gc_mark_locations(const VALUE*, const VALUE*); +void rb_mark_tbl(struct st_table*); +void rb_mark_tbl_no_pin(struct st_table*); +void rb_mark_set(struct st_table*); +void rb_mark_hash(struct st_table*); +void rb_gc_update_tbl_refs(st_table *ptr); +void rb_gc_mark_maybe(VALUE); +void rb_gc_mark(VALUE); +void rb_gc_mark_movable(VALUE); +VALUE rb_gc_location(VALUE); +void rb_gc_force_recycle(VALUE); +void rb_gc(void); +void rb_gc_copy_finalizer(VALUE,VALUE); +VALUE rb_gc_enable(void); +VALUE rb_gc_disable(void); +VALUE rb_gc_start(void); +VALUE rb_define_finalizer(VALUE, VALUE); +VALUE rb_undefine_finalizer(VALUE); +size_t rb_gc_count(void); +size_t rb_gc_stat(VALUE); +VALUE rb_gc_latest_gc_info(VALUE); +void rb_gc_adjust_memory_usage(ssize_t); +/* hash.c */ +void rb_st_foreach_safe(struct st_table *, int (*)(st_data_t, st_data_t, st_data_t), st_data_t); +#define st_foreach_safe rb_st_foreach_safe +VALUE rb_check_hash_type(VALUE); +void rb_hash_foreach(VALUE, int (*)(VALUE, VALUE, VALUE), VALUE); +VALUE rb_hash(VALUE); +VALUE rb_hash_new(void); +VALUE rb_hash_dup(VALUE); +VALUE rb_hash_freeze(VALUE); +VALUE rb_hash_aref(VALUE, VALUE); +VALUE rb_hash_lookup(VALUE, VALUE); +VALUE rb_hash_lookup2(VALUE, VALUE, VALUE); +VALUE rb_hash_fetch(VALUE, VALUE); +VALUE rb_hash_aset(VALUE, VALUE, VALUE); +VALUE rb_hash_clear(VALUE); +VALUE rb_hash_delete_if(VALUE); +VALUE rb_hash_delete(VALUE,VALUE); +VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone); +void rb_hash_bulk_insert(long, const VALUE *, VALUE); +typedef VALUE rb_hash_update_func(VALUE newkey, VALUE oldkey, VALUE value); +VALUE rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func); +struct st_table *rb_hash_tbl(VALUE, const char *file, int line); +int rb_path_check(const char*); +int rb_env_path_tainted(void); +VALUE rb_env_clear(void); +VALUE rb_hash_size(VALUE); +void rb_hash_free(VALUE); +/* io.c */ +#define rb_defout rb_stdout +RUBY_EXTERN VALUE rb_fs; +RUBY_EXTERN VALUE rb_output_fs; +RUBY_EXTERN VALUE rb_rs; +RUBY_EXTERN VALUE rb_default_rs; +RUBY_EXTERN VALUE rb_output_rs; +VALUE rb_io_write(VALUE, VALUE); +VALUE rb_io_gets(VALUE); +VALUE rb_io_getbyte(VALUE); +VALUE rb_io_ungetc(VALUE, VALUE); +VALUE rb_io_ungetbyte(VALUE, VALUE); +VALUE rb_io_close(VALUE); +VALUE rb_io_flush(VALUE); +VALUE rb_io_eof(VALUE); +VALUE rb_io_binmode(VALUE); +VALUE rb_io_ascii8bit_binmode(VALUE); +VALUE rb_io_addstr(VALUE, VALUE); +VALUE rb_io_printf(int, const VALUE*, VALUE); +VALUE rb_io_print(int, const VALUE*, VALUE); +VALUE rb_io_puts(int, const VALUE*, VALUE); +VALUE rb_io_fdopen(int, int, const char*); +VALUE rb_io_get_io(VALUE); +VALUE rb_file_open(const char*, const char*); +VALUE rb_file_open_str(VALUE, const char*); +VALUE rb_gets(void); +void rb_write_error(const char*); +void rb_write_error2(const char*, long); +void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds); +int rb_pipe(int *pipes); +int rb_reserved_fd_p(int fd); +int rb_cloexec_open(const char *pathname, int flags, mode_t mode); +int rb_cloexec_dup(int oldfd); +int rb_cloexec_dup2(int oldfd, int newfd); +int rb_cloexec_pipe(int fildes[2]); +int rb_cloexec_fcntl_dupfd(int fd, int minfd); +#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd) +void rb_update_max_fd(int fd); +void rb_fd_fix_cloexec(int fd); +/* marshal.c */ +VALUE rb_marshal_dump(VALUE, VALUE); +VALUE rb_marshal_load(VALUE); +void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE)); +/* numeric.c */ +NORETURN(void rb_num_zerodiv(void)); +#define RB_NUM_COERCE_FUNCS_NEED_OPID 1 +VALUE rb_num_coerce_bin(VALUE, VALUE, ID); +VALUE rb_num_coerce_cmp(VALUE, VALUE, ID); +VALUE rb_num_coerce_relop(VALUE, VALUE, ID); +VALUE rb_num_coerce_bit(VALUE, VALUE, ID); +VALUE rb_num2fix(VALUE); +VALUE rb_fix2str(VALUE, int); +CONSTFUNC(VALUE rb_dbl_cmp(double, double)); +/* object.c */ +int rb_eql(VALUE, VALUE); +VALUE rb_any_to_s(VALUE); +VALUE rb_inspect(VALUE); +VALUE rb_obj_is_instance_of(VALUE, VALUE); +VALUE rb_obj_is_kind_of(VALUE, VALUE); +VALUE rb_obj_alloc(VALUE); +VALUE rb_obj_clone(VALUE); +VALUE rb_obj_dup(VALUE); +VALUE rb_obj_init_copy(VALUE,VALUE); +VALUE rb_obj_taint(VALUE); +PUREFUNC(VALUE rb_obj_tainted(VALUE)); +VALUE rb_obj_untaint(VALUE); +VALUE rb_obj_untrust(VALUE); +PUREFUNC(VALUE rb_obj_untrusted(VALUE)); +VALUE rb_obj_trust(VALUE); +VALUE rb_obj_freeze(VALUE); +PUREFUNC(VALUE rb_obj_frozen_p(VALUE)); +VALUE rb_obj_id(VALUE); +VALUE rb_memory_id(VALUE); +VALUE rb_obj_class(VALUE); +PUREFUNC(VALUE rb_class_real(VALUE)); +PUREFUNC(VALUE rb_class_inherited_p(VALUE, VALUE)); +VALUE rb_class_superclass(VALUE); +VALUE rb_class_get_superclass(VALUE); +VALUE rb_convert_type(VALUE,int,const char*,const char*); +VALUE rb_check_convert_type(VALUE,int,const char*,const char*); +VALUE rb_check_to_integer(VALUE, const char *); +VALUE rb_check_to_float(VALUE); +VALUE rb_to_int(VALUE); +VALUE rb_check_to_int(VALUE); +VALUE rb_Integer(VALUE); +VALUE rb_to_float(VALUE); +VALUE rb_Float(VALUE); +VALUE rb_String(VALUE); +VALUE rb_Array(VALUE); +VALUE rb_Hash(VALUE); +double rb_cstr_to_dbl(const char*, int); +double rb_str_to_dbl(VALUE, int); +/* parse.y */ +ID rb_id_attrset(ID); +CONSTFUNC(int rb_is_const_id(ID)); +CONSTFUNC(int rb_is_global_id(ID)); +CONSTFUNC(int rb_is_instance_id(ID)); +CONSTFUNC(int rb_is_attrset_id(ID)); +CONSTFUNC(int rb_is_class_id(ID)); +CONSTFUNC(int rb_is_local_id(ID)); +CONSTFUNC(int rb_is_junk_id(ID)); +int rb_symname_p(const char*); +int rb_sym_interned_p(VALUE); +VALUE rb_backref_get(void); +void rb_backref_set(VALUE); +VALUE rb_lastline_get(void); +void rb_lastline_set(VALUE); +/* process.c */ +void rb_last_status_set(int status, rb_pid_t pid); +VALUE rb_last_status_get(void); +int rb_proc_exec(const char*); +NORETURN(VALUE rb_f_exec(int, const VALUE*)); +rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags); +void rb_syswait(rb_pid_t pid); +rb_pid_t rb_spawn(int, const VALUE*); +rb_pid_t rb_spawn_err(int, const VALUE*, char*, size_t); +VALUE rb_proc_times(VALUE); +VALUE rb_detach_process(rb_pid_t pid); +/* range.c */ +VALUE rb_range_new(VALUE, VALUE, int); +VALUE rb_range_beg_len(VALUE, long*, long*, long, int); +int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp); +/* random.c */ +unsigned int rb_genrand_int32(void); +double rb_genrand_real(void); +void rb_reset_random_seed(void); +VALUE rb_random_bytes(VALUE rnd, long n); +VALUE rb_random_int(VALUE rnd, VALUE max); +unsigned int rb_random_int32(VALUE rnd); +double rb_random_real(VALUE rnd); +unsigned long rb_random_ulong_limited(VALUE rnd, unsigned long limit); +unsigned long rb_genrand_ulong_limited(unsigned long i); +/* re.c */ +#define rb_memcmp memcmp +int rb_memcicmp(const void*,const void*,long); +void rb_match_busy(VALUE); +VALUE rb_reg_nth_defined(int, VALUE); +VALUE rb_reg_nth_match(int, VALUE); +int rb_reg_backref_number(VALUE match, VALUE backref); +VALUE rb_reg_last_match(VALUE); +VALUE rb_reg_match_pre(VALUE); +VALUE rb_reg_match_post(VALUE); +VALUE rb_reg_match_last(VALUE); +#define HAVE_RB_REG_NEW_STR 1 +VALUE rb_reg_new_str(VALUE, int); +VALUE rb_reg_new(const char *, long, int); +VALUE rb_reg_alloc(void); +VALUE rb_reg_init_str(VALUE re, VALUE s, int options); +VALUE rb_reg_match(VALUE, VALUE); +VALUE rb_reg_match2(VALUE); +int rb_reg_options(VALUE); +/* ruby.c */ +#define rb_argv rb_get_argv() +RUBY_EXTERN VALUE rb_argv0; +VALUE rb_get_argv(void); +void *rb_load_file(const char*); +void *rb_load_file_str(VALUE); +/* signal.c */ +VALUE rb_f_kill(int, const VALUE*); +#ifdef POSIX_SIGNAL +#define posix_signal ruby_posix_signal +RETSIGTYPE (*posix_signal(int, RETSIGTYPE (*)(int)))(int); +#endif +const char *ruby_signal_name(int); +void ruby_default_signal(int); +/* sprintf.c */ +VALUE rb_f_sprintf(int, const VALUE*); +PRINTF_ARGS(VALUE rb_sprintf(const char*, ...), 1, 2); +VALUE rb_vsprintf(const char*, va_list); +PRINTF_ARGS(VALUE rb_str_catf(VALUE, const char*, ...), 2, 3); +VALUE rb_str_vcatf(VALUE, const char*, va_list); +VALUE rb_str_format(int, const VALUE *, VALUE); +/* string.c */ +VALUE rb_str_new(const char*, long); +VALUE rb_str_new_cstr(const char*); +VALUE rb_str_new_shared(VALUE); +VALUE rb_str_new_frozen(VALUE); +VALUE rb_str_new_with_class(VALUE, const char*, long); +VALUE rb_tainted_str_new_cstr(const char*); +VALUE rb_tainted_str_new(const char*, long); +VALUE rb_external_str_new(const char*, long); +VALUE rb_external_str_new_cstr(const char*); +VALUE rb_locale_str_new(const char*, long); +VALUE rb_locale_str_new_cstr(const char*); +VALUE rb_filesystem_str_new(const char*, long); +VALUE rb_filesystem_str_new_cstr(const char*); +VALUE rb_str_buf_new(long); +VALUE rb_str_buf_new_cstr(const char*); +VALUE rb_str_buf_new2(const char*); +VALUE rb_str_tmp_new(long); +VALUE rb_usascii_str_new(const char*, long); +VALUE rb_usascii_str_new_cstr(const char*); +VALUE rb_utf8_str_new(const char*, long); +VALUE rb_utf8_str_new_cstr(const char*); +VALUE rb_str_new_static(const char *, long); +VALUE rb_usascii_str_new_static(const char *, long); +VALUE rb_utf8_str_new_static(const char *, long); +void rb_str_free(VALUE); +void rb_str_shared_replace(VALUE, VALUE); +VALUE rb_str_buf_append(VALUE, VALUE); +VALUE rb_str_buf_cat(VALUE, const char*, long); +VALUE rb_str_buf_cat2(VALUE, const char*); +VALUE rb_str_buf_cat_ascii(VALUE, const char*); +VALUE rb_obj_as_string(VALUE); +VALUE rb_check_string_type(VALUE); +void rb_must_asciicompat(VALUE); +VALUE rb_str_dup(VALUE); +VALUE rb_str_resurrect(VALUE str); +VALUE rb_str_locktmp(VALUE); +VALUE rb_str_unlocktmp(VALUE); +VALUE rb_str_dup_frozen(VALUE); +#define rb_str_dup_frozen rb_str_new_frozen +VALUE rb_str_plus(VALUE, VALUE); +VALUE rb_str_times(VALUE, VALUE); +long rb_str_sublen(VALUE, long); +VALUE rb_str_substr(VALUE, long, long); +VALUE rb_str_subseq(VALUE, long, long); +char *rb_str_subpos(VALUE, long, long*); +void rb_str_modify(VALUE); +void rb_str_modify_expand(VALUE, long); +VALUE rb_str_freeze(VALUE); +void rb_str_set_len(VALUE, long); +VALUE rb_str_resize(VALUE, long); +VALUE rb_str_cat(VALUE, const char*, long); +VALUE rb_str_cat_cstr(VALUE, const char*); +VALUE rb_str_cat2(VALUE, const char*); +VALUE rb_str_append(VALUE, VALUE); +VALUE rb_str_concat(VALUE, VALUE); +st_index_t rb_memhash(const void *ptr, long len); +st_index_t rb_hash_start(st_index_t); +st_index_t rb_hash_uint32(st_index_t, uint32_t); +st_index_t rb_hash_uint(st_index_t, st_index_t); +st_index_t rb_hash_end(st_index_t); +#define rb_hash_uint32(h, i) st_hash_uint32((h), (i)) +#define rb_hash_uint(h, i) st_hash_uint((h), (i)) +#define rb_hash_end(h) st_hash_end(h) +st_index_t rb_str_hash(VALUE); +int rb_str_hash_cmp(VALUE,VALUE); +int rb_str_comparable(VALUE, VALUE); +int rb_str_cmp(VALUE, VALUE); +VALUE rb_str_equal(VALUE str1, VALUE str2); +VALUE rb_str_drop_bytes(VALUE, long); +void rb_str_update(VALUE, long, long, VALUE); +VALUE rb_str_replace(VALUE, VALUE); +VALUE rb_str_inspect(VALUE); +VALUE rb_str_dump(VALUE); +VALUE rb_str_split(VALUE, const char*); +rb_gvar_setter_t rb_str_setter; +VALUE rb_str_intern(VALUE); +VALUE rb_sym_to_s(VALUE); +long rb_str_strlen(VALUE); +VALUE rb_str_length(VALUE); +long rb_str_offset(VALUE, long); +PUREFUNC(size_t rb_str_capacity(VALUE)); +VALUE rb_str_ellipsize(VALUE, long); +VALUE rb_str_scrub(VALUE, VALUE); +/* symbol.c */ +VALUE rb_sym_all_symbols(void); + +#ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P +#define rb_str_new(str, len) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_str_new_static((str), (len)) : \ + rb_str_new((str), (len)) \ +) +#define rb_str_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_str_new_static((str), (long)strlen(str)) : \ + rb_str_new_cstr(str) \ +) +#define rb_usascii_str_new(str, len) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_usascii_str_new_static((str), (len)) : \ + rb_usascii_str_new((str), (len)) \ +) +#define rb_utf8_str_new(str, len) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_utf8_str_new_static((str), (len)) : \ + rb_utf8_str_new((str), (len)) \ +) +#define rb_tainted_str_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_tainted_str_new((str), (long)strlen(str)) : \ + rb_tainted_str_new_cstr(str) \ +) +#define rb_usascii_str_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_usascii_str_new_static((str), (long)strlen(str)) : \ + rb_usascii_str_new_cstr(str) \ +) +#define rb_utf8_str_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_utf8_str_new_static((str), (long)strlen(str)) : \ + rb_utf8_str_new_cstr(str) \ +) +#define rb_external_str_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_external_str_new((str), (long)strlen(str)) : \ + rb_external_str_new_cstr(str) \ +) +#define rb_locale_str_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_locale_str_new((str), (long)strlen(str)) : \ + rb_locale_str_new_cstr(str) \ +) +#define rb_str_buf_new_cstr(str) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(str)) ? \ + rb_str_buf_cat(rb_str_buf_new((long)strlen(str)), \ + (str), (long)strlen(str)) : \ + rb_str_buf_new_cstr(str) \ +) +#define rb_str_cat_cstr(str, ptr) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(ptr)) ? \ + rb_str_cat((str), (ptr), (long)strlen(ptr)) : \ + rb_str_cat_cstr((str), (ptr)) \ +) +#define rb_exc_new_cstr(klass, ptr) RB_GNUC_EXTENSION_BLOCK( \ + (__builtin_constant_p(ptr)) ? \ + rb_exc_new((klass), (ptr), (long)strlen(ptr)) : \ + rb_exc_new_cstr((klass), (ptr)) \ +) +#endif +#define rb_str_new2 rb_str_new_cstr +#define rb_str_new3 rb_str_new_shared +#define rb_str_new4 rb_str_new_frozen +#define rb_str_new5 rb_str_new_with_class +#define rb_tainted_str_new2 rb_tainted_str_new_cstr +#define rb_str_buf_new2 rb_str_buf_new_cstr +#define rb_usascii_str_new2 rb_usascii_str_new_cstr +#define rb_str_buf_cat rb_str_cat +#define rb_str_buf_cat2 rb_str_cat_cstr +#define rb_str_cat2 rb_str_cat_cstr +#define rb_strlen_lit(str) (sizeof(str "") - 1) +#define rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str)) +#define rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str)) +#define rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str)) +#define rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc)) +#define rb_str_new_literal(str) rb_str_new_lit(str) +#define rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str) +#define rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str) +#define rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc) + +/* struct.c */ +VALUE rb_struct_new(VALUE, ...); +VALUE rb_struct_define(const char*, ...); +VALUE rb_struct_define_under(VALUE, const char*, ...); +VALUE rb_struct_alloc(VALUE, VALUE); +VALUE rb_struct_initialize(VALUE, VALUE); +VALUE rb_struct_aref(VALUE, VALUE); +VALUE rb_struct_aset(VALUE, VALUE, VALUE); +VALUE rb_struct_getmember(VALUE, ID); +VALUE rb_struct_s_members(VALUE); +VALUE rb_struct_members(VALUE); +VALUE rb_struct_size(VALUE s); +VALUE rb_struct_alloc_noinit(VALUE); +VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...); +VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, ...); + +/* thread.c */ +typedef void rb_unblock_function_t(void *); +typedef VALUE rb_blocking_function_t(void *); +void rb_thread_check_ints(void); +int rb_thread_interrupted(VALUE thval); + +#define RUBY_UBF_IO ((rb_unblock_function_t *)-1) +#define RUBY_UBF_PROCESS ((rb_unblock_function_t *)-1) +VALUE rb_mutex_new(void); +VALUE rb_mutex_locked_p(VALUE mutex); +VALUE rb_mutex_trylock(VALUE mutex); +VALUE rb_mutex_lock(VALUE mutex); +VALUE rb_mutex_unlock(VALUE mutex); +VALUE rb_mutex_sleep(VALUE self, VALUE timeout); +VALUE rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg); +/* time.c */ +struct timespec; +void rb_timespec_now(struct timespec *); +VALUE rb_time_new(time_t, long); +VALUE rb_time_nano_new(time_t, long); +VALUE rb_time_timespec_new(const struct timespec *, int); +VALUE rb_time_num_new(VALUE, VALUE); +struct timeval rb_time_interval(VALUE num); +struct timeval rb_time_timeval(VALUE time); +struct timespec rb_time_timespec(VALUE time); +struct timespec rb_time_timespec_interval(VALUE num); +VALUE rb_time_utc_offset(VALUE time); +/* variable.c */ +VALUE rb_mod_name(VALUE); +VALUE rb_class_path(VALUE); +VALUE rb_class_path_cached(VALUE); +void rb_set_class_path(VALUE, VALUE, const char*); +void rb_set_class_path_string(VALUE, VALUE, VALUE); +VALUE rb_path_to_class(VALUE); +VALUE rb_path2class(const char*); +VALUE rb_class_name(VALUE); +VALUE rb_autoload_load(VALUE, ID); +VALUE rb_autoload_p(VALUE, ID); +VALUE rb_f_trace_var(int, const VALUE*); +VALUE rb_f_untrace_var(int, const VALUE*); +VALUE rb_f_global_variables(void); +void rb_alias_variable(ID, ID); +void rb_copy_generic_ivar(VALUE,VALUE); +void rb_free_generic_ivar(VALUE); +VALUE rb_ivar_get(VALUE, ID); +VALUE rb_ivar_set(VALUE, ID, VALUE); +VALUE rb_ivar_defined(VALUE, ID); +void rb_ivar_foreach(VALUE, int (*)(ID, VALUE, st_data_t), st_data_t); +st_index_t rb_ivar_count(VALUE); +VALUE rb_attr_get(VALUE, ID); +VALUE rb_obj_instance_variables(VALUE); +VALUE rb_obj_remove_instance_variable(VALUE, VALUE); +void *rb_mod_const_at(VALUE, void*); +void *rb_mod_const_of(VALUE, void*); +VALUE rb_const_list(void*); +VALUE rb_mod_constants(int, const VALUE *, VALUE); +VALUE rb_mod_remove_const(VALUE, VALUE); +int rb_const_defined(VALUE, ID); +int rb_const_defined_at(VALUE, ID); +int rb_const_defined_from(VALUE, ID); +VALUE rb_const_get(VALUE, ID); +VALUE rb_const_get_at(VALUE, ID); +VALUE rb_const_get_from(VALUE, ID); +void rb_const_set(VALUE, ID, VALUE); +VALUE rb_const_remove(VALUE, ID); +#if 0 /* EXPERIMENTAL: remove if no problem */ +NORETURN(VALUE rb_mod_const_missing(VALUE,VALUE)); +#endif +VALUE rb_cvar_defined(VALUE, ID); +void rb_cvar_set(VALUE, ID, VALUE); +VALUE rb_cvar_get(VALUE, ID); +void rb_cv_set(VALUE, const char*, VALUE); +VALUE rb_cv_get(VALUE, const char*); +void rb_define_class_variable(VALUE, const char*, VALUE); +VALUE rb_mod_class_variables(int, const VALUE*, VALUE); +VALUE rb_mod_remove_cvar(VALUE, VALUE); + +ID rb_frame_callee(void); +int rb_frame_method_id_and_class(ID *idp, VALUE *klassp); +VALUE rb_str_succ(VALUE); +VALUE rb_time_succ(VALUE); +VALUE rb_make_backtrace(void); +VALUE rb_make_exception(int, const VALUE*); + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +extern "C++" { +#endif + +#if defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P) +# define rb_f_notimplement_p(f) __builtin_types_compatible_p(__typeof__(f),__typeof__(rb_f_notimplement)) +#else +# define rb_f_notimplement_p(f) 0 +#endif + +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) && !defined(_WIN32) && !defined(__CYGWIN__) +#if defined(__has_attribute) && __has_attribute(transparent_union) && __has_attribute(unused) && __has_attribute(weakref) && __has_attribute(nonnull) +#define RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,funcargs) \ + __attribute__((__unused__,__weakref__(#def),__nonnull__ nonnull))static void defname(RB_UNWRAP_MACRO decl,VALUE(*func)funcargs,int arity); +#endif +#endif + +#if defined(RB_METHOD_DEFINITION_DECL_C) || defined(__cplusplus) +#ifndef RB_METHOD_DEFINITION_DECL_C +#define RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,funcargs) \ + static inline void defname(RB_UNWRAP_MACRO decl,VALUE(*func)funcargs,int arity) \ + { \ + def(RB_UNWRAP_MACRO vars,(VALUE(*)(ANYARGS))(func),arity); \ + } +#endif + +#define RB_UNWRAP_MACRO(...) __VA_ARGS__ + +#ifdef __cplusplus +#define RB_METHOD_DEFINITION_DECL_CXX_BEGIN(def) template <int Arity> struct def##_tmpl {}; +#define RB_METHOD_DEFINITION_DECL_CXX(def,defname,decl,vars,funcargs,arity) \ + template <> struct def##_tmpl<arity> { \ + static void define(RB_UNWRAP_MACRO decl, VALUE (*func)funcargs) {::defname(RB_UNWRAP_MACRO vars, func, arity);} \ + static void define(RB_UNWRAP_MACRO decl, VALUE (*func)(...)) {::defname(RB_UNWRAP_MACRO vars, reinterpret_cast<VALUE(*)funcargs>(func), arity);} \ + }; +#else +#define RB_METHOD_DEFINITION_DECL_CXX_BEGIN(def) /* nothing */ +#define RB_METHOD_DEFINITION_DECL_CXX(def,defname,decl,vars,funcargs,arity) /* nothing */ +#endif +#define RB_METHOD_DEFINITION_DECL_1(def,nonnull,defname,arity,decl,vars,funcargs) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,funcargs) \ + RB_METHOD_DEFINITION_DECL_CXX(def,defname,decl,vars,funcargs,arity) + +#define RB_METHOD_DEFINITION_DECL(def,nonnull,decl,vars) \ +RB_METHOD_DEFINITION_DECL_CXX_BEGIN(def) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##0 ,0 ,decl,vars,(VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##1 ,1 ,decl,vars,(VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##2 ,2 ,decl,vars,(VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##3 ,3 ,decl,vars,(VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##4 ,4 ,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##5 ,5 ,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##6 ,6 ,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##7 ,7 ,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##8 ,8 ,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##9 ,9 ,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##10,10,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##11,11,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##12,12,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##13,13,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##14,14,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##15,15,decl,vars,(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_M3(def,nonnull,def##m3,decl,vars) \ +RB_METHOD_DEFINITION_DECL_1(def,nonnull,def##m2,-2,decl,vars,(VALUE,VALUE)) \ +RB_METHOD_DEFINITION_DECL_M1(def,nonnull,def##m1,decl,vars) /* END */ +#ifdef __cplusplus +#define RB_METHOD_DEFINITION_DECL_M1(def,nonnull,defname,decl,vars) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,(int,VALUE*,VALUE)) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,(int,const VALUE*,VALUE)) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,(int,const VALUE*,VALUE,VALUE)) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,(...)) \ + template <> struct def##_tmpl<-1> { \ + static void define(RB_UNWRAP_MACRO decl, VALUE (*func)(int,VALUE*,VALUE)) {::defname(RB_UNWRAP_MACRO vars, func, -1);} \ + static void define(RB_UNWRAP_MACRO decl, VALUE (*func)(int,const VALUE*,VALUE)) {::defname(RB_UNWRAP_MACRO vars, func, -1);} \ + static void define(RB_UNWRAP_MACRO decl, VALUE (*func)(int,const VALUE*,VALUE,VALUE)) {::defname(RB_UNWRAP_MACRO vars, func, -1);} \ + static void define(RB_UNWRAP_MACRO decl, VALUE (*func)(...)) {::defname(RB_UNWRAP_MACRO vars, func, -1);} \ + }; +#define RB_METHOD_DEFINITION_DECL_M3(def,nonnull,defname,decl,vars) /* nothing */ +#else +#define RB_METHOD_DEFINITION_DECL_M1(def,nonnull,defname,decl,vars) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,(int,union{VALUE*x;const VALUE*y;}__attribute__((__transparent_union__)),VALUE)) +#define RB_METHOD_DEFINITION_DECL_M3(def,nonnull,defname,decl,vars) \ + RB_METHOD_DEFINITION_DECL_C(def,nonnull,defname,decl,vars,()) +#endif + +#endif + +#ifdef RB_METHOD_DEFINITION_DECL + +RB_METHOD_DEFINITION_DECL(rb_define_method_id, (3), (VALUE klass, ID name), (klass, name)) +#ifdef __cplusplus +#define rb_define_method_id(m, n, f, a) rb_define_method_id_tmpl<a>::define(m, n, f) +#else +#define rb_define_method_id_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_method_id15,rb_define_method_idm3) +#define rb_define_method_id_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_method_id14,rb_define_method_id_choose_prototype15(n)) +#define rb_define_method_id_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_method_id13,rb_define_method_id_choose_prototype14(n)) +#define rb_define_method_id_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_method_id12,rb_define_method_id_choose_prototype13(n)) +#define rb_define_method_id_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_method_id11,rb_define_method_id_choose_prototype12(n)) +#define rb_define_method_id_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_method_id10,rb_define_method_id_choose_prototype11(n)) +#define rb_define_method_id_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_method_id9, rb_define_method_id_choose_prototype10(n)) +#define rb_define_method_id_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_method_id8, rb_define_method_id_choose_prototype9(n)) +#define rb_define_method_id_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_method_id7, rb_define_method_id_choose_prototype8(n)) +#define rb_define_method_id_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_method_id6, rb_define_method_id_choose_prototype7(n)) +#define rb_define_method_id_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_method_id5, rb_define_method_id_choose_prototype6(n)) +#define rb_define_method_id_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_method_id4, rb_define_method_id_choose_prototype5(n)) +#define rb_define_method_id_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_method_id3, rb_define_method_id_choose_prototype4(n)) +#define rb_define_method_id_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_method_id2, rb_define_method_id_choose_prototype3(n)) +#define rb_define_method_id_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_method_id1, rb_define_method_id_choose_prototype2(n)) +#define rb_define_method_id_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_method_id0, rb_define_method_id_choose_prototype1(n)) +#define rb_define_method_id_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_method_idm1,rb_define_method_id_choose_prototype0(n)) +#define rb_define_method_id_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_method_idm2,rb_define_method_id_choose_prototypem1(n)) +#define rb_define_method_id_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_method_idm3,rb_define_method_id_choose_prototypem2(n)) +#define rb_define_method_id(klass, mid, func, arity) rb_define_method_id_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity)); +#endif + +RB_METHOD_DEFINITION_DECL(rb_define_protected_method, (2,3), (VALUE klass, const char *name), (klass, name)) +#ifdef __cplusplus +#define rb_define_protected_method(m, n, f, a) rb_define_protected_method_tmpl<a>::define(m, n, f) +#else +#define rb_define_protected_method_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_protected_method15,rb_define_protected_methodm3) +#define rb_define_protected_method_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_protected_method14,rb_define_protected_method_choose_prototype15(n)) +#define rb_define_protected_method_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_protected_method13,rb_define_protected_method_choose_prototype14(n)) +#define rb_define_protected_method_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_protected_method12,rb_define_protected_method_choose_prototype13(n)) +#define rb_define_protected_method_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_protected_method11,rb_define_protected_method_choose_prototype12(n)) +#define rb_define_protected_method_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_protected_method10,rb_define_protected_method_choose_prototype11(n)) +#define rb_define_protected_method_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_protected_method9, rb_define_protected_method_choose_prototype10(n)) +#define rb_define_protected_method_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_protected_method8, rb_define_protected_method_choose_prototype9(n)) +#define rb_define_protected_method_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_protected_method7, rb_define_protected_method_choose_prototype8(n)) +#define rb_define_protected_method_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_protected_method6, rb_define_protected_method_choose_prototype7(n)) +#define rb_define_protected_method_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_protected_method5, rb_define_protected_method_choose_prototype6(n)) +#define rb_define_protected_method_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_protected_method4, rb_define_protected_method_choose_prototype5(n)) +#define rb_define_protected_method_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_protected_method3, rb_define_protected_method_choose_prototype4(n)) +#define rb_define_protected_method_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_protected_method2, rb_define_protected_method_choose_prototype3(n)) +#define rb_define_protected_method_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_protected_method1, rb_define_protected_method_choose_prototype2(n)) +#define rb_define_protected_method_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_protected_method0, rb_define_protected_method_choose_prototype1(n)) +#define rb_define_protected_method_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_protected_methodm1,rb_define_protected_method_choose_prototype0(n)) +#define rb_define_protected_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_protected_methodm2,rb_define_protected_method_choose_prototypem1(n)) +#define rb_define_protected_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_protected_methodm3,rb_define_protected_method_choose_prototypem2(n)) +#define rb_define_protected_method(klass, mid, func, arity) rb_define_protected_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity)); +#endif + +RB_METHOD_DEFINITION_DECL(rb_define_private_method, (2,3), (VALUE klass, const char *name), (klass, name)) +#ifdef __cplusplus +#define rb_define_private_method(m, n, f, a) rb_define_private_method_tmpl<a>::define(m, n, f) +#else +#define rb_define_private_method_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_private_method15,rb_define_private_methodm3) +#define rb_define_private_method_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_private_method14,rb_define_private_method_choose_prototype15(n)) +#define rb_define_private_method_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_private_method13,rb_define_private_method_choose_prototype14(n)) +#define rb_define_private_method_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_private_method12,rb_define_private_method_choose_prototype13(n)) +#define rb_define_private_method_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_private_method11,rb_define_private_method_choose_prototype12(n)) +#define rb_define_private_method_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_private_method10,rb_define_private_method_choose_prototype11(n)) +#define rb_define_private_method_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_private_method9, rb_define_private_method_choose_prototype10(n)) +#define rb_define_private_method_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_private_method8, rb_define_private_method_choose_prototype9(n)) +#define rb_define_private_method_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_private_method7, rb_define_private_method_choose_prototype8(n)) +#define rb_define_private_method_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_private_method6, rb_define_private_method_choose_prototype7(n)) +#define rb_define_private_method_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_private_method5, rb_define_private_method_choose_prototype6(n)) +#define rb_define_private_method_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_private_method4, rb_define_private_method_choose_prototype5(n)) +#define rb_define_private_method_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_private_method3, rb_define_private_method_choose_prototype4(n)) +#define rb_define_private_method_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_private_method2, rb_define_private_method_choose_prototype3(n)) +#define rb_define_private_method_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_private_method1, rb_define_private_method_choose_prototype2(n)) +#define rb_define_private_method_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_private_method0, rb_define_private_method_choose_prototype1(n)) +#define rb_define_private_method_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_private_methodm1,rb_define_private_method_choose_prototype0(n)) +#define rb_define_private_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_private_methodm2,rb_define_private_method_choose_prototypem1(n)) +#define rb_define_private_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_private_methodm3,rb_define_private_method_choose_prototypem2(n)) +#define rb_define_private_method(klass, mid, func, arity) rb_define_private_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity)); +#endif + +RB_METHOD_DEFINITION_DECL(rb_define_singleton_method, (2,3), (VALUE klass, const char *name), (klass, name)) +#ifdef __cplusplus +#define rb_define_singleton_method(m, n, f, a) rb_define_singleton_method_tmpl<a>::define(m, n, f) +#else +#define rb_define_singleton_method_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_singleton_method15,rb_define_singleton_methodm3) +#define rb_define_singleton_method_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_singleton_method14,rb_define_singleton_method_choose_prototype15(n)) +#define rb_define_singleton_method_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_singleton_method13,rb_define_singleton_method_choose_prototype14(n)) +#define rb_define_singleton_method_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_singleton_method12,rb_define_singleton_method_choose_prototype13(n)) +#define rb_define_singleton_method_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_singleton_method11,rb_define_singleton_method_choose_prototype12(n)) +#define rb_define_singleton_method_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_singleton_method10,rb_define_singleton_method_choose_prototype11(n)) +#define rb_define_singleton_method_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_singleton_method9, rb_define_singleton_method_choose_prototype10(n)) +#define rb_define_singleton_method_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_singleton_method8, rb_define_singleton_method_choose_prototype9(n)) +#define rb_define_singleton_method_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_singleton_method7, rb_define_singleton_method_choose_prototype8(n)) +#define rb_define_singleton_method_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_singleton_method6, rb_define_singleton_method_choose_prototype7(n)) +#define rb_define_singleton_method_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_singleton_method5, rb_define_singleton_method_choose_prototype6(n)) +#define rb_define_singleton_method_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_singleton_method4, rb_define_singleton_method_choose_prototype5(n)) +#define rb_define_singleton_method_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_singleton_method3, rb_define_singleton_method_choose_prototype4(n)) +#define rb_define_singleton_method_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_singleton_method2, rb_define_singleton_method_choose_prototype3(n)) +#define rb_define_singleton_method_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_singleton_method1, rb_define_singleton_method_choose_prototype2(n)) +#define rb_define_singleton_method_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_singleton_method0, rb_define_singleton_method_choose_prototype1(n)) +#define rb_define_singleton_method_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_singleton_methodm1,rb_define_singleton_method_choose_prototype0(n)) +#define rb_define_singleton_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_singleton_methodm2,rb_define_singleton_method_choose_prototypem1(n)) +#define rb_define_singleton_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_singleton_methodm3,rb_define_singleton_method_choose_prototypem2(n)) +#define rb_define_singleton_method(klass, mid, func, arity) rb_define_singleton_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity)); +#endif + +#endif + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C++" { */ +#endif + +#endif /* RUBY_INTERN_H */ diff --git a/include/ruby/io.h b/include/ruby/io.h new file mode 100644 index 0000000000..152f4ef763 --- /dev/null +++ b/include/ruby/io.h @@ -0,0 +1,185 @@ +/********************************************************************** + + rubyio.h - + + $Author$ + created at: Fri Nov 12 16:47:09 JST 1993 + + Copyright (C) 1993-2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_IO_H +#define RUBY_IO_H 1 + +#ifdef RUBY_INTERNAL_H +#error "Include this file before internal.h" +#endif + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include <stdio.h> +#include "ruby/encoding.h" + +#if defined(HAVE_STDIO_EXT_H) +#include <stdio_ext.h> +#endif + +#include "ruby/config.h" +#include <errno.h> +#if defined(HAVE_POLL) +# ifdef _AIX +# define reqevents events +# define rtnevents revents +# endif +# include <poll.h> +# ifdef _AIX +# undef reqevents +# undef rtnevents +# undef events +# undef revents +# endif +# define RB_WAITFD_IN POLLIN +# define RB_WAITFD_PRI POLLPRI +# define RB_WAITFD_OUT POLLOUT +#else +# define RB_WAITFD_IN 0x001 +# define RB_WAITFD_PRI 0x002 +# define RB_WAITFD_OUT 0x004 +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t { + char *ptr; /* off + len <= capa */ + int off; + int len; + int capa; +}); +typedef struct rb_io_buffer_t rb_io_buffer_t; + +typedef struct rb_io_t { + FILE *stdio_file; /* stdio ptr for read/write if available */ + int fd; /* file descriptor */ + int mode; /* mode flags: FMODE_XXXs */ + rb_pid_t pid; /* child's pid (for pipes) */ + int lineno; /* number of lines read */ + VALUE pathv; /* pathname for file */ + void (*finalize)(struct rb_io_t*,int); /* finalize proc */ + + rb_io_buffer_t wbuf, rbuf; + + VALUE tied_io_for_writing; + + /* + * enc enc2 read action write action + * NULL NULL force_encoding(default_external) write the byte sequence of str + * e1 NULL force_encoding(e1) convert str.encoding to e1 + * e1 e2 convert from e2 to e1 convert str.encoding to e2 + */ + struct rb_io_enc_t { + rb_encoding *enc; + rb_encoding *enc2; + int ecflags; + VALUE ecopts; + } encs; + + rb_econv_t *readconv; + rb_io_buffer_t cbuf; + + rb_econv_t *writeconv; + VALUE writeconv_asciicompat; + int writeconv_initialized; + int writeconv_pre_ecflags; + VALUE writeconv_pre_ecopts; + + VALUE write_lock; +} rb_io_t; + +typedef struct rb_io_enc_t rb_io_enc_t; + +#define HAVE_RB_IO_T 1 + +#define FMODE_READABLE 0x00000001 +#define FMODE_WRITABLE 0x00000002 +#define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE) +#define FMODE_BINMODE 0x00000004 +#define FMODE_SYNC 0x00000008 +#define FMODE_TTY 0x00000010 +#define FMODE_DUPLEX 0x00000020 +#define FMODE_APPEND 0x00000040 +#define FMODE_CREATE 0x00000080 +/* #define FMODE_NOREVLOOKUP 0x00000100 */ +#define FMODE_EXCL 0x00000400 +#define FMODE_TRUNC 0x00000800 +#define FMODE_TEXTMODE 0x00001000 +/* #define FMODE_PREP 0x00010000 */ +#define FMODE_SETENC_BY_BOM 0x00100000 +/* #define FMODE_UNIX 0x00200000 */ +/* #define FMODE_INET 0x00400000 */ +/* #define FMODE_INET6 0x00800000 */ + +#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) + +#define MakeOpenFile(obj, fp) do {\ + (fp) = rb_io_make_open_file(obj);\ +} while (0) + +rb_io_t *rb_io_make_open_file(VALUE obj); + +FILE *rb_io_stdio_file(rb_io_t *fptr); + +FILE *rb_fdopen(int, const char*); +int rb_io_modestr_fmode(const char *modestr); +int rb_io_modestr_oflags(const char *modestr); +CONSTFUNC(int rb_io_oflags_fmode(int oflags)); +void rb_io_check_writable(rb_io_t*); +void rb_io_check_readable(rb_io_t*); +void rb_io_check_char_readable(rb_io_t *fptr); +void rb_io_check_byte_readable(rb_io_t *fptr); +int rb_io_fptr_finalize(rb_io_t*); +void rb_io_synchronized(rb_io_t*); +void rb_io_check_initialized(rb_io_t*); +void rb_io_check_closed(rb_io_t*); +VALUE rb_io_get_io(VALUE io); +VALUE rb_io_check_io(VALUE io); +VALUE rb_io_get_write_io(VALUE io); +VALUE rb_io_set_write_io(VALUE io, VALUE w); +int rb_io_wait_readable(int); +int rb_io_wait_writable(int); +int rb_wait_for_single_fd(int fd, int events, struct timeval *tv); +void rb_io_set_nonblock(rb_io_t *fptr); +int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p); +void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, rb_io_enc_t *convconfig_p); +ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size); + +/* compatibility for ruby 1.8 and older */ +#define rb_io_mode_flags(modestr) [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">] +#define rb_io_modenum_flags(oflags) [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">] + +VALUE rb_io_taint_check(VALUE); +NORETURN(void rb_eof_error(void)); + +void rb_io_read_check(rb_io_t*); +int rb_io_read_pending(rb_io_t*); + +struct stat; +VALUE rb_stat_new(const struct stat *); + +/* gc.c */ + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_IO_H */ diff --git a/include/ruby/missing.h b/include/ruby/missing.h new file mode 100644 index 0000000000..03657042ce --- /dev/null +++ b/include/ruby/missing.h @@ -0,0 +1,278 @@ +/************************************************ + + missing.h - prototype for *.c in ./missing, and + for missing timeval struct + + $Author$ + created at: Sat May 11 23:46:03 JST 2002 + +************************************************/ + +#ifndef RUBY_MISSING_H +#define RUBY_MISSING_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/config.h" +#include <stddef.h> +#include <math.h> /* for INFINITY and NAN */ +#ifdef RUBY_ALTERNATIVE_MALLOC_HEADER +# include RUBY_ALTERNATIVE_MALLOC_HEADER +#endif +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif + +#if !defined(HAVE_STRUCT_TIMEVAL) || !defined(HAVE_STRUCT_TIMESPEC) +#if defined(HAVE_TIME_H) +# include <time.h> +#endif +#if defined(HAVE_SYS_TIME_H) +# include <sys/time.h> +#endif +#endif + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif +#ifndef M_PI_2 +# define M_PI_2 (M_PI/2) +#endif + +#ifndef RUBY_SYMBOL_EXPORT_BEGIN +# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */ +# define RUBY_SYMBOL_EXPORT_END /* end */ +#endif + +#if !defined(HAVE_STRUCT_TIMEVAL) +struct timeval { + time_t tv_sec; /* seconds */ + long tv_usec; /* microseconds */ +}; +#endif /* HAVE_STRUCT_TIMEVAL */ + +#if !defined(HAVE_STRUCT_TIMESPEC) +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ +}; +#endif + +#if !defined(HAVE_STRUCT_TIMEZONE) +struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; +#endif + +#ifdef RUBY_EXPORT +#undef RUBY_EXTERN +#endif +#ifndef RUBY_EXTERN +#define RUBY_EXTERN extern +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +#ifndef HAVE_ACOSH +RUBY_EXTERN double acosh(double); +RUBY_EXTERN double asinh(double); +RUBY_EXTERN double atanh(double); +#endif + +#ifndef HAVE_CRYPT +RUBY_EXTERN char *crypt(const char *, const char *); +#endif + +#ifndef HAVE_DUP2 +RUBY_EXTERN int dup2(int, int); +#endif + +#ifndef HAVE_EACCESS +RUBY_EXTERN int eaccess(const char*, int); +#endif + +#ifndef HAVE_ROUND +RUBY_EXTERN double round(double); /* numeric.c */ +#endif + +#ifndef HAVE_FINITE +RUBY_EXTERN int finite(double); +#endif + +#ifndef HAVE_FLOCK +RUBY_EXTERN int flock(int, int); +#endif + +/* +#ifndef HAVE_FREXP +RUBY_EXTERN double frexp(double, int *); +#endif +*/ + +#ifndef HAVE_HYPOT +RUBY_EXTERN double hypot(double, double); +#endif + +#ifndef HAVE_ERF +RUBY_EXTERN double erf(double); +RUBY_EXTERN double erfc(double); +#endif + +#ifndef HAVE_TGAMMA +RUBY_EXTERN double tgamma(double); +#endif + +#ifndef HAVE_LGAMMA_R +RUBY_EXTERN double lgamma_r(double, int *); +#endif + +#ifndef HAVE_CBRT +RUBY_EXTERN double cbrt(double); +#endif + +#if !defined(INFINITY) || !defined(NAN) +union bytesequence4_or_float { + unsigned char bytesequence[4]; + float float_value; +}; +#endif + +#ifndef INFINITY +/** @internal */ +RUBY_EXTERN const union bytesequence4_or_float rb_infinity; +# define INFINITY (rb_infinity.float_value) +# define USE_RB_INFINITY 1 +#endif + +#ifndef NAN +/** @internal */ +RUBY_EXTERN const union bytesequence4_or_float rb_nan; +# define NAN (rb_nan.float_value) +# define USE_RB_NAN 1 +#endif + +#ifndef HUGE_VAL +# define HUGE_VAL ((double)INFINITY) +#endif + +#ifndef isinf +# ifndef HAVE_ISINF +# if defined(HAVE_FINITE) && defined(HAVE_ISNAN) +# ifdef HAVE_IEEEFP_H +# include <ieeefp.h> +# endif +# define isinf(x) (!finite(x) && !isnan(x)) +# elif defined(__cplusplus) && __cplusplus >= 201103L +# include <cmath> // it must include constexpr bool isinf(double); +# else +RUBY_EXTERN int isinf(double); +# endif +# endif +#endif + +#ifndef isnan +# ifndef HAVE_ISNAN +# if defined(__cplusplus) && __cplusplus >= 201103L +# include <cmath> // it must include constexpr bool isnan(double); +# else +RUBY_EXTERN int isnan(double); +# endif +# endif +#endif + +#ifndef isfinite +# ifndef HAVE_ISFINITE +# define HAVE_ISFINITE 1 +# define isfinite(x) finite(x) +# endif +#endif + +#ifndef HAVE_NAN +RUBY_EXTERN double nan(const char *); +#endif + +#ifndef HAVE_NEXTAFTER +RUBY_EXTERN double nextafter(double x, double y); +#endif + +/* +#ifndef HAVE_MEMCMP +RUBY_EXTERN int memcmp(const void *, const void *, size_t); +#endif +*/ + +#ifndef HAVE_MEMMOVE +RUBY_EXTERN void *memmove(void *, const void *, size_t); +#endif + +/* +#ifndef HAVE_MODF +RUBY_EXTERN double modf(double, double *); +#endif +*/ + +#ifndef HAVE_STRCHR +RUBY_EXTERN char *strchr(const char *, int); +RUBY_EXTERN char *strrchr(const char *, int); +#endif + +#ifndef HAVE_STRERROR +RUBY_EXTERN char *strerror(int); +#endif + +#ifndef HAVE_STRSTR +RUBY_EXTERN char *strstr(const char *, const char *); +#endif + +#ifndef HAVE_STRLCPY +RUBY_EXTERN size_t strlcpy(char *, const char*, size_t); +#endif + +#ifndef HAVE_STRLCAT +RUBY_EXTERN size_t strlcat(char *, const char*, size_t); +#endif + +#ifndef HAVE_SIGNBIT +RUBY_EXTERN int signbit(double x); +#endif + +#ifndef HAVE_FFS +RUBY_EXTERN int ffs(int); +#endif + +#ifdef BROKEN_CLOSE +#include <sys/types.h> +#include <sys/socket.h> +RUBY_EXTERN int ruby_getpeername(int, struct sockaddr *, socklen_t *); +RUBY_EXTERN int ruby_getsockname(int, struct sockaddr *, socklen_t *); +RUBY_EXTERN int ruby_shutdown(int, int); +RUBY_EXTERN int ruby_close(int); +#endif + +#ifndef HAVE_SETPROCTITLE +RUBY_EXTERN void setproctitle(const char *fmt, ...); +#endif + +#ifndef HAVE_EXPLICIT_BZERO +RUBY_EXTERN void explicit_bzero(void *b, size_t len); +# if defined SecureZeroMemory +# define explicit_bzero(b, len) SecureZeroMemory(b, len) +# endif +#endif + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_MISSING_H */ diff --git a/include/ruby/onigmo.h b/include/ruby/onigmo.h new file mode 100644 index 0000000000..6187b37dc3 --- /dev/null +++ b/include/ruby/onigmo.h @@ -0,0 +1,941 @@ +#ifndef ONIGMO_H +#define ONIGMO_H +/********************************************************************** + onigmo.h - Onigmo (Oniguruma-mod) (regular expression library) +**********************************************************************/ +/*- + * Copyright (c) 2002-2009 K.Kosako <sndgk393 AT ybb DOT ne DOT jp> + * Copyright (c) 2011-2017 K.Takata <kentkt AT csc DOT jp> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef __cplusplus +extern "C" { +# if 0 +} /* satisfy cc-mode */ +# endif +#endif + +#define ONIGMO_VERSION_MAJOR 6 +#define ONIGMO_VERSION_MINOR 1 +#define ONIGMO_VERSION_TEENY 3 + +#ifndef ONIG_EXTERN +# ifdef RUBY_EXTERN +# define ONIG_EXTERN RUBY_EXTERN +# else +# if defined(_WIN32) && !defined(__GNUC__) +# if defined(EXPORT) || defined(RUBY_EXPORT) +# define ONIG_EXTERN extern __declspec(dllexport) +# else +# define ONIG_EXTERN extern __declspec(dllimport) +# endif +# endif +# endif +#endif + +#ifndef ONIG_EXTERN +# define ONIG_EXTERN extern +#endif + +#ifndef RUBY +# ifndef RUBY_SYMBOL_EXPORT_BEGIN +# define RUBY_SYMBOL_EXPORT_BEGIN +# define RUBY_SYMBOL_EXPORT_END +# endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +#include <stddef.h> /* for size_t */ + +/* PART: character encoding */ + +#ifndef ONIG_ESCAPE_UCHAR_COLLISION +# define UChar OnigUChar +#endif + +typedef unsigned char OnigUChar; +typedef unsigned int OnigCodePoint; +typedef unsigned int OnigCtype; +typedef size_t OnigDistance; +typedef ptrdiff_t OnigPosition; + +#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0) + +/* + * Onig casefold/case mapping flags and related definitions + * + * Subfields (starting with 0 at LSB): + * 0-2: Code point count in casefold.h + * 3-12: Index into SpecialCaseMapping array in casefold.h + * 13-22: Case folding/mapping flags + */ +typedef unsigned int OnigCaseFoldType; /* case fold flag */ + +ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag; + +/* bits for actual code point count; 3 bits is more than enough, currently only 2 used */ +#define OnigCodePointMaskWidth 3 +#define OnigCodePointMask ((1<<OnigCodePointMaskWidth)-1) +#define OnigCodePointCount(n) ((n)&OnigCodePointMask) +#define OnigCaseFoldFlags(n) ((n)&~OnigCodePointMask) + +/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */ /* no longer usable with these values! */ +/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */ /* no longer usable with these values! */ + +/* bits for index into table with separate titlecase mappings */ +/* 10 bits provide 1024 values */ +#define OnigSpecialIndexShift 3 +#define OnigSpecialIndexWidth 10 + +#define ONIGENC_CASE_UPCASE (1<<13) /* has/needs uppercase mapping */ +#define ONIGENC_CASE_DOWNCASE (1<<14) /* has/needs lowercase mapping */ +#define ONIGENC_CASE_TITLECASE (1<<15) /* has/needs (special) titlecase mapping */ +#define ONIGENC_CASE_SPECIAL_OFFSET 3 /* offset in bits from ONIGENC_CASE to ONIGENC_CASE_SPECIAL */ +#define ONIGENC_CASE_UP_SPECIAL (1<<16) /* has special upcase mapping */ +#define ONIGENC_CASE_DOWN_SPECIAL (1<<17) /* has special downcase mapping */ +#define ONIGENC_CASE_MODIFIED (1<<18) /* data has been modified */ +#define ONIGENC_CASE_FOLD (1<<19) /* has/needs case folding */ + +#define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20) /* needs mapping specific to Turkic languages; better not change original value! */ + +#define ONIGENC_CASE_FOLD_LITHUANIAN (1<<21) /* needs Lithuanian-specific mapping */ +#define ONIGENC_CASE_ASCII_ONLY (1<<22) /* only modify ASCII range */ +#define ONIGENC_CASE_IS_TITLECASE (1<<23) /* character itself is already titlecase */ + +#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30) /* better not change original value! */ + +#define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR +#define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag + + +#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3 +#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13 +/* 13 => Unicode:0x1ffc */ + +/* code range */ +#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0]) +#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1] +#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2] + +typedef struct { + int byte_len; /* argument(original) character(s) byte length */ + int code_len; /* number of code */ + OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN]; +} OnigCaseFoldCodeItem; + +typedef struct { + OnigCodePoint esc; + OnigCodePoint anychar; + OnigCodePoint anytime; + OnigCodePoint zero_or_one_time; + OnigCodePoint one_or_more_time; + OnigCodePoint anychar_anytime; +} OnigMetaCharTableType; + +typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg); + +typedef struct OnigEncodingTypeST { + int (*precise_mbc_enc_len)(const OnigUChar* p,const OnigUChar* e, const struct OnigEncodingTypeST* enc); + const char* name; + int max_enc_len; + int min_enc_len; + int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end, const struct OnigEncodingTypeST* enc); + OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end, const struct OnigEncodingTypeST* enc); + int (*code_to_mbclen)(OnigCodePoint code, const struct OnigEncodingTypeST* enc); + int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf, const struct OnigEncodingTypeST* enc); + int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to, const struct OnigEncodingTypeST* enc); + int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, const struct OnigEncodingTypeST* enc); + int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[], const struct OnigEncodingTypeST* enc); + int (*property_name_to_ctype)(const struct OnigEncodingTypeST* enc, const OnigUChar* p, const OnigUChar* end); + int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype, const struct OnigEncodingTypeST* enc); + int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[], const struct OnigEncodingTypeST* enc); + OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p, const OnigUChar* end, const struct OnigEncodingTypeST* enc); + int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end, const struct OnigEncodingTypeST* enc); + int (*case_map)(OnigCaseFoldType* flagP, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to, OnigUChar* to_end, const struct OnigEncodingTypeST* enc); + int ruby_encoding_index; + unsigned int flags; +} OnigEncodingType; + +typedef const OnigEncodingType* OnigEncoding; + +ONIG_EXTERN const OnigEncodingType OnigEncodingASCII; +#ifndef RUBY +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_1; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_2; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_3; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_4; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_5; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_6; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_7; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_8; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_9; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_10; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_11; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_13; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_14; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_15; +ONIG_EXTERN const OnigEncodingType OnigEncodingISO_8859_16; +ONIG_EXTERN const OnigEncodingType OnigEncodingUTF_8; +ONIG_EXTERN const OnigEncodingType OnigEncodingUTF_16BE; +ONIG_EXTERN const OnigEncodingType OnigEncodingUTF_16LE; +ONIG_EXTERN const OnigEncodingType OnigEncodingUTF_32BE; +ONIG_EXTERN const OnigEncodingType OnigEncodingUTF_32LE; +ONIG_EXTERN const OnigEncodingType OnigEncodingEUC_JP; +ONIG_EXTERN const OnigEncodingType OnigEncodingEUC_TW; +ONIG_EXTERN const OnigEncodingType OnigEncodingEUC_KR; +ONIG_EXTERN const OnigEncodingType OnigEncodingEUC_CN; +ONIG_EXTERN const OnigEncodingType OnigEncodingShift_JIS; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_31J; +/* ONIG_EXTERN const OnigEncodingType OnigEncodingKOI8; */ +ONIG_EXTERN const OnigEncodingType OnigEncodingKOI8_R; +ONIG_EXTERN const OnigEncodingType OnigEncodingKOI8_U; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_1250; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_1251; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_1252; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_1253; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_1254; +ONIG_EXTERN const OnigEncodingType OnigEncodingWindows_1257; +ONIG_EXTERN const OnigEncodingType OnigEncodingBIG5; +ONIG_EXTERN const OnigEncodingType OnigEncodingGB18030; +#endif /* RUBY */ + +#define ONIG_ENCODING_ASCII (&OnigEncodingASCII) +#ifndef RUBY +# define ONIG_ENCODING_ISO_8859_1 (&OnigEncodingISO_8859_1) +# define ONIG_ENCODING_ISO_8859_2 (&OnigEncodingISO_8859_2) +# define ONIG_ENCODING_ISO_8859_3 (&OnigEncodingISO_8859_3) +# define ONIG_ENCODING_ISO_8859_4 (&OnigEncodingISO_8859_4) +# define ONIG_ENCODING_ISO_8859_5 (&OnigEncodingISO_8859_5) +# define ONIG_ENCODING_ISO_8859_6 (&OnigEncodingISO_8859_6) +# define ONIG_ENCODING_ISO_8859_7 (&OnigEncodingISO_8859_7) +# define ONIG_ENCODING_ISO_8859_8 (&OnigEncodingISO_8859_8) +# define ONIG_ENCODING_ISO_8859_9 (&OnigEncodingISO_8859_9) +# define ONIG_ENCODING_ISO_8859_10 (&OnigEncodingISO_8859_10) +# define ONIG_ENCODING_ISO_8859_11 (&OnigEncodingISO_8859_11) +# define ONIG_ENCODING_ISO_8859_13 (&OnigEncodingISO_8859_13) +# define ONIG_ENCODING_ISO_8859_14 (&OnigEncodingISO_8859_14) +# define ONIG_ENCODING_ISO_8859_15 (&OnigEncodingISO_8859_15) +# define ONIG_ENCODING_ISO_8859_16 (&OnigEncodingISO_8859_16) +# define ONIG_ENCODING_UTF_8 (&OnigEncodingUTF_8) +# define ONIG_ENCODING_UTF_16BE (&OnigEncodingUTF_16BE) +# define ONIG_ENCODING_UTF_16LE (&OnigEncodingUTF_16LE) +# define ONIG_ENCODING_UTF_32BE (&OnigEncodingUTF_32BE) +# define ONIG_ENCODING_UTF_32LE (&OnigEncodingUTF_32LE) +# define ONIG_ENCODING_EUC_JP (&OnigEncodingEUC_JP) +# define ONIG_ENCODING_EUC_TW (&OnigEncodingEUC_TW) +# define ONIG_ENCODING_EUC_KR (&OnigEncodingEUC_KR) +# define ONIG_ENCODING_EUC_CN (&OnigEncodingEUC_CN) +# define ONIG_ENCODING_SHIFT_JIS (&OnigEncodingShift_JIS) +# define ONIG_ENCODING_WINDOWS_31J (&OnigEncodingWindows_31J) +/* # define ONIG_ENCODING_KOI8 (&OnigEncodingKOI8) */ +# define ONIG_ENCODING_KOI8_R (&OnigEncodingKOI8_R) +# define ONIG_ENCODING_KOI8_U (&OnigEncodingKOI8_U) +# define ONIG_ENCODING_WINDOWS_1250 (&OnigEncodingWindows_1250) +# define ONIG_ENCODING_WINDOWS_1251 (&OnigEncodingWindows_1251) +# define ONIG_ENCODING_WINDOWS_1252 (&OnigEncodingWindows_1252) +# define ONIG_ENCODING_WINDOWS_1253 (&OnigEncodingWindows_1253) +# define ONIG_ENCODING_WINDOWS_1254 (&OnigEncodingWindows_1254) +# define ONIG_ENCODING_WINDOWS_1257 (&OnigEncodingWindows_1257) +# define ONIG_ENCODING_BIG5 (&OnigEncodingBIG5) +# define ONIG_ENCODING_GB18030 (&OnigEncodingGB18030) + +/* old names */ +# define ONIG_ENCODING_SJIS ONIG_ENCODING_SHIFT_JIS +# define ONIG_ENCODING_CP932 ONIG_ENCODING_WINDOWS_31J +# define ONIG_ENCODING_CP1250 ONIG_ENCODING_WINDOWS_1250 +# define ONIG_ENCODING_CP1251 ONIG_ENCODING_WINDOWS_1251 +# define ONIG_ENCODING_CP1252 ONIG_ENCODING_WINDOWS_1252 +# define ONIG_ENCODING_CP1253 ONIG_ENCODING_WINDOWS_1253 +# define ONIG_ENCODING_CP1254 ONIG_ENCODING_WINDOWS_1254 +# define ONIG_ENCODING_CP1257 ONIG_ENCODING_WINDOWS_1257 +# define ONIG_ENCODING_UTF8 ONIG_ENCODING_UTF_8 +# define ONIG_ENCODING_UTF16_BE ONIG_ENCODING_UTF_16BE +# define ONIG_ENCODING_UTF16_LE ONIG_ENCODING_UTF_16LE +# define ONIG_ENCODING_UTF32_BE ONIG_ENCODING_UTF_32BE +# define ONIG_ENCODING_UTF32_LE ONIG_ENCODING_UTF_32LE +#endif /* RUBY */ + +#define ONIG_ENCODING_UNDEF ((OnigEncoding )0) + +/* this declaration needs to be here because it is used in string.c in Ruby */ +ONIG_EXTERN +int onigenc_ascii_only_case_map(OnigCaseFoldType* flagP, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to, OnigUChar* to_end, const struct OnigEncodingTypeST* enc); + + +/* work size */ +#define ONIGENC_CODE_TO_MBC_MAXLEN 7 +#define ONIGENC_MBC_CASE_FOLD_MAXLEN 18 +/* 18: 6(max-byte) * 3(case-fold chars) */ + +/* character types */ +#define ONIGENC_CTYPE_NEWLINE 0 +#define ONIGENC_CTYPE_ALPHA 1 +#define ONIGENC_CTYPE_BLANK 2 +#define ONIGENC_CTYPE_CNTRL 3 +#define ONIGENC_CTYPE_DIGIT 4 +#define ONIGENC_CTYPE_GRAPH 5 +#define ONIGENC_CTYPE_LOWER 6 +#define ONIGENC_CTYPE_PRINT 7 +#define ONIGENC_CTYPE_PUNCT 8 +#define ONIGENC_CTYPE_SPACE 9 +#define ONIGENC_CTYPE_UPPER 10 +#define ONIGENC_CTYPE_XDIGIT 11 +#define ONIGENC_CTYPE_WORD 12 +#define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */ +#define ONIGENC_CTYPE_ASCII 14 +#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII + +/* flags */ +#define ONIGENC_FLAG_NONE 0U +#define ONIGENC_FLAG_UNICODE 1U + +#define onig_enc_len(enc,p,e) ONIGENC_MBC_ENC_LEN(enc, p, e) + +#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF) +#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1) +#define ONIGENC_IS_MBC_HEAD(enc,p,e) (ONIGENC_MBC_ENC_LEN(enc,p,e) != 1) +#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128) +#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128) +#define ONIGENC_IS_MBC_WORD(enc,s,end) \ + ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end)) +#define ONIGENC_IS_MBC_ASCII_WORD(enc,s,end) \ + onigenc_ascii_is_code_ctype( \ + ONIGENC_MBC_TO_CODE(enc,s,end),ONIGENC_CTYPE_WORD,enc) +#define ONIGENC_IS_UNICODE(enc) ((enc)->flags & ONIGENC_FLAG_UNICODE) + + +#define ONIGENC_NAME(enc) ((enc)->name) + +#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \ + (enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf,enc) +#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \ + (enc)->is_allowed_reverse_match(s,end,enc) +#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s,end) \ + (enc)->left_adjust_char_head(start, s, end, enc) +#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \ + (enc)->apply_all_case_fold(case_fold_flag,f,arg,enc) +#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \ + (enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs,enc) +#define ONIGENC_STEP_BACK(enc,start,s,end,n) \ + onigenc_step_back((enc),(start),(s),(end),(n)) + +#define ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) (n) +#define ONIGENC_MBCLEN_CHARFOUND_P(r) (0 < (r)) +#define ONIGENC_MBCLEN_CHARFOUND_LEN(r) (r) + +#define ONIGENC_CONSTRUCT_MBCLEN_INVALID() (-1) +#define ONIGENC_MBCLEN_INVALID_P(r) ((r) == -1) + +#define ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(n) (-1-(n)) +#define ONIGENC_MBCLEN_NEEDMORE_P(r) ((r) < -1) +#define ONIGENC_MBCLEN_NEEDMORE_LEN(r) (-1-(r)) + +#define ONIGENC_PRECISE_MBC_ENC_LEN(enc,p,e) (enc)->precise_mbc_enc_len(p,e,enc) + +ONIG_EXTERN +int onigenc_mbclen_approximate(const OnigUChar* p,const OnigUChar* e, const struct OnigEncodingTypeST* enc); + +#define ONIGENC_MBC_ENC_LEN(enc,p,e) onigenc_mbclen_approximate(p,e,enc) +#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len) +#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc) +#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len) +#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end),enc) +#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end),enc) +#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code,enc) +#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf,enc) +#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \ + (enc)->property_name_to_ctype(enc,p,end) + +#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype,enc) + +#define ONIGENC_IS_CODE_NEWLINE(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE) +#define ONIGENC_IS_CODE_GRAPH(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH) +#define ONIGENC_IS_CODE_PRINT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT) +#define ONIGENC_IS_CODE_ALNUM(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM) +#define ONIGENC_IS_CODE_ALPHA(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA) +#define ONIGENC_IS_CODE_LOWER(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER) +#define ONIGENC_IS_CODE_UPPER(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER) +#define ONIGENC_IS_CODE_CNTRL(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL) +#define ONIGENC_IS_CODE_PUNCT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT) +#define ONIGENC_IS_CODE_SPACE(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE) +#define ONIGENC_IS_CODE_BLANK(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK) +#define ONIGENC_IS_CODE_DIGIT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT) +#define ONIGENC_IS_CODE_XDIGIT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT) +#define ONIGENC_IS_CODE_WORD(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD) + +#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \ + (enc)->get_ctype_code_range(ctype,sbout,ranges,enc) + +ONIG_EXTERN +OnigUChar* onigenc_step_back(OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end, int n); + + +/* encoding API */ +ONIG_EXTERN +int onigenc_init(void); +ONIG_EXTERN +int onigenc_set_default_encoding(OnigEncoding enc); +ONIG_EXTERN +OnigEncoding onigenc_get_default_encoding(void); +ONIG_EXTERN +OnigUChar* onigenc_get_right_adjust_char_head_with_prev(OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end, const OnigUChar** prev); +ONIG_EXTERN +OnigUChar* onigenc_get_prev_char_head(OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end); +ONIG_EXTERN +OnigUChar* onigenc_get_left_adjust_char_head(OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end); +ONIG_EXTERN +OnigUChar* onigenc_get_right_adjust_char_head(OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end); +ONIG_EXTERN +int onigenc_strlen(OnigEncoding enc, const OnigUChar* p, const OnigUChar* end); +ONIG_EXTERN +int onigenc_strlen_null(OnigEncoding enc, const OnigUChar* p); +ONIG_EXTERN +int onigenc_str_bytelen_null(OnigEncoding enc, const OnigUChar* p); + + + +/* PART: regular expression */ + +/* config parameters */ +#define ONIG_NREGION 4 +#define ONIG_MAX_CAPTURE_GROUP_NUM 32767 +#define ONIG_MAX_BACKREF_NUM 1000 +#define ONIG_MAX_REPEAT_NUM 100000 +#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000 +/* constants */ +#define ONIG_MAX_ERROR_MESSAGE_LEN 90 + +typedef unsigned int OnigOptionType; + +#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE + +/* options */ +#define ONIG_OPTION_NONE 0U +#define ONIG_OPTION_IGNORECASE 1U +#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1) +#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1) +#define ONIG_OPTION_DOTALL ONIG_OPTION_MULTILINE +#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1) +#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1) +#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1) +#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1) +#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1) +#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1) +/* options (search time) */ +#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1) +#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1) +#define ONIG_OPTION_NOTBOS (ONIG_OPTION_NOTEOL << 1) +#define ONIG_OPTION_NOTEOS (ONIG_OPTION_NOTBOS << 1) +/* options (ctype range) */ +#define ONIG_OPTION_ASCII_RANGE (ONIG_OPTION_NOTEOS << 1) +#define ONIG_OPTION_POSIX_BRACKET_ALL_RANGE (ONIG_OPTION_ASCII_RANGE << 1) +#define ONIG_OPTION_WORD_BOUND_ALL_RANGE (ONIG_OPTION_POSIX_BRACKET_ALL_RANGE << 1) +/* options (newline) */ +#define ONIG_OPTION_NEWLINE_CRLF (ONIG_OPTION_WORD_BOUND_ALL_RANGE << 1) +#define ONIG_OPTION_MAXBIT ONIG_OPTION_NEWLINE_CRLF /* limit */ + +#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt)) +#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt)) +#define ONIG_IS_OPTION_ON(options,option) ((options) & (option)) + +/* syntax */ +typedef struct { + unsigned int op; + unsigned int op2; + unsigned int behavior; + OnigOptionType options; /* default option */ + OnigMetaCharTableType meta_char_table; +} OnigSyntaxType; + +ONIG_EXTERN const OnigSyntaxType OnigSyntaxASIS; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxPosixBasic; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxPosixExtended; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxEmacs; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxGrep; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxGnuRegex; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxJava; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl58; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl58_NG; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxRuby; +ONIG_EXTERN const OnigSyntaxType OnigSyntaxPython; + +/* predefined syntaxes (see regsyntax.c) */ +#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS) +#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic) +#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended) +#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs) +#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep) +#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex) +#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava) +#define ONIG_SYNTAX_PERL58 (&OnigSyntaxPerl58) +#define ONIG_SYNTAX_PERL58_NG (&OnigSyntaxPerl58_NG) +#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl) +#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby) +#define ONIG_SYNTAX_PYTHON (&OnigSyntaxPython) + +/* default syntax */ +ONIG_EXTERN const OnigSyntaxType* OnigDefaultSyntax; +#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax + +/* syntax (operators) */ +#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0) +#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */ +#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */ +#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3) +#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */ +#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5) +#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */ +#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7) +#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */ +#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */ +#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */ +#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */ +#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */ +#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */ +#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */ +#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */ +#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */ +#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */ +#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */ +#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */ +#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */ +#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */ +#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */ +#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */ +#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */ +#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */ +#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */ +#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */ +#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */ +#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */ +#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */ +#define ONIG_SYN_OP_ESC_O_BRACE_OCTAL (1U<<31) /* \o{OOO} */ + +#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */ +#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */ +#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsxadlu), (?-imsx), (?^imsxalu) */ +#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imxadu), (?-imx) */ +#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */ +#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */ +#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */ +#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */ +#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */ +#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */ +#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */ +#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */ +#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */ +#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */ +#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */ +#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */ +#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */ +#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */ +/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */ +#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */ +#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */ +#define ONIG_SYN_OP2_ESC_CAPITAL_R_LINEBREAK (1U<<21) /* \R as (?>\x0D\x0A|[\x0A-\x0D\x{85}\x{2028}\x{2029}]) */ +#define ONIG_SYN_OP2_ESC_CAPITAL_X_EXTENDED_GRAPHEME_CLUSTER (1U<<22) /* \X */ +#define ONIG_SYN_OP2_ESC_V_VERTICAL_WHITESPACE (1U<<23) /* \v, \V -- Perl */ /* NOTIMPL */ +#define ONIG_SYN_OP2_ESC_H_HORIZONTAL_WHITESPACE (1U<<24) /* \h, \H -- Perl */ /* NOTIMPL */ +#define ONIG_SYN_OP2_ESC_CAPITAL_K_KEEP (1U<<25) /* \K */ +#define ONIG_SYN_OP2_ESC_G_BRACE_BACKREF (1U<<26) /* \g{name}, \g{n} */ +#define ONIG_SYN_OP2_QMARK_SUBEXP_CALL (1U<<27) /* (?&name), (?n), (?R), (?0) */ +#define ONIG_SYN_OP2_QMARK_VBAR_BRANCH_RESET (1U<<28) /* (?|...) */ /* NOTIMPL */ +#define ONIG_SYN_OP2_QMARK_LPAREN_CONDITION (1U<<29) /* (?(cond)yes...|no...) */ +#define ONIG_SYN_OP2_QMARK_CAPITAL_P_NAMED_GROUP (1U<<30) /* (?P<name>...), (?P=name), (?P>name) -- Python/PCRE */ +#define ONIG_SYN_OP2_QMARK_TILDE_ABSENT (1U<<31) /* (?~...) */ +/* #define ONIG_SYN_OP2_OPTION_JAVA (1U<<xx) */ /* (?idmsux), (?-idmsux) */ /* NOTIMPL */ + +/* syntax (behavior) */ +#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */ +#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */ +#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */ +#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */ +#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */ +#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */ +#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/ +#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */ +#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */ +#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */ +#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */ +#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME_CALL (1U<<10) /* (?<x>)(?<x>)(?&x) */ +#define ONIG_SYN_USE_LEFT_MOST_NAMED_GROUP (1U<<11) /* (?<x>)(?<x>)\k<x> */ + +/* syntax (behavior) in char class [...] */ +#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */ +#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */ +#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22) +#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */ +/* syntax (behavior) warning */ +#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */ +#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */ +#define ONIG_SYN_WARN_CC_DUP (1U<<26) /* [aa] */ + +/* meta character specifiers (onig_set_meta_char()) */ +#define ONIG_META_CHAR_ESCAPE 0 +#define ONIG_META_CHAR_ANYCHAR 1 +#define ONIG_META_CHAR_ANYTIME 2 +#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3 +#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4 +#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5 + +#define ONIG_INEFFECTIVE_META_CHAR 0 + +/* error codes */ +#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000) +/* normal return */ +#define ONIG_NORMAL 0 +#define ONIG_MISMATCH -1 +#define ONIG_NO_SUPPORT_CONFIG -2 + +/* internal error */ +#define ONIGERR_MEMORY -5 +#define ONIGERR_TYPE_BUG -6 +#define ONIGERR_PARSER_BUG -11 +#define ONIGERR_STACK_BUG -12 +#define ONIGERR_UNDEFINED_BYTECODE -13 +#define ONIGERR_UNEXPECTED_BYTECODE -14 +#define ONIGERR_MATCH_STACK_LIMIT_OVER -15 +#define ONIGERR_PARSE_DEPTH_LIMIT_OVER -16 +#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SET -21 +#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22 +/* general error */ +#define ONIGERR_INVALID_ARGUMENT -30 +/* syntax error */ +#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100 +#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101 +#define ONIGERR_EMPTY_CHAR_CLASS -102 +#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103 +#define ONIGERR_END_PATTERN_AT_ESCAPE -104 +#define ONIGERR_END_PATTERN_AT_META -105 +#define ONIGERR_END_PATTERN_AT_CONTROL -106 +#define ONIGERR_META_CODE_SYNTAX -108 +#define ONIGERR_CONTROL_CODE_SYNTAX -109 +#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110 +#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111 +#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112 +#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113 +#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114 +#define ONIGERR_NESTED_REPEAT_OPERATOR -115 +#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116 +#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117 +#define ONIGERR_END_PATTERN_IN_GROUP -118 +#define ONIGERR_UNDEFINED_GROUP_OPTION -119 +#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121 +#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122 +#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123 +#define ONIGERR_INVALID_CONDITION_PATTERN -124 +/* values error (syntax error) */ +#define ONIGERR_TOO_BIG_NUMBER -200 +#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201 +#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202 +#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203 +#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204 +#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205 +#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206 +#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207 +#define ONIGERR_INVALID_BACKREF -208 +#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209 +#define ONIGERR_TOO_MANY_CAPTURE_GROUPS -210 +#define ONIGERR_TOO_SHORT_DIGITS -211 +#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212 +#define ONIGERR_EMPTY_GROUP_NAME -214 +#define ONIGERR_INVALID_GROUP_NAME -215 +#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216 +#define ONIGERR_UNDEFINED_NAME_REFERENCE -217 +#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218 +#define ONIGERR_MULTIPLEX_DEFINED_NAME -219 +#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220 +#define ONIGERR_NEVER_ENDING_RECURSION -221 +#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222 +#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223 +#define ONIGERR_INVALID_CODE_POINT_VALUE -400 +#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400 +#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401 +#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402 +#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403 + +/* errors related to thread */ +/* #define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001 */ + + +/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */ +#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31 +#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \ + ((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i]) + +#ifdef USE_CAPTURE_HISTORY +typedef struct OnigCaptureTreeNodeStruct { + int group; /* group number */ + OnigPosition beg; + OnigPosition end; + int allocated; + int num_childs; + struct OnigCaptureTreeNodeStruct** childs; +} OnigCaptureTreeNode; +#endif + +/* match result region type */ +struct re_registers { + int allocated; + int num_regs; + OnigPosition* beg; + OnigPosition* end; +#ifdef USE_CAPTURE_HISTORY + /* extended */ + OnigCaptureTreeNode* history_root; /* capture history tree root */ +#endif +}; + +/* capture tree traverse */ +#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1 +#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2 +#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \ + ( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST ) + + +#define ONIG_REGION_NOTPOS -1 + +typedef struct re_registers OnigRegion; + +typedef struct { + OnigEncoding enc; + OnigUChar* par; + OnigUChar* par_end; +} OnigErrorInfo; + +typedef struct { + int lower; + int upper; +} OnigRepeatRange; + +typedef void (*OnigWarnFunc)(const char* s); +extern void onig_null_warn(const char* s); +#define ONIG_NULL_WARN onig_null_warn + +#define ONIG_CHAR_TABLE_SIZE 256 + +typedef struct re_pattern_buffer { + /* common members of BBuf(bytes-buffer) */ + unsigned char* p; /* compiled pattern */ + unsigned int used; /* used space for p */ + unsigned int alloc; /* allocated space for p */ + + int num_mem; /* used memory(...) num counted from 1 */ + int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */ + int num_null_check; /* OP_NULL_CHECK_START/END id counter */ + int num_comb_exp_check; /* combination explosion check */ + int num_call; /* number of subexp call */ + unsigned int capture_history; /* (?@...) flag (1-31) */ + unsigned int bt_mem_start; /* need backtrack flag */ + unsigned int bt_mem_end; /* need backtrack flag */ + int stack_pop_level; + int repeat_range_alloc; + + OnigOptionType options; + + OnigRepeatRange* repeat_range; + + OnigEncoding enc; + const OnigSyntaxType* syntax; + void* name_table; + OnigCaseFoldType case_fold_flag; + + /* optimization info (string search, char-map and anchors) */ + int optimize; /* optimize flag */ + int threshold_len; /* search str-length for apply optimize */ + int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */ + OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */ + OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */ + int sub_anchor; /* start-anchor for exact or map */ + unsigned char *exact; + unsigned char *exact_end; + unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */ + int *int_map; /* BM skip for exact_len > 255 */ + int *int_map_backward; /* BM skip for backward search */ + OnigDistance dmin; /* min-distance of exact or map */ + OnigDistance dmax; /* max-distance of exact or map */ + + /* regex_t link chain */ + struct re_pattern_buffer* chain; /* escape compile-conflict */ +} OnigRegexType; + +typedef OnigRegexType* OnigRegex; + +#ifndef ONIG_ESCAPE_REGEX_T_COLLISION +typedef OnigRegexType regex_t; +#endif + + +typedef struct { + int num_of_elements; + OnigEncoding pattern_enc; + OnigEncoding target_enc; + const OnigSyntaxType* syntax; + OnigOptionType option; + OnigCaseFoldType case_fold_flag; +} OnigCompileInfo; + +/* Oniguruma Native API */ +ONIG_EXTERN +int onig_initialize(OnigEncoding encodings[], int n); +ONIG_EXTERN +int onig_init(void); +ONIG_EXTERN +int onig_error_code_to_str(OnigUChar* s, OnigPosition err_code, ...); +ONIG_EXTERN +void onig_set_warn_func(OnigWarnFunc f); +ONIG_EXTERN +void onig_set_verb_warn_func(OnigWarnFunc f); +ONIG_EXTERN +int onig_new(OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax, OnigErrorInfo* einfo); +ONIG_EXTERN +int onig_reg_init(OnigRegex reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType* syntax); +ONIG_EXTERN +int onig_new_without_alloc(OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax, OnigErrorInfo* einfo); +ONIG_EXTERN +int onig_new_deluxe(OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo); +ONIG_EXTERN +void onig_free(OnigRegex); +ONIG_EXTERN +void onig_free_body(OnigRegex); +ONIG_EXTERN +OnigPosition onig_scan(OnigRegex reg, const OnigUChar* str, const OnigUChar* end, OnigRegion* region, OnigOptionType option, int (*scan_callback)(OnigPosition, OnigPosition, OnigRegion*, void*), void* callback_arg); +ONIG_EXTERN +OnigPosition onig_search(OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option); +ONIG_EXTERN +OnigPosition onig_search_gpos(OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* global_pos, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option); +ONIG_EXTERN +OnigPosition onig_match(OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option); +ONIG_EXTERN +OnigRegion* onig_region_new(void); +ONIG_EXTERN +void onig_region_init(OnigRegion* region); +ONIG_EXTERN +void onig_region_free(OnigRegion* region, int free_self); +ONIG_EXTERN +void onig_region_copy(OnigRegion* to, const OnigRegion* from); +ONIG_EXTERN +void onig_region_clear(OnigRegion* region); +ONIG_EXTERN +int onig_region_resize(OnigRegion* region, int n); +ONIG_EXTERN +int onig_region_set(OnigRegion* region, int at, int beg, int end); +ONIG_EXTERN +int onig_name_to_group_numbers(OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums); +ONIG_EXTERN +int onig_name_to_backref_number(OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, const OnigRegion *region); +ONIG_EXTERN +int onig_foreach_name(OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg); +ONIG_EXTERN +int onig_number_of_names(const OnigRegexType *reg); +ONIG_EXTERN +int onig_number_of_captures(const OnigRegexType *reg); +ONIG_EXTERN +int onig_number_of_capture_histories(const OnigRegexType *reg); +#ifdef USE_CAPTURE_HISTORY +ONIG_EXTERN +OnigCaptureTreeNode* onig_get_capture_tree(OnigRegion* region); +#endif +ONIG_EXTERN +int onig_capture_tree_traverse(OnigRegion* region, int at, int(*callback_func)(int,OnigPosition,OnigPosition,int,int,void*), void* arg); +ONIG_EXTERN +int onig_noname_group_capture_is_active(const OnigRegexType *reg); +ONIG_EXTERN +OnigEncoding onig_get_encoding(const OnigRegexType *reg); +ONIG_EXTERN +OnigOptionType onig_get_options(const OnigRegexType *reg); +ONIG_EXTERN +OnigCaseFoldType onig_get_case_fold_flag(const OnigRegexType *reg); +ONIG_EXTERN +const OnigSyntaxType* onig_get_syntax(const OnigRegexType *reg); +ONIG_EXTERN +int onig_set_default_syntax(const OnigSyntaxType* syntax); +ONIG_EXTERN +void onig_copy_syntax(OnigSyntaxType* to, const OnigSyntaxType* from); +ONIG_EXTERN +unsigned int onig_get_syntax_op(const OnigSyntaxType* syntax); +ONIG_EXTERN +unsigned int onig_get_syntax_op2(const OnigSyntaxType* syntax); +ONIG_EXTERN +unsigned int onig_get_syntax_behavior(const OnigSyntaxType* syntax); +ONIG_EXTERN +OnigOptionType onig_get_syntax_options(const OnigSyntaxType* syntax); +ONIG_EXTERN +void onig_set_syntax_op(OnigSyntaxType* syntax, unsigned int op); +ONIG_EXTERN +void onig_set_syntax_op2(OnigSyntaxType* syntax, unsigned int op2); +ONIG_EXTERN +void onig_set_syntax_behavior(OnigSyntaxType* syntax, unsigned int behavior); +ONIG_EXTERN +void onig_set_syntax_options(OnigSyntaxType* syntax, OnigOptionType options); +ONIG_EXTERN +int onig_set_meta_char(OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code); +ONIG_EXTERN +void onig_copy_encoding(OnigEncodingType *to, OnigEncoding from); +ONIG_EXTERN +OnigCaseFoldType onig_get_default_case_fold_flag(void); +ONIG_EXTERN +int onig_set_default_case_fold_flag(OnigCaseFoldType case_fold_flag); +ONIG_EXTERN +unsigned int onig_get_match_stack_limit_size(void); +ONIG_EXTERN +int onig_set_match_stack_limit_size(unsigned int size); +ONIG_EXTERN +unsigned int onig_get_parse_depth_limit(void); +ONIG_EXTERN +int onig_set_parse_depth_limit(unsigned int depth); +ONIG_EXTERN +int onig_end(void); +ONIG_EXTERN +const char* onig_version(void); +ONIG_EXTERN +const char* onig_copyright(void); + +RUBY_SYMBOL_EXPORT_END + +#ifdef __cplusplus +# if 0 +{ /* satisfy cc-mode */ +# endif +} +#endif + +#endif /* ONIGMO_H */ diff --git a/include/ruby/oniguruma.h b/include/ruby/oniguruma.h new file mode 100644 index 0000000000..dc83754aca --- /dev/null +++ b/include/ruby/oniguruma.h @@ -0,0 +1,8 @@ +#ifndef ONIGURUMA_H +#define ONIGURUMA_H +#include "onigmo.h" +#define ONIGURUMA +#define ONIGURUMA_VERSION_MAJOR ONIGMO_VERSION_MAJOR +#define ONIGURUMA_VERSION_MINOR ONIGMO_VERSION_MINOR +#define ONIGURUMA_VERSION_TEENY ONIGMO_VERSION_TEENY +#endif /* ONIGURUMA_H */ diff --git a/include/ruby/re.h b/include/ruby/re.h new file mode 100644 index 0000000000..7102c7ace4 --- /dev/null +++ b/include/ruby/re.h @@ -0,0 +1,71 @@ +/********************************************************************** + + re.h - + + $Author$ + created at: Thu Sep 30 14:18:32 JST 1993 + + Copyright (C) 1993-2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_RE_H +#define RUBY_RE_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include <sys/types.h> +#include <stdio.h> + +#include "ruby/regex.h" + +RUBY_SYMBOL_EXPORT_BEGIN + +typedef struct re_pattern_buffer Regexp; + +struct rmatch_offset { + long beg; + long end; +}; + +struct rmatch { + struct re_registers regs; + + struct rmatch_offset *char_offset; + int char_offset_num_allocated; +}; + +struct RMatch { + struct RBasic basic; + VALUE str; + struct rmatch *rmatch; + VALUE regexp; /* RRegexp */ +}; + +#define RMATCH(obj) (R_CAST(RMatch)(obj)) +#define RMATCH_REGS(obj) (&(R_CAST(RMatch)(obj))->rmatch->regs) + +VALUE rb_reg_regcomp(VALUE); +long rb_reg_search(VALUE, VALUE, long, int); +VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE); +long rb_reg_adjust_startpos(VALUE, VALUE, long, int); +void rb_match_busy(VALUE); +VALUE rb_reg_quote(VALUE); +regex_t *rb_reg_prepare_re(VALUE re, VALUE str); +int rb_reg_region_copy(struct re_registers *, const struct re_registers *); + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_RE_H */ diff --git a/include/ruby/regex.h b/include/ruby/regex.h new file mode 100644 index 0000000000..024bed4a4e --- /dev/null +++ b/include/ruby/regex.h @@ -0,0 +1,46 @@ +/********************************************************************** + + regex.h - + + $Author$ + + Copyright (C) 1993-2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef ONIGURUMA_REGEX_H +#define ONIGURUMA_REGEX_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#ifdef RUBY +#include "ruby/oniguruma.h" +#else +#include "oniguruma.h" +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +#ifndef ONIG_RUBY_M17N + +ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding; + +#define mbclen(p,e,enc) rb_enc_mbclen((p),(e),(enc)) + +#endif /* ifndef ONIG_RUBY_M17N */ + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* ONIGURUMA_REGEX_H */ diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h new file mode 100644 index 0000000000..bd95d5b0b1 --- /dev/null +++ b/include/ruby/ruby.h @@ -0,0 +1,2873 @@ +/********************************************************************** + + ruby/ruby.h - + + $Author$ + created at: Thu Jun 10 14:26:32 JST 1993 + + Copyright (C) 1993-2008 Yukihiro Matsumoto + Copyright (C) 2000 Network Applied Communication Laboratory, Inc. + Copyright (C) 2000 Information-technology Promotion Agency, Japan + +**********************************************************************/ + +#ifndef RUBY_RUBY_H +#define RUBY_RUBY_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/config.h" +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif + +#include "defines.h" +#include "ruby/assert.h" + +/* For MinGW, we need __declspec(dllimport) for RUBY_EXTERN on MJIT. + mswin's RUBY_EXTERN already has that. See also: win32/Makefile.sub */ +#if defined(MJIT_HEADER) && defined(_WIN32) && defined(__GNUC__) +# undef RUBY_EXTERN +# define RUBY_EXTERN extern __declspec(dllimport) +#endif + +#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 +#elif GCC_VERSION_BEFORE(4,8,6) /* Bug #14221 */ +# undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P +#endif + +#ifndef ASSUME +# ifdef UNREACHABLE +# define ASSUME(x) (RB_LIKELY(!!(x)) ? (void)0 : UNREACHABLE) +# else +# define ASSUME(x) ((void)(x)) +# endif +#endif +#ifndef UNREACHABLE_RETURN +# ifdef UNREACHABLE +# define UNREACHABLE_RETURN(val) UNREACHABLE +# else +# define UNREACHABLE_RETURN(val) return (val) +# endif +#endif +#ifndef UNREACHABLE +# define UNREACHABLE ((void)0) /* unreachable */ +#endif + +#define RUBY_MACRO_SELECT(base, n) TOKEN_PASTE(base, n) + +#ifdef HAVE_INTRINSICS_H +# include <intrinsics.h> +#endif + +#include <stdarg.h> + +RUBY_SYMBOL_EXPORT_BEGIN + +/* Make alloca work the best possible way. */ +#ifdef __GNUC__ +# ifndef alloca +# define alloca __builtin_alloca +# endif +#else +# ifdef HAVE_ALLOCA_H +# include <alloca.h> +# else +# ifdef _AIX +#pragma alloca +# else +# ifndef alloca /* predefined by HP cc +Olibcalls */ +void *alloca(); +# endif +# endif /* AIX */ +# endif /* HAVE_ALLOCA_H */ +#endif /* __GNUC__ */ + +#if defined HAVE_UINTPTR_T && 0 +typedef uintptr_t VALUE; +typedef uintptr_t ID; +# define SIGNED_VALUE intptr_t +# define SIZEOF_VALUE SIZEOF_UINTPTR_T +# undef PRI_VALUE_PREFIX +#elif SIZEOF_LONG == SIZEOF_VOIDP +typedef unsigned long VALUE; +typedef unsigned long ID; +# define SIGNED_VALUE long +# define SIZEOF_VALUE SIZEOF_LONG +# define PRI_VALUE_PREFIX "l" +#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP +typedef unsigned LONG_LONG VALUE; +typedef unsigned LONG_LONG ID; +# define SIGNED_VALUE LONG_LONG +# define LONG_LONG_VALUE 1 +# define SIZEOF_VALUE SIZEOF_LONG_LONG +# define PRI_VALUE_PREFIX PRI_LL_PREFIX +#else +# error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<---- +#endif + +typedef char ruby_check_sizeof_int[SIZEOF_INT == sizeof(int) ? 1 : -1]; +typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1]; +#ifdef HAVE_LONG_LONG +typedef char ruby_check_sizeof_long_long[SIZEOF_LONG_LONG == sizeof(LONG_LONG) ? 1 : -1]; +#endif +typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1]; + +#ifndef PRI_INT_PREFIX +#define PRI_INT_PREFIX "" +#endif +#ifndef PRI_LONG_PREFIX +#define PRI_LONG_PREFIX "l" +#endif +#ifndef PRI_SHORT_PREFIX +#define PRI_SHORT_PREFIX "h" +#endif + +#ifndef PRI_64_PREFIX +#if SIZEOF_LONG == 8 +#define PRI_64_PREFIX PRI_LONG_PREFIX +#elif SIZEOF_LONG_LONG == 8 +#define PRI_64_PREFIX PRI_LL_PREFIX +#endif +#endif + +#ifndef PRIdPTR +#define PRIdPTR PRI_PTR_PREFIX"d" +#define PRIiPTR PRI_PTR_PREFIX"i" +#define PRIoPTR PRI_PTR_PREFIX"o" +#define PRIuPTR PRI_PTR_PREFIX"u" +#define PRIxPTR PRI_PTR_PREFIX"x" +#define PRIXPTR PRI_PTR_PREFIX"X" +#endif + +#define RUBY_PRI_VALUE_MARK "\v" +#if defined PRIdPTR && !defined PRI_VALUE_PREFIX +#define PRIdVALUE PRIdPTR +#define PRIoVALUE PRIoPTR +#define PRIuVALUE PRIuPTR +#define PRIxVALUE PRIxPTR +#define PRIXVALUE PRIXPTR +#define PRIsVALUE PRIiPTR"" RUBY_PRI_VALUE_MARK +#else +#define PRIdVALUE PRI_VALUE_PREFIX"d" +#define PRIoVALUE PRI_VALUE_PREFIX"o" +#define PRIuVALUE PRI_VALUE_PREFIX"u" +#define PRIxVALUE PRI_VALUE_PREFIX"x" +#define PRIXVALUE PRI_VALUE_PREFIX"X" +#define PRIsVALUE PRI_VALUE_PREFIX"i" RUBY_PRI_VALUE_MARK +#endif +#ifndef PRI_VALUE_PREFIX +# define PRI_VALUE_PREFIX "" +#endif + +#ifndef PRI_TIMET_PREFIX +# if SIZEOF_TIME_T == SIZEOF_INT +# define PRI_TIMET_PREFIX +# elif SIZEOF_TIME_T == SIZEOF_LONG +# define PRI_TIMET_PREFIX "l" +# elif SIZEOF_TIME_T == SIZEOF_LONG_LONG +# define PRI_TIMET_PREFIX PRI_LL_PREFIX +# endif +#endif + +#if defined PRI_PTRDIFF_PREFIX +#elif SIZEOF_PTRDIFF_T == SIZEOF_INT +# define PRI_PTRDIFF_PREFIX "" +#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG +# define PRI_PTRDIFF_PREFIX "l" +#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG +# define PRI_PTRDIFF_PREFIX PRI_LL_PREFIX +#endif +#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" +#define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i" +#define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o" +#define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u" +#define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x" +#define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X" + +#if defined PRI_SIZE_PREFIX +#elif SIZEOF_SIZE_T == SIZEOF_INT +# define PRI_SIZE_PREFIX "" +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define PRI_SIZE_PREFIX "l" +#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG +# define PRI_SIZE_PREFIX PRI_LL_PREFIX +#endif +#define PRIdSIZE PRI_SIZE_PREFIX"d" +#define PRIiSIZE PRI_SIZE_PREFIX"i" +#define PRIoSIZE PRI_SIZE_PREFIX"o" +#define PRIuSIZE PRI_SIZE_PREFIX"u" +#define PRIxSIZE PRI_SIZE_PREFIX"x" +#define PRIXSIZE PRI_SIZE_PREFIX"X" + +#ifdef __STDC__ +# include <limits.h> +#else +# ifndef LONG_MAX +# ifdef HAVE_LIMITS_H +# include <limits.h> +# else + /* assuming 32bit(2's complement) long */ +# define LONG_MAX 2147483647 +# endif +# endif +# ifndef LONG_MIN +# define LONG_MIN (-LONG_MAX-1) +# endif +# ifndef CHAR_BIT +# define CHAR_BIT 8 +# endif +#endif + +#ifdef HAVE_LONG_LONG +# ifndef LLONG_MAX +# ifdef LONG_LONG_MAX +# define LLONG_MAX LONG_LONG_MAX +# else +# ifdef _I64_MAX +# define LLONG_MAX _I64_MAX +# else + /* assuming 64bit(2's complement) long long */ +# define LLONG_MAX 9223372036854775807LL +# endif +# endif +# endif +# ifndef LLONG_MIN +# ifdef LONG_LONG_MIN +# define LLONG_MIN LONG_LONG_MIN +# else +# ifdef _I64_MIN +# define LLONG_MIN _I64_MIN +# else +# define LLONG_MIN (-LLONG_MAX-1) +# endif +# endif +# endif +#endif + +#define RUBY_FIXNUM_MAX (LONG_MAX>>1) +#define RUBY_FIXNUM_MIN RSHIFT((long)LONG_MIN,1) +#define FIXNUM_MAX RUBY_FIXNUM_MAX +#define FIXNUM_MIN RUBY_FIXNUM_MIN + +#define RB_INT2FIX(i) (((VALUE)(i))<<1 | RUBY_FIXNUM_FLAG) +#define INT2FIX(i) RB_INT2FIX(i) +#define RB_LONG2FIX(i) RB_INT2FIX(i) +#define LONG2FIX(i) RB_INT2FIX(i) +#define rb_fix_new(v) RB_INT2FIX(v) +VALUE rb_int2inum(intptr_t); + +#define rb_int_new(v) rb_int2inum(v) +VALUE rb_uint2inum(uintptr_t); + +#define rb_uint_new(v) rb_uint2inum(v) + +#ifdef HAVE_LONG_LONG +VALUE rb_ll2inum(LONG_LONG); +#define LL2NUM(v) rb_ll2inum(v) +VALUE rb_ull2inum(unsigned LONG_LONG); +#define ULL2NUM(v) rb_ull2inum(v) +#endif + +#ifndef OFFT2NUM +#if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define OFFT2NUM(v) LL2NUM(v) +#elif SIZEOF_OFF_T == SIZEOF_LONG +# define OFFT2NUM(v) LONG2NUM(v) +#else +# define OFFT2NUM(v) INT2NUM(v) +#endif +#endif + +#if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define SIZET2NUM(v) ULL2NUM(v) +# define SSIZET2NUM(v) LL2NUM(v) +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define SIZET2NUM(v) ULONG2NUM(v) +# define SSIZET2NUM(v) LONG2NUM(v) +#else +# define SIZET2NUM(v) UINT2NUM(v) +# define SSIZET2NUM(v) INT2NUM(v) +#endif + +#ifndef SIZE_MAX +# if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define SIZE_MAX ULLONG_MAX +# define SIZE_MIN ULLONG_MIN +# elif SIZEOF_SIZE_T == SIZEOF_LONG +# define SIZE_MAX ULONG_MAX +# define SIZE_MIN ULONG_MIN +# elif SIZEOF_SIZE_T == SIZEOF_INT +# define SIZE_MAX UINT_MAX +# define SIZE_MIN UINT_MIN +# else +# define SIZE_MAX USHRT_MAX +# define SIZE_MIN USHRT_MIN +# endif +#endif + +#ifndef SSIZE_MAX +# if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define SSIZE_MAX LLONG_MAX +# define SSIZE_MIN LLONG_MIN +# elif SIZEOF_SIZE_T == SIZEOF_LONG +# define SSIZE_MAX LONG_MAX +# define SSIZE_MIN LONG_MIN +# elif SIZEOF_SIZE_T == SIZEOF_INT +# define SSIZE_MAX INT_MAX +# define SSIZE_MIN INT_MIN +# else +# define SSIZE_MAX SHRT_MAX +# define SSIZE_MIN SHRT_MIN +# endif +#endif + +#if SIZEOF_INT < SIZEOF_VALUE +NORETURN(void rb_out_of_int(SIGNED_VALUE num)); +#endif + +#if SIZEOF_INT < SIZEOF_LONG +static inline int +rb_long2int_inline(long n) +{ + int i = (int)n; + if ((long)i != n) + rb_out_of_int(n); + + return i; +} +#define rb_long2int(n) rb_long2int_inline(n) +#else +#define rb_long2int(n) ((int)(n)) +#endif + +#ifndef PIDT2NUM +#define PIDT2NUM(v) LONG2NUM(v) +#endif +#ifndef NUM2PIDT +#define NUM2PIDT(v) NUM2LONG(v) +#endif +#ifndef UIDT2NUM +#define UIDT2NUM(v) LONG2NUM(v) +#endif +#ifndef NUM2UIDT +#define NUM2UIDT(v) NUM2LONG(v) +#endif +#ifndef GIDT2NUM +#define GIDT2NUM(v) LONG2NUM(v) +#endif +#ifndef NUM2GIDT +#define NUM2GIDT(v) NUM2LONG(v) +#endif +#ifndef NUM2MODET +#define NUM2MODET(v) NUM2INT(v) +#endif +#ifndef MODET2NUM +#define MODET2NUM(v) INT2NUM(v) +#endif + +#define RB_FIX2LONG(x) ((long)RSHIFT((SIGNED_VALUE)(x),1)) +static inline long +rb_fix2long(VALUE x) +{ + return RB_FIX2LONG(x); +} +#define RB_FIX2ULONG(x) ((unsigned long)RB_FIX2LONG(x)) +static inline unsigned long +rb_fix2ulong(VALUE x) +{ + return RB_FIX2ULONG(x); +} +#define RB_FIXNUM_P(f) (((int)(SIGNED_VALUE)(f))&RUBY_FIXNUM_FLAG) +#define RB_POSFIXABLE(f) ((f) < RUBY_FIXNUM_MAX+1) +#define RB_NEGFIXABLE(f) ((f) >= RUBY_FIXNUM_MIN) +#define RB_FIXABLE(f) (RB_POSFIXABLE(f) && RB_NEGFIXABLE(f)) +#define FIX2LONG(x) RB_FIX2LONG(x) +#define FIX2ULONG(x) RB_FIX2ULONG(x) +#define FIXNUM_P(f) RB_FIXNUM_P(f) +#define POSFIXABLE(f) RB_POSFIXABLE(f) +#define NEGFIXABLE(f) RB_NEGFIXABLE(f) +#define FIXABLE(f) RB_FIXABLE(f) + +#define RB_IMMEDIATE_P(x) ((VALUE)(x) & RUBY_IMMEDIATE_MASK) +#define IMMEDIATE_P(x) RB_IMMEDIATE_P(x) + +ID rb_sym2id(VALUE); +VALUE rb_id2sym(ID); +#define RB_STATIC_SYM_P(x) (((VALUE)(x)&~((~(VALUE)0)<<RUBY_SPECIAL_SHIFT)) == RUBY_SYMBOL_FLAG) +#define RB_DYNAMIC_SYM_P(x) (!RB_SPECIAL_CONST_P(x) && RB_BUILTIN_TYPE(x) == (RUBY_T_SYMBOL)) +#define RB_SYMBOL_P(x) (RB_STATIC_SYM_P(x)||RB_DYNAMIC_SYM_P(x)) +#define RB_ID2SYM(x) (rb_id2sym(x)) +#define RB_SYM2ID(x) (rb_sym2id(x)) +#define STATIC_SYM_P(x) RB_STATIC_SYM_P(x) +#define DYNAMIC_SYM_P(x) RB_DYNAMIC_SYM_P(x) +#define SYMBOL_P(x) RB_SYMBOL_P(x) +#define ID2SYM(x) RB_ID2SYM(x) +#define SYM2ID(x) RB_SYM2ID(x) + +#ifndef USE_FLONUM +#if SIZEOF_VALUE >= SIZEOF_DOUBLE +#define USE_FLONUM 1 +#else +#define USE_FLONUM 0 +#endif +#endif + +#if USE_FLONUM +#define RB_FLONUM_P(x) ((((int)(SIGNED_VALUE)(x))&RUBY_FLONUM_MASK) == RUBY_FLONUM_FLAG) +#else +#define RB_FLONUM_P(x) 0 +#endif +#define FLONUM_P(x) RB_FLONUM_P(x) + +/* Module#methods, #singleton_methods and so on return Symbols */ +#define USE_SYMBOL_AS_METHOD_NAME 1 + +/* special constants - i.e. non-zero and non-fixnum constants */ +enum ruby_special_consts { +#if USE_FLONUM + RUBY_Qfalse = 0x00, /* ...0000 0000 */ + RUBY_Qtrue = 0x14, /* ...0001 0100 */ + RUBY_Qnil = 0x08, /* ...0000 1000 */ + RUBY_Qundef = 0x34, /* ...0011 0100 */ + + RUBY_IMMEDIATE_MASK = 0x07, + RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ + RUBY_FLONUM_MASK = 0x03, + RUBY_FLONUM_FLAG = 0x02, /* ...xxxx xx10 */ + RUBY_SYMBOL_FLAG = 0x0c, /* ...0000 1100 */ +#else + RUBY_Qfalse = 0, /* ...0000 0000 */ + RUBY_Qtrue = 2, /* ...0000 0010 */ + RUBY_Qnil = 4, /* ...0000 0100 */ + RUBY_Qundef = 6, /* ...0000 0110 */ + + RUBY_IMMEDIATE_MASK = 0x03, + RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ + RUBY_FLONUM_MASK = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */ + RUBY_FLONUM_FLAG = 0x02, + RUBY_SYMBOL_FLAG = 0x0e, /* ...0000 1110 */ +#endif + RUBY_SPECIAL_SHIFT = 8 +}; + +#define RUBY_Qfalse ((VALUE)RUBY_Qfalse) +#define RUBY_Qtrue ((VALUE)RUBY_Qtrue) +#define RUBY_Qnil ((VALUE)RUBY_Qnil) +#define RUBY_Qundef ((VALUE)RUBY_Qundef) /* undefined value for placeholder */ +#define Qfalse RUBY_Qfalse +#define Qtrue RUBY_Qtrue +#define Qnil RUBY_Qnil +#define Qundef RUBY_Qundef +#define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK +#define FIXNUM_FLAG RUBY_FIXNUM_FLAG +#if USE_FLONUM +#define FLONUM_MASK RUBY_FLONUM_MASK +#define FLONUM_FLAG RUBY_FLONUM_FLAG +#endif +#define SYMBOL_FLAG RUBY_SYMBOL_FLAG + +#define RB_TEST(v) !(((VALUE)(v) & (VALUE)~RUBY_Qnil) == 0) +#define RB_NIL_P(v) !((VALUE)(v) != RUBY_Qnil) +#define RTEST(v) RB_TEST(v) +#define NIL_P(v) RB_NIL_P(v) + +#define CLASS_OF(v) rb_class_of((VALUE)(v)) + +enum ruby_value_type { + RUBY_T_NONE = 0x00, + + RUBY_T_OBJECT = 0x01, + RUBY_T_CLASS = 0x02, + RUBY_T_MODULE = 0x03, + RUBY_T_FLOAT = 0x04, + RUBY_T_STRING = 0x05, + RUBY_T_REGEXP = 0x06, + RUBY_T_ARRAY = 0x07, + RUBY_T_HASH = 0x08, + RUBY_T_STRUCT = 0x09, + RUBY_T_BIGNUM = 0x0a, + RUBY_T_FILE = 0x0b, + RUBY_T_DATA = 0x0c, + RUBY_T_MATCH = 0x0d, + RUBY_T_COMPLEX = 0x0e, + RUBY_T_RATIONAL = 0x0f, + + RUBY_T_NIL = 0x11, + RUBY_T_TRUE = 0x12, + RUBY_T_FALSE = 0x13, + RUBY_T_SYMBOL = 0x14, + RUBY_T_FIXNUM = 0x15, + RUBY_T_UNDEF = 0x16, + + RUBY_T_IMEMO = 0x1a, /*!< @see imemo_type */ + RUBY_T_NODE = 0x1b, + RUBY_T_ICLASS = 0x1c, + RUBY_T_ZOMBIE = 0x1d, + RUBY_T_MOVED = 0x1e, + + RUBY_T_MASK = 0x1f +}; + +#define T_NONE RUBY_T_NONE +#define T_NIL RUBY_T_NIL +#define T_OBJECT RUBY_T_OBJECT +#define T_CLASS RUBY_T_CLASS +#define T_ICLASS RUBY_T_ICLASS +#define T_MODULE RUBY_T_MODULE +#define T_FLOAT RUBY_T_FLOAT +#define T_STRING RUBY_T_STRING +#define T_REGEXP RUBY_T_REGEXP +#define T_ARRAY RUBY_T_ARRAY +#define T_HASH RUBY_T_HASH +#define T_STRUCT RUBY_T_STRUCT +#define T_BIGNUM RUBY_T_BIGNUM +#define T_FILE RUBY_T_FILE +#define T_FIXNUM RUBY_T_FIXNUM +#define T_TRUE RUBY_T_TRUE +#define T_FALSE RUBY_T_FALSE +#define T_DATA RUBY_T_DATA +#define T_MATCH RUBY_T_MATCH +#define T_SYMBOL RUBY_T_SYMBOL +#define T_RATIONAL RUBY_T_RATIONAL +#define T_COMPLEX RUBY_T_COMPLEX +#define T_IMEMO RUBY_T_IMEMO +#define T_UNDEF RUBY_T_UNDEF +#define T_NODE RUBY_T_NODE +#define T_ZOMBIE RUBY_T_ZOMBIE +#define T_MOVED RUBY_T_MOVED +#define T_MASK RUBY_T_MASK + +#define RB_BUILTIN_TYPE(x) (int)(((struct RBasic*)(x))->flags & RUBY_T_MASK) +#define BUILTIN_TYPE(x) RB_BUILTIN_TYPE(x) + +static inline int rb_type(VALUE obj); +#define TYPE(x) rb_type((VALUE)(x)) + +#define RB_FLOAT_TYPE_P(obj) (\ + RB_FLONUM_P(obj) || \ + (!RB_SPECIAL_CONST_P(obj) && RB_BUILTIN_TYPE(obj) == RUBY_T_FLOAT)) + +#define RB_TYPE_P(obj, type) ( \ + ((type) == RUBY_T_FIXNUM) ? RB_FIXNUM_P(obj) : \ + ((type) == RUBY_T_TRUE) ? ((obj) == RUBY_Qtrue) : \ + ((type) == RUBY_T_FALSE) ? ((obj) == RUBY_Qfalse) : \ + ((type) == RUBY_T_NIL) ? ((obj) == RUBY_Qnil) : \ + ((type) == RUBY_T_UNDEF) ? ((obj) == RUBY_Qundef) : \ + ((type) == RUBY_T_SYMBOL) ? RB_SYMBOL_P(obj) : \ + ((type) == RUBY_T_FLOAT) ? RB_FLOAT_TYPE_P(obj) : \ + (!RB_SPECIAL_CONST_P(obj) && RB_BUILTIN_TYPE(obj) == (type))) + +#ifdef __GNUC__ +#define RB_GC_GUARD(v) \ + (*__extension__ ({ \ + volatile VALUE *rb_gc_guarded_ptr = &(v); \ + __asm__("" : : "m"(rb_gc_guarded_ptr)); \ + rb_gc_guarded_ptr; \ + })) +#elif defined _MSC_VER +#pragma optimize("", off) +static inline volatile VALUE *rb_gc_guarded_ptr(volatile VALUE *ptr) {return ptr;} +#pragma optimize("", on) +#define RB_GC_GUARD(v) (*rb_gc_guarded_ptr(&(v))) +#else +volatile VALUE *rb_gc_guarded_ptr_val(volatile VALUE *ptr, VALUE val); +#define HAVE_RB_GC_GUARDED_PTR_VAL 1 +#define RB_GC_GUARD(v) (*rb_gc_guarded_ptr_val(&(v),(v))) +#endif + +#ifdef __GNUC__ +#define RB_UNUSED_VAR(x) x __attribute__ ((unused)) +#else +#define RB_UNUSED_VAR(x) x +#endif + +void rb_check_type(VALUE,int); +#define Check_Type(v,t) rb_check_type((VALUE)(v),(t)) + +VALUE rb_str_to_str(VALUE); +VALUE rb_string_value(volatile VALUE*); +char *rb_string_value_ptr(volatile VALUE*); +char *rb_string_value_cstr(volatile VALUE*); + +#define StringValue(v) rb_string_value(&(v)) +#define StringValuePtr(v) rb_string_value_ptr(&(v)) +#define StringValueCStr(v) rb_string_value_cstr(&(v)) + +void rb_check_safe_obj(VALUE); +#define SafeStringValue(v) StringValue(v) +#if GCC_VERSION_SINCE(4,4,0) +void rb_check_safe_str(VALUE) __attribute__((error("rb_check_safe_str() and Check_SafeStr() are obsolete; use StringValue() instead"))); +# define Check_SafeStr(v) rb_check_safe_str((VALUE)(v)) +#else +# define rb_check_safe_str(x) [<"rb_check_safe_str() is obsolete; use StringValue() instead">] +# define Check_SafeStr(v) [<"Check_SafeStr() is obsolete; use StringValue() instead">] +#endif + +VALUE rb_str_export(VALUE); +#define ExportStringValue(v) do {\ + StringValue(v);\ + (v) = rb_str_export(v);\ +} while (0) +VALUE rb_str_export_locale(VALUE); + +VALUE rb_get_path(VALUE); +#define FilePathValue(v) (RB_GC_GUARD(v) = rb_get_path(v)) + +VALUE rb_get_path_no_checksafe(VALUE); +#define FilePathStringValue(v) ((v) = rb_get_path(v)) + +/* Remove in 3.0 */ +#define RUBY_SAFE_LEVEL_MAX 1 +void rb_secure(int); +int rb_safe_level(void); +void rb_set_safe_level(int); +#if GCC_VERSION_SINCE(4,4,0) +int ruby_safe_level_2_error(void) __attribute__((error("$SAFE=2 to 4 are obsolete"))); +int ruby_safe_level_2_warning(void) __attribute__((const,warning("$SAFE=2 to 4 are obsolete"))); +# ifdef RUBY_EXPORT +# define ruby_safe_level_2_warning() ruby_safe_level_2_error() +# endif +# if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# define RUBY_SAFE_LEVEL_INVALID_P(level) \ + __extension__(\ + __builtin_choose_expr(\ + __builtin_constant_p(level), \ + ((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level)), 0)) +# define RUBY_SAFE_LEVEL_CHECK(level, type) \ + __extension__(__builtin_choose_expr(RUBY_SAFE_LEVEL_INVALID_P(level), ruby_safe_level_2_##type(), (level))) +# else +/* in gcc 4.8 or earlier, __builtin_choose_expr() does not consider + * __builtin_constant_p(variable) a constant expression. + */ +# define RUBY_SAFE_LEVEL_INVALID_P(level) \ + __extension__(__builtin_constant_p(level) && \ + ((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level))) +# define RUBY_SAFE_LEVEL_CHECK(level, type) \ + (RUBY_SAFE_LEVEL_INVALID_P(level) ? ruby_safe_level_2_##type() : (level)) +# endif +# define rb_secure(level) rb_secure(RUBY_SAFE_LEVEL_CHECK(level, warning)) +# define rb_set_safe_level(level) rb_set_safe_level(RUBY_SAFE_LEVEL_CHECK(level, error)) +#endif +void rb_set_safe_level_force(int); +void rb_secure_update(VALUE); +NORETURN(void rb_insecure_operation(void)); + +VALUE rb_errinfo(void); +void rb_set_errinfo(VALUE); + +long rb_num2long(VALUE); +unsigned long rb_num2ulong(VALUE); +static inline long +rb_num2long_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return RB_FIX2LONG(x); + else + return rb_num2long(x); +} +#define RB_NUM2LONG(x) rb_num2long_inline(x) +#define NUM2LONG(x) RB_NUM2LONG(x) +static inline unsigned long +rb_num2ulong_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return RB_FIX2ULONG(x); + else + return rb_num2ulong(x); +} +#define RB_NUM2ULONG(x) rb_num2ulong_inline(x) +#define NUM2ULONG(x) RB_NUM2ULONG(x) +#if SIZEOF_INT < SIZEOF_LONG +long rb_num2int(VALUE); +long rb_fix2int(VALUE); +#define RB_FIX2INT(x) ((int)rb_fix2int((VALUE)(x))) + +static inline int +rb_num2int_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return (int)rb_fix2int(x); + else + return (int)rb_num2int(x); +} +#define RB_NUM2INT(x) rb_num2int_inline(x) + +unsigned long rb_num2uint(VALUE); +#define RB_NUM2UINT(x) ((unsigned int)rb_num2uint(x)) +unsigned long rb_fix2uint(VALUE); +#define RB_FIX2UINT(x) ((unsigned int)rb_fix2uint(x)) +#else /* SIZEOF_INT < SIZEOF_LONG */ +#define RB_NUM2INT(x) ((int)RB_NUM2LONG(x)) +#define RB_NUM2UINT(x) ((unsigned int)RB_NUM2ULONG(x)) +#define RB_FIX2INT(x) ((int)RB_FIX2LONG(x)) +#define RB_FIX2UINT(x) ((unsigned int)RB_FIX2ULONG(x)) +#endif /* SIZEOF_INT < SIZEOF_LONG */ +#define NUM2INT(x) RB_NUM2INT(x) +#define NUM2UINT(x) RB_NUM2UINT(x) +#define FIX2INT(x) RB_FIX2INT(x) +#define FIX2UINT(x) RB_FIX2UINT(x) + +short rb_num2short(VALUE); +unsigned short rb_num2ushort(VALUE); +short rb_fix2short(VALUE); +unsigned short rb_fix2ushort(VALUE); +#define RB_FIX2SHORT(x) (rb_fix2short((VALUE)(x))) +#define FIX2SHORT(x) RB_FIX2SHORT(x) +static inline short +rb_num2short_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return rb_fix2short(x); + else + return rb_num2short(x); +} + +#define RB_NUM2SHORT(x) rb_num2short_inline(x) +#define RB_NUM2USHORT(x) rb_num2ushort(x) +#define NUM2SHORT(x) RB_NUM2SHORT(x) +#define NUM2USHORT(x) RB_NUM2USHORT(x) + +#ifdef HAVE_LONG_LONG +LONG_LONG rb_num2ll(VALUE); +unsigned LONG_LONG rb_num2ull(VALUE); +static inline LONG_LONG +rb_num2ll_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return RB_FIX2LONG(x); + else + return rb_num2ll(x); +} +# define RB_NUM2LL(x) rb_num2ll_inline(x) +# define RB_NUM2ULL(x) rb_num2ull(x) +# define NUM2LL(x) RB_NUM2LL(x) +# define NUM2ULL(x) RB_NUM2ULL(x) +#endif + +#if !defined(NUM2OFFT) +# if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG +# define NUM2OFFT(x) ((off_t)NUM2LL(x)) +# else +# define NUM2OFFT(x) NUM2LONG(x) +# endif +#endif + +#if defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T > SIZEOF_LONG +# define NUM2SIZET(x) ((size_t)NUM2ULL(x)) +# define NUM2SSIZET(x) ((ssize_t)NUM2LL(x)) +#else +# define NUM2SIZET(x) NUM2ULONG(x) +# define NUM2SSIZET(x) NUM2LONG(x) +#endif + +double rb_num2dbl(VALUE); +#define NUM2DBL(x) rb_num2dbl((VALUE)(x)) + +VALUE rb_uint2big(uintptr_t); +VALUE rb_int2big(intptr_t); + +VALUE rb_newobj(void); +VALUE rb_newobj_of(VALUE, VALUE); +VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type); +#define RB_NEWOBJ(obj,type) type *(obj) = (type*)rb_newobj() +#define RB_NEWOBJ_OF(obj,type,klass,flags) type *(obj) = (type*)rb_newobj_of(klass, flags) +#define NEWOBJ(obj,type) RB_NEWOBJ(obj,type) +#define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags) /* core has special NEWOBJ_OF() in internal.h */ +#define OBJSETUP(obj,c,t) rb_obj_setup(obj, c, t) /* use NEWOBJ_OF instead of NEWOBJ()+OBJSETUP() */ +#define CLONESETUP(clone,obj) rb_clone_setup(clone,obj) +#define DUPSETUP(dup,obj) rb_dup_setup(dup,obj) + +#ifndef USE_RGENGC +#define USE_RGENGC 1 +#ifndef USE_RINCGC +#define USE_RINCGC 1 +#endif +#endif + +#if USE_RGENGC == 0 +#define USE_RINCGC 0 +#endif + +#ifndef RGENGC_WB_PROTECTED_ARRAY +#define RGENGC_WB_PROTECTED_ARRAY 1 +#endif +#ifndef RGENGC_WB_PROTECTED_HASH +#define RGENGC_WB_PROTECTED_HASH 1 +#endif +#ifndef RGENGC_WB_PROTECTED_STRUCT +#define RGENGC_WB_PROTECTED_STRUCT 1 +#endif +#ifndef RGENGC_WB_PROTECTED_STRING +#define RGENGC_WB_PROTECTED_STRING 1 +#endif +#ifndef RGENGC_WB_PROTECTED_OBJECT +#define RGENGC_WB_PROTECTED_OBJECT 1 +#endif +#ifndef RGENGC_WB_PROTECTED_REGEXP +#define RGENGC_WB_PROTECTED_REGEXP 1 +#endif +#ifndef RGENGC_WB_PROTECTED_CLASS +#define RGENGC_WB_PROTECTED_CLASS 1 +#endif +#ifndef RGENGC_WB_PROTECTED_FLOAT +#define RGENGC_WB_PROTECTED_FLOAT 1 +#endif +#ifndef RGENGC_WB_PROTECTED_COMPLEX +#define RGENGC_WB_PROTECTED_COMPLEX 1 +#endif +#ifndef RGENGC_WB_PROTECTED_RATIONAL +#define RGENGC_WB_PROTECTED_RATIONAL 1 +#endif +#ifndef RGENGC_WB_PROTECTED_BIGNUM +#define RGENGC_WB_PROTECTED_BIGNUM 1 +#endif +#ifndef RGENGC_WB_PROTECTED_NODE_CREF +#define RGENGC_WB_PROTECTED_NODE_CREF 1 +#endif + +#ifdef __GNUC__ +__extension__ +#endif +enum ruby_fl_type { + RUBY_FL_WB_PROTECTED = (1<<5), + RUBY_FL_PROMOTED0 = (1<<5), + RUBY_FL_PROMOTED1 = (1<<6), + RUBY_FL_PROMOTED = RUBY_FL_PROMOTED0|RUBY_FL_PROMOTED1, + RUBY_FL_FINALIZE = (1<<7), + RUBY_FL_TAINT = (1<<8), + RUBY_FL_UNTRUSTED = RUBY_FL_TAINT, + RUBY_FL_SEEN_OBJ_ID = (1<<9), + RUBY_FL_EXIVAR = (1<<10), + RUBY_FL_FREEZE = (1<<11), + + RUBY_FL_USHIFT = 12, + +#define RUBY_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n)) + RUBY_FL_USER_N(0), + RUBY_FL_USER_N(1), + RUBY_FL_USER_N(2), + RUBY_FL_USER_N(3), + RUBY_FL_USER_N(4), + RUBY_FL_USER_N(5), + RUBY_FL_USER_N(6), + RUBY_FL_USER_N(7), + RUBY_FL_USER_N(8), + RUBY_FL_USER_N(9), + RUBY_FL_USER_N(10), + RUBY_FL_USER_N(11), + RUBY_FL_USER_N(12), + RUBY_FL_USER_N(13), + RUBY_FL_USER_N(14), + RUBY_FL_USER_N(15), + RUBY_FL_USER_N(16), + RUBY_FL_USER_N(17), + RUBY_FL_USER_N(18), +#if defined ENUM_OVER_INT || SIZEOF_INT*CHAR_BIT>12+19+1 + RUBY_FL_USER_N(19), +#else +#define RUBY_FL_USER19 (((VALUE)1)<<(RUBY_FL_USHIFT+19)) +#endif + + RUBY_ELTS_SHARED = RUBY_FL_USER2, + RUBY_FL_DUPPED = (RUBY_T_MASK|RUBY_FL_EXIVAR|RUBY_FL_TAINT), + RUBY_FL_SINGLETON = RUBY_FL_USER0 +}; + +struct RUBY_ALIGNAS(SIZEOF_VALUE) RBasic { + VALUE flags; + const VALUE klass; +}; + +VALUE rb_obj_hide(VALUE obj); +VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */ + +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \ + __extension__( \ + __builtin_choose_expr( \ + RGENGC_WB_PROTECTED_##type, \ + OBJ_WB_UNPROTECT((VALUE)(obj)), ((VALUE)(obj)))) +#else +# define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \ + (RGENGC_WB_PROTECTED_##type ? \ + OBJ_WB_UNPROTECT((VALUE)(obj)) : ((VALUE)(obj))) +#endif + +#define RBASIC_CLASS(obj) (RBASIC(obj)->klass) + +#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX +enum ruby_rvalue_flags { + RVALUE_EMBED_LEN_MAX = 3, +}; + +#define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX +#define ROBJECT_EMBED ROBJECT_EMBED +enum ruby_robject_flags { + ROBJECT_EMBED_LEN_MAX = RVALUE_EMBED_LEN_MAX, + ROBJECT_EMBED = RUBY_FL_USER1, + + ROBJECT_ENUM_END +}; + +struct RObject { + struct RBasic basic; + union { + struct { + uint32_t numiv; + VALUE *ivptr; + void *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */ + } heap; + VALUE ary[ROBJECT_EMBED_LEN_MAX]; + } as; +}; +#define ROBJECT_NUMIV(o) \ + ((RBASIC(o)->flags & ROBJECT_EMBED) ? \ + ROBJECT_EMBED_LEN_MAX : \ + ROBJECT(o)->as.heap.numiv) +#define ROBJECT_IVPTR(o) \ + ((RBASIC(o)->flags & ROBJECT_EMBED) ? \ + ROBJECT(o)->as.ary : \ + ROBJECT(o)->as.heap.ivptr) +#define ROBJECT_IV_INDEX_TBL(o) \ + ((RBASIC(o)->flags & ROBJECT_EMBED) ? \ + RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \ + ROBJECT(o)->as.heap.iv_index_tbl) + +#define RCLASS_SUPER(c) rb_class_get_superclass(c) +#define RMODULE_IV_TBL(m) RCLASS_IV_TBL(m) +#define RMODULE_CONST_TBL(m) RCLASS_CONST_TBL(m) +#define RMODULE_M_TBL(m) RCLASS_M_TBL(m) +#define RMODULE_SUPER(m) RCLASS_SUPER(m) +#define RMODULE_IS_OVERLAID RMODULE_IS_OVERLAID +#define RMODULE_IS_REFINEMENT RMODULE_IS_REFINEMENT +#define RMODULE_INCLUDED_INTO_REFINEMENT RMODULE_INCLUDED_INTO_REFINEMENT +enum ruby_rmodule_flags { + RMODULE_IS_OVERLAID = RUBY_FL_USER2, + RMODULE_IS_REFINEMENT = RUBY_FL_USER3, + RMODULE_INCLUDED_INTO_REFINEMENT = RUBY_FL_USER4, + + RMODULE_ENUM_END +}; + +PUREFUNC(double rb_float_value(VALUE)); +VALUE rb_float_new(double); +VALUE rb_float_new_in_heap(double); + +#define RFLOAT_VALUE(v) rb_float_value(v) +#define DBL2NUM(dbl) rb_float_new(dbl) + +#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED +#define ELTS_SHARED RUBY_ELTS_SHARED + +#define RSTRING_NOEMBED RSTRING_NOEMBED +#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 +#define RSTRING_FSTR RSTRING_FSTR +enum ruby_rstring_flags { + RSTRING_NOEMBED = RUBY_FL_USER1, + RSTRING_EMBED_LEN_MASK = (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4| + RUBY_FL_USER5|RUBY_FL_USER6), + RSTRING_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+2), + RSTRING_EMBED_LEN_MAX = (int)((sizeof(VALUE)*RVALUE_EMBED_LEN_MAX)/sizeof(char)-1), + RSTRING_FSTR = RUBY_FL_USER17, + + RSTRING_ENUM_END +}; + +struct RString { + struct RBasic basic; + union { + struct { + long len; + char *ptr; + union { + long capa; + VALUE shared; + } aux; + } heap; + char ary[RSTRING_EMBED_LEN_MAX + 1]; + } as; +}; +#define RSTRING_EMBED_LEN(str) \ + (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \ + (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) +#define RSTRING_LEN(str) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + RSTRING_EMBED_LEN(str) : \ + RSTRING(str)->as.heap.len) +#define RSTRING_PTR(str) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + RSTRING(str)->as.ary : \ + RSTRING(str)->as.heap.ptr) +#define RSTRING_END(str) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + (RSTRING(str)->as.ary + RSTRING_EMBED_LEN(str)) : \ + (RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len)) +#define RSTRING_LENINT(str) rb_long2int(RSTRING_LEN(str)) +#define RSTRING_GETMEM(str, ptrvar, lenvar) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + ((ptrvar) = RSTRING(str)->as.ary, (lenvar) = RSTRING_EMBED_LEN(str)) : \ + ((ptrvar) = RSTRING(str)->as.heap.ptr, (lenvar) = RSTRING(str)->as.heap.len)) + +#ifndef USE_TRANSIENT_HEAP +#define USE_TRANSIENT_HEAP 1 +#endif + +enum ruby_rarray_flags { + RARRAY_EMBED_LEN_MAX = RVALUE_EMBED_LEN_MAX, + RARRAY_EMBED_FLAG = RUBY_FL_USER1, + /* RUBY_FL_USER2 is for ELTS_SHARED */ + RARRAY_EMBED_LEN_MASK = (RUBY_FL_USER4|RUBY_FL_USER3), + RARRAY_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+3), + +#if USE_TRANSIENT_HEAP + RARRAY_TRANSIENT_FLAG = RUBY_FL_USER13, +#define RARRAY_TRANSIENT_FLAG RARRAY_TRANSIENT_FLAG +#else +#define RARRAY_TRANSIENT_FLAG 0 +#endif + + RARRAY_ENUM_END +}; +#define RARRAY_EMBED_FLAG (VALUE)RARRAY_EMBED_FLAG +#define RARRAY_EMBED_LEN_MASK (VALUE)RARRAY_EMBED_LEN_MASK +#define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX +#define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT + +struct RArray { + struct RBasic basic; + union { + struct { + long len; + union { + long capa; +#if defined(__clang__) /* <- clang++ is sane */ || \ + !defined(__cplusplus) /* <- C99 is sane */ || \ + (__cplusplus > 199711L) /* <- C++11 is sane */ + const +#endif + VALUE shared_root; + } aux; + const VALUE *ptr; + } heap; + const VALUE ary[RARRAY_EMBED_LEN_MAX]; + } as; +}; +#define RARRAY_EMBED_LEN(a) \ + (long)((RBASIC(a)->flags >> RARRAY_EMBED_LEN_SHIFT) & \ + (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)) +#define RARRAY_LEN(a) rb_array_len(a) +#define RARRAY_LENINT(ary) rb_long2int(RARRAY_LEN(ary)) +#define RARRAY_CONST_PTR(a) rb_array_const_ptr(a) +#define RARRAY_CONST_PTR_TRANSIENT(a) rb_array_const_ptr_transient(a) + +#if USE_TRANSIENT_HEAP +#define RARRAY_TRANSIENT_P(ary) FL_TEST_RAW((ary), RARRAY_TRANSIENT_FLAG) +#else +#define RARRAY_TRANSIENT_P(ary) 0 +#endif + +#define RARRAY_PTR_USE_START_TRANSIENT(a) rb_array_ptr_use_start(a, 1) +#define RARRAY_PTR_USE_END_TRANSIENT(a) rb_array_ptr_use_end(a, 1) + +#define RARRAY_PTR_USE_TRANSIENT(ary, ptr_name, expr) do { \ + const VALUE _ary = (ary); \ + VALUE *ptr_name = (VALUE *)RARRAY_PTR_USE_START_TRANSIENT(_ary); \ + expr; \ + RARRAY_PTR_USE_END_TRANSIENT(_ary); \ +} while (0) + +#define RARRAY_PTR_USE_START(a) rb_array_ptr_use_start(a, 0) +#define RARRAY_PTR_USE_END(a) rb_array_ptr_use_end(a, 0) + +#define RARRAY_PTR_USE(ary, ptr_name, expr) do { \ + const VALUE _ary = (ary); \ + VALUE *ptr_name = (VALUE *)RARRAY_PTR_USE_START(_ary); \ + expr; \ + RARRAY_PTR_USE_END(_ary); \ +} while (0) + +#define RARRAY_AREF(a, i) (RARRAY_CONST_PTR_TRANSIENT(a)[i]) +#define RARRAY_ASET(a, i, v) do { \ + const VALUE _ary = (a); \ + const VALUE _v = (v); \ + VALUE *ptr = (VALUE *)RARRAY_PTR_USE_START_TRANSIENT(_ary); \ + RB_OBJ_WRITE(_ary, &ptr[i], _v); \ + RARRAY_PTR_USE_END_TRANSIENT(_ary); \ +} while (0) + +#define RARRAY_PTR(a) ((VALUE *)RARRAY_CONST_PTR(RB_OBJ_WB_UNPROTECT_FOR(ARRAY, a))) + +struct RRegexp { + struct RBasic basic; + struct re_pattern_buffer *ptr; + const VALUE src; + unsigned long usecnt; +}; +#define RREGEXP_PTR(r) (RREGEXP(r)->ptr) +#define RREGEXP_SRC(r) (RREGEXP(r)->src) +#define RREGEXP_SRC_PTR(r) RSTRING_PTR(RREGEXP(r)->src) +#define RREGEXP_SRC_LEN(r) RSTRING_LEN(RREGEXP(r)->src) +#define RREGEXP_SRC_END(r) RSTRING_END(RREGEXP(r)->src) + +/* RHash is defined at internal.h */ +size_t rb_hash_size_num(VALUE hash); + +#define RHASH_TBL(h) rb_hash_tbl(h, __FILE__, __LINE__) +#define RHASH_ITER_LEV(h) rb_hash_iter_lev(h) +#define RHASH_IFNONE(h) rb_hash_ifnone(h) +#define RHASH_SIZE(h) rb_hash_size_num(h) +#define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0) +#define RHASH_SET_IFNONE(h, ifnone) rb_hash_set_ifnone((VALUE)h, ifnone) + +struct RFile { + struct RBasic basic; + struct rb_io_t *fptr; +}; + +struct RData { + struct RBasic basic; + void (*dmark)(void*); + void (*dfree)(void*); + void *data; +}; + +typedef struct rb_data_type_struct rb_data_type_t; + +struct rb_data_type_struct { + const char *wrap_struct_name; + struct { + void (*dmark)(void*); + void (*dfree)(void*); + size_t (*dsize)(const void *); + void (*dcompact)(void*); + void *reserved[1]; /* For future extension. + This array *must* be filled with ZERO. */ + } function; + const rb_data_type_t *parent; + void *data; /* This area can be used for any purpose + by a programmer who define the type. */ + VALUE flags; /* RUBY_FL_WB_PROTECTED */ +}; + +#define HAVE_TYPE_RB_DATA_TYPE_T 1 +#define HAVE_RB_DATA_TYPE_T_FUNCTION 1 +#define HAVE_RB_DATA_TYPE_T_PARENT 1 + +struct RTypedData { + struct RBasic basic; + const rb_data_type_t *type; + VALUE typed_flag; /* 1 or not */ + void *data; +}; + +#define DATA_PTR(dta) (RDATA(dta)->data) + +#define RTYPEDDATA_P(v) (RTYPEDDATA(v)->typed_flag == 1) +#define RTYPEDDATA_TYPE(v) (RTYPEDDATA(v)->type) +#define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data) + +/* +#define RUBY_DATA_FUNC(func) ((void (*)(void*))(func)) +*/ +typedef void (*RUBY_DATA_FUNC)(void*); + +#ifndef RUBY_UNTYPED_DATA_WARNING +# if defined RUBY_EXPORT +# define RUBY_UNTYPED_DATA_WARNING 1 +# else +# define RUBY_UNTYPED_DATA_WARNING 0 +# endif +#endif +VALUE rb_data_object_wrap(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC); +VALUE rb_data_object_zalloc(VALUE,size_t,RUBY_DATA_FUNC,RUBY_DATA_FUNC); +VALUE rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *); +VALUE rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type); +int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent); +int rb_typeddata_is_kind_of(VALUE, const rb_data_type_t *); +void *rb_check_typeddata(VALUE, const rb_data_type_t *); +#define Check_TypedStruct(v,t) rb_check_typeddata((VALUE)(v),(t)) +#define RUBY_DEFAULT_FREE ((RUBY_DATA_FUNC)-1) +#define RUBY_NEVER_FREE ((RUBY_DATA_FUNC)0) +#define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE +#define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE + +/* bits for rb_data_type_struct::flags */ +#define RUBY_TYPED_FREE_IMMEDIATELY 1 /* TYPE field */ +#define RUBY_TYPED_WB_PROTECTED RUBY_FL_WB_PROTECTED /* THIS FLAG DEPENDS ON Ruby version */ +#define RUBY_TYPED_PROMOTED1 RUBY_FL_PROMOTED1 /* THIS FLAG DEPENDS ON Ruby version */ + +#define Data_Wrap_Struct(klass,mark,free,sval)\ + rb_data_object_wrap((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free)) + +#define Data_Make_Struct0(result, klass, type, size, mark, free, sval) \ + VALUE result = rb_data_object_zalloc((klass), (size), \ + (RUBY_DATA_FUNC)(mark), \ + (RUBY_DATA_FUNC)(free)); \ + (void)((sval) = (type *)DATA_PTR(result)); + +#ifdef __GNUC__ +#define Data_Make_Struct(klass,type,mark,free,sval) ({\ + 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),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free),(void **)&(sval),sizeof(type)) \ +) +#endif + +#define TypedData_Wrap_Struct(klass,data_type,sval)\ + rb_data_typed_object_wrap((klass),(sval),(data_type)) + +#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \ + VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \ + (void)((sval) = (type *)DATA_PTR(result)); + +#ifdef __GNUC__ +#define TypedData_Make_Struct(klass, type, data_type, sval) ({\ + 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),(void **)&(sval),sizeof(type)) \ +) +#endif + +#define Data_Get_Struct(obj,type,sval) \ + ((sval) = (type*)rb_data_object_get(obj)) + +#define TypedData_Get_Struct(obj,type,data_type,sval) \ + ((sval) = (type*)rb_check_typeddata((obj), (data_type))) + +#define RSTRUCT_LEN(st) NUM2LONG(rb_struct_size(st)) +#define RSTRUCT_PTR(st) rb_struct_ptr(st) +#define RSTRUCT_SET(st, idx, v) rb_struct_aset(st, INT2NUM(idx), (v)) +#define RSTRUCT_GET(st, idx) rb_struct_aref(st, INT2NUM(idx)) + +int rb_big_sign(VALUE); +#define RBIGNUM_SIGN(b) (rb_big_sign(b)) +#define RBIGNUM_POSITIVE_P(b) (RBIGNUM_SIGN(b)!=0) +#define RBIGNUM_NEGATIVE_P(b) (RBIGNUM_SIGN(b)==0) + +#define R_CAST(st) (struct st*) +#define RMOVED(obj) (R_CAST(RMoved)(obj)) +#define RBASIC(obj) (R_CAST(RBasic)(obj)) +#define ROBJECT(obj) (R_CAST(RObject)(obj)) +#define RCLASS(obj) (R_CAST(RClass)(obj)) +#define RMODULE(obj) RCLASS(obj) +#define RSTRING(obj) (R_CAST(RString)(obj)) +#define RREGEXP(obj) (R_CAST(RRegexp)(obj)) +#define RARRAY(obj) (R_CAST(RArray)(obj)) +#define RDATA(obj) (R_CAST(RData)(obj)) +#define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj)) +#define RFILE(obj) (R_CAST(RFile)(obj)) + +#define FL_SINGLETON ((VALUE)RUBY_FL_SINGLETON) +#define FL_WB_PROTECTED ((VALUE)RUBY_FL_WB_PROTECTED) +#define FL_PROMOTED0 ((VALUE)RUBY_FL_PROMOTED0) +#define FL_PROMOTED1 ((VALUE)RUBY_FL_PROMOTED1) +#define FL_FINALIZE ((VALUE)RUBY_FL_FINALIZE) +#define FL_TAINT ((VALUE)RUBY_FL_TAINT) +#define FL_UNTRUSTED ((VALUE)RUBY_FL_UNTRUSTED) +#define FL_SEEN_OBJ_ID ((VALUE)RUBY_FL_SEEN_OBJ_ID) +#define FL_EXIVAR ((VALUE)RUBY_FL_EXIVAR) +#define FL_FREEZE ((VALUE)RUBY_FL_FREEZE) + +#define FL_USHIFT ((VALUE)RUBY_FL_USHIFT) + +#define FL_USER0 ((VALUE)RUBY_FL_USER0) +#define FL_USER1 ((VALUE)RUBY_FL_USER1) +#define FL_USER2 ((VALUE)RUBY_FL_USER2) +#define FL_USER3 ((VALUE)RUBY_FL_USER3) +#define FL_USER4 ((VALUE)RUBY_FL_USER4) +#define FL_USER5 ((VALUE)RUBY_FL_USER5) +#define FL_USER6 ((VALUE)RUBY_FL_USER6) +#define FL_USER7 ((VALUE)RUBY_FL_USER7) +#define FL_USER8 ((VALUE)RUBY_FL_USER8) +#define FL_USER9 ((VALUE)RUBY_FL_USER9) +#define FL_USER10 ((VALUE)RUBY_FL_USER10) +#define FL_USER11 ((VALUE)RUBY_FL_USER11) +#define FL_USER12 ((VALUE)RUBY_FL_USER12) +#define FL_USER13 ((VALUE)RUBY_FL_USER13) +#define FL_USER14 ((VALUE)RUBY_FL_USER14) +#define FL_USER15 ((VALUE)RUBY_FL_USER15) +#define FL_USER16 ((VALUE)RUBY_FL_USER16) +#define FL_USER17 ((VALUE)RUBY_FL_USER17) +#define FL_USER18 ((VALUE)RUBY_FL_USER18) +#define FL_USER19 ((VALUE)(unsigned int)RUBY_FL_USER19) + +#define RB_SPECIAL_CONST_P(x) (RB_IMMEDIATE_P(x) || !RB_TEST(x)) +#define SPECIAL_CONST_P(x) RB_SPECIAL_CONST_P(x) + +#define RB_FL_ABLE(x) (!RB_SPECIAL_CONST_P(x) && RB_BUILTIN_TYPE(x) != RUBY_T_NODE) +#define RB_FL_TEST_RAW(x,f) (RBASIC(x)->flags&(f)) +#define RB_FL_TEST(x,f) (RB_FL_ABLE(x)?RB_FL_TEST_RAW((x),(f)):0) +#define RB_FL_ANY_RAW(x,f) RB_FL_TEST_RAW((x),(f)) +#define RB_FL_ANY(x,f) RB_FL_TEST((x),(f)) +#define RB_FL_ALL_RAW(x,f) (RB_FL_TEST_RAW((x),(f)) == (f)) +#define RB_FL_ALL(x,f) (RB_FL_TEST((x),(f)) == (f)) +#define RB_FL_SET_RAW(x,f) (void)(RBASIC(x)->flags |= (f)) +#define RB_FL_SET(x,f) (RB_FL_ABLE(x) ? RB_FL_SET_RAW(x, f) : (void)0) +#define RB_FL_UNSET_RAW(x,f) (void)(RBASIC(x)->flags &= ~(VALUE)(f)) +#define RB_FL_UNSET(x,f) (RB_FL_ABLE(x) ? RB_FL_UNSET_RAW(x, f) : (void)0) +#define RB_FL_REVERSE_RAW(x,f) (void)(RBASIC(x)->flags ^= (f)) +#define RB_FL_REVERSE(x,f) (RB_FL_ABLE(x) ? RB_FL_REVERSE_RAW(x, f) : (void)0) + +#define RB_OBJ_TAINTABLE(x) (RB_FL_ABLE(x) && RB_BUILTIN_TYPE(x) != RUBY_T_BIGNUM && RB_BUILTIN_TYPE(x) != RUBY_T_FLOAT) +#define RB_OBJ_TAINTED_RAW(x) RB_FL_TEST_RAW(x, RUBY_FL_TAINT) +#define RB_OBJ_TAINTED(x) (!!RB_FL_TEST((x), RUBY_FL_TAINT)) +#define RB_OBJ_TAINT_RAW(x) RB_FL_SET_RAW(x, RUBY_FL_TAINT) +#define RB_OBJ_TAINT(x) (RB_OBJ_TAINTABLE(x) ? RB_OBJ_TAINT_RAW(x) : (void)0) +#define RB_OBJ_UNTRUSTED(x) RB_OBJ_TAINTED(x) +#define RB_OBJ_UNTRUST(x) RB_OBJ_TAINT(x) +#define RB_OBJ_INFECT_RAW(x,s) RB_FL_SET_RAW(x, RB_OBJ_TAINTED_RAW(s)) +#define RB_OBJ_INFECT(x,s) ( \ + (RB_OBJ_TAINTABLE(x) && RB_FL_ABLE(s)) ? \ + RB_OBJ_INFECT_RAW(x, s) : (void)0) + +#define RB_OBJ_FROZEN_RAW(x) (RBASIC(x)->flags&RUBY_FL_FREEZE) +#define RB_OBJ_FROZEN(x) (!RB_FL_ABLE(x) || RB_OBJ_FROZEN_RAW(x)) +#define RB_OBJ_FREEZE_RAW(x) (void)(RBASIC(x)->flags |= RUBY_FL_FREEZE) +#define RB_OBJ_FREEZE(x) rb_obj_freeze_inline((VALUE)x) + +/*! + * \defgroup deprecated_macros deprecated macro APIs + * \{ + * \par These macros are deprecated. Prefer their `RB_`-prefixed versions. + */ +#define FL_ABLE(x) RB_FL_ABLE(x) +#define FL_TEST_RAW(x,f) RB_FL_TEST_RAW(x,f) +#define FL_TEST(x,f) RB_FL_TEST(x,f) +#define FL_ANY_RAW(x,f) RB_FL_ANY_RAW(x,f) +#define FL_ANY(x,f) RB_FL_ANY(x,f) +#define FL_ALL_RAW(x,f) RB_FL_ALL_RAW(x,f) +#define FL_ALL(x,f) RB_FL_ALL(x,f) +#define FL_SET_RAW(x,f) RB_FL_SET_RAW(x,f) +#define FL_SET(x,f) RB_FL_SET(x,f) +#define FL_UNSET_RAW(x,f) RB_FL_UNSET_RAW(x,f) +#define FL_UNSET(x,f) RB_FL_UNSET(x,f) +#define FL_REVERSE_RAW(x,f) RB_FL_REVERSE_RAW(x,f) +#define FL_REVERSE(x,f) RB_FL_REVERSE(x,f) + +#define OBJ_TAINTABLE(x) RB_OBJ_TAINTABLE(x) +#define OBJ_TAINTED_RAW(x) RB_OBJ_TAINTED_RAW(x) +#define OBJ_TAINTED(x) RB_OBJ_TAINTED(x) +#define OBJ_TAINT_RAW(x) RB_OBJ_TAINT_RAW(x) +#define OBJ_TAINT(x) RB_OBJ_TAINT(x) +#define OBJ_UNTRUSTED(x) RB_OBJ_UNTRUSTED(x) +#define OBJ_UNTRUST(x) RB_OBJ_UNTRUST(x) +#define OBJ_INFECT_RAW(x,s) RB_OBJ_INFECT_RAW(x,s) +#define OBJ_INFECT(x,s) RB_OBJ_INFECT(x,s) +#define OBJ_FROZEN_RAW(x) RB_OBJ_FROZEN_RAW(x) +#define OBJ_FROZEN(x) RB_OBJ_FROZEN(x) +#define OBJ_FREEZE_RAW(x) RB_OBJ_FREEZE_RAW(x) +#define OBJ_FREEZE(x) RB_OBJ_FREEZE(x) + +/* \} */ + +void rb_freeze_singleton_class(VALUE klass); + +static inline void +rb_obj_freeze_inline(VALUE x) +{ + if (RB_FL_ABLE(x)) { + RB_OBJ_FREEZE_RAW(x); + if (RBASIC_CLASS(x) && !(RBASIC(x)->flags & RUBY_FL_SINGLETON)) { + rb_freeze_singleton_class(x); + } + } +} + +#if GCC_VERSION_SINCE(4,4,0) +# define RUBY_UNTYPED_DATA_FUNC(func) func __attribute__((warning("untyped Data is unsafe; use TypedData instead"))) +#else +# define RUBY_UNTYPED_DATA_FUNC(func) DEPRECATED(func) +#endif + +#if defined(__GNUC__) && !defined(__NO_INLINE__) +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +RUBY_UNTYPED_DATA_FUNC(static inline VALUE rb_data_object_wrap_warning(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC)); +#endif +RUBY_UNTYPED_DATA_FUNC(static inline void *rb_data_object_get_warning(VALUE)); + +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); +} + +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +#define rb_data_object_wrap_warning(klass, ptr, mark, free) \ + __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 +#endif + +static inline void * +rb_data_object_get(VALUE obj) +{ + Check_Type(obj, RUBY_T_DATA); + return ((struct RData *)obj)->data; +} + +#if defined(__GNUC__) && !defined(__NO_INLINE__) +static inline void * +rb_data_object_get_warning(VALUE obj) +{ + return rb_data_object_get(obj); +} +#endif + +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; +} + +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; +} + +#ifndef rb_data_object_alloc +DEPRECATED_BY(rb_data_object_wrap, static inline VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC)); +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); +} +#endif + +#ifndef rb_data_typed_object_alloc +DEPRECATED_BY(rb_data_typed_object_wrap, static inline VALUE rb_data_typed_object_alloc(VALUE,void*,const rb_data_type_t*)); +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 + +#if defined(__GNUC__) && !defined(__NO_INLINE__) +#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 RUBY_MACRO_SELECT(rb_data_object_wrap_, 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 RUBY_MACRO_SELECT(rb_data_object_get_, 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 RUBY_MACRO_SELECT(rb_data_object_make_, RUBY_UNTYPED_DATA_WARNING) +#endif + +#if USE_RGENGC +#define RB_OBJ_PROMOTED_RAW(x) RB_FL_ALL_RAW(x, RUBY_FL_PROMOTED) +#define RB_OBJ_PROMOTED(x) (RB_SPECIAL_CONST_P(x) ? 0 : RB_OBJ_PROMOTED_RAW(x)) +#define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__) + +void rb_gc_writebarrier(VALUE a, VALUE b); +void rb_gc_writebarrier_unprotect(VALUE obj); + +#else /* USE_RGENGC */ +#define RB_OBJ_PROMOTED(x) 0 +#define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__) +#endif +#define OBJ_PROMOTED_RAW(x) RB_OBJ_PROMOTED_RAW(x) +#define OBJ_PROMOTED(x) RB_OBJ_PROMOTED(x) +#define OBJ_WB_UNPROTECT(x) RB_OBJ_WB_UNPROTECT(x) + +/* Write barrier (WB) interfaces: + * - RB_OBJ_WRITE(a, slot, b): WB for new reference from `a' to `b'. + * Write `b' into `*slot'. `slot' is a pointer in `a'. + * - RB_OBJ_WRITTEN(a, oldv, b): WB for new reference from `a' to `b'. + * This doesn't write any values, but only a WB declaration. + * `oldv' is replaced value with `b' (not used in current Ruby). + * + * NOTE: The following core interfaces can be changed in the future. + * Please catch up if you want to insert WB into C-extensions + * correctly. + */ +#define RB_OBJ_WRITE(a, slot, b) rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__) +#define RB_OBJ_WRITTEN(a, oldv, b) rb_obj_written((VALUE)(a), (VALUE)(oldv), (VALUE)(b), __FILE__, __LINE__) + +#ifndef USE_RGENGC_LOGGING_WB_UNPROTECT +#define USE_RGENGC_LOGGING_WB_UNPROTECT 0 +#endif + +#if USE_RGENGC_LOGGING_WB_UNPROTECT +void rb_gc_unprotect_logging(void *objptr, const char *filename, int line); +#define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging +#endif + +static inline VALUE +rb_obj_wb_unprotect(VALUE x, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) +{ +#ifdef RGENGC_LOGGING_WB_UNPROTECT + RGENGC_LOGGING_WB_UNPROTECT((void *)x, filename, line); +#endif +#if USE_RGENGC + rb_gc_writebarrier_unprotect(x); +#endif + return x; +} + +static inline VALUE +rb_obj_written(VALUE a, RB_UNUSED_VAR(VALUE oldv), VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) +{ +#ifdef RGENGC_LOGGING_OBJ_WRITTEN + RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line); +#endif + +#if USE_RGENGC + if (!RB_SPECIAL_CONST_P(b)) { + rb_gc_writebarrier(a, b); + } +#endif + + return a; +} + +static inline VALUE +rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) +{ +#ifdef RGENGC_LOGGING_WRITE + RGENGC_LOGGING_WRITE(a, slot, b, filename, line); +#endif + + *slot = b; + +#if USE_RGENGC + rb_obj_written(a, RUBY_Qundef /* ignore `oldv' now */, b, filename, line); +#endif + return a; +} + +#define RUBY_INTEGER_UNIFICATION 1 +#define RB_INTEGER_TYPE_P(obj) rb_integer_type_p(obj) +#if defined __GNUC__ && !GCC_VERSION_SINCE(4, 3, 0) +/* clang 3.x (4.2 compatible) can't eliminate CSE of RB_BUILTIN_TYPE + * in inline function and caller function */ +#define rb_integer_type_p(obj) \ + __extension__ ({ \ + const VALUE integer_type_obj = (obj); \ + (RB_FIXNUM_P(integer_type_obj) || \ + (!RB_SPECIAL_CONST_P(integer_type_obj) && \ + RB_BUILTIN_TYPE(integer_type_obj) == RUBY_T_BIGNUM)); \ + }) +#else +static inline int +rb_integer_type_p(VALUE obj) +{ + return (RB_FIXNUM_P(obj) || + (!RB_SPECIAL_CONST_P(obj) && + RB_BUILTIN_TYPE(obj) == RUBY_T_BIGNUM)); +} +#endif + +#if SIZEOF_INT < SIZEOF_LONG +# define RB_INT2NUM(v) RB_INT2FIX((int)(v)) +# define RB_UINT2NUM(v) RB_LONG2FIX((unsigned int)(v)) +#else +static inline VALUE +rb_int2num_inline(int v) +{ + if (RB_FIXABLE(v)) + return RB_INT2FIX(v); + else + return rb_int2big(v); +} +#define RB_INT2NUM(x) rb_int2num_inline(x) + +static inline VALUE +rb_uint2num_inline(unsigned int v) +{ + if (RB_POSFIXABLE(v)) + return RB_LONG2FIX(v); + else + return rb_uint2big(v); +} +#define RB_UINT2NUM(x) rb_uint2num_inline(x) +#endif +#define INT2NUM(x) RB_INT2NUM(x) +#define UINT2NUM(x) RB_UINT2NUM(x) + +static inline VALUE +rb_long2num_inline(long v) +{ + if (RB_FIXABLE(v)) + return RB_LONG2FIX(v); + else + return rb_int2big(v); +} +#define RB_LONG2NUM(x) rb_long2num_inline(x) + +static inline VALUE +rb_ulong2num_inline(unsigned long v) +{ + if (RB_POSFIXABLE(v)) + return RB_LONG2FIX(v); + else + return rb_uint2big(v); +} +#define RB_ULONG2NUM(x) rb_ulong2num_inline(x) + +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 (char)(NUM2INT(x) & 0xff); +} +#define RB_NUM2CHR(x) rb_num2char_inline(x) + +#define RB_CHR2FIX(x) RB_INT2FIX((long)((x)&0xff)) + +#define LONG2NUM(x) RB_LONG2NUM(x) +#define ULONG2NUM(x) RB_ULONG2NUM(x) +#define USHORT2NUM(x) RB_INT2FIX(x) +#define NUM2CHR(x) RB_NUM2CHR(x) +#define CHR2FIX(x) RB_CHR2FIX(x) + +#if SIZEOF_LONG < SIZEOF_VALUE +#define RB_ST2FIX(h) RB_LONG2FIX((long)((h) > 0 ? (h) & (unsigned long)-1 >> 2 : (h) | ~((unsigned long)-1 >> 2))) +#else +#define RB_ST2FIX(h) RB_LONG2FIX((long)(h)) +#endif +#define ST2FIX(h) RB_ST2FIX(h) + +#define RB_ALLOC_N(type,n) ((type*)ruby_xmalloc2((size_t)(n),sizeof(type))) +#define RB_ALLOC(type) ((type*)ruby_xmalloc(sizeof(type))) +#define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((size_t)(n),sizeof(type))) +#define RB_ZALLOC(type) (RB_ZALLOC_N(type,1)) +#define RB_REALLOC_N(var,type,n) ((var)=(type*)ruby_xrealloc2((char*)(var),(size_t)(n),sizeof(type))) + +#define ALLOC_N(type,n) RB_ALLOC_N(type,n) +#define ALLOC(type) RB_ALLOC(type) +#define ZALLOC_N(type,n) RB_ZALLOC_N(type,n) +#define ZALLOC(type) RB_ZALLOC(type) +#define REALLOC_N(var,type,n) RB_REALLOC_N(var,type,n) + +#if GCC_VERSION_BEFORE(4,9,5) +/* 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#Other-Builtins */ +# undef HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN +#endif + +#if defined(HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN) && defined(RUBY_ALIGNOF) +/* I don't know why but __builtin_alloca_with_align's second argument + takes bits rather than bytes. */ +#define ALLOCA_N(type, n) \ + (type*)__builtin_alloca_with_align((sizeof(type)*(n)), \ + RUBY_ALIGNOF(type) * CHAR_BIT) +#else +#define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n))) +#endif + +void *rb_alloc_tmp_buffer(volatile VALUE *store, long len) RUBY_ATTR_ALLOC_SIZE((2)); +void *rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t len,size_t count) RUBY_ATTR_ALLOC_SIZE((2,3)); +void rb_free_tmp_buffer(volatile VALUE *store); +NORETURN(void ruby_malloc_size_overflow(size_t, size_t)); +#if HAVE_LONG_LONG && SIZEOF_SIZE_T * 2 <= SIZEOF_LONG_LONG +# define DSIZE_T unsigned LONG_LONG +#elif defined(HAVE_INT128_T) +# define DSIZE_T uint128_t +#endif +static inline int +rb_mul_size_overflow(size_t a, size_t b, size_t max, size_t *c) +{ +#ifdef DSIZE_T +# ifdef __GNUC__ + __extension__ +# endif + DSIZE_T c2 = (DSIZE_T)a * (DSIZE_T)b; + if (c2 > max) return 1; + *c = (size_t)c2; +#else + if (b != 0 && a > max / b) return 1; + *c = a * b; +#endif + return 0; +} +static inline void * +rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize) +{ + size_t cnt = (size_t)count; + if (elsize == sizeof(VALUE)) { + if (RB_UNLIKELY(cnt > LONG_MAX / sizeof(VALUE))) { + ruby_malloc_size_overflow(cnt, elsize); + } + } + else { + size_t size, max = LONG_MAX - sizeof(VALUE) + 1; + if (RB_UNLIKELY(rb_mul_size_overflow(cnt, elsize, max, &size))) { + ruby_malloc_size_overflow(cnt, elsize); + } + cnt = (size + sizeof(VALUE) - 1) / sizeof(VALUE); + } + return rb_alloc_tmp_buffer_with_count(store, cnt * sizeof(VALUE), cnt); +} +/* allocates _n_ bytes temporary buffer and stores VALUE including it + * in _v_. _n_ may be evaluated twice. */ +#ifdef C_ALLOCA +# define RB_ALLOCV(v, n) rb_alloc_tmp_buffer(&(v), (n)) +# define RB_ALLOCV_N(type, v, n) \ + rb_alloc_tmp_buffer2(&(v), (n), sizeof(type)) +#else +# define RUBY_ALLOCV_LIMIT 1024 +# define RB_ALLOCV(v, n) ((n) < RUBY_ALLOCV_LIMIT ? \ + ((v) = 0, alloca(n)) : \ + rb_alloc_tmp_buffer(&(v), (n))) +# define RB_ALLOCV_N(type, v, n) \ + ((type*)(((size_t)(n) < RUBY_ALLOCV_LIMIT / sizeof(type)) ? \ + ((v) = 0, alloca((size_t)(n) * sizeof(type))) : \ + rb_alloc_tmp_buffer2(&(v), (long)(n), sizeof(type)))) +#endif +#define RB_ALLOCV_END(v) rb_free_tmp_buffer(&(v)) + +#define ALLOCV(v, n) RB_ALLOCV(v, n) +#define ALLOCV_N(type, v, n) RB_ALLOCV_N(type, v, n) +#define ALLOCV_END(v) RB_ALLOCV_END(v) + +#define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(size_t)(n)) +#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(size_t)(n)) +#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(size_t)(n)) +#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(size_t)(n)) +#ifdef __GLIBC__ +static inline void * +ruby_nonempty_memcpy(void *dest, const void *src, size_t n) +{ + /* if nothing to be copied, src may be NULL */ + return (n ? memcpy(dest, src, n) : dest); +} +#define memcpy(p1,p2,n) ruby_nonempty_memcpy(p1, p2, n) +#endif + +void rb_obj_infect(VALUE victim, VALUE carrier); + +typedef int ruby_glob_func(const char*,VALUE, void*); +void rb_glob(const char*,void(*)(const char*,VALUE,void*),VALUE); +int ruby_glob(const char*,int,ruby_glob_func*,VALUE); +int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE); + +VALUE rb_define_class(const char*,VALUE); +VALUE rb_define_module(const char*); +VALUE rb_define_class_under(VALUE, const char*, VALUE); +VALUE rb_define_module_under(VALUE, const char*); + +void rb_include_module(VALUE,VALUE); +void rb_extend_object(VALUE,VALUE); +void rb_prepend_module(VALUE,VALUE); + +typedef VALUE rb_gvar_getter_t(ID id, VALUE *data); +typedef void rb_gvar_setter_t(VALUE val, ID id, VALUE *data); +typedef void rb_gvar_marker_t(VALUE *var); + +rb_gvar_getter_t rb_gvar_undef_getter; +rb_gvar_setter_t rb_gvar_undef_setter; +rb_gvar_marker_t rb_gvar_undef_marker; + +rb_gvar_getter_t rb_gvar_val_getter; +rb_gvar_setter_t rb_gvar_val_setter; +rb_gvar_marker_t rb_gvar_val_marker; + +rb_gvar_getter_t rb_gvar_var_getter; +rb_gvar_setter_t rb_gvar_var_setter; +rb_gvar_marker_t rb_gvar_var_marker; + +NORETURN(rb_gvar_setter_t rb_gvar_readonly_setter); + +void rb_define_variable(const char*,VALUE*); +void rb_define_virtual_variable(const char*,rb_gvar_getter_t*,rb_gvar_setter_t*); +void rb_define_hooked_variable(const char*,VALUE*,rb_gvar_getter_t*,rb_gvar_setter_t*); +void rb_define_readonly_variable(const char*,const VALUE*); +void rb_define_const(VALUE,const char*,VALUE); +void rb_define_global_const(const char*,VALUE); + +void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int); +void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int); +void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int); + +void rb_undef_method(VALUE,const char*); +void rb_define_alias(VALUE,const char*,const char*); +void rb_define_attr(VALUE,const char*,int,int); + +void rb_global_variable(VALUE*); +void rb_gc_register_mark_object(VALUE); +void rb_gc_register_address(VALUE*); +void rb_gc_unregister_address(VALUE*); + +ID rb_intern(const char*); +ID rb_intern2(const char*, long); +ID rb_intern_str(VALUE str); +const char *rb_id2name(ID); +ID rb_check_id(volatile VALUE *); +ID rb_to_id(VALUE); +VALUE rb_id2str(ID); +VALUE rb_sym2str(VALUE); +VALUE rb_to_symbol(VALUE name); +VALUE rb_check_symbol(volatile VALUE *namep); + +#define RUBY_CONST_ID_CACHE_NB(result, str) \ + static ID rb_intern_id_cache; \ + if (!rb_intern_id_cache) \ + rb_intern_id_cache = rb_intern2((str), (long)strlen(str)); \ + result rb_intern_id_cache; +#define RUBY_CONST_ID_CACHE(result, str) \ + { \ + RUBY_CONST_ID_CACHE_NB(result, str) \ + } +#define RUBY_CONST_ID(var, str) \ + do RUBY_CONST_ID_CACHE((var) =, (str)) while (0) +#define CONST_ID_CACHE(result, str) RUBY_CONST_ID_CACHE(result, str) +#define CONST_ID(var, str) RUBY_CONST_ID(var, str) +#if defined(HAVE_BUILTIN___BUILTIN_CONSTANT_P) && defined(HAVE_STMT_AND_DECL_IN_EXPR) +/* __builtin_constant_p and statement expression is available + * since gcc-2.7.2.3 at least. */ +#define rb_intern(str) \ + (__builtin_constant_p(str) ? \ + __extension__ ({RUBY_CONST_ID_CACHE_NB((ID), (str))}) : \ + rb_intern(str)) +#define rb_intern_const(str) \ + (__builtin_constant_p(str) ? \ + __extension__ (rb_intern2((str), (long)strlen(str))) : \ + (rb_intern)(str)) + +# define rb_varargs_argc_check_runtime(argc, vargc) \ + (((argc) <= (vargc)) ? (argc) : \ + (rb_fatal("argc(%d) exceeds actual arguments(%d)", \ + argc, vargc), 0)) +# define rb_varargs_argc_valid_p(argc, vargc) \ + ((argc) == 0 ? (vargc) <= 1 : /* [ruby-core:85266] [Bug #14425] */ \ + (argc) == (vargc)) +# if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# if HAVE_ATTRIBUTE_ERRORFUNC +ERRORFUNC((" argument length doesn't match"), int rb_varargs_bad_length(int,int)); +# else +# define rb_varargs_bad_length(argc, vargc) \ + ((argc)/rb_varargs_argc_valid_p(argc, vargc)) +# endif +# define rb_varargs_argc_check(argc, vargc) \ + __builtin_choose_expr(__builtin_constant_p(argc), \ + (rb_varargs_argc_valid_p(argc, vargc) ? (argc) : \ + rb_varargs_bad_length(argc, vargc)), \ + rb_varargs_argc_check_runtime(argc, vargc)) +# else +# define rb_varargs_argc_check(argc, vargc) \ + rb_varargs_argc_check_runtime(argc, vargc) +# endif + +#else +#define rb_intern_const(str) rb_intern2((str), (long)strlen(str)) +#endif + +const char *rb_class2name(VALUE); +const char *rb_obj_classname(VALUE); + +void rb_p(VALUE); + +VALUE rb_eval_string(const char*); +VALUE rb_eval_string_protect(const char*, int*); +VALUE rb_eval_string_wrap(const char*, int*); +VALUE rb_funcall(VALUE, ID, int, ...); +VALUE rb_funcallv(VALUE, ID, int, const VALUE*); +VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE*, int); +VALUE rb_funcallv_public(VALUE, ID, int, const VALUE*); +VALUE rb_funcallv_public_kw(VALUE, ID, int, const VALUE*, int); +#define rb_funcall2 rb_funcallv +#define rb_funcall3 rb_funcallv_public +VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*); +VALUE rb_funcall_passing_block_kw(VALUE, ID, int, const VALUE*, int); +VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE*, VALUE); +VALUE rb_funcall_with_block_kw(VALUE, ID, int, const VALUE*, VALUE, int); +int rb_scan_args(int, const VALUE*, const char*, ...); +#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS 0 +#define RB_SCAN_ARGS_KEYWORDS 1 +#define RB_SCAN_ARGS_EMPTY_KEYWORDS 2 /* Will be removed in 3.0 */ +#define RB_SCAN_ARGS_LAST_HASH_KEYWORDS 3 +int rb_scan_args_kw(int, int, const VALUE*, const char*, ...); +VALUE rb_call_super(int, const VALUE*); +VALUE rb_call_super_kw(int, const VALUE*, int); +VALUE rb_current_receiver(void); +int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *); +VALUE rb_extract_keywords(VALUE *orighash); + +/* rb_scan_args() format allows ':' for optional hash */ +#define HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1 + +VALUE rb_gv_set(const char*, VALUE); +VALUE rb_gv_get(const char*); +VALUE rb_iv_get(VALUE, const char*); +VALUE rb_iv_set(VALUE, const char*, VALUE); + +VALUE rb_equal(VALUE,VALUE); + +VALUE *rb_ruby_verbose_ptr(void); +VALUE *rb_ruby_debug_ptr(void); +#define ruby_verbose (*rb_ruby_verbose_ptr()) +#define ruby_debug (*rb_ruby_debug_ptr()) + +/* for rb_readwrite_sys_fail first argument */ +enum rb_io_wait_readwrite {RB_IO_WAIT_READABLE, RB_IO_WAIT_WRITABLE}; +#define RB_IO_WAIT_READABLE RB_IO_WAIT_READABLE +#define RB_IO_WAIT_WRITABLE RB_IO_WAIT_WRITABLE + +PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2); +COLDFUNC PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2); +NORETURN(void rb_bug_errno(const char*, int)); +NORETURN(void rb_sys_fail(const char*)); +NORETURN(void rb_sys_fail_str(VALUE)); +NORETURN(void rb_mod_sys_fail(VALUE, const char*)); +NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE)); +NORETURN(void rb_readwrite_sys_fail(enum rb_io_wait_readwrite, const char*)); +NORETURN(void rb_iter_break(void)); +NORETURN(void rb_iter_break_value(VALUE)); +NORETURN(void rb_exit(int)); +NORETURN(void rb_notimplement(void)); +VALUE rb_syserr_new(int, const char *); +VALUE rb_syserr_new_str(int n, VALUE arg); +NORETURN(void rb_syserr_fail(int, const char*)); +NORETURN(void rb_syserr_fail_str(int, VALUE)); +NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*)); +NORETURN(void rb_mod_syserr_fail_str(VALUE, int, VALUE)); +NORETURN(void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite, int, const char*)); + +/* reports if `-W' specified */ +PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4); +PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2); +/* reports always */ +COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4); + +#define RB_BLOCK_CALL_FUNC_STRICT 1 +#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1 +#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) \ + VALUE yielded_arg, VALUE callback_arg, int argc, const VALUE *argv, VALUE blockarg +typedef VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); +typedef rb_block_call_func *rb_block_call_func_t; + +VALUE rb_each(VALUE); +VALUE rb_yield(VALUE); +VALUE rb_yield_values(int n, ...); +VALUE rb_yield_values2(int n, const VALUE *argv); +VALUE rb_yield_values_kw(int n, const VALUE *argv, int kw_splat); +VALUE rb_yield_splat(VALUE); +VALUE rb_yield_splat_kw(VALUE, int); +VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); /* rb_block_call_func */ +#define RB_NO_KEYWORDS 0 +#define RB_PASS_KEYWORDS 1 +#define RB_PASS_EMPTY_KEYWORDS 2 /* Will be removed in 3.0 */ +#define RB_PASS_CALLED_KEYWORDS 3 +int rb_keyword_given_p(void); +int rb_block_given_p(void); +void rb_need_block(void); +VALUE rb_iterate(VALUE(*)(VALUE),VALUE,rb_block_call_func_t,VALUE); +VALUE rb_block_call(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE); +VALUE rb_block_call_kw(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE,int); +VALUE rb_rescue(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE); +VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...); +VALUE rb_vrescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,va_list); +VALUE rb_ensure(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE),VALUE); +VALUE rb_catch(const char*,rb_block_call_func_t,VALUE); +VALUE rb_catch_obj(VALUE,rb_block_call_func_t,VALUE); +NORETURN(void rb_throw(const char*,VALUE)); +NORETURN(void rb_throw_obj(VALUE,VALUE)); + +VALUE rb_require(const char*); + +RUBY_EXTERN VALUE rb_mKernel; +RUBY_EXTERN VALUE rb_mComparable; +RUBY_EXTERN VALUE rb_mEnumerable; +RUBY_EXTERN VALUE rb_mErrno; +RUBY_EXTERN VALUE rb_mFileTest; +RUBY_EXTERN VALUE rb_mGC; +RUBY_EXTERN VALUE rb_mMath; +RUBY_EXTERN VALUE rb_mProcess; +RUBY_EXTERN VALUE rb_mWaitReadable; +RUBY_EXTERN VALUE rb_mWaitWritable; + +RUBY_EXTERN VALUE rb_cBasicObject; +RUBY_EXTERN VALUE rb_cObject; +RUBY_EXTERN VALUE rb_cArray; +#ifndef RUBY_INTEGER_UNIFICATION +RUBY_EXTERN VALUE rb_cBignum; +#endif +RUBY_EXTERN VALUE rb_cBinding; +RUBY_EXTERN VALUE rb_cClass; +RUBY_EXTERN VALUE rb_cCont; +RUBY_EXTERN VALUE rb_cData; +RUBY_EXTERN VALUE rb_cDir; +RUBY_EXTERN VALUE rb_cEncoding; +RUBY_EXTERN VALUE rb_cEnumerator; +RUBY_EXTERN VALUE rb_cFalseClass; +RUBY_EXTERN VALUE rb_cFile; +#ifndef RUBY_INTEGER_UNIFICATION +RUBY_EXTERN VALUE rb_cFixnum; +#endif +RUBY_EXTERN VALUE rb_cComplex; +RUBY_EXTERN VALUE rb_cFloat; +RUBY_EXTERN VALUE rb_cHash; +RUBY_EXTERN VALUE rb_cIO; +RUBY_EXTERN VALUE rb_cInteger; +RUBY_EXTERN VALUE rb_cMatch; +RUBY_EXTERN VALUE rb_cMethod; +RUBY_EXTERN VALUE rb_cModule; +RUBY_EXTERN VALUE rb_cNameErrorMesg; +RUBY_EXTERN VALUE rb_cNilClass; +RUBY_EXTERN VALUE rb_cNumeric; +RUBY_EXTERN VALUE rb_cProc; +RUBY_EXTERN VALUE rb_cRandom; +RUBY_EXTERN VALUE rb_cRange; +RUBY_EXTERN VALUE rb_cRational; +RUBY_EXTERN VALUE rb_cRegexp; +RUBY_EXTERN VALUE rb_cStat; +RUBY_EXTERN VALUE rb_cString; +RUBY_EXTERN VALUE rb_cStruct; +RUBY_EXTERN VALUE rb_cSymbol; +RUBY_EXTERN VALUE rb_cThread; +RUBY_EXTERN VALUE rb_cTime; +RUBY_EXTERN VALUE rb_cTrueClass; +RUBY_EXTERN VALUE rb_cUnboundMethod; + +RUBY_EXTERN VALUE rb_eException; +RUBY_EXTERN VALUE rb_eStandardError; +RUBY_EXTERN VALUE rb_eSystemExit; +RUBY_EXTERN VALUE rb_eInterrupt; +RUBY_EXTERN VALUE rb_eSignal; +RUBY_EXTERN VALUE rb_eFatal; +RUBY_EXTERN VALUE rb_eArgError; +RUBY_EXTERN VALUE rb_eEOFError; +RUBY_EXTERN VALUE rb_eIndexError; +RUBY_EXTERN VALUE rb_eStopIteration; +RUBY_EXTERN VALUE rb_eKeyError; +RUBY_EXTERN VALUE rb_eRangeError; +RUBY_EXTERN VALUE rb_eIOError; +RUBY_EXTERN VALUE rb_eRuntimeError; +RUBY_EXTERN VALUE rb_eFrozenError; +RUBY_EXTERN VALUE rb_eSecurityError; +RUBY_EXTERN VALUE rb_eSystemCallError; +RUBY_EXTERN VALUE rb_eThreadError; +RUBY_EXTERN VALUE rb_eTypeError; +RUBY_EXTERN VALUE rb_eZeroDivError; +RUBY_EXTERN VALUE rb_eNotImpError; +RUBY_EXTERN VALUE rb_eNoMemError; +RUBY_EXTERN VALUE rb_eNoMethodError; +RUBY_EXTERN VALUE rb_eFloatDomainError; +RUBY_EXTERN VALUE rb_eLocalJumpError; +RUBY_EXTERN VALUE rb_eSysStackError; +RUBY_EXTERN VALUE rb_eRegexpError; +RUBY_EXTERN VALUE rb_eEncodingError; +RUBY_EXTERN VALUE rb_eEncCompatError; +RUBY_EXTERN VALUE rb_eNoMatchingPatternError; + +RUBY_EXTERN VALUE rb_eScriptError; +RUBY_EXTERN VALUE rb_eNameError; +RUBY_EXTERN VALUE rb_eSyntaxError; +RUBY_EXTERN VALUE rb_eLoadError; + +RUBY_EXTERN VALUE rb_eMathDomainError; + +RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr; + +static inline VALUE +rb_class_of(VALUE obj) +{ + if (RB_IMMEDIATE_P(obj)) { + if (RB_FIXNUM_P(obj)) return rb_cInteger; + if (RB_FLONUM_P(obj)) return rb_cFloat; + if (obj == RUBY_Qtrue) return rb_cTrueClass; + if (RB_STATIC_SYM_P(obj)) return rb_cSymbol; + } + else if (!RB_TEST(obj)) { + if (obj == RUBY_Qnil) return rb_cNilClass; + if (obj == RUBY_Qfalse) return rb_cFalseClass; + } + return RBASIC(obj)->klass; +} + +static inline int +rb_type(VALUE obj) +{ + if (RB_IMMEDIATE_P(obj)) { + if (RB_FIXNUM_P(obj)) return RUBY_T_FIXNUM; + if (RB_FLONUM_P(obj)) return RUBY_T_FLOAT; + if (obj == RUBY_Qtrue) return RUBY_T_TRUE; + if (RB_STATIC_SYM_P(obj)) return RUBY_T_SYMBOL; + if (obj == RUBY_Qundef) return RUBY_T_UNDEF; + } + else if (!RB_TEST(obj)) { + if (obj == RUBY_Qnil) return RUBY_T_NIL; + if (obj == RUBY_Qfalse) return RUBY_T_FALSE; + } + return RB_BUILTIN_TYPE(obj); +} + +#ifdef __GNUC__ +#define rb_type_p(obj, type) \ + __extension__ (__builtin_constant_p(type) ? RB_TYPE_P((obj), (type)) : \ + rb_type(obj) == (type)) +#else +#define rb_type_p(obj, type) (rb_type(obj) == (type)) +#endif + +#ifdef __GNUC__ +#define rb_special_const_p(obj) \ + __extension__ ({ \ + VALUE special_const_obj = (obj); \ + (int)(RB_SPECIAL_CONST_P(special_const_obj) ? RUBY_Qtrue : RUBY_Qfalse); \ + }) +#else +static inline int +rb_special_const_p(VALUE obj) +{ + if (RB_SPECIAL_CONST_P(obj)) return (int)RUBY_Qtrue; + return (int)RUBY_Qfalse; +} +#endif + +#include "ruby/intern.h" + +static inline void +rb_clone_setup(VALUE clone, VALUE obj) +{ + rb_obj_setup(clone, rb_singleton_class_clone(obj), + RBASIC(obj)->flags & ~(FL_PROMOTED0|FL_PROMOTED1|FL_FINALIZE)); + rb_singleton_class_attached(RBASIC_CLASS(clone), clone); + if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(clone, obj); +} + +static inline void +rb_dup_setup(VALUE dup, VALUE obj) +{ + rb_obj_setup(dup, rb_obj_class(obj), RB_FL_TEST_RAW(obj, RUBY_FL_DUPPED)); + if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(dup, obj); +} + +static inline long +rb_array_len(VALUE a) +{ + return (RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? + RARRAY_EMBED_LEN(a) : RARRAY(a)->as.heap.len; +} + +#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 + +/* internal function. do not use this function */ +static inline const VALUE * +rb_array_const_ptr_transient(VALUE a) +{ + return FIX_CONST_VALUE_PTR((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? + RARRAY(a)->as.ary : RARRAY(a)->as.heap.ptr); +} + +/* internal function. do not use this function */ +static inline const VALUE * +rb_array_const_ptr(VALUE a) +{ +#if USE_TRANSIENT_HEAP + void rb_ary_detransient(VALUE a); + + if (RARRAY_TRANSIENT_P(a)) { + rb_ary_detransient(a); + } +#endif + return rb_array_const_ptr_transient(a); +} + +/* internal function. do not use this function */ +static inline VALUE * +rb_array_ptr_use_start(VALUE a, int allow_transient) +{ + VALUE *rb_ary_ptr_use_start(VALUE ary); + +#if USE_TRANSIENT_HEAP + if (!allow_transient) { + if (RARRAY_TRANSIENT_P(a)) { + void rb_ary_detransient(VALUE a); + rb_ary_detransient(a); + } + } +#endif + (void)allow_transient; + + return rb_ary_ptr_use_start(a); +} + +/* internal function. do not use this function */ +static inline void +rb_array_ptr_use_end(VALUE a, int allow_transient) +{ + void rb_ary_ptr_use_end(VALUE a); + rb_ary_ptr_use_end(a); + (void)allow_transient; +} + +#if defined(EXTLIB) && defined(USE_DLN_A_OUT) +/* hook for external modules */ +static char *dln_libs_to_be_linked[] = { EXTLIB, 0 }; +#endif + +#define RUBY_VM 1 /* YARV */ +#define HAVE_NATIVETHREAD +int ruby_native_thread_p(void); + +/* traditional set_trace_func events */ +#define RUBY_EVENT_NONE 0x0000 +#define RUBY_EVENT_LINE 0x0001 +#define RUBY_EVENT_CLASS 0x0002 +#define RUBY_EVENT_END 0x0004 +#define RUBY_EVENT_CALL 0x0008 +#define RUBY_EVENT_RETURN 0x0010 +#define RUBY_EVENT_C_CALL 0x0020 +#define RUBY_EVENT_C_RETURN 0x0040 +#define RUBY_EVENT_RAISE 0x0080 +#define RUBY_EVENT_ALL 0x00ff + +/* for TracePoint extended events */ +#define RUBY_EVENT_B_CALL 0x0100 +#define RUBY_EVENT_B_RETURN 0x0200 +#define RUBY_EVENT_THREAD_BEGIN 0x0400 +#define RUBY_EVENT_THREAD_END 0x0800 +#define RUBY_EVENT_FIBER_SWITCH 0x1000 +#define RUBY_EVENT_SCRIPT_COMPILED 0x2000 +#define RUBY_EVENT_TRACEPOINT_ALL 0xffff + +/* special events */ +#define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 + +/* internal events */ +#define RUBY_INTERNAL_EVENT_SWITCH 0x040000 +#define RUBY_EVENT_SWITCH 0x040000 /* obsolete name. this macro is for compatibility */ + /* 0x080000 */ +#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 +#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 +#define RUBY_INTERNAL_EVENT_GC_START 0x400000 +#define RUBY_INTERNAL_EVENT_GC_END_MARK 0x800000 +#define RUBY_INTERNAL_EVENT_GC_END_SWEEP 0x1000000 +#define RUBY_INTERNAL_EVENT_GC_ENTER 0x2000000 +#define RUBY_INTERNAL_EVENT_GC_EXIT 0x4000000 +#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x7f00000 +#define RUBY_INTERNAL_EVENT_MASK 0xffff0000 + +typedef uint32_t rb_event_flag_t; +typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass); + +#define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1 +void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); +int rb_remove_event_hook(rb_event_hook_func_t func); + +/* locale insensitive functions */ + +static inline int rb_isascii(int c){ return '\0' <= c && c <= '\x7f'; } +static inline int rb_isupper(int c){ return 'A' <= c && c <= 'Z'; } +static inline int rb_islower(int c){ return 'a' <= c && c <= 'z'; } +static inline int rb_isalpha(int c){ return rb_isupper(c) || rb_islower(c); } +static inline int rb_isdigit(int c){ return '0' <= c && c <= '9'; } +static inline int rb_isalnum(int c){ return rb_isalpha(c) || rb_isdigit(c); } +static inline int rb_isxdigit(int c){ return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); } +static inline int rb_isblank(int c){ return c == ' ' || c == '\t'; } +static inline int rb_isspace(int c){ return c == ' ' || ('\t' <= c && c <= '\r'); } +static inline int rb_iscntrl(int c){ return ('\0' <= c && c < ' ') || c == '\x7f'; } +static inline int rb_isprint(int c){ return ' ' <= c && c <= '\x7e'; } +static inline int rb_ispunct(int c){ return !rb_isalnum(c); } +static inline int rb_isgraph(int c){ return '!' <= c && c <= '\x7e'; } +static inline int rb_tolower(int c) { return rb_isupper(c) ? (c|0x20) : c; } +static inline int rb_toupper(int c) { return rb_islower(c) ? (c&0x5f) : c; } + +#ifndef ISPRINT +#define ISASCII(c) rb_isascii(c) +#define ISPRINT(c) rb_isprint(c) +#define ISGRAPH(c) rb_isgraph(c) +#define ISSPACE(c) rb_isspace(c) +#define ISUPPER(c) rb_isupper(c) +#define ISLOWER(c) rb_islower(c) +#define ISALNUM(c) rb_isalnum(c) +#define ISALPHA(c) rb_isalpha(c) +#define ISDIGIT(c) rb_isdigit(c) +#define ISXDIGIT(c) rb_isxdigit(c) +#define ISBLANK(c) rb_isblank(c) +#define ISCNTRL(c) rb_iscntrl(c) +#define ISPUNCT(c) rb_ispunct(c) +#endif +#define TOUPPER(c) rb_toupper(c) +#define TOLOWER(c) rb_tolower(c) + +int st_locale_insensitive_strcasecmp(const char *s1, const char *s2); +int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n); +#define STRCASECMP(s1, s2) (st_locale_insensitive_strcasecmp((s1), (s2))) +#define STRNCASECMP(s1, s2, n) (st_locale_insensitive_strncasecmp((s1), (s2), (n))) + +unsigned long ruby_strtoul(const char *str, char **endptr, int base); +#define STRTOUL(str, endptr, base) (ruby_strtoul((str), (endptr), (base))) + +#define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();} + +PRINTF_ARGS(int ruby_snprintf(char *str, size_t n, char const *fmt, ...), 3, 4); +int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap); + +/* -- Remove In 3.0, Only public for rb_scan_args optimized version -- */ +int rb_empty_keyword_given_p(void); + +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) && defined(HAVE_VA_ARGS_MACRO) && defined(__OPTIMIZE__) +# define rb_scan_args(argc,argvp,fmt,...) \ + __builtin_choose_expr(__builtin_constant_p(fmt), \ + rb_scan_args0(argc,argvp,fmt,\ + (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ + ((VALUE*[]){__VA_ARGS__})), \ + rb_scan_args(argc,argvp,fmt,##__VA_ARGS__)) +# if HAVE_ATTRIBUTE_ERRORFUNC +ERRORFUNC(("bad scan arg format"), void rb_scan_args_bad_format(const char*)); +ERRORFUNC(("variable argument length doesn't match"), void rb_scan_args_length_mismatch(const char*,int)); +# else +# define rb_scan_args_bad_format(fmt) ((void)0) +# define rb_scan_args_length_mismatch(fmt, varc) ((void)0) +# endif + +# define rb_scan_args_isdigit(c) ((unsigned char)((c)-'0')<10) + +# define rb_scan_args_count_end(fmt, ofs, vari) \ + (fmt[ofs] ? -1 : (vari)) + +# define rb_scan_args_count_block(fmt, ofs, vari) \ + (fmt[ofs]!='&' ? \ + rb_scan_args_count_end(fmt, ofs, vari) : \ + rb_scan_args_count_end(fmt, ofs+1, vari+1)) + +# define rb_scan_args_count_hash(fmt, ofs, vari) \ + (fmt[ofs]!=':' ? \ + rb_scan_args_count_block(fmt, ofs, vari) : \ + rb_scan_args_count_block(fmt, ofs+1, vari+1)) + +# define rb_scan_args_count_trail(fmt, ofs, vari) \ + (!rb_scan_args_isdigit(fmt[ofs]) ? \ + rb_scan_args_count_hash(fmt, ofs, vari) : \ + rb_scan_args_count_hash(fmt, ofs+1, vari+(fmt[ofs]-'0'))) + +# define rb_scan_args_count_var(fmt, ofs, vari) \ + (fmt[ofs]!='*' ? \ + rb_scan_args_count_trail(fmt, ofs, vari) : \ + rb_scan_args_count_trail(fmt, ofs+1, vari+1)) + +# define rb_scan_args_count_opt(fmt, ofs, vari) \ + (!rb_scan_args_isdigit(fmt[ofs]) ? \ + rb_scan_args_count_var(fmt, ofs, vari) : \ + rb_scan_args_count_var(fmt, ofs+1, vari+fmt[ofs]-'0')) + +# define rb_scan_args_count_lead(fmt, ofs, vari) \ + (!rb_scan_args_isdigit(fmt[ofs]) ? \ + rb_scan_args_count_var(fmt, ofs, vari) : \ + rb_scan_args_count_opt(fmt, ofs+1, vari+fmt[ofs]-'0')) + +# define rb_scan_args_count(fmt) rb_scan_args_count_lead(fmt, 0, 0) + +# if defined(__has_attribute) && __has_attribute(diagnose_if) +# define rb_scan_args_verify(fmt, varc) (void)0 +# else +# define rb_scan_args_verify(fmt, varc) \ + (sizeof(char[1-2*(rb_scan_args_count(fmt)<0)])!=1 ? \ + rb_scan_args_bad_format(fmt) : \ + sizeof(char[1-2*(rb_scan_args_count(fmt)!=(varc))])!=1 ? \ + rb_scan_args_length_mismatch(fmt, varc) : \ + (void)0) +# endif + +ALWAYS_INLINE(static int rb_scan_args_lead_p(const char *fmt)); +static inline int +rb_scan_args_lead_p(const char *fmt) +{ + return rb_scan_args_isdigit(fmt[0]); +} + +ALWAYS_INLINE(static int rb_scan_args_n_lead(const char *fmt)); +static inline int +rb_scan_args_n_lead(const char *fmt) +{ + return (rb_scan_args_lead_p(fmt) ? fmt[0]-'0' : 0); +} + +ALWAYS_INLINE(static int rb_scan_args_opt_p(const char *fmt)); +static inline int +rb_scan_args_opt_p(const char *fmt) +{ + return (rb_scan_args_lead_p(fmt) && rb_scan_args_isdigit(fmt[1])); +} + +ALWAYS_INLINE(static int rb_scan_args_n_opt(const char *fmt)); +static inline int +rb_scan_args_n_opt(const char *fmt) +{ + return (rb_scan_args_opt_p(fmt) ? fmt[1]-'0' : 0); +} + +ALWAYS_INLINE(static int rb_scan_args_var_idx(const char *fmt)); +static inline int +rb_scan_args_var_idx(const char *fmt) +{ + return (!rb_scan_args_lead_p(fmt) ? 0 : !rb_scan_args_isdigit(fmt[1]) ? 1 : 2); +} + +ALWAYS_INLINE(static int rb_scan_args_f_var(const char *fmt)); +static inline int +rb_scan_args_f_var(const char *fmt) +{ + return (fmt[rb_scan_args_var_idx(fmt)]=='*'); +} + +ALWAYS_INLINE(static int rb_scan_args_trail_idx(const char *fmt)); +static inline int +rb_scan_args_trail_idx(const char *fmt) +{ + const int idx = rb_scan_args_var_idx(fmt); + return idx+(fmt[idx]=='*'); +} + +ALWAYS_INLINE(static int rb_scan_args_n_trail(const char *fmt)); +static inline int +rb_scan_args_n_trail(const char *fmt) +{ + const int idx = rb_scan_args_trail_idx(fmt); + return (rb_scan_args_isdigit(fmt[idx]) ? fmt[idx]-'0' : 0); +} + +ALWAYS_INLINE(static int rb_scan_args_hash_idx(const char *fmt)); +static inline int +rb_scan_args_hash_idx(const char *fmt) +{ + const int idx = rb_scan_args_trail_idx(fmt); + return idx+rb_scan_args_isdigit(fmt[idx]); +} + +ALWAYS_INLINE(static int rb_scan_args_f_hash(const char *fmt)); +static inline int +rb_scan_args_f_hash(const char *fmt) +{ + return (fmt[rb_scan_args_hash_idx(fmt)]==':'); +} + +ALWAYS_INLINE(static int rb_scan_args_block_idx(const char *fmt)); +static inline int +rb_scan_args_block_idx(const char *fmt) +{ + const int idx = rb_scan_args_hash_idx(fmt); + return idx+(fmt[idx]==':'); +} + +ALWAYS_INLINE(static int rb_scan_args_f_block(const char *fmt)); +static inline int +rb_scan_args_f_block(const char *fmt) +{ + return (fmt[rb_scan_args_block_idx(fmt)]=='&'); +} + +# if 0 +ALWAYS_INLINE(static int rb_scan_args_end_idx(const char *fmt)); +static inline int +rb_scan_args_end_idx(const char *fmt) +{ + const int idx = rb_scan_args_block_idx(fmt); + return idx+(fmt[idx]=='&'); +} +# endif + +/* NOTE: Use `char *fmt` instead of `const char *fmt` because of clang's bug*/ +/* https://bugs.llvm.org/show_bug.cgi?id=38095 */ +# define rb_scan_args0(argc, argv, fmt, varc, vars) \ + rb_scan_args_set(argc, argv, \ + rb_scan_args_n_lead(fmt), \ + rb_scan_args_n_opt(fmt), \ + rb_scan_args_n_trail(fmt), \ + rb_scan_args_f_var(fmt), \ + rb_scan_args_f_hash(fmt), \ + rb_scan_args_f_block(fmt), \ + (rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc) +ALWAYS_INLINE(static int +rb_scan_args_set(int argc, const VALUE *argv, + int n_lead, int n_opt, int n_trail, + int f_var, int f_hash, int f_block, + VALUE *vars[], char *fmt, int varc)); + +inline int +rb_scan_args_set(int argc, const VALUE *argv, + int n_lead, int n_opt, int n_trail, + int f_var, int f_hash, int f_block, + VALUE *vars[], RB_UNUSED_VAR(char *fmt), RB_UNUSED_VAR(int varc)) +# if defined(__has_attribute) && __has_attribute(diagnose_if) + __attribute__((diagnose_if(rb_scan_args_count(fmt)<0,"bad scan arg format","error"))) + __attribute__((diagnose_if(rb_scan_args_count(fmt)!=varc,"variable argument length doesn't match","error"))) +# endif +{ + int i, argi = 0, vari = 0, last_idx = -1; + VALUE *var, hash = Qnil, last_hash = 0; + const int n_mand = n_lead + n_trail; + int keyword_given = rb_keyword_given_p(); + int empty_keyword_given = 0; + VALUE tmp_buffer = 0; + + if (!keyword_given) { + empty_keyword_given = rb_empty_keyword_given_p(); + } + + /* capture an option hash - phase 1: pop */ + /* Ignore final positional hash if empty keywords given */ + if (argc > 0 && !(f_hash && empty_keyword_given)) { + VALUE last = argv[argc - 1]; + + if (f_hash && n_mand < argc) { + if (keyword_given) { + if (!RB_TYPE_P(last, T_HASH)) { + rb_warn("Keyword flag set when calling rb_scan_args, but last entry is not a hash"); + } + else { + hash = last; + } + } + else if (NIL_P(last)) { + /* For backwards compatibility, nil is taken as an empty + option hash only if it is not ambiguous; i.e. '*' is + not specified and arguments are given more than sufficient. + This will be removed in Ruby 3. */ + if (!f_var && n_mand + n_opt < argc) { + rb_warn("The last argument is nil, treating as empty keywords"); + argc--; + } + } + else { + hash = rb_check_hash_type(last); + } + + /* Ruby 3: Remove if branch, as it will not attempt to split hashes */ + if (!NIL_P(hash)) { + VALUE opts = rb_extract_keywords(&hash); + + if (!(last_hash = hash)) { + if (!keyword_given) { + /* Warn if treating positional as keyword, as in Ruby 3, + this will be an error */ + rb_warn("Using the last argument as keyword parameters is deprecated"); + } + argc--; + } + else { + /* Warn if splitting either positional hash to keywords or keywords + to positional hash, as in Ruby 3, no splitting will be done */ + rb_warn("The last argument is split into positional and keyword parameters"); + last_idx = argc - 1; + } + hash = opts ? opts : Qnil; + } + } + else if (f_hash && keyword_given && n_mand == argc) { + /* Warn if treating keywords as positional, as in Ruby 3, this will be an error */ + rb_warn("Passing the keyword argument as the last hash parameter is deprecated"); + } + } + if (f_hash && n_mand > 0 && n_mand == argc+1 && empty_keyword_given) { + VALUE *ptr = (VALUE *)rb_alloc_tmp_buffer2(&tmp_buffer, argc+1, sizeof(VALUE)); + memcpy(ptr, argv, sizeof(VALUE)*argc); + ptr[argc] = rb_hash_new(); + argc++; + *(&argv) = ptr; + rb_warn("Passing the keyword argument as the last hash parameter is deprecated"); + } + + + if (argc < n_mand) { + goto argc_error; + } + + /* capture leading mandatory arguments */ + for (i = n_lead; i-- > 0; ) { + var = vars[vari++]; + if (var) *var = (argi == last_idx) ? last_hash : argv[argi]; + argi++; + } + /* capture optional arguments */ + for (i = n_opt; i-- > 0; ) { + var = vars[vari++]; + if (argi < argc - n_trail) { + if (var) *var = (argi == last_idx) ? last_hash : argv[argi]; + argi++; + } + else { + if (var) *var = Qnil; + } + } + /* capture variable length arguments */ + if (f_var) { + int n_var = argc - argi - n_trail; + + var = vars[vari++]; + if (0 < n_var) { + if (var) { + int f_last = (last_idx + 1 == argc - n_trail); + *var = rb_ary_new4(n_var-f_last, &argv[argi]); + if (f_last) rb_ary_push(*var, last_hash); + } + argi += n_var; + } + else { + if (var) *var = rb_ary_new(); + } + } + /* capture trailing mandatory arguments */ + for (i = n_trail; i-- > 0; ) { + var = vars[vari++]; + if (var) *var = (argi == last_idx) ? last_hash : argv[argi]; + argi++; + } + /* capture an option hash - phase 2: assignment */ + if (f_hash) { + var = vars[vari++]; + if (var) *var = hash; + } + /* capture iterator block */ + if (f_block) { + var = vars[vari++]; + if (rb_block_given_p()) { + *var = rb_block_proc(); + } + else { + *var = Qnil; + } + } + + if (argi < argc) { + argc_error: + if (tmp_buffer) rb_free_tmp_buffer(&tmp_buffer); + rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt); + } + + if (tmp_buffer) rb_free_tmp_buffer(&tmp_buffer); + return argc; +} +#endif + +#if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO) && defined(__OPTIMIZE__) +# define rb_yield_values(argc, ...) \ +__extension__({ \ + const int rb_yield_values_argc = (argc); \ + const VALUE rb_yield_values_args[] = {__VA_ARGS__}; \ + const int rb_yield_values_nargs = \ + (int)(sizeof(rb_yield_values_args) / sizeof(VALUE)); \ + rb_yield_values2( \ + rb_varargs_argc_check(rb_yield_values_argc, rb_yield_values_nargs), \ + rb_yield_values_nargs ? rb_yield_values_args : NULL); \ + }) + +# define rb_funcall(recv, mid, argc, ...) \ +__extension__({ \ + const int rb_funcall_argc = (argc); \ + const VALUE rb_funcall_args[] = {__VA_ARGS__}; \ + const int rb_funcall_nargs = \ + (int)(sizeof(rb_funcall_args) / sizeof(VALUE)); \ + rb_funcallv(recv, mid, \ + rb_varargs_argc_check(rb_funcall_argc, rb_funcall_nargs), \ + rb_funcall_nargs ? rb_funcall_args : NULL); \ + }) +#endif + +#ifndef RUBY_DONT_SUBST +#include "ruby/subst.h" +#endif + +/** + * @defgroup embed CRuby Embedding APIs + * CRuby interpreter APIs. These are APIs to embed MRI interpreter into your + * program. + * These functions are not a part of Ruby extension library API. + * Extension libraries of Ruby should not depend on these functions. + * @{ + */ + +/** @defgroup ruby1 ruby(1) implementation + * A part of the implementation of ruby(1) command. + * Other programs that embed Ruby interpreter do not always need to use these + * functions. + * @{ + */ + +void ruby_sysinit(int *argc, char ***argv); +void ruby_init(void); +void* ruby_options(int argc, char** argv); +int ruby_executable_node(void *n, int *status); +int ruby_run_node(void *n); + +/* version.c */ +void ruby_show_version(void); +void ruby_show_copyright(void); + + +/*! A convenience macro to call ruby_init_stack(). Must be placed just after + * variable declarations */ +#define RUBY_INIT_STACK \ + VALUE variable_in_this_stack_frame; \ + ruby_init_stack(&variable_in_this_stack_frame); +/*! @} */ + +void ruby_init_stack(volatile VALUE*); + +int ruby_setup(void); +int ruby_cleanup(volatile int); + +void ruby_finalize(void); +NORETURN(void ruby_stop(int)); + +void ruby_set_stack_size(size_t); +int ruby_stack_check(void); +size_t ruby_stack_length(VALUE**); + +int ruby_exec_node(void *n); + +void ruby_script(const char* name); +void ruby_set_script_name(VALUE name); + +void ruby_prog_init(void); +void ruby_set_argv(int, char**); +void *ruby_process_options(int, char**); +void ruby_init_loadpath(void); +void ruby_incpush(const char*); +void ruby_sig_finalize(void); + +/*! @} */ + +#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY +# include "ruby/backward.h" +#endif + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +extern "C++" { +#endif + +#ifdef RB_METHOD_DEFINITION_DECL + +RB_METHOD_DEFINITION_DECL(rb_define_method, (2,3), (VALUE klass, const char *name), (klass, name)) +#ifdef __cplusplus +#define rb_define_method(m, n, f, a) rb_define_method_tmpl<a>::define(m, n, f) +#else +#define rb_define_method_if_constexpr(x, t, f) __builtin_choose_expr(__builtin_choose_expr(__builtin_constant_p(x),(x),0),(t),(f)) +#define rb_define_method_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_method15,rb_define_methodm3) +#define rb_define_method_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_method14,rb_define_method_choose_prototype15(n)) +#define rb_define_method_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_method13,rb_define_method_choose_prototype14(n)) +#define rb_define_method_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_method12,rb_define_method_choose_prototype13(n)) +#define rb_define_method_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_method11,rb_define_method_choose_prototype12(n)) +#define rb_define_method_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_method10,rb_define_method_choose_prototype11(n)) +#define rb_define_method_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_method9, rb_define_method_choose_prototype10(n)) +#define rb_define_method_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_method8, rb_define_method_choose_prototype9(n)) +#define rb_define_method_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_method7, rb_define_method_choose_prototype8(n)) +#define rb_define_method_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_method6, rb_define_method_choose_prototype7(n)) +#define rb_define_method_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_method5, rb_define_method_choose_prototype6(n)) +#define rb_define_method_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_method4, rb_define_method_choose_prototype5(n)) +#define rb_define_method_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_method3, rb_define_method_choose_prototype4(n)) +#define rb_define_method_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_method2, rb_define_method_choose_prototype3(n)) +#define rb_define_method_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_method1, rb_define_method_choose_prototype2(n)) +#define rb_define_method_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_method0, rb_define_method_choose_prototype1(n)) +#define rb_define_method_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_methodm1,rb_define_method_choose_prototype0(n)) +#define rb_define_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_methodm2,rb_define_method_choose_prototypem1(n)) +#define rb_define_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_methodm3,rb_define_method_choose_prototypem2(n)) +#define rb_define_method(klass, mid, func, arity) rb_define_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity)); +#endif + +RB_METHOD_DEFINITION_DECL(rb_define_module_function, (2,3), (VALUE klass, const char *name), (klass, name)) +#ifdef __cplusplus +#define rb_define_module_function(m, n, f, a) rb_define_module_function_tmpl<a>::define(m, n, f) +#else +#define rb_define_module_function_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_module_function15,rb_define_module_functionm3) +#define rb_define_module_function_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_module_function14,rb_define_module_function_choose_prototype15(n)) +#define rb_define_module_function_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_module_function13,rb_define_module_function_choose_prototype14(n)) +#define rb_define_module_function_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_module_function12,rb_define_module_function_choose_prototype13(n)) +#define rb_define_module_function_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_module_function11,rb_define_module_function_choose_prototype12(n)) +#define rb_define_module_function_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_module_function10,rb_define_module_function_choose_prototype11(n)) +#define rb_define_module_function_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_module_function9, rb_define_module_function_choose_prototype10(n)) +#define rb_define_module_function_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_module_function8, rb_define_module_function_choose_prototype9(n)) +#define rb_define_module_function_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_module_function7, rb_define_module_function_choose_prototype8(n)) +#define rb_define_module_function_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_module_function6, rb_define_module_function_choose_prototype7(n)) +#define rb_define_module_function_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_module_function5, rb_define_module_function_choose_prototype6(n)) +#define rb_define_module_function_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_module_function4, rb_define_module_function_choose_prototype5(n)) +#define rb_define_module_function_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_module_function3, rb_define_module_function_choose_prototype4(n)) +#define rb_define_module_function_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_module_function2, rb_define_module_function_choose_prototype3(n)) +#define rb_define_module_function_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_module_function1, rb_define_module_function_choose_prototype2(n)) +#define rb_define_module_function_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_module_function0, rb_define_module_function_choose_prototype1(n)) +#define rb_define_module_function_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_module_functionm1,rb_define_module_function_choose_prototype0(n)) +#define rb_define_module_function_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_module_functionm2,rb_define_module_function_choose_prototypem1(n)) +#define rb_define_module_function_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_module_functionm3,rb_define_module_function_choose_prototypem2(n)) +#define rb_define_module_function(klass, mid, func, arity) rb_define_module_function_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity)); +#endif + +RB_METHOD_DEFINITION_DECL(rb_define_global_function, (1,2), (const char *name), (name)) +#ifdef __cplusplus +#define rb_define_global_function(n, f, a) rb_define_global_function_tmpl<a>::define(n, f) +#else +#define rb_define_global_function_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_global_function15,rb_define_global_functionm3) +#define rb_define_global_function_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_global_function14,rb_define_global_function_choose_prototype15(n)) +#define rb_define_global_function_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_global_function13,rb_define_global_function_choose_prototype14(n)) +#define rb_define_global_function_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_global_function12,rb_define_global_function_choose_prototype13(n)) +#define rb_define_global_function_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_global_function11,rb_define_global_function_choose_prototype12(n)) +#define rb_define_global_function_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_global_function10,rb_define_global_function_choose_prototype11(n)) +#define rb_define_global_function_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_global_function9, rb_define_global_function_choose_prototype10(n)) +#define rb_define_global_function_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_global_function8, rb_define_global_function_choose_prototype9(n)) +#define rb_define_global_function_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_global_function7, rb_define_global_function_choose_prototype8(n)) +#define rb_define_global_function_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_global_function6, rb_define_global_function_choose_prototype7(n)) +#define rb_define_global_function_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_global_function5, rb_define_global_function_choose_prototype6(n)) +#define rb_define_global_function_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_global_function4, rb_define_global_function_choose_prototype5(n)) +#define rb_define_global_function_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_global_function3, rb_define_global_function_choose_prototype4(n)) +#define rb_define_global_function_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_global_function2, rb_define_global_function_choose_prototype3(n)) +#define rb_define_global_function_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_global_function1, rb_define_global_function_choose_prototype2(n)) +#define rb_define_global_function_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_global_function0, rb_define_global_function_choose_prototype1(n)) +#define rb_define_global_function_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_global_functionm1,rb_define_global_function_choose_prototype0(n)) +#define rb_define_global_function_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_global_functionm2,rb_define_global_function_choose_prototypem1(n)) +#define rb_define_global_function_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_global_functionm3,rb_define_global_function_choose_prototypem2(n)) +#define rb_define_global_function(mid, func, arity) rb_define_global_function_choose_prototypem3((arity),(func))((mid),(func),(arity)); +#endif + +#endif + +#if defined(RUBY_DEVEL) && RUBY_DEVEL && (!defined(__cplusplus) || defined(RB_METHOD_DEFINITION_DECL)) +# define RUBY_METHOD_FUNC(func) (func) +#else +# define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))(func)) +#endif + +#ifdef __cplusplus +#include "backward/cxxanyargs.hpp" + +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C++" { */ +#endif + +#endif /* RUBY_RUBY_H */ diff --git a/include/ruby/st.h b/include/ruby/st.h new file mode 100644 index 0000000000..ea1637bd9f --- /dev/null +++ b/include/ruby/st.h @@ -0,0 +1,197 @@ +/* This is a public domain general purpose hash table package + originally written by Peter Moore @ UCB. + + The hash table data strutures were redesigned and the package was + rewritten by Vladimir Makarov <vmakarov@redhat.com>. */ + +#ifndef RUBY_ST_H +#define RUBY_ST_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/defines.h" + +RUBY_SYMBOL_EXPORT_BEGIN + +#if SIZEOF_LONG == SIZEOF_VOIDP +typedef unsigned long st_data_t; +#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP +typedef unsigned LONG_LONG st_data_t; +#else +# error ---->> st.c requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<---- +#endif +#define ST_DATA_T_DEFINED + +#ifndef CHAR_BIT +# ifdef HAVE_LIMITS_H +# include <limits.h> +# else +# define CHAR_BIT 8 +# endif +#endif +#ifndef _ +# define _(args) args +#endif +#ifndef ANYARGS +# ifdef __cplusplus +# define ANYARGS ... +# else +# define ANYARGS +# endif +#endif + +typedef struct st_table st_table; + +typedef st_data_t st_index_t; + +/* Maximal value of unsigned integer type st_index_t. */ +#define MAX_ST_INDEX_VAL (~(st_index_t) 0) + +typedef int st_compare_func(st_data_t, st_data_t); +typedef st_index_t st_hash_func(st_data_t); + +typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1]; +#define SIZEOF_ST_INDEX_T SIZEOF_VOIDP + +struct st_hash_type { + int (*compare)(st_data_t, st_data_t); /* st_compare_func* */ + st_index_t (*hash)(st_data_t); /* st_hash_func* */ +}; + +#define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT) + +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P) +# define ST_DATA_COMPATIBLE_P(type) \ + __builtin_choose_expr(__builtin_types_compatible_p(type, st_data_t), 1, 0) +#else +# define ST_DATA_COMPATIBLE_P(type) 0 +#endif + +typedef struct st_table_entry st_table_entry; + +struct st_table_entry; /* defined in st.c */ + +struct st_table { + /* Cached features of the table -- see st.c for more details. */ + unsigned char entry_power, bin_power, size_ind; + /* How many times the table was rebuilt. */ + unsigned int rebuilds_num; + const struct st_hash_type *type; + /* Number of entries currently in the table. */ + st_index_t num_entries; + /* Array of bins used for access by keys. */ + st_index_t *bins; + /* Start and bound index of entries in array entries. + entries_starts and entries_bound are in interval + [0,allocated_entries]. */ + st_index_t entries_start, entries_bound; + /* Array of size 2^entry_power. */ + st_table_entry *entries; +}; + +#define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0) + +enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK, ST_REPLACE}; + +st_table *rb_st_init_table(const struct st_hash_type *); +#define st_init_table rb_st_init_table +st_table *rb_st_init_table_with_size(const struct st_hash_type *, st_index_t); +#define st_init_table_with_size rb_st_init_table_with_size +st_table *rb_st_init_numtable(void); +#define st_init_numtable rb_st_init_numtable +st_table *rb_st_init_numtable_with_size(st_index_t); +#define st_init_numtable_with_size rb_st_init_numtable_with_size +st_table *rb_st_init_strtable(void); +#define st_init_strtable rb_st_init_strtable +st_table *rb_st_init_strtable_with_size(st_index_t); +#define st_init_strtable_with_size rb_st_init_strtable_with_size +st_table *rb_st_init_strcasetable(void); +#define st_init_strcasetable rb_st_init_strcasetable +st_table *rb_st_init_strcasetable_with_size(st_index_t); +#define st_init_strcasetable_with_size rb_st_init_strcasetable_with_size +int rb_st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */ +#define st_delete rb_st_delete +int rb_st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t); +#define st_delete_safe rb_st_delete_safe +int rb_st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */ +#define st_shift rb_st_shift +int rb_st_insert(st_table *, st_data_t, st_data_t); +#define st_insert rb_st_insert +int rb_st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t)); +#define st_insert2 rb_st_insert2 +int rb_st_lookup(st_table *, st_data_t, st_data_t *); +#define st_lookup rb_st_lookup +int rb_st_get_key(st_table *, st_data_t, st_data_t *); +#define st_get_key rb_st_get_key +typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing); +/* *key may be altered, but must equal to the old key, i.e., the + * results of hash() are same and compare() returns 0, otherwise the + * behavior is undefined */ +int rb_st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg); +#define st_update rb_st_update +typedef int st_foreach_callback_func(st_data_t, st_data_t, st_data_t); +typedef int st_foreach_check_callback_func(st_data_t, st_data_t, st_data_t, int); +int rb_st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg); +#define st_foreach_with_replace rb_st_foreach_with_replace +int rb_st_foreach(st_table *, st_foreach_callback_func *, st_data_t); +#define st_foreach rb_st_foreach +int rb_st_foreach_check(st_table *, st_foreach_check_callback_func *, st_data_t, st_data_t); +#define st_foreach_check rb_st_foreach_check +st_index_t rb_st_keys(st_table *table, st_data_t *keys, st_index_t size); +#define st_keys rb_st_keys +st_index_t rb_st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never); +#define st_keys_check rb_st_keys_check +st_index_t rb_st_values(st_table *table, st_data_t *values, st_index_t size); +#define st_values rb_st_values +st_index_t rb_st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never); +#define st_values_check rb_st_values_check +void rb_st_add_direct(st_table *, st_data_t, st_data_t); +#define st_add_direct rb_st_add_direct +void rb_st_free_table(st_table *); +#define st_free_table rb_st_free_table +void rb_st_cleanup_safe(st_table *, st_data_t); +#define st_cleanup_safe rb_st_cleanup_safe +void rb_st_clear(st_table *); +#define st_clear rb_st_clear +st_table *rb_st_copy(st_table *); +#define st_copy rb_st_copy +CONSTFUNC(int rb_st_numcmp(st_data_t, st_data_t)); +#define st_numcmp rb_st_numcmp +CONSTFUNC(st_index_t rb_st_numhash(st_data_t)); +#define st_numhash rb_st_numhash +PUREFUNC(int rb_st_locale_insensitive_strcasecmp(const char *s1, const char *s2)); +#define st_locale_insensitive_strcasecmp rb_st_locale_insensitive_strcasecmp +PUREFUNC(int rb_st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n)); +#define st_locale_insensitive_strncasecmp rb_st_locale_insensitive_strncasecmp +#define st_strcasecmp rb_st_locale_insensitive_strcasecmp +#define st_strncasecmp rb_st_locale_insensitive_strncasecmp +PUREFUNC(size_t rb_st_memsize(const st_table *)); +#define st_memsize rb_st_memsize +PUREFUNC(st_index_t rb_st_hash(const void *ptr, size_t len, st_index_t h)); +#define st_hash rb_st_hash +CONSTFUNC(st_index_t rb_st_hash_uint32(st_index_t h, uint32_t i)); +#define st_hash_uint32 rb_st_hash_uint32 +CONSTFUNC(st_index_t rb_st_hash_uint(st_index_t h, st_index_t i)); +#define st_hash_uint rb_st_hash_uint +CONSTFUNC(st_index_t rb_st_hash_end(st_index_t h)); +#define st_hash_end rb_st_hash_end +CONSTFUNC(st_index_t rb_st_hash_start(st_index_t h)); +#define st_hash_start(h) ((st_index_t)(h)) + +void rb_hash_bulk_insert_into_st_table(long, const VALUE *, VALUE); + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_ST_H */ diff --git a/include/ruby/subst.h b/include/ruby/subst.h new file mode 100644 index 0000000000..1f0e6db5a4 --- /dev/null +++ b/include/ruby/subst.h @@ -0,0 +1,19 @@ +#ifndef RUBY_SUBST_H +#define RUBY_SUBST_H 1 + +#undef snprintf +#undef vsnprintf +#define snprintf ruby_snprintf +#define vsnprintf ruby_vsnprintf + +#ifdef BROKEN_CLOSE +#undef getpeername +#define getpeername ruby_getpeername +#undef getsockname +#define getsockname ruby_getsockname +#undef shutdown +#define shutdown ruby_shutdown +#undef close +#define close ruby_close +#endif +#endif diff --git a/include/ruby/thread.h b/include/ruby/thread.h new file mode 100644 index 0000000000..d398cc127e --- /dev/null +++ b/include/ruby/thread.h @@ -0,0 +1,57 @@ +/********************************************************************** + + thread.h - + + $Author: matz $ + created at: Tue Jul 10 17:35:43 JST 2012 + + Copyright (C) 2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_THREAD_H +#define RUBY_THREAD_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/intern.h" + +/* flags for rb_nogvl */ +#define RB_NOGVL_INTR_FAIL (0x1) +#define RB_NOGVL_UBF_ASYNC_SAFE (0x2) + +RUBY_SYMBOL_EXPORT_BEGIN + +void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1); + +void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1, + rb_unblock_function_t *ubf, void *data2); +void *rb_thread_call_without_gvl2(void *(*func)(void *), void *data1, + rb_unblock_function_t *ubf, void *data2); + +/* + * XXX: unstable/unapproved - out-of-tree code should NOT not depend + * on this until it hits Ruby 2.6.1 + */ +void *rb_nogvl(void *(*func)(void *), void *data1, + rb_unblock_function_t *ubf, void *data2, + int flags); + +#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_AFTER 0x01 +#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_ + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_THREAD_H */ diff --git a/include/ruby/thread_native.h b/include/ruby/thread_native.h new file mode 100644 index 0000000000..8e500c5a13 --- /dev/null +++ b/include/ruby/thread_native.h @@ -0,0 +1,56 @@ +/********************************************************************** + + thread_native.h - + + $Author: ko1 $ + created at: Wed May 14 19:37:31 2014 + + Copyright (C) 2014 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_THREAD_NATIVE_H +#define RUBY_THREAD_NATIVE_H 1 + +/* + * This file contains wrapper APIs for native thread primitives + * which Ruby interpreter uses. + * + * Now, we only suppors pthread and Windows threads. + * + * If you want to use Ruby's Mutex and so on to synchronize Ruby Threads, + * please use Mutex directly. + */ + + +#if defined(_WIN32) +#include <windows.h> +typedef HANDLE rb_nativethread_id_t; + +typedef union rb_thread_lock_union { + HANDLE mutex; + CRITICAL_SECTION crit; +} rb_nativethread_lock_t; + +#elif defined(HAVE_PTHREAD_H) +#include <pthread.h> +typedef pthread_t rb_nativethread_id_t; +typedef pthread_mutex_t rb_nativethread_lock_t; + +#else +#error "unsupported thread type" + +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +rb_nativethread_id_t rb_nativethread_self(); + +void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock); +void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock); +void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock); +void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock); + +RUBY_SYMBOL_EXPORT_END + +#endif diff --git a/include/ruby/util.h b/include/ruby/util.h new file mode 100644 index 0000000000..3fecba8ebc --- /dev/null +++ b/include/ruby/util.h @@ -0,0 +1,89 @@ +/********************************************************************** + + util.h - + + $Author$ + created at: Thu Mar 9 11:55:53 JST 1995 + + Copyright (C) 1993-2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_UTIL_H +#define RUBY_UTIL_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/defines.h" +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif + +#ifndef _ +#ifdef __cplusplus +# ifndef HAVE_PROTOTYPES +# define HAVE_PROTOTYPES 1 +# endif +# ifndef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 +# endif +#endif +#ifdef HAVE_PROTOTYPES +# define _(args) args +#else +# define _(args) () +#endif +#ifdef HAVE_STDARG_PROTOTYPES +# define __(args) args +#else +# define __(args) () +#endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999) +/* an approximation of ceil(n * log10(2)), up to 65536 at least */ + +#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e))) +unsigned long ruby_scan_oct(const char *, size_t, size_t *); +#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e))) +unsigned long ruby_scan_hex(const char *, size_t, size_t *); + +#ifdef HAVE_GNU_QSORT_R +# define ruby_qsort qsort_r +#else +void ruby_qsort(void *, const size_t, const size_t, + int (*)(const void *, const void *, void *), void *); +#endif + +void ruby_setenv(const char *, const char *); +void ruby_unsetenv(const char *); + +char *ruby_strdup(const char *); +#undef strdup +#define strdup(s) ruby_strdup(s) + +char *ruby_getcwd(void); + +double ruby_strtod(const char *, char **); +#undef strtod +#define strtod(s,e) ruby_strtod((s),(e)) + +void ruby_each_words(const char *, void (*)(const char*, int, void*), void *); + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_UTIL_H */ diff --git a/include/ruby/version.h b/include/ruby/version.h new file mode 100644 index 0000000000..64c5c614e0 --- /dev/null +++ b/include/ruby/version.h @@ -0,0 +1,74 @@ +/********************************************************************** + + ruby/version.h - + + $Author$ + created at: Wed May 13 12:56:56 JST 2009 + + Copyright (C) 1993-2009 Yukihiro Matsumoto + Copyright (C) 2000 Network Applied Communication Laboratory, Inc. + Copyright (C) 2000 Information-technology Promotion Agency, Japan + +**********************************************************************/ + +/* + * This file contains only + * - never-changeable information, and + * - interfaces accessible from extension libraries. + * + * Never try to check RUBY_VERSION_CODE etc in extension libraries, + * check the features with mkmf.rb instead. + */ + +#ifndef RUBY_VERSION_H +#define RUBY_VERSION_H 1 + +/* The origin. */ +#define RUBY_AUTHOR "Yukihiro Matsumoto" +#define RUBY_BIRTH_YEAR 1993 +#define RUBY_BIRTH_MONTH 2 +#define RUBY_BIRTH_DAY 24 + +/* API version */ +#define RUBY_API_VERSION_MAJOR 2 +#define RUBY_API_VERSION_MINOR 7 +#define RUBY_API_VERSION_TEENY 0 +#define RUBY_API_VERSION_CODE (RUBY_API_VERSION_MAJOR*10000+RUBY_API_VERSION_MINOR*100+RUBY_API_VERSION_TEENY) + +#ifdef RUBY_EXTERN +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +/* + * Interfaces from extension libraries. + * + * Before using these infos, think thrice whether they are really + * necessary or not, and if the answer was yes, think twice a week + * later again. + */ +RUBY_EXTERN const int ruby_api_version[3]; +RUBY_EXTERN const char ruby_version[]; +RUBY_EXTERN const char ruby_release_date[]; +RUBY_EXTERN const char ruby_platform[]; +RUBY_EXTERN const int ruby_patchlevel; +RUBY_EXTERN const char ruby_description[]; +RUBY_EXTERN const char ruby_copyright[]; +RUBY_EXTERN const char ruby_engine[]; + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif +#endif + +#endif diff --git a/include/ruby/vm.h b/include/ruby/vm.h new file mode 100644 index 0000000000..b137a280c9 --- /dev/null +++ b/include/ruby/vm.h @@ -0,0 +1,63 @@ +/********************************************************************** + + ruby/vm.h - + + $Author$ + created at: Sat May 31 15:17:36 2008 + + Copyright (C) 2008 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_VM_H +#define RUBY_VM_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +/* Place holder. + * + * We will prepare VM creation/control APIs on 1.9.2 or later. + * + */ + +/* VM type declaration */ +typedef struct rb_vm_struct ruby_vm_t; + +/* core API */ +int ruby_vm_destruct(ruby_vm_t *vm); + +/** + * ruby_vm_at_exit registers a function _func_ to be invoked when a VM + * passed away. Functions registered this way runs in reverse order + * of registration, just like END {} block does. The difference is + * its timing to be triggered. ruby_vm_at_exit functions runs when a + * VM _passed_ _away_, while END {} blocks runs just _before_ a VM + * _is_ _passing_ _away_. + * + * You cannot register a function to another VM than where you are in. + * So where to register is intuitive, omitted. OTOH the argument + * _func_ cannot know which VM it is in because at the time of + * invocation, the VM has already died and there is no execution + * context. The VM itself is passed as the first argument to it. + * + * @param[in] func the function to register. + */ +void ruby_vm_at_exit(void(*func)(ruby_vm_t *)); + +RUBY_SYMBOL_EXPORT_END + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_VM_H */ diff --git a/include/ruby/win32.h b/include/ruby/win32.h new file mode 100644 index 0000000000..b29470b0c4 --- /dev/null +++ b/include/ruby/win32.h @@ -0,0 +1,825 @@ +#ifndef RUBY_WIN32_H +#define RUBY_WIN32_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +/* + * Copyright (c) 1993, Intergraph Corporation + * + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the perl README file. + * + */ + +/* + * Definitions for NT port of Perl + */ + + +/* + * Ok now we can include the normal include files. + */ + +/* #include <stdarg.h> conflict with varargs.h? */ +#if !defined(WSAAPI) +#if defined(__cplusplus) && defined(_MSC_VER) +extern "C++" { /* template without extern "C++" */ +#endif +#if !defined(_WIN64) && !defined(WIN32) +#define WIN32 +#endif +#if defined(_MSC_VER) && _MSC_VER <= 1200 +#include <windows.h> +#endif +#include <winsock2.h> +#include <ws2tcpip.h> +#if !defined(_MSC_VER) || _MSC_VER >= 1400 +#include <iphlpapi.h> +#endif +#if defined(__cplusplus) && defined(_MSC_VER) +} +#endif +#endif + +/* + * We're not using Microsoft's "extensions" to C for + * Structured Exception Handling (SEH) so we can nuke these + */ +#undef try +#undef except +#undef finally +#undef leave + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <direct.h> +#include <process.h> +#include <time.h> +#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200 +extern "C++" { /* template without extern "C++" */ +#endif +#include <math.h> +#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200 +} +#endif +#include <signal.h> +#include <sys/stat.h> +#include <sys/types.h> +#ifdef HAVE_SYS_UTIME_H +# include <sys/utime.h> +#else +# include <utime.h> +#endif +#include <io.h> +#include <malloc.h> +#if defined __MINGW32__ +# include <stdint.h> +#else +# if !defined(_INTPTR_T_DEFINED) +# ifdef _WIN64 +typedef __int64 intptr_t; +# else +typedef int intptr_t; +# endif +# define _INTPTR_T_DEFINED +# endif +# if !defined(INTPTR_MAX) +# ifdef _WIN64 +# define INTPTR_MAX 9223372036854775807I64 +# else +# define INTPTR_MAX 2147483647 +# endif +# define INTPTR_MIN (-INTPTR_MAX-1) +# endif +# if !defined(_UINTPTR_T_DEFINED) +# ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +# else +typedef unsigned int uintptr_t; +# endif +# define _UINTPTR_T_DEFINED +# endif +# if !defined(UINTPTR_MAX) +# ifdef _WIN64 +# define UINTPTR_MAX 18446744073709551615UI64 +# else +# define UINTPTR_MAX 4294967295U +# endif +# endif +#endif +#ifndef __MINGW32__ +# define mode_t int +#endif +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#define rb_w32_iswinnt() TRUE +#define rb_w32_iswin95() FALSE + +#define WNOHANG -1 + +#define O_SHARE_DELETE 0x20000000 /* for rb_w32_open(), rb_w32_wopen() */ + +typedef int clockid_t; +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 + +#undef utime +#undef lseek +#undef stat +#undef fstat +#ifdef RUBY_EXPORT +#define utime(_p, _t) rb_w32_utime(_p, _t) +#undef HAVE_UTIMES +#define HAVE_UTIMES 1 +#define utimes(_p, _t) rb_w32_utimes(_p, _t) +#undef HAVE_UTIMENSAT +#define HAVE_UTIMENSAT 1 +#define AT_FDCWD -100 +#define utimensat(_d, _p, _t, _f) rb_w32_utimensat(_d, _p, _t, _f) +#define lseek(_f, _o, _w) rb_w32_lseek(_f, _o, _w) + +#define pipe(p) rb_w32_pipe(p) +#define open rb_w32_open +#define close(h) rb_w32_close(h) +#define fclose(f) rb_w32_fclose(f) +#define read(f, b, s) rb_w32_read(f, b, s) +#define write(f, b, s) rb_w32_write(f, b, s) +#define getpid() rb_w32_getpid() +#define getppid() rb_w32_getppid() +#define sleep(x) rb_w32_Sleep((x)*1000) +#define Sleep(msec) (void)rb_w32_Sleep(msec) + +#undef execv +#define execv(path,argv) rb_w32_aspawn(P_OVERLAY,path,argv) +#undef isatty +#define isatty(h) rb_w32_isatty(h) + +#undef mkdir +#define mkdir(p, m) rb_w32_mkdir(p, m) +#undef rmdir +#define rmdir(p) rb_w32_rmdir(p) +#undef unlink +#define unlink(p) rb_w32_unlink(p) +#endif /* RUBY_EXPORT */ + +/* same with stati64 except the size of st_ino and nanosecond timestamps */ +struct stati128 { + _dev_t st_dev; + unsigned __int64 st_ino; + __int64 st_inohigh; + unsigned short st_mode; + short st_nlink; + short st_uid; + short st_gid; + _dev_t st_rdev; + __int64 st_size; + __time64_t st_atime; + long st_atimensec; + __time64_t st_mtime; + long st_mtimensec; + __time64_t st_ctime; + long st_ctimensec; +}; + +#if SIZEOF_OFF_T == 8 +#define off_t __int64 +#define stat stati128 +#undef SIZEOF_STRUCT_STAT_ST_INO +#define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64) +#define HAVE_STRUCT_STAT_ST_INOHIGH +#define HAVE_STRUCT_STAT_ST_ATIMENSEC +#define HAVE_STRUCT_STAT_ST_MTIMENSEC +#define HAVE_STRUCT_STAT_ST_CTIMENSEC +#define fstat(fd,st) rb_w32_fstati128(fd,st) +#define stati128(path, st) rb_w32_stati128(path,st) +#else +#define stat(path,st) rb_w32_stat(path,st) +#define fstat(fd,st) rb_w32_fstat(fd,st) +extern int rb_w32_stat(const char *, struct stat *); +extern int rb_w32_fstat(int, struct stat *); +#endif +#define lstat(path,st) rb_w32_lstati128(path,st) +#define access(path,mode) rb_w32_access(path,mode) + +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#define fsync _commit + +struct timezone; + +#ifdef __MINGW32__ +#undef isascii +#define isascii __isascii +#endif + +struct iovec { + void *iov_base; + size_t iov_len; +}; +struct msghdr { + void *msg_name; + int msg_namelen; + struct iovec *msg_iov; + int msg_iovlen; + void *msg_control; + int msg_controllen; + int msg_flags; +}; + +/* for getifaddrs() and others */ +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + u_int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_broadaddr; + struct sockaddr *ifa_dstaddr; + void *ifa_data; +}; +#ifdef IF_NAMESIZE +#define IFNAMSIZ IF_NAMESIZE +#else +#define IFNAMSIZ 256 +#endif +#ifdef IFF_POINTTOPOINT +#define IFF_POINTOPOINT IFF_POINTTOPOINT +#endif + +extern void rb_w32_sysinit(int *, char ***); +extern DWORD rb_w32_osid(void); +extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *); +extern int flock(int fd, int oper); +extern int rb_w32_io_cancelable_p(int); +extern int rb_w32_is_socket(int); +extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int); +extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int); +extern void rb_w32_fdset(int, fd_set*); +extern void rb_w32_fdclr(int, fd_set*); +extern int rb_w32_fdisset(int, fd_set*); +extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *); +extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *); +extern int WSAAPI rb_w32_listen(int, int); +extern int WSAAPI rb_w32_recv(int, char *, int, int); +extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_send(int, const char *, int, int); +extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int); +extern int recvmsg(int, struct msghdr *, int); +extern int sendmsg(int, const struct msghdr *, int); +extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int); +extern int WSAAPI rb_w32_shutdown(int, int); +extern int WSAAPI rb_w32_socket(int, int, int); +extern SOCKET rb_w32_get_osfhandle(int); +extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int); +extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *); +extern int WSAAPI rb_w32_gethostname(char *, int); +extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *); +extern struct protoent *WSAAPI rb_w32_getprotobynumber(int); +extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *); +extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *); +extern int socketpair(int, int, int, int *); +extern int getifaddrs(struct ifaddrs **); +extern void freeifaddrs(struct ifaddrs *); +extern char * rb_w32_getcwd(char *, int); +extern char * rb_w32_ugetenv(const char *); +extern char * rb_w32_getenv(const char *); +extern int rb_w32_rename(const char *, const char *); +extern int rb_w32_urename(const char *, const char *); +extern char **rb_w32_get_environ(void); +extern void rb_w32_free_environ(char **); +extern int rb_w32_map_errno(DWORD); +extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t); +extern int WSAAPI rb_w32_inet_pton(int,const char *,void *); +extern DWORD rb_w32_osver(void); + +extern int chown(const char *, int, int); +extern int rb_w32_uchown(const char *, int, int); +extern int link(const char *, const char *); +extern int rb_w32_ulink(const char *, const char *); +extern ssize_t readlink(const char *, char *, size_t); +extern ssize_t rb_w32_ureadlink(const char *, char *, size_t); +extern ssize_t rb_w32_wreadlink(const WCHAR *, WCHAR *, size_t); +extern int symlink(const char *src, const char *link); +extern int rb_w32_usymlink(const char *src, const char *link); +extern int gettimeofday(struct timeval *, struct timezone *); +extern int clock_gettime(clockid_t, struct timespec *); +extern int clock_getres(clockid_t, struct timespec *); +extern rb_pid_t waitpid (rb_pid_t, int *, int); +extern rb_pid_t rb_w32_spawn(int, const char *, const char*); +extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *); +extern rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD); +extern rb_pid_t rb_w32_uspawn(int, const char *, const char*); +extern rb_pid_t rb_w32_uaspawn(int, const char *, char *const *); +extern rb_pid_t rb_w32_uaspawn_flags(int, const char *, char *const *, DWORD); +extern int kill(int, int); +extern int fcntl(int, int, ...); +extern int rb_w32_set_nonblock(int); +extern rb_pid_t rb_w32_getpid(void); +extern rb_pid_t rb_w32_getppid(void); +extern int rb_w32_isatty(int); +extern int rb_w32_uchdir(const char *); +extern int rb_w32_mkdir(const char *, int); +extern int rb_w32_umkdir(const char *, int); +extern int rb_w32_rmdir(const char *); +extern int rb_w32_urmdir(const char *); +extern int rb_w32_unlink(const char *); +extern int rb_w32_uunlink(const char *); +extern int rb_w32_uchmod(const char *, int); +extern int rb_w32_stati128(const char *, struct stati128 *); +extern int rb_w32_ustati128(const char *, struct stati128 *); +extern int rb_w32_lstati128(const char *, struct stati128 *); +extern int rb_w32_ulstati128(const char *, struct stati128 *); +extern int rb_w32_access(const char *, int); +extern int rb_w32_uaccess(const char *, int); +extern char rb_w32_fd_is_text(int); +extern int rb_w32_fstati128(int, struct stati128 *); +extern int rb_w32_dup2(int, int); + +#include <float.h> + +#if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY +#pragma warning(push) +#pragma warning(disable:4756) +static inline float +rb_infinity_float(void) +{ + return INFINITY; +} +#pragma warning(pop) +#undef INFINITY +#define INFINITY rb_infinity_float() +#endif + +#if !defined __MINGW32__ || defined __NO_ISOCEXT +#ifndef isnan +#define isnan(x) _isnan(x) +#endif +static inline int +finite(double x) +{ + return _finite(x); +} +#ifndef copysign +#define copysign(a, b) _copysign(a, b) +#endif +static inline double +scalb(double a, long b) +{ + return _scalb(a, b); +} +#else +__declspec(dllimport) extern int finite(double); +#endif + +#if !defined S_IFIFO && defined _S_IFIFO +#define S_IFIFO _S_IFIFO +#endif + +#if !defined S_IRUSR && !defined __MINGW32__ +#define S_IRUSR 0400 +#endif +#ifndef S_IRGRP +#define S_IRGRP 0040 +#endif +#ifndef S_IROTH +#define S_IROTH 0004 +#endif + +#if !defined S_IWUSR && !defined __MINGW32__ +#define S_IWUSR 0200 +#endif +#ifndef S_IWGRP +#define S_IWGRP 0020 +#endif +#ifndef S_IWOTH +#define S_IWOTH 0002 +#endif + +#if !defined S_IXUSR && !defined __MINGW32__ +#define S_IXUSR 0100 +#endif +#ifndef S_IXGRP +#define S_IXGRP 0010 +#endif +#ifndef S_IXOTH +#define S_IXOTH 0001 +#endif + +#define S_IFLNK 0xa000 + +/* + * define this so we can do inplace editing + */ + +#define SUFFIX + +extern int rb_w32_ftruncate(int fd, off_t length); +extern int rb_w32_truncate(const char *path, off_t length); +extern int rb_w32_utruncate(const char *path, off_t length); + +#undef HAVE_FTRUNCATE +#define HAVE_FTRUNCATE 1 +#if defined HAVE_FTRUNCATE64 +#define ftruncate ftruncate64 +#else +#define ftruncate rb_w32_ftruncate +#endif + +#undef HAVE_TRUNCATE +#define HAVE_TRUNCATE 1 +#if defined HAVE_TRUNCATE64 +#define truncate truncate64 +#else +#define truncate rb_w32_truncate +#endif + +#if defined(_MSC_VER) && _MSC_VER >= 1400 && _MSC_VER < 1800 +#define strtoll _strtoi64 +#define strtoull _strtoui64 +#endif + +/* + * stubs + */ +extern int ioctl (int, int, ...); +extern rb_uid_t getuid (void); +extern rb_uid_t geteuid (void); +extern rb_gid_t getgid (void); +extern rb_gid_t getegid (void); +extern int setuid (rb_uid_t); +extern int setgid (rb_gid_t); + +extern char *rb_w32_strerror(int); + +#ifdef RUBY_EXPORT +#define strerror(e) rb_w32_strerror(e) +#endif + +#define PIPE_BUF 1024 + +#define LOCK_SH 1 +#define LOCK_EX 2 +#define LOCK_NB 4 +#define LOCK_UN 8 + + +#ifndef SIGINT +#define SIGINT 2 +#endif +#ifndef SIGKILL +#define SIGKILL 9 +#endif + + +/* #undef va_start */ +/* #undef va_end */ + +/* winsock error map */ +#include <errno.h> + +#ifndef EWOULDBLOCK +# define EWOULDBLOCK WSAEWOULDBLOCK +#endif +#ifndef EINPROGRESS +# define EINPROGRESS WSAEINPROGRESS +#endif +#ifndef EALREADY +# define EALREADY WSAEALREADY +#endif +#ifndef ENOTSOCK +# define ENOTSOCK WSAENOTSOCK +#endif +#ifndef EDESTADDRREQ +# define EDESTADDRREQ WSAEDESTADDRREQ +#endif +#ifndef EMSGSIZE +# define EMSGSIZE WSAEMSGSIZE +#endif +#ifndef EPROTOTYPE +# define EPROTOTYPE WSAEPROTOTYPE +#endif +#ifndef ENOPROTOOPT +# define ENOPROTOOPT WSAENOPROTOOPT +#endif +#ifndef EPROTONOSUPPORT +# define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#endif +#ifndef ESOCKTNOSUPPORT +# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +#endif +#ifndef EOPNOTSUPP +# define EOPNOTSUPP WSAEOPNOTSUPP +#endif +#ifndef EPFNOSUPPORT +# define EPFNOSUPPORT WSAEPFNOSUPPORT +#endif +#ifndef EAFNOSUPPORT +# define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif +#ifndef EADDRINUSE +# define EADDRINUSE WSAEADDRINUSE +#endif +#ifndef EADDRNOTAVAIL +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#endif +#ifndef ENETDOWN +# define ENETDOWN WSAENETDOWN +#endif +#ifndef ENETUNREACH +# define ENETUNREACH WSAENETUNREACH +#endif +#ifndef ENETRESET +# define ENETRESET WSAENETRESET +#endif +#ifndef ECONNABORTED +# define ECONNABORTED WSAECONNABORTED +#endif +#ifndef ECONNRESET +# define ECONNRESET WSAECONNRESET +#endif +#ifndef ENOBUFS +# define ENOBUFS WSAENOBUFS +#endif +#ifndef EISCONN +# define EISCONN WSAEISCONN +#endif +#ifndef ENOTCONN +# define ENOTCONN WSAENOTCONN +#endif +#ifndef ESHUTDOWN +# define ESHUTDOWN WSAESHUTDOWN +#endif +#ifndef ETOOMANYREFS +# define ETOOMANYREFS WSAETOOMANYREFS +#endif +#ifndef ETIMEDOUT +# define ETIMEDOUT WSAETIMEDOUT +#endif +#ifndef ECONNREFUSED +# define ECONNREFUSED WSAECONNREFUSED +#endif +#ifndef ELOOP +# define ELOOP WSAELOOP +#endif +/*#define ENAMETOOLONG WSAENAMETOOLONG*/ +#ifndef EHOSTDOWN +# define EHOSTDOWN WSAEHOSTDOWN +#endif +#ifndef EHOSTUNREACH +# define EHOSTUNREACH WSAEHOSTUNREACH +#endif +/*#define ENOTEMPTY WSAENOTEMPTY*/ +#ifndef EPROCLIM +# define EPROCLIM WSAEPROCLIM +#endif +#ifndef EUSERS +# define EUSERS WSAEUSERS +#endif +#ifndef EDQUOT +# define EDQUOT WSAEDQUOT +#endif +#ifndef ESTALE +# define ESTALE WSAESTALE +#endif +#ifndef EREMOTE +# define EREMOTE WSAEREMOTE +#endif + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#if 0 +#define F_GETFL 3 +#endif +#define F_SETFL 4 +#define F_DUPFD_CLOEXEC 67 +#define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */ +#define O_NONBLOCK 1 + +#undef FD_SET +#define FD_SET(fd, set) do {\ + unsigned int i;\ + SOCKET s = _get_osfhandle(fd);\ +\ + for (i = 0; i < (set)->fd_count; i++) {\ + if ((set)->fd_array[i] == s) {\ + break;\ + }\ + }\ + if (i == (set)->fd_count) {\ + if ((set)->fd_count < FD_SETSIZE) {\ + (set)->fd_array[i] = s;\ + (set)->fd_count++;\ + }\ + }\ +} while(0) + +#undef FD_CLR +#define FD_CLR(f, s) rb_w32_fdclr(f, s) + +#undef FD_ISSET +#define FD_ISSET(f, s) rb_w32_fdisset(f, s) + +#ifdef RUBY_EXPORT +#undef inet_ntop +#define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l) + +#undef inet_pton +#define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d) + +#undef accept +#define accept(s, a, l) rb_w32_accept(s, a, l) + +#undef bind +#define bind(s, a, l) rb_w32_bind(s, a, l) + +#undef connect +#define connect(s, a, l) rb_w32_connect(s, a, l) + +#undef select +#define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t) + +#undef getpeername +#define getpeername(s, a, l) rb_w32_getpeername(s, a, l) + +#undef getsockname +#define getsockname(s, a, l) rb_w32_getsockname(s, a, l) + +#undef getsockopt +#define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l) + +#undef ioctlsocket +#define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a) + +#undef listen +#define listen(s, b) rb_w32_listen(s, b) + +#undef recv +#define recv(s, b, l, f) rb_w32_recv(s, b, l, f) + +#undef recvfrom +#define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl) + +#undef send +#define send(s, b, l, f) rb_w32_send(s, b, l, f) + +#undef sendto +#define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl) + +#undef setsockopt +#define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l) + +#undef shutdown +#define shutdown(s, h) rb_w32_shutdown(s, h) + +#undef socket +#define socket(s, t, p) rb_w32_socket(s, t, p) + +#undef gethostbyaddr +#define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t) + +#undef gethostbyname +#define gethostbyname(n) rb_w32_gethostbyname(n) + +#undef gethostname +#define gethostname(n, l) rb_w32_gethostname(n, l) + +#undef getprotobyname +#define getprotobyname(n) rb_w32_getprotobyname(n) + +#undef getprotobynumber +#define getprotobynumber(n) rb_w32_getprotobynumber(n) + +#undef getservbyname +#define getservbyname(n, p) rb_w32_getservbyname(n, p) + +#undef getservbyport +#define getservbyport(p, pr) rb_w32_getservbyport(p, pr) + +#undef get_osfhandle +#define get_osfhandle(h) rb_w32_get_osfhandle(h) + +#undef getcwd +#define getcwd(b, s) rb_w32_getcwd(b, s) + +#undef getenv +#define getenv(n) rb_w32_getenv(n) + +#undef rename +#define rename(o, n) rb_w32_rename(o, n) + +#undef times +#define times(t) rb_w32_times(t) + +#undef dup2 +#define dup2(o, n) rb_w32_dup2(o, n) +#endif + +struct tms { + long tms_utime; + long tms_stime; + long tms_cutime; + long tms_cstime; +}; + +int rb_w32_times(struct tms *); + +struct tm *gmtime_r(const time_t *, struct tm *); +struct tm *localtime_r(const time_t *, struct tm *); + +/* thread stuff */ +int rb_w32_sleep(unsigned long msec); +int rb_w32_open(const char *, int, ...); +int rb_w32_uopen(const char *, int, ...); +int rb_w32_wopen(const WCHAR *, int, ...); +int rb_w32_close(int); +int rb_w32_fclose(FILE*); +int rb_w32_pipe(int[2]); +ssize_t rb_w32_read(int, void *, size_t); +ssize_t rb_w32_write(int, const void *, size_t); +off_t rb_w32_lseek(int, off_t, int); +int rb_w32_utime(const char *, const struct utimbuf *); +int rb_w32_uutime(const char *, const struct utimbuf *); +int rb_w32_utimes(const char *, const struct timeval *); +int rb_w32_uutimes(const char *, const struct timeval *); +int rb_w32_utimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */); +int rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */); +long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */ +int WINAPI rb_w32_Sleep(unsigned long msec); +int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout); +int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait); +int rb_w32_wrap_io_handle(HANDLE, int); +int rb_w32_unwrap_io_handle(int); +WCHAR *rb_w32_mbstr_to_wstr(UINT, const char *, int, long *); +char *rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *); + +/* +== ***CAUTION*** +Since this function is very dangerous, ((*NEVER*)) +* lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or, +* use anything like rb_thread_call_without_gvl, +in asynchronous_func_t. +*/ +typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv); +uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval); + +RUBY_SYMBOL_EXPORT_END + +#if (defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)) && !defined(__cplusplus) +#ifdef RUBY_MINGW64_BROKEN_FREXP_MODF +/* License: Ruby's */ +/* get rid of bugs in math.h of mingw */ +#define frexp(_X, _Y) __extension__ ({\ + int intpart_frexp_bug = intpart_frexp_bug;\ + double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\ + *(_Y) = intpart_frexp_bug;\ + result_frexp_bug;\ +}) +/* License: Ruby's */ +#define modf(_X, _Y) __extension__ ({\ + double intpart_modf_bug = intpart_modf_bug;\ + double result_modf_bug = modf((_X), &intpart_modf_bug);\ + *(_Y) = intpart_modf_bug;\ + result_modf_bug;\ +}) +#endif + +#if defined(__MINGW64__) +/* + * Use powl() instead of broken pow() of x86_64-w64-mingw32. + * This workaround will fix test failures in test_bignum.rb, + * test_fixnum.rb and test_float.rb etc. + */ +static inline double +rb_w32_pow(double x, double y) +{ + return (double)powl(x, y); +} +#elif defined(__MINGW64_VERSION_MAJOR) +double rb_w32_pow(double x, double y); +#endif +#define pow rb_w32_pow +#endif + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_WIN32_H */ |
