diff options
Diffstat (limited to 'include/ruby/internal/core')
-rw-r--r-- | include/ruby/internal/core/rarray.h | 275 | ||||
-rw-r--r-- | include/ruby/internal/core/rbasic.h | 85 | ||||
-rw-r--r-- | include/ruby/internal/core/rbignum.h | 51 | ||||
-rw-r--r-- | include/ruby/internal/core/rclass.h | 47 | ||||
-rw-r--r-- | include/ruby/internal/core/rdata.h | 174 | ||||
-rw-r--r-- | include/ruby/internal/core/rfile.h | 36 | ||||
-rw-r--r-- | include/ruby/internal/core/rhash.h | 62 | ||||
-rw-r--r-- | include/ruby/internal/core/rmatch.h | 73 | ||||
-rw-r--r-- | include/ruby/internal/core/robject.h | 97 | ||||
-rw-r--r-- | include/ruby/internal/core/rregexp.h | 84 | ||||
-rw-r--r-- | include/ruby/internal/core/rstring.h | 215 | ||||
-rw-r--r-- | include/ruby/internal/core/rstruct.h | 73 | ||||
-rw-r--r-- | include/ruby/internal/core/rtypeddata.h | 184 |
13 files changed, 1456 insertions, 0 deletions
diff --git a/include/ruby/internal/core/rarray.h b/include/ruby/internal/core/rarray.h new file mode 100644 index 0000000000..04f8f0dd49 --- /dev/null +++ b/include/ruby/internal/core/rarray.h @@ -0,0 +1,275 @@ +#ifndef RBIMPL_RARRAY_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RARRAY_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines struct ::RArray. + */ +#include "ruby/impl/arithmetic/long.h" +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/attr/maybe_unused.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/core/rbasic.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/fl_type.h" +#include "ruby/impl/rgengc.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" +#include "ruby/assert.h" + +#ifndef USE_TRANSIENT_HEAP +# define USE_TRANSIENT_HEAP 1 +#endif + +#define RARRAY(obj) RBIMPL_CAST((struct RArray *)(obj)) +#define RARRAY_EMBED_FLAG RARRAY_EMBED_FLAG +#define RARRAY_EMBED_LEN_MASK RARRAY_EMBED_LEN_MASK +#define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX +#define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT +#if USE_TRANSIENT_HEAP +# define RARRAY_TRANSIENT_FLAG RARRAY_TRANSIENT_FLAG +#else +# define RARRAY_TRANSIENT_FLAG 0 +#endif +#define RARRAY_LEN rb_array_len +#define RARRAY_CONST_PTR rb_array_const_ptr +#define RARRAY_CONST_PTR_TRANSIENT rb_array_const_ptr_transient + +/** @cond INTERNAL_MACRO */ +#if defined(__fcc__) || defined(__fcc_version) || \ + defined(__FCC__) || defined(__FCC_VERSION) +/* workaround for old version of Fujitsu C Compiler (fcc) */ +# define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x)) +#else +# define FIX_CONST_VALUE_PTR(x) (x) +#endif + +#define RARRAY_EMBED_LEN RARRAY_EMBED_LEN +#define RARRAY_LENINT RARRAY_LENINT +#define RARRAY_TRANSIENT_P RARRAY_TRANSIENT_P +#define RARRAY_ASET RARRAY_ASET +#define RARRAY_PTR RARRAY_PTR +/** @endcond */ + +enum ruby_rarray_flags { + RARRAY_EMBED_FLAG = RUBY_FL_USER1, + /* RUBY_FL_USER2 is for ELTS_SHARED */ + RARRAY_EMBED_LEN_MASK = RUBY_FL_USER4 | RUBY_FL_USER3 +#if USE_TRANSIENT_HEAP + , + RARRAY_TRANSIENT_FLAG = RUBY_FL_USER13 +#endif +}; + +enum ruby_rarray_consts { + RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3, + RARRAY_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE) +}; + +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; +}; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE *rb_ary_ptr_use_start(VALUE ary); +void rb_ary_ptr_use_end(VALUE a); +#if USE_TRANSIENT_HEAP +void rb_ary_detransient(VALUE a); +#endif +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline long +RARRAY_EMBED_LEN(VALUE ary) +{ + RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY); + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ANY_RAW(ary, RARRAY_EMBED_FLAG)); + + VALUE f = RBASIC(ary)->flags; + f &= RARRAY_EMBED_LEN_MASK; + f >>= RARRAY_EMBED_LEN_SHIFT; + return RBIMPL_CAST((long)f); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +static inline long +rb_array_len(VALUE a) +{ + RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY); + + if (RB_FL_ANY_RAW(a, RARRAY_EMBED_FLAG)) { + return RARRAY_EMBED_LEN(a); + } + else { + return RARRAY(a)->as.heap.len; + } +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline int +RARRAY_LENINT(VALUE ary) +{ + return rb_long2int(RARRAY_LEN(ary)); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RARRAY_TRANSIENT_P(VALUE ary) +{ + RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY); + +#if USE_TRANSIENT_HEAP + return RB_FL_ANY_RAW(ary, RARRAY_TRANSIENT_FLAG); +#else + return false; +#endif +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +/* internal function. do not use this function */ +static inline const VALUE * +rb_array_const_ptr_transient(VALUE a) +{ + RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY); + + if (RB_FL_ANY_RAW(a, RARRAY_EMBED_FLAG)) { + return FIX_CONST_VALUE_PTR(RARRAY(a)->as.ary); + } + else { + return FIX_CONST_VALUE_PTR(RARRAY(a)->as.heap.ptr); + } +} + +#if ! USE_TRANSIENT_HEAP +RBIMPL_ATTR_PURE_ON_NDEBUG() +#endif +/* internal function. do not use this function */ +static inline const VALUE * +rb_array_const_ptr(VALUE a) +{ + RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY); + +#if USE_TRANSIENT_HEAP + if (RARRAY_TRANSIENT_P(a)) { + rb_ary_detransient(a); + } +#endif + return rb_array_const_ptr_transient(a); +} + +/* internal function. do not use this function */ +static inline VALUE * +rb_array_ptr_use_start(VALUE a, + RBIMPL_ATTR_MAYBE_UNUSED() + int allow_transient) +{ + RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY); + +#if USE_TRANSIENT_HEAP + if (!allow_transient) { + if (RARRAY_TRANSIENT_P(a)) { + rb_ary_detransient(a); + } + } +#endif + + return rb_ary_ptr_use_start(a); +} + +/* internal function. do not use this function */ +static inline void +rb_array_ptr_use_end(VALUE a, + RBIMPL_ATTR_MAYBE_UNUSED() + int allow_transient) +{ + RBIMPL_ASSERT_TYPE(a, RUBY_T_ARRAY); + rb_ary_ptr_use_end(a); +} + +#define RBIMPL_RARRAY_STMT(flag, ary, var, expr) do { \ + RBIMPL_ASSERT_TYPE((ary), RUBY_T_ARRAY); \ + const VALUE rbimpl_ary = (ary); \ + VALUE *var = rb_array_ptr_use_start(rbimpl_ary, (flag)); \ + expr; \ + rb_array_ptr_use_end(rbimpl_ary, (flag)); \ +} while (0) + +#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) \ + RBIMPL_RARRAY_STMT(0, ary, ptr_name, expr) + +#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) \ + RBIMPL_RARRAY_STMT(1, ary, ptr_name, expr) + +static inline VALUE * +RARRAY_PTR(VALUE ary) +{ + RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY); + + VALUE tmp = RB_OBJ_WB_UNPROTECT_FOR(ARRAY, ary); + return RBIMPL_CAST((VALUE *)RARRAY_CONST_PTR(tmp)); +} + +static inline void +RARRAY_ASET(VALUE ary, long i, VALUE v) +{ + RARRAY_PTR_USE_TRANSIENT(ary, ptr, + RB_OBJ_WRITE(ary, &ptr[i], v)); +} + +/* RARRAY_AREF is used as a lvalue. Cannot be a function. */ +#if 0 +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RARRAY_AREF(VALUE ary, long i) +{ + RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY); + + return RARRAY_CONST_PTR_TRANSIENT(ary)[i]; +} +#else +# undef RARRAY_AREF +# define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i] +#endif + +#endif /* RBIMPL_RARRAY_H */ diff --git a/include/ruby/internal/core/rbasic.h b/include/ruby/internal/core/rbasic.h new file mode 100644 index 0000000000..751b30c24c --- /dev/null +++ b/include/ruby/internal/core/rbasic.h @@ -0,0 +1,85 @@ +#ifndef RBIMPL_RBASIC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RBASIC_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines struct ::RBasic. + */ +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/attr/forceinline.h" +#include "ruby/impl/attr/noalias.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" +#include "ruby/impl/value.h" +#include "ruby/assert.h" + +#define RBASIC(obj) RBIMPL_CAST((struct RBasic *)(obj)) +#define RBASIC_CLASS RBASIC_CLASS +#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX + +/** @cond INTERNAL_MACRO */ +#define RBIMPL_EMBED_LEN_MAX_OF(T) \ + RBIMPL_CAST((int)(sizeof(VALUE[RVALUE_EMBED_LEN_MAX]) / sizeof(T))) +/** @endcond */ + +enum ruby_rvalue_flags { RVALUE_EMBED_LEN_MAX = 3 }; + +struct +RUBY_ALIGNAS(SIZEOF_VALUE) +RBasic { + VALUE flags; /**< @see enum ::ruby_fl_type. */ + const VALUE klass; + +#ifdef __cplusplus + public: + RBIMPL_ATTR_CONSTEXPR(CXX11) + RBIMPL_ATTR_ARTIFICIAL() + RBIMPL_ATTR_FORCEINLINE() + RBIMPL_ATTR_NOALIAS() + /** + * We need to define this explicit constructor because the field `klass` is + * const-qualified above, which effectively defines the implicit default + * constructor as "deleted" (as of C++11) -- No way but to define one by + * ourselves. + */ + RBasic() : + flags(RBIMPL_VALUE_NULL), + klass(RBIMPL_VALUE_NULL) + { + } +#endif +}; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE rb_obj_hide(VALUE obj); +VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */ +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RBASIC_CLASS(VALUE obj) +{ + RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); + return RBASIC(obj)->klass; +} + +#endif /* RBIMPL_RBASIC_H */ diff --git a/include/ruby/internal/core/rbignum.h b/include/ruby/internal/core/rbignum.h new file mode 100644 index 0000000000..9a77456ba3 --- /dev/null +++ b/include/ruby/internal/core/rbignum.h @@ -0,0 +1,51 @@ +#ifndef RBIMPL_RBIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RBIGNUM_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Routines to manipulate struct ::RBignum. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" +#include "ruby/impl/stdbool.h" + +#define RBIGNUM_SIGN rb_big_sign + +/** @cond INTERNAL_MACRO */ +#define RBIGNUM_POSITIVE_P RBIGNUM_POSITIVE_P +#define RBIGNUM_NEGATIVE_P RBIGNUM_NEGATIVE_P +/** @endcond */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() +int rb_big_sign(VALUE num); +RBIMPL_SYMBOL_EXPORT_END() + +static inline bool +RBIGNUM_POSITIVE_P(VALUE b) { + RBIMPL_ASSERT_TYPE(b, RUBY_T_BIGNUM); + return RBIGNUM_SIGN(b); +} + +static inline bool +RBIGNUM_NEGATIVE_P(VALUE b) { + RBIMPL_ASSERT_TYPE(b, RUBY_T_BIGNUM); + return ! RBIGNUM_POSITIVE_P(b); +} + +#endif /* RBIMPL_RBIGNUM_H */ diff --git a/include/ruby/internal/core/rclass.h b/include/ruby/internal/core/rclass.h new file mode 100644 index 0000000000..c9864e2436 --- /dev/null +++ b/include/ruby/internal/core/rclass.h @@ -0,0 +1,47 @@ +#ifndef RBIMPL_RCLASS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RCLASS_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Routines to manipulate struct ::RClass. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/cast.h" + +#define RMODULE_IS_OVERLAID RMODULE_IS_OVERLAID +#define RMODULE_IS_REFINEMENT RMODULE_IS_REFINEMENT +#define RMODULE_INCLUDED_INTO_REFINEMENT RMODULE_INCLUDED_INTO_REFINEMENT + +#define RCLASS(obj) RBIMPL_CAST((struct RClass *)(obj)) +#define RMODULE RCLASS +#define RCLASS_SUPER rb_class_get_superclass + +enum ruby_rmodule_flags { + RMODULE_IS_OVERLAID = RUBY_FL_USER2, + RMODULE_IS_REFINEMENT = RUBY_FL_USER3, + RMODULE_INCLUDED_INTO_REFINEMENT = RUBY_FL_USER4 +}; + +struct RClass; /* Opaque, declared here for RCLASS() macro. */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE rb_class_get_superclass(VALUE); +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_RCLASS_H */ diff --git a/include/ruby/internal/core/rdata.h b/include/ruby/internal/core/rdata.h new file mode 100644 index 0000000000..4a0b09498c --- /dev/null +++ b/include/ruby/internal/core/rdata.h @@ -0,0 +1,174 @@ +#ifndef RBIMPL_RDATA_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RDATA_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines struct ::RData. + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include <stddef.h> +#endif + +#include "ruby/impl/attr/deprecated.h" +#include "ruby/impl/attr/warning.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/core/rbasic.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/fl_type.h" +#include "ruby/impl/token_paste.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" +#include "ruby/defines.h" + +#ifdef RUBY_UNTYPED_DATA_WARNING +# /* Take that. */ +#elif defined(RUBY_EXPORT) +# define RUBY_UNTYPED_DATA_WARNING 1 +#else +# define RUBY_UNTYPED_DATA_WARNING 0 +#endif + +/** @cond INTERNAL_MACRO */ +#define RBIMPL_DATA_FUNC(f) RBIMPL_CAST((void (*)(void *))(f)) +#define RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() \ + RBIMPL_ATTR_WARNING(("untyped Data is unsafe; use TypedData instead")) \ + RBIMPL_ATTR_DEPRECATED(("by TypedData")) +/** @endcond */ + +#define RDATA(obj) RBIMPL_CAST((struct RData *)(obj)) +#define DATA_PTR(obj) RDATA(obj)->data +#define RUBY_MACRO_SELECT RBIMPL_TOKEN_PASTE +#define RUBY_DEFAULT_FREE RBIMPL_DATA_FUNC(-1) +#define RUBY_NEVER_FREE RBIMPL_DATA_FUNC(0) +#define RUBY_UNTYPED_DATA_FUNC(f) f RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() + +/* +#define RUBY_DATA_FUNC(func) ((void (*)(void*))(func)) +*/ +typedef void (*RUBY_DATA_FUNC)(void*); + +struct RData { + struct RBasic basic; + RUBY_DATA_FUNC dmark; + RUBY_DATA_FUNC dfree; + void *data; +}; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE rb_data_object_wrap(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree); +VALUE rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree); +RBIMPL_SYMBOL_EXPORT_END() + +#define Data_Wrap_Struct(klass, mark, free, sval) \ + rb_data_object_wrap( \ + (klass), \ + (sval), \ + RBIMPL_DATA_FUNC(mark), \ + RBIMPL_DATA_FUNC(free)) + +#define Data_Make_Struct0(result, klass, type, size, mark, free, sval) \ + VALUE result = rb_data_object_zalloc( \ + (klass), \ + (size), \ + RBIMPL_DATA_FUNC(mark), \ + RBIMPL_DATA_FUNC(free)); \ + (sval) = RBIMPL_CAST((type *)DATA_PTR(result)); \ + RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval)) + +#ifdef HAVE_STMT_AND_DECL_IN_EXPR +#define Data_Make_Struct(klass, type, mark, free, sval) \ + RB_GNUC_EXTENSION({ \ + Data_Make_Struct0( \ + data_struct_obj, \ + klass, \ + type, \ + sizeof(type), \ + mark, \ + free, \ + sval); \ + data_struct_obj; \ + }) +#else +#define Data_Make_Struct(klass, type, mark, free, sval) \ + rb_data_object_make( \ + (klass), \ + RBIMPL_DATA_FUNC(mark), \ + RBIMPL_DATA_FUNC(free), \ + RBIMPL_CAST((void **)&(sval)), \ + sizeof(type)) +#endif + +#define Data_Get_Struct(obj, type, sval) \ + ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj))) + +RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() +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); +} + +static inline void * +rb_data_object_get(VALUE obj) +{ + Check_Type(obj, RUBY_T_DATA); + return DATA_PTR(obj); +} + +RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() +static inline void * +rb_data_object_get_warning(VALUE obj) +{ + return rb_data_object_get(obj); +} + +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# define rb_data_object_wrap_warning(klass, ptr, mark, free) \ + RB_GNUC_EXTENSION( \ + __builtin_choose_expr( \ + __builtin_constant_p(klass) && !(klass), \ + rb_data_object_wrap(klass, ptr, mark, free), \ + (rb_data_object_wrap_warning)(klass, ptr, mark, free))) +#endif + +static inline VALUE +rb_data_object_make(VALUE klass, RUBY_DATA_FUNC mark_func, RUBY_DATA_FUNC free_func, void **datap, size_t size) +{ + Data_Make_Struct0(result, klass, void, size, mark_func, free_func, *datap); + return result; +} + +RBIMPL_ATTR_DEPRECATED(("by: rb_data_object_wrap")) +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); +} + +#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 /* RBIMPL_RDATA_H */ diff --git a/include/ruby/internal/core/rfile.h b/include/ruby/internal/core/rfile.h new file mode 100644 index 0000000000..4f3ff3f8af --- /dev/null +++ b/include/ruby/internal/core/rfile.h @@ -0,0 +1,36 @@ +#ifndef RBIMPL_RFILE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RFILE_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines struct ::RFile. + */ +#include "ruby/impl/core/rbasic.h" +#include "ruby/impl/cast.h" + +/* rb_io_t is in ruby/io.h. The header file has historically not been included + * into ruby/ruby.h. We follow that tradition. */ +struct rb_io_t; + +struct RFile { + struct RBasic basic; + struct rb_io_t *fptr; +}; + +#define RFILE(obj) RBIMPL_CAST((struct RFile *)(obj)) +#endif /* RBIMPL_RFILE_H */ diff --git a/include/ruby/internal/core/rhash.h b/include/ruby/internal/core/rhash.h new file mode 100644 index 0000000000..a4be7a3a11 --- /dev/null +++ b/include/ruby/internal/core/rhash.h @@ -0,0 +1,62 @@ +#ifndef RBIMPL_RHASH_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RHASH_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Routines to manipulate struct ::RHash. + * + * Shyouhei really suffered agnish over placement of macros in this file. They + * are half-brken. The situation (as of wriring) is: + * + * - #RHASH_TBL: works. + * - #RHASH_ITER_LEV: compile-time error. + * - #RHASH_IFNONE: compile-time error. + * - #RHASH_SIZE: works. + * - #RHASH_EMPTY_P: works. + * - #RHASH_SET_IFNONE: works (why... given you cannot query). + * + * Shyouhei stopped thinking. Let them be as is. + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include <stddef.h> +#endif + +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY +# include "ruby/backward.h" +#endif + +#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 st_table; /* in ruby/st.h */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() +size_t rb_hash_size_num(VALUE hash); +struct st_table *rb_hash_tbl(VALUE, const char *file, int line); +VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone); +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_RHASH_H */ diff --git a/include/ruby/internal/core/rmatch.h b/include/ruby/internal/core/rmatch.h new file mode 100644 index 0000000000..9474b82e4c --- /dev/null +++ b/include/ruby/internal/core/rmatch.h @@ -0,0 +1,73 @@ +#ifndef RBIMPL_RMATCH_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RMATCH_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines struct ::RMatch. + */ +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/attr/returns_nonnull.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/core/rbasic.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" +#include "ruby/assert.h" + +#define RMATCH(obj) RBIMPL_CAST((struct RMatch *)(obj)) +/** @cond INTERNAL_MACRO */ +#define RMATCH_REGS RMATCH_REGS +/** @endcond */ + +struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */ +struct re_registers; /* Also in onigmo.h */ + +/* @shyouhei wonders: is anyone actively using this typedef ...? */ +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 */ +}; + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ARTIFICIAL() +static inline struct re_registers * +RMATCH_REGS(VALUE match) +{ + RBIMPL_ASSERT_TYPE(match, RUBY_T_MATCH); + RBIMPL_ASSERT_OR_ASSUME(RMATCH(match)->rmatch != NULL); + return &RMATCH(match)->rmatch->regs; +} + +#endif /* RBIMPL_RMATCH_H */ diff --git a/include/ruby/internal/core/robject.h b/include/ruby/internal/core/robject.h new file mode 100644 index 0000000000..5a65bc1d0a --- /dev/null +++ b/include/ruby/internal/core/robject.h @@ -0,0 +1,97 @@ +#ifndef RBIMPL_ROBJECT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ROBJECT_H +/** + * @file + * @author Ruby developers <[email protected]> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines struct ::RObject. + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_STDINT_H +# include <stdint.h> +#endif + +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/fl_type.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" + +#define ROBJECT(obj) RBIMPL_CAST((struct RObject *)(obj)) +#define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX +#define ROBJECT_EMBED ROBJECT_EMBED +/** @cond INTERNAL_MACRO */ +#define ROBJECT_NUMIV ROBJECT_NUMIV +#define ROBJECT_IVPTR ROBJECT_IVPTR +/** @endcond */ + +enum ruby_robject_flags { ROBJECT_EMBED = RUBY_FL_USER1 }; + +enum ruby_robject_consts { ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE) }; + +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; +}; + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline uint32_t +ROBJECT_NUMIV(VALUE obj) +{ + RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT); + + if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) { + return ROBJECT_EMBED_LEN_MAX; + } + else { + return ROBJECT(obj)->as.heap.numiv; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE * +ROBJECT_IVPTR(VALUE obj) +{ + RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT); + + struct RObject *const ptr = ROBJECT(obj); + + if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) { + return ptr->as.ary; + } + else { + return ptr->as.heap.ivptr; + } +} + +#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) + +#endif /* RBIMPL_ROBJECT_H */ diff --git a/include/ruby/internal/core/rregexp.h b/include/ruby/internal/core/rregexp.h new file mode 100644 index 0000000000..eff7bcc6e9 --- /dev/null +++ b/include/ruby/internal/core/rregexp.h @@ -0,0 +1,84 @@ +#ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RREGEXP_H +/** + * @file + * @author Ruby developers < |