1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

mv include/ruby/{impl,internal}

Devs do not love "impl".
This commit is contained in:
卜部昌平 2020-05-08 18:10:13 +09:00
parent 0d88fe3a72
commit b85fd1d690
Notes: git 2020-05-11 09:24:41 +09:00
143 changed files with 0 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,84 @@
#ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RREGEXP_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RRegexp.
*/
#include "ruby/impl/attr/artificial.h"
#include "ruby/impl/attr/pure.h"
#include "ruby/impl/cast.h"
#include "ruby/impl/core/rbasic.h"
#include "ruby/impl/core/rstring.h"
#include "ruby/impl/value.h"
#include "ruby/impl/value_type.h"
#define RREGEXP(obj) RBIMPL_CAST((struct RRegexp *)(obj))
#define RREGEXP_PTR(obj) (RREGEXP(obj)->ptr)
/** @cond INTERNAL_MACRO */
#define RREGEXP_SRC RREGEXP_SRC
#define RREGEXP_SRC_PTR RREGEXP_SRC_PTR
#define RREGEXP_SRC_LEN RREGEXP_SRC_LEN
#define RREGEXP_SRC_END RREGEXP_SRC_END
/** @endcond */
struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
struct RRegexp {
struct RBasic basic;
struct re_pattern_buffer *ptr;
const VALUE src;
unsigned long usecnt;
};
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline VALUE
RREGEXP_SRC(VALUE rexp)
{
RBIMPL_ASSERT_TYPE(rexp, RUBY_T_REGEXP);
VALUE ret = RREGEXP(rexp)->src;
RBIMPL_ASSERT_TYPE(ret, RUBY_T_STRING);
return ret;
}
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline char *
RREGEXP_SRC_PTR(VALUE rexp)
{
return RSTRING_PTR(RREGEXP_SRC(rexp));
}
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline long
RREGEXP_SRC_LEN(VALUE rexp)
{
return RSTRING_LEN(RREGEXP_SRC(rexp));
}
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline char *
RREGEXP_SRC_END(VALUE rexp)
{
return RSTRING_END(RREGEXP_SRC(rexp));
}
#endif /* RBIMPL_RREGEXP_H */

View file

@ -0,0 +1,215 @@
#ifndef RBIMPL_RSTRING_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RSTRING_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RString.
*/
#include "ruby/impl/config.h"
#include "ruby/impl/arithmetic/long.h"
#include "ruby/impl/attr/artificial.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/value_type.h"
#include "ruby/impl/warning_push.h"
#include "ruby/assert.h"
#define RSTRING(obj) RBIMPL_CAST((struct RString *)(obj))
#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
/** @cond INTERNAL_MACRO */
#define RSTRING_EMBED_LEN RSTRING_EMBED_LEN
#define RSTRING_LEN RSTRING_LEN
#define RSTRING_LENINT RSTRING_LENINT
#define RSTRING_PTR RSTRING_PTR
#define RSTRING_END RSTRING_END
/** @endcond */
#define StringValue(v) rb_string_value(&(v))
#define StringValuePtr(v) rb_string_value_ptr(&(v))
#define StringValueCStr(v) rb_string_value_cstr(&(v))
#define SafeStringValue(v) StringValue(v)
#define ExportStringValue(v) do { \
StringValue(v); \
(v) = rb_str_export(v); \
} while (0)
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,
/* Actually, string encodings are also encoded into the flags, using
* remaining bits.*/
RSTRING_FSTR = RUBY_FL_USER17
};
enum ruby_rstring_consts {
RSTRING_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 2,
RSTRING_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(char) - 1
};
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;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
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*);
VALUE rb_str_export(VALUE);
VALUE rb_str_export_locale(VALUE);
RBIMPL_ATTR_ERROR(("rb_check_safe_str() and Check_SafeStr() are obsolete; use StringValue() instead"))
void rb_check_safe_str(VALUE);
#define Check_SafeStr(v) rb_check_safe_str(RBIMPL_CAST((VALUE)(v)))
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline long
RSTRING_EMBED_LEN(VALUE str)
{
RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING);
RBIMPL_ASSERT_OR_ASSUME(! RB_FL_ANY_RAW(str, RSTRING_NOEMBED));
VALUE f = RBASIC(str)->flags;
f &= RSTRING_EMBED_LEN_MASK;
f >>= RSTRING_EMBED_LEN_SHIFT;
return RBIMPL_CAST((long)f);
}
RBIMPL_WARNING_PUSH()
#if RBIMPL_COMPILER_IS(Intel)
RBIMPL_WARNING_IGNORED(413)
#endif
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline struct RString
rbimpl_rstring_getmem(VALUE str)
{
RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING);
if (RB_FL_ANY_RAW(str, RSTRING_NOEMBED)) {
return *RSTRING(str);
}
else {
/* Expecting compilers to optimize this on-stack struct away. */
struct RString retval;
retval.as.heap.len = RSTRING_EMBED_LEN(str);
retval.as.heap.ptr = RSTRING(str)->as.ary;
return retval;
}
}
RBIMPL_WARNING_POP()
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline long
RSTRING_LEN(VALUE str)
{
return rbimpl_rstring_getmem(str).as.heap.len;
}
RBIMPL_ATTR_ARTIFICIAL()
static inline char *
RSTRING_PTR(VALUE str)
{
char *ptr = rbimpl_rstring_getmem(str).as.heap.ptr;
if (RB_UNLIKELY(! ptr)) {
/* :BEWARE: @shyouhei thinks that currently, there are rooms for this
* function to return NULL. In the 20th century that was a pointless
* concern. However struct RString can hold fake strings nowadays. It
* seems no check against NULL are exercised around handling of them
* (one of such usages is located in marshal.c, which scares
* @shyouhei). Better check here for maximum safety.
*
* Also, this is not rb_warn() because RSTRING_PTR() can be called
* during GC (see what obj_info() does). rb_warn() needs to allocate
* Ruby objects. That is not possible at this moment. */
fprintf(stderr, "%s\n",
"RSTRING_PTR is returning NULL!! "
"SIGSEGV is highly expected to follow immediately. "
"If you could reproduce, attach your debugger here, "
"and look at the passed string."
);
}
return ptr;
}
RBIMPL_ATTR_ARTIFICIAL()
static inline char *
RSTRING_END(VALUE str)
{
struct RString buf = rbimpl_rstring_getmem(str);
if (RB_UNLIKELY(! buf.as.heap.ptr)) {
/* Ditto. */
fprintf(stderr, "%s\n",
"RSTRING_END is returning NULL!! "
"SIGSEGV is highly expected to follow immediately. "
"If you could reproduce, attach your debugger here, "
"and look at the passed string."
);
}
return &buf.as.heap.ptr[buf.as.heap.len];
}
RBIMPL_ATTR_ARTIFICIAL()
static inline int
RSTRING_LENINT(VALUE str)
{
return rb_long2int(RSTRING_LEN(str));
}
#ifdef HAVE_STMT_AND_DECL_IN_EXPR
# define RSTRING_GETMEM(str, ptrvar, lenvar) \
__extension__ ({ \
struct RString rbimpl_str = rbimpl_rstring_getmem(str); \
(ptrvar) = rbimpl_str.as.heap.ptr; \
(lenvar) = rbimpl_str.as.heap.len; \
})
#else
# define RSTRING_GETMEM(str, ptrvar, lenvar) \
((ptrvar) = RSTRING_PTR(str), \
(lenvar) = RSTRING_LEN(str))
#endif /* HAVE_STMT_AND_DECL_IN_EXPR */
#endif /* RBIMPL_RSTRING_H */

View file

@ -0,0 +1,73 @@
#ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RSTRUCT_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Routines to manipulate struct ::RStruct.
*/
#include "ruby/impl/attr/artificial.h"
#include "ruby/impl/dllexport.h"
#include "ruby/impl/value.h"
#include "ruby/impl/value_type.h"
#include "ruby/impl/arithmetic/long.h"
#include "ruby/impl/arithmetic/int.h"
#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY
# include "ruby/backward.h"
#endif
#define RSTRUCT_PTR(st) rb_struct_ptr(st)
/** @cond INTERNAL_MACRO */
#define RSTRUCT_LEN RSTRUCT_LEN
#define RSTRUCT_SET RSTRUCT_SET
#define RSTRUCT_GET RSTRUCT_GET
/** @endcond */
RBIMPL_SYMBOL_EXPORT_BEGIN()
VALUE rb_struct_size(VALUE s);
VALUE rb_struct_aref(VALUE, VALUE);
VALUE rb_struct_aset(VALUE, VALUE, VALUE);
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_ARTIFICIAL()
static inline long
RSTRUCT_LEN(VALUE st)
{
RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
return RB_NUM2LONG(rb_struct_size(st));
}
RBIMPL_ATTR_ARTIFICIAL()
static inline VALUE
RSTRUCT_SET(VALUE st, int k, VALUE v)
{
RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
return rb_struct_aset(st, INT2NUM(k), (v));
}
RBIMPL_ATTR_ARTIFICIAL()
static inline VALUE
RSTRUCT_GET(VALUE st, int k)
{
RBIMPL_ASSERT_TYPE(st, RUBY_T_STRUCT);
return rb_struct_aref(st, INT2NUM(k));
}
#endif /* RBIMPL_RSTRUCT_H */

View file

@ -0,0 +1,184 @@
#ifndef RBIMPL_RTYPEDDATA_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_RTYPEDDATA_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines struct ::RTypedData.
*/
#include "ruby/impl/config.h"
#ifdef STDC_HEADERS
# include <stddef.h>
#endif
#include "ruby/impl/assume.h"
#include "ruby/impl/attr/artificial.h"
#include "ruby/impl/attr/pure.h"
#include "ruby/impl/cast.h"
#include "ruby/impl/core/rbasic.h"
#include "ruby/impl/core/rdata.h"
#include "ruby/impl/dllexport.h"
#include "ruby/impl/error.h"
#include "ruby/impl/fl_type.h"
#include "ruby/impl/stdbool.h"
#include "ruby/impl/value_type.h"
#define HAVE_TYPE_RB_DATA_TYPE_T 1
#define HAVE_RB_DATA_TYPE_T_FUNCTION 1
#define HAVE_RB_DATA_TYPE_T_PARENT 1
#define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
#define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE
#define RTYPEDDATA(obj) RBIMPL_CAST((struct RTypedData *)(obj))
#define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data)
#define Check_TypedStruct(v, t) \
rb_check_typeddata(RBIMPL_CAST((VALUE)(v)), (t))
/** @cond INTERNAL_MACRO */
#define RTYPEDDATA_P RTYPEDDATA_P
#define RTYPEDDATA_TYPE RTYPEDDATA_TYPE
#define RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY
#define RUBY_TYPED_WB_PROTECTED RUBY_TYPED_WB_PROTECTED
#define RUBY_TYPED_PROMOTED1 RUBY_TYPED_PROMOTED1
/** @endcond */
/* bits for rb_data_type_struct::flags */
enum rbimpl_typeddata_flags {
RUBY_TYPED_FREE_IMMEDIATELY = 1,
RUBY_TYPED_WB_PROTECTED = RUBY_FL_WB_PROTECTED, /* THIS FLAG DEPENDS ON Ruby version */
RUBY_TYPED_PROMOTED1 = RUBY_FL_PROMOTED1 /* THIS FLAG DEPENDS ON Ruby version */
};
typedef struct rb_data_type_struct rb_data_type_t;
struct rb_data_type_struct {
const char *wrap_struct_name;
struct {
RUBY_DATA_FUNC dmark;
RUBY_DATA_FUNC dfree;
size_t (*dsize)(const void *);
RUBY_DATA_FUNC dcompact;
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 */
};
struct RTypedData {
struct RBasic basic;
const rb_data_type_t *type;
VALUE typed_flag; /* 1 or not */
void *data;
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
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 obj, const rb_data_type_t *data_type);
void *rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type);
RBIMPL_SYMBOL_EXPORT_END()
#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); \
(sval) = RBIMPL_CAST((type *)RTYPEDDATA_DATA(result)); \
RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval))
#ifdef HAVE_STMT_AND_DECL_IN_EXPR
#define TypedData_Make_Struct(klass, type, data_type, sval) \
RB_GNUC_EXTENSION({ \
TypedData_Make_Struct0( \
data_struct_obj, \
klass, \
type, \
sizeof(type), \
data_type, \
sval); \
data_struct_obj; \
})
#else
#define TypedData_Make_Struct(klass, type, data_type, sval) \
rb_data_typed_object_make( \
(klass), \
(data_type), \
RBIMPL_CAST((void **)&(sval)), \
sizeof(type))
#endif
#define TypedData_Get_Struct(obj,type,data_type,sval) \
((sval) = RBIMPL_CAST((type *)rb_check_typeddata((obj), (data_type))))
RBIMPL_ATTR_PURE()
RBIMPL_ATTR_ARTIFICIAL()
static inline bool
rbimpl_rtypeddata_p(VALUE obj)
{
return RTYPEDDATA(obj)->typed_flag == 1;
}
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
static inline bool
RTYPEDDATA_P(VALUE obj)
{
#if ! RUBY_NDEBUG
if (RB_UNLIKELY(! RB_TYPE_P(obj, RUBY_T_DATA))) {
Check_Type(obj, RUBY_T_DATA);
RBIMPL_UNREACHABLE_RETURN(false);
}
#endif
return rbimpl_rtypeddata_p(obj);
}
RBIMPL_ATTR_PURE_ON_NDEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */
static inline const struct rb_data_type_struct *
RTYPEDDATA_TYPE(VALUE obj)
{
#if ! RUBY_NDEBUG
if (RB_UNLIKELY(! RTYPEDDATA_P(obj))) {
rb_unexpected_type(obj, RUBY_T_DATA);
RBIMPL_UNREACHABLE_RETURN(NULL);
}
#endif
return RTYPEDDATA(obj)->type;
}
static inline VALUE
rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)
{
TypedData_Make_Struct0(result, klass, void, size, type, *datap);
return result;
}
RBIMPL_ATTR_DEPRECATED(("by: rb_data_typed_object_wrap"))
static inline VALUE
rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type)
{
return rb_data_typed_object_wrap(klass, datap, type);
}
#endif /* RBIMPL_RTYPEDDATA_H */