From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/internal.h | 1187 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1187 insertions(+) create mode 100644 jni/ruby/internal.h (limited to 'jni/ruby/internal.h') diff --git a/jni/ruby/internal.h b/jni/ruby/internal.h new file mode 100644 index 0000000..9161122 --- /dev/null +++ b/jni/ruby/internal.h @@ -0,0 +1,1187 @@ +/********************************************************************** + + internal.h - + + $Author$ + created at: Tue May 17 11:42:20 JST 2011 + + Copyright (C) 2011 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_INTERNAL_H +#define RUBY_INTERNAL_H 1 + +#include "ruby.h" +#include "ruby/encoding.h" +#include "ruby/io.h" + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +/* likely */ +#if __GNUC__ >= 3 +#define LIKELY(x) (__builtin_expect((x), 1)) +#define UNLIKELY(x) (__builtin_expect((x), 0)) +#else /* __GNUC__ >= 3 */ +#define LIKELY(x) (x) +#define UNLIKELY(x) (x) +#endif /* __GNUC__ >= 3 */ + +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif + +#if __has_attribute(unused) +#define UNINITIALIZED_VAR(x) x __attribute__((unused)) +#elif defined(__GNUC__) && __GNUC__ >= 3 +#define UNINITIALIZED_VAR(x) x = x +#else +#define UNINITIALIZED_VAR(x) x +#endif + +#if __has_attribute(warn_unused_result) +#define WARN_UNUSED_RESULT(x) x __attribute__((warn_unused_result)) +#elif defined(__GNUC__) && (__GNUC__ * 1000 + __GNUC_MINOR__) >= 3004 +#define WARN_UNUSED_RESULT(x) x __attribute__((warn_unused_result)) +#else +#define WARN_UNUSED_RESULT(x) x +#endif + +#ifdef HAVE_VALGRIND_MEMCHECK_H +# include +# ifndef VALGRIND_MAKE_MEM_DEFINED +# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n)) +# endif +# ifndef VALGRIND_MAKE_MEM_UNDEFINED +# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n)) +# endif +#else +# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0 +# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 +#endif + +#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) + +#define GCC_VERSION_SINCE(major, minor, patchlevel) \ + (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ + ((__GNUC__ > (major)) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) + +#if GCC_VERSION_SINCE(4, 6, 0) +# define STATIC_ASSERT(name, expr) _Static_assert(expr, #name ": " #expr) +#else +# define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)] +#endif + +#define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1) +#define SIGNED_INTEGER_MAX(sint_type) \ + (sint_type) \ + ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \ + ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1)) +#define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1) +#define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0) + +#if SIGNEDNESS_OF_TIME_T < 0 /* signed */ +# define TIMET_MAX SIGNED_INTEGER_MAX(time_t) +# define TIMET_MIN SIGNED_INTEGER_MIN(time_t) +#elif SIGNEDNESS_OF_TIME_T > 0 /* unsigned */ +# define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t) +# define TIMET_MIN ((time_t)0) +#endif +#define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1)) + +#define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \ + (a) == 0 ? 0 : \ + (a) == -1 ? (b) < -(max) : \ + (a) > 0 ? \ + ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \ + ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b))) +#define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX) +#define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX) +#define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX) + +#ifndef swap16 +# ifdef HAVE_BUILTIN___BUILTIN_BSWAP16 +# define swap16(x) __builtin_bswap16(x) +# endif +#endif + +#ifndef swap16 +# define swap16(x) ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF))) +#endif + +#ifndef swap32 +# ifdef HAVE_BUILTIN___BUILTIN_BSWAP32 +# define swap32(x) __builtin_bswap32(x) +# endif +#endif + +#ifndef swap32 +# define swap32(x) ((uint32_t)((((x)&0xFF)<<24) \ + |(((x)>>24)&0xFF) \ + |(((x)&0x0000FF00)<<8) \ + |(((x)&0x00FF0000)>>8) )) +#endif + +#ifndef swap64 +# ifdef HAVE_BUILTIN___BUILTIN_BSWAP64 +# define swap64(x) __builtin_bswap64(x) +# endif +#endif + +#ifndef swap64 +# ifdef HAVE_INT64_T +# define byte_in_64bit(n) ((uint64_t)0xff << (n)) +# define swap64(x) ((uint64_t)((((x)&byte_in_64bit(0))<<56) \ + |(((x)>>56)&0xFF) \ + |(((x)&byte_in_64bit(8))<<40) \ + |(((x)&byte_in_64bit(48))>>40) \ + |(((x)&byte_in_64bit(16))<<24) \ + |(((x)&byte_in_64bit(40))>>24) \ + |(((x)&byte_in_64bit(24))<<8) \ + |(((x)&byte_in_64bit(32))>>8))) +# endif +#endif + +static inline int +nlz_int(unsigned int x) +{ +#if defined(HAVE_BUILTIN___BUILTIN_CLZ) + if (x == 0) return SIZEOF_INT * CHAR_BIT; + return __builtin_clz(x); +#else + unsigned int y; +# if 64 < SIZEOF_INT * CHAR_BIT + int n = 128; +# elif 32 < SIZEOF_INT * CHAR_BIT + int n = 64; +# else + int n = 32; +# endif +# if 64 < SIZEOF_INT * CHAR_BIT + y = x >> 64; if (y) {n -= 64; x = y;} +# endif +# if 32 < SIZEOF_INT * CHAR_BIT + y = x >> 32; if (y) {n -= 32; x = y;} +# endif + y = x >> 16; if (y) {n -= 16; x = y;} + y = x >> 8; if (y) {n -= 8; x = y;} + y = x >> 4; if (y) {n -= 4; x = y;} + y = x >> 2; if (y) {n -= 2; x = y;} + y = x >> 1; if (y) {return n - 2;} + return (int)(n - x); +#endif +} + +static inline int +nlz_long(unsigned long x) +{ +#if defined(HAVE_BUILTIN___BUILTIN_CLZL) + if (x == 0) return SIZEOF_LONG * CHAR_BIT; + return __builtin_clzl(x); +#else + unsigned long y; +# if 64 < SIZEOF_LONG * CHAR_BIT + int n = 128; +# elif 32 < SIZEOF_LONG * CHAR_BIT + int n = 64; +# else + int n = 32; +# endif +# if 64 < SIZEOF_LONG * CHAR_BIT + y = x >> 64; if (y) {n -= 64; x = y;} +# endif +# if 32 < SIZEOF_LONG * CHAR_BIT + y = x >> 32; if (y) {n -= 32; x = y;} +# endif + y = x >> 16; if (y) {n -= 16; x = y;} + y = x >> 8; if (y) {n -= 8; x = y;} + y = x >> 4; if (y) {n -= 4; x = y;} + y = x >> 2; if (y) {n -= 2; x = y;} + y = x >> 1; if (y) {return n - 2;} + return (int)(n - x); +#endif +} + +#ifdef HAVE_LONG_LONG +static inline int +nlz_long_long(unsigned LONG_LONG x) +{ +#if defined(HAVE_BUILTIN___BUILTIN_CLZLL) + if (x == 0) return SIZEOF_LONG_LONG * CHAR_BIT; + return __builtin_clzll(x); +#else + unsigned LONG_LONG y; +# if 64 < SIZEOF_LONG_LONG * CHAR_BIT + int n = 128; +# elif 32 < SIZEOF_LONG_LONG * CHAR_BIT + int n = 64; +# else + int n = 32; +# endif +# if 64 < SIZEOF_LONG_LONG * CHAR_BIT + y = x >> 64; if (y) {n -= 64; x = y;} +# endif +# if 32 < SIZEOF_LONG_LONG * CHAR_BIT + y = x >> 32; if (y) {n -= 32; x = y;} +# endif + y = x >> 16; if (y) {n -= 16; x = y;} + y = x >> 8; if (y) {n -= 8; x = y;} + y = x >> 4; if (y) {n -= 4; x = y;} + y = x >> 2; if (y) {n -= 2; x = y;} + y = x >> 1; if (y) {return n - 2;} + return (int)(n - x); +#endif +} +#endif + +#ifdef HAVE_UINT128_T +static inline int +nlz_int128(uint128_t x) +{ + uint128_t y; + int n = 128; + y = x >> 64; if (y) {n -= 64; x = y;} + y = x >> 32; if (y) {n -= 32; x = y;} + y = x >> 16; if (y) {n -= 16; x = y;} + y = x >> 8; if (y) {n -= 8; x = y;} + y = x >> 4; if (y) {n -= 4; x = y;} + y = x >> 2; if (y) {n -= 2; x = y;} + y = x >> 1; if (y) {return n - 2;} + return (int)(n - x); +} +#endif + +#if defined(HAVE_UINT128_T) +# define bit_length(x) \ + (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ + sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \ + sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \ + SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x))) +#elif defined(HAVE_LONG_LONG) +# define bit_length(x) \ + (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ + sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \ + SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x))) +#else +# define bit_length(x) \ + (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ + SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x))) +#endif + +struct rb_deprecated_classext_struct { + char conflict[sizeof(VALUE) * 3]; +}; + +struct rb_subclass_entry; +typedef struct rb_subclass_entry rb_subclass_entry_t; + +struct rb_subclass_entry { + VALUE klass; + rb_subclass_entry_t *next; +}; + +#if defined(HAVE_LONG_LONG) +typedef unsigned LONG_LONG rb_serial_t; +#define SERIALT2NUM ULL2NUM +#elif defined(HAVE_UINT64_T) +typedef uint64_t rb_serial_t; +#define SERIALT2NUM SIZET2NUM +#else +typedef unsigned long rb_serial_t; +#define SERIALT2NUM ULONG2NUM +#endif + +struct rb_classext_struct { + struct st_table *iv_index_tbl; + struct st_table *iv_tbl; + struct st_table *const_tbl; + rb_subclass_entry_t *subclasses; + rb_subclass_entry_t **parent_subclasses; + /** + * In the case that this is an `ICLASS`, `module_subclasses` points to the link + * in the module's `subclasses` list that indicates that the klass has been + * included. Hopefully that makes sense. + */ + rb_subclass_entry_t **module_subclasses; + rb_serial_t class_serial; + VALUE origin; + VALUE refined_class; + rb_alloc_func_t allocator; +}; + +struct method_table_wrapper { + st_table *tbl; + size_t serial; +}; + +#ifndef BDIGIT +# if SIZEOF_INT*2 <= SIZEOF_LONG_LONG +# define BDIGIT unsigned int +# define SIZEOF_BDIGIT SIZEOF_INT +# define BDIGIT_DBL unsigned LONG_LONG +# define BDIGIT_DBL_SIGNED LONG_LONG +# define PRI_BDIGIT_PREFIX "" +# define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX +# elif SIZEOF_INT*2 <= SIZEOF_LONG +# define BDIGIT unsigned int +# define SIZEOF_BDIGIT SIZEOF_INT +# define BDIGIT_DBL unsigned long +# define BDIGIT_DBL_SIGNED long +# define PRI_BDIGIT_PREFIX "" +# define PRI_BDIGIT_DBL_PREFIX "l" +# elif SIZEOF_SHORT*2 <= SIZEOF_LONG +# define BDIGIT unsigned short +# define SIZEOF_BDIGIT SIZEOF_SHORT +# define BDIGIT_DBL unsigned long +# define BDIGIT_DBL_SIGNED long +# define PRI_BDIGIT_PREFIX "h" +# define PRI_BDIGIT_DBL_PREFIX "l" +# else +# define BDIGIT unsigned short +# define SIZEOF_BDIGIT (SIZEOF_LONG/2) +# define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG +# define BDIGIT_DBL unsigned long +# define BDIGIT_DBL_SIGNED long +# define PRI_BDIGIT_PREFIX "h" +# define PRI_BDIGIT_DBL_PREFIX "l" +# endif +#endif +#ifndef SIZEOF_ACTUAL_BDIGIT +# define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT +#endif + +#ifdef PRI_BDIGIT_PREFIX +# define PRIdBDIGIT PRI_BDIGIT_PREFIX"d" +# define PRIiBDIGIT PRI_BDIGIT_PREFIX"i" +# define PRIoBDIGIT PRI_BDIGIT_PREFIX"o" +# define PRIuBDIGIT PRI_BDIGIT_PREFIX"u" +# define PRIxBDIGIT PRI_BDIGIT_PREFIX"x" +# define PRIXBDIGIT PRI_BDIGIT_PREFIX"X" +#endif + +#ifdef PRI_BDIGIT_DBL_PREFIX +# define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d" +# define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i" +# define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o" +# define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u" +# define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x" +# define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X" +#endif + +#define BIGNUM_EMBED_LEN_NUMBITS 3 +#ifndef BIGNUM_EMBED_LEN_MAX +# if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1 +# define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) +# else +# define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1) +# endif +#endif + +struct RBignum { + struct RBasic basic; + union { + struct { + size_t len; + BDIGIT *digits; + } heap; + BDIGIT ary[BIGNUM_EMBED_LEN_MAX]; + } as; +}; +#define BIGNUM_SIGN_BIT FL_USER1 +/* sign: positive:1, negative:0 */ +#define BIGNUM_SIGN(b) ((RBASIC(b)->flags & BIGNUM_SIGN_BIT) != 0) +#define BIGNUM_SET_SIGN(b,sign) \ + ((sign) ? (RBASIC(b)->flags |= BIGNUM_SIGN_BIT) \ + : (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT)) +#define BIGNUM_POSITIVE_P(b) BIGNUM_SIGN(b) +#define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b)) + +#define BIGNUM_EMBED_FLAG FL_USER2 +#define BIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3) +#define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS) +#define BIGNUM_LEN(b) \ + ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \ + (long)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \ + (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \ + RBIGNUM(b)->as.heap.len) +/* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */ +#define BIGNUM_DIGITS(b) \ + ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \ + RBIGNUM(b)->as.ary : \ + RBIGNUM(b)->as.heap.digits) +#define BIGNUM_LENINT(b) rb_long2int(BIGNUM_LEN(b)) + +#define RBIGNUM(obj) (R_CAST(RBignum)(obj)) + +struct RRational { + struct RBasic basic; + const VALUE num; + const VALUE den; +}; + +#define RRATIONAL(obj) (R_CAST(RRational)(obj)) + +struct RFloat { + struct RBasic basic; + double float_value; +}; + +#define RFLOAT(obj) (R_CAST(RFloat)(obj)) + +struct RComplex { + struct RBasic basic; + const VALUE real; + const VALUE imag; +}; + +#define RCOMPLEX(obj) (R_CAST(RComplex)(obj)) + +#ifdef RCOMPLEX_SET_REAL /* shortcut macro for internal only */ +#undef RCOMPLEX_SET_REAL +#undef RCOMPLEX_SET_REAL +#define RCOMPLEX_SET_REAL(cmp, r) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->real,(r)) +#define RCOMPLEX_SET_IMAG(cmp, i) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->imag,(i)) +#endif + +struct RHash { + struct RBasic basic; + struct st_table *ntbl; /* possibly 0 */ + int iter_lev; + const VALUE ifnone; +}; + +#define RHASH(obj) (R_CAST(RHash)(obj)) + +#ifdef RHASH_ITER_LEV +#undef RHASH_ITER_LEV +#undef RHASH_IFNONE +#undef RHASH_SIZE +#define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev) +#define RHASH_IFNONE(h) (RHASH(h)->ifnone) +#define RHASH_SIZE(h) (RHASH(h)->ntbl ? (st_index_t)RHASH(h)->ntbl->num_entries : 0) +#endif + +/* missing/setproctitle.c */ +#ifndef HAVE_SETPROCTITLE +extern void ruby_init_setproctitle(int argc, char *argv[]); +#endif + +/* class.c */ +void rb_class_subclass_add(VALUE super, VALUE klass); +void rb_class_remove_from_super_subclasses(VALUE); + +#define RCLASS_EXT(c) (RCLASS(c)->ptr) +#define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl) +#define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl) +#define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper) +#define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0) +#define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl) +#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin) +#define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class) +#define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial) + +static inline void +RCLASS_M_TBL_INIT(VALUE c) +{ + struct method_table_wrapper *wrapper; + wrapper = ALLOC(struct method_table_wrapper); + wrapper->tbl = st_init_numtable(); + wrapper->serial = 0; + RCLASS_M_TBL_WRAPPER(c) = wrapper; +} + +#undef RCLASS_SUPER +static inline VALUE +RCLASS_SUPER(VALUE klass) +{ + return RCLASS(klass)->super; +} + +static inline VALUE +RCLASS_SET_SUPER(VALUE klass, VALUE super) +{ + if (super) { + rb_class_remove_from_super_subclasses(klass); + rb_class_subclass_add(super, klass); + } + RB_OBJ_WRITE(klass, &RCLASS(klass)->super, super); + return super; +} + +struct vtm; /* defined by timev.h */ + +/* array.c */ +VALUE rb_ary_last(int, const VALUE *, VALUE); +void rb_ary_set_len(VALUE, long); +void rb_ary_delete_same(VALUE, VALUE); +VALUE rb_ary_tmp_new_fill(long capa); +size_t rb_ary_memsize(VALUE); +#ifdef __GNUC__ +#define rb_ary_new_from_args(n, ...) \ + __extension__ ({ \ + const VALUE args_to_new_ary[] = {__VA_ARGS__}; \ + if (__builtin_constant_p(n)) { \ + STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \ + } \ + rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \ + }) +#endif + +/* bignum.c */ +extern const char ruby_digitmap[]; +VALUE rb_big_fdiv(VALUE x, VALUE y); +VALUE rb_big_uminus(VALUE x); +VALUE rb_integer_float_cmp(VALUE x, VALUE y); +VALUE rb_integer_float_eq(VALUE x, VALUE y); + +/* class.c */ +void rb_class_foreach_subclass(VALUE klass, void(*f)(VALUE)); +void rb_class_detach_subclasses(VALUE); +void rb_class_detach_module_subclasses(VALUE); +void rb_class_remove_from_module_subclasses(VALUE); +VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj); +VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj); +VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj); +VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj); +int rb_obj_basic_to_s_p(VALUE); +VALUE rb_special_singleton_class(VALUE); +VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach); +VALUE rb_singleton_class_get(VALUE obj); +void Init_class_hierarchy(void); + +/* compar.c */ +VALUE rb_invcmp(VALUE, VALUE); + +/* compile.c */ +int rb_dvar_defined(ID); +int rb_local_defined(ID); +int rb_parse_in_eval(void); +int rb_parse_in_main(void); +const char * rb_insns_name(int i); +VALUE rb_insns_name_array(void); + +/* cont.c */ +VALUE rb_obj_is_fiber(VALUE); +void rb_fiber_reset_root_local_storage(VALUE); +void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS)); + +/* debug.c */ +PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2); + +/* dmyext.c */ +void Init_enc(void); +void Init_ext(void); + +/* encoding.c */ +enum ruby_preserved_encindex { + ENCINDEX_ASCII, + ENCINDEX_UTF_8, + ENCINDEX_US_ASCII, + + /* preserved indexes */ + ENCINDEX_UTF_16BE, + ENCINDEX_UTF_16LE, + ENCINDEX_UTF_32BE, + ENCINDEX_UTF_32LE, + ENCINDEX_UTF_16, + ENCINDEX_UTF_32, + ENCINDEX_UTF8_MAC, + + /* for old options of regexp */ + ENCINDEX_EUC_JP, + ENCINDEX_Windows_31J, + + ENCINDEX_BUILTIN_MAX +}; + +#define rb_ascii8bit_encindex() ENCINDEX_ASCII +#define rb_utf8_encindex() ENCINDEX_UTF_8 +#define rb_usascii_encindex() ENCINDEX_US_ASCII +ID rb_id_encoding(void); +void rb_gc_mark_encodings(void); +rb_encoding *rb_enc_get_from_index(int index); +int rb_encdb_replicate(const char *alias, const char *orig); +int rb_encdb_alias(const char *alias, const char *orig); +int rb_encdb_dummy(const char *name); +void rb_encdb_declare(const char *name); +void rb_enc_set_base(const char *name, const char *orig); +int rb_enc_set_dummy(int index); +void rb_encdb_set_unicode(int index); + +/* enum.c */ +VALUE rb_f_send(int argc, VALUE *argv, VALUE recv); + +/* error.c */ +extern VALUE rb_eEAGAIN; +extern VALUE rb_eEWOULDBLOCK; +extern VALUE rb_eEINPROGRESS; +NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4)); +VALUE rb_check_backtrace(VALUE); +NORETURN(void rb_async_bug_errno(const char *,int)); +const char *rb_builtin_type_name(int t); +const char *rb_builtin_class_name(VALUE x); +PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); + +/* eval.c */ +VALUE rb_refinement_module_get_refined_class(VALUE module); + +/* eval_error.c */ +void ruby_error_print(void); +VALUE rb_get_backtrace(VALUE info); + +/* eval_jump.c */ +void rb_call_end_proc(VALUE data); +void rb_mark_end_proc(void); + +/* file.c */ +VALUE rb_home_dir_of(VALUE user, VALUE result); +VALUE rb_default_home_dir(VALUE result); +VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict); +void rb_file_const(const char*, VALUE); +int rb_file_load_ok(const char *); +VALUE rb_file_expand_path_fast(VALUE, VALUE); +VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE); +VALUE rb_get_path_check_to_string(VALUE, int); +VALUE rb_get_path_check_convert(VALUE, VALUE, int); +void Init_File(void); + +#ifdef RUBY_FUNCTION_NAME_STRING +# if defined __GNUC__ && __GNUC__ >= 4 +# pragma GCC visibility push(default) +# endif +NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path)); +NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path)); +# if defined __GNUC__ && __GNUC__ >= 4 +# pragma GCC visibility pop +# endif +# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path) +# define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path)) +#else +# define rb_sys_fail_path(path) rb_sys_fail_str(path) +# define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path)) +#endif + +/* gc.c */ +extern VALUE *ruby_initial_gc_stress_ptr; +extern int ruby_disable_gc; +void Init_heap(void); +void *ruby_mimmalloc(size_t size); +void ruby_mimfree(void *ptr); +void rb_objspace_set_event_hook(const rb_event_flag_t event); +#if USE_RGENGC +void rb_gc_writebarrier_remember(VALUE obj); +#else +#define rb_gc_writebarrier_remember(obj) 0 +#endif +void ruby_gc_set_params(int safe_level); +void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj); + +#if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32) +#define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size) +#define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size) +#define ruby_sized_xfree(ptr, size) ruby_xfree(ptr) +#define SIZED_REALLOC_N(var,type,n,old_n) REALLOC_N(var, type, n) +#else +void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_ALLOC_SIZE((2)); +void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_ALLOC_SIZE((2, 3)); +void ruby_sized_xfree(void *x, size_t size); +#define SIZED_REALLOC_N(var,type,n,old_n) ((var)=(type*)ruby_sized_xrealloc((char*)(var), (n) * sizeof(type), (old_n) * sizeof(type))) +#endif + +void rb_gc_resurrect(VALUE ptr); + +/* hash.c */ +struct st_table *rb_hash_tbl_raw(VALUE hash); +VALUE rb_hash_has_key(VALUE hash, VALUE key); +VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc); +long rb_objid_hash(st_index_t index); +VALUE rb_ident_hash_new(void); +st_table *rb_init_identtable(void); +st_table *rb_init_identtable_with_size(st_index_t size); + +#define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h) +VALUE rb_hash_keys(VALUE hash); +VALUE rb_hash_values(VALUE hash); +#define HASH_DELETED FL_USER1 +#define HASH_PROC_DEFAULT FL_USER2 + +/* inits.c */ +void rb_call_inits(void); + +/* io.c */ +const char *ruby_get_inplace_mode(void); +void ruby_set_inplace_mode(const char *); +ssize_t rb_io_bufread(VALUE io, void *buf, size_t size); +void rb_stdio_set_default_encoding(void); +void rb_write_error_str(VALUE mesg); +VALUE rb_io_flush_raw(VALUE, int); +size_t rb_io_memsize(const rb_io_t *); + +/* iseq.c */ +VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase); +VALUE rb_iseq_path(VALUE iseqval); +VALUE rb_iseq_absolute_path(VALUE iseqval); +VALUE rb_iseq_label(VALUE iseqval); +VALUE rb_iseq_base_label(VALUE iseqval); +VALUE rb_iseq_first_lineno(VALUE iseqval); +VALUE rb_iseq_klass(VALUE iseqval); /* completely temporary fucntion */ +VALUE rb_iseq_method_name(VALUE self); + +/* load.c */ +VALUE rb_get_load_path(void); +VALUE rb_get_expanded_load_path(void); +int rb_require_internal(VALUE fname, int safe); +NORETURN(void rb_load_fail(VALUE, const char*)); + +/* loadpath.c */ +extern const char ruby_exec_prefix[]; +extern const char ruby_initial_load_paths[]; + +/* localeinit.c */ +int Init_enc_set_filesystem_encoding(void); + +/* math.c */ +VALUE rb_math_atan2(VALUE, VALUE); +VALUE rb_math_cos(VALUE); +VALUE rb_math_cosh(VALUE); +VALUE rb_math_exp(VALUE); +VALUE rb_math_hypot(VALUE, VALUE); +VALUE rb_math_log(int argc, const VALUE *argv); +VALUE rb_math_sin(VALUE); +VALUE rb_math_sinh(VALUE); +#if 0 +VALUE rb_math_sqrt(VALUE); +#endif + +/* newline.c */ +void Init_newline(void); + +/* numeric.c */ +int rb_num_to_uint(VALUE val, unsigned int *ret); +VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl); +int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl); +double ruby_float_mod(double x, double y); +int rb_num_negative_p(VALUE); +VALUE rb_int_succ(VALUE num); +VALUE rb_int_pred(VALUE num); +VALUE rb_dbl_hash(double d); + +#if USE_FLONUM +#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n))) +#define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n))) +#endif + +static inline double +rb_float_value_inline(VALUE v) +{ +#if USE_FLONUM + if (FLONUM_P(v)) { + if (v != (VALUE)0x8000000000000002) { /* LIKELY */ + union { + double d; + VALUE v; + } t; + + VALUE b63 = (v >> 63); + /* e: xx1... -> 011... */ + /* xx0... -> 100... */ + /* ^b63 */ + t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3); + return t.d; + } + else { + return 0.0; + } + } +#endif + return ((struct RFloat *)v)->float_value; +} + +static inline VALUE +rb_float_new_inline(double d) +{ +#if USE_FLONUM + union { + double d; + VALUE v; + } t; + int bits; + + t.d = d; + bits = (int)((VALUE)(t.v >> 60) & 0x7); + /* bits contains 3 bits of b62..b60. */ + /* bits - 3 = */ + /* b011 -> b000 */ + /* b100 -> b001 */ + + if (t.v != 0x3000000000000000 /* 1.72723e-77 */ && + !((bits-3) & ~0x01)) { + return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02; + } + else if (t.v == (VALUE)0) { + /* +0.0 */ + return 0x8000000000000002; + } + /* out of range */ +#endif + return rb_float_new_in_heap(d); +} + +#define rb_float_value(v) rb_float_value_inline(v) +#define rb_float_new(d) rb_float_new_inline(d) + +/* object.c */ +void rb_obj_copy_ivar(VALUE dest, VALUE obj); +VALUE rb_obj_equal(VALUE obj1, VALUE obj2); +VALUE rb_class_search_ancestor(VALUE klass, VALUE super); + +struct RBasicRaw { + VALUE flags; + VALUE klass; +}; + +#define RBASIC_CLEAR_CLASS(obj) (((struct RBasicRaw *)((VALUE)(obj)))->klass = 0) +#define RBASIC_SET_CLASS_RAW(obj, cls) (((struct RBasicRaw *)((VALUE)(obj)))->klass = (cls)) +#define RBASIC_SET_CLASS(obj, cls) do { \ + VALUE _obj_ = (obj); \ + RB_OBJ_WRITE(_obj_, &((struct RBasicRaw *)(_obj_))->klass, cls); \ +} while (0) + +/* parse.y */ +#ifndef USE_SYMBOL_GC +#define USE_SYMBOL_GC 1 +#endif +VALUE rb_parser_get_yydebug(VALUE); +VALUE rb_parser_set_yydebug(VALUE, VALUE); +int rb_is_const_name(VALUE name); +int rb_is_class_name(VALUE name); +int rb_is_global_name(VALUE name); +int rb_is_instance_name(VALUE name); +int rb_is_attrset_name(VALUE name); +int rb_is_local_name(VALUE name); +int rb_is_method_name(VALUE name); +int rb_is_junk_name(VALUE name); +int rb_is_const_sym(VALUE sym); +int rb_is_class_sym(VALUE sym); +int rb_is_global_sym(VALUE sym); +int rb_is_instance_sym(VALUE sym); +int rb_is_attrset_sym(VALUE sym); +int rb_is_local_sym(VALUE sym); +int rb_is_method_sym(VALUE sym); +int rb_is_junk_sym(VALUE sym); +ID rb_make_internal_id(void); +void rb_gc_free_dsymbol(VALUE); +ID rb_id_attrget(ID id); + +/* proc.c */ +VALUE rb_proc_location(VALUE self); +st_index_t rb_hash_proc(st_index_t hash, VALUE proc); +int rb_block_arity(void); +VALUE rb_block_clear_env_self(VALUE proc); + +/* process.c */ +#define RB_MAX_GROUPS (65536) + +struct rb_execarg { + union { + struct { + VALUE shell_script; + } sh; + struct { + VALUE command_name; + VALUE command_abspath; /* full path string or nil */ + VALUE argv_str; + VALUE argv_buf; + } cmd; + } invoke; + VALUE redirect_fds; + VALUE envp_str; + VALUE envp_buf; + VALUE dup2_tmpbuf; + unsigned use_shell : 1; + unsigned pgroup_given : 1; + unsigned umask_given : 1; + unsigned unsetenv_others_given : 1; + unsigned unsetenv_others_do : 1; + unsigned close_others_given : 1; + unsigned close_others_do : 1; + unsigned chdir_given : 1; + unsigned new_pgroup_given : 1; + unsigned new_pgroup_flag : 1; + unsigned uid_given : 1; + unsigned gid_given : 1; + rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0