From b85fd1d690b65efaa126cf9c24da73f31eee7a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Fri, 8 May 2020 18:10:13 +0900 Subject: mv include/ruby/{impl,internal} Devs do not love "impl". --- include/ruby/impl/anyargs.h | 375 ------------------- include/ruby/impl/arithmetic.h | 38 -- include/ruby/impl/arithmetic/char.h | 58 --- include/ruby/impl/arithmetic/double.h | 39 -- include/ruby/impl/arithmetic/fixnum.h | 44 --- include/ruby/impl/arithmetic/gid_t.h | 34 -- include/ruby/impl/arithmetic/int.h | 163 -------- include/ruby/impl/arithmetic/intptr_t.h | 42 --- include/ruby/impl/arithmetic/long.h | 244 ------------ include/ruby/impl/arithmetic/long_long.h | 53 --- include/ruby/impl/arithmetic/mode_t.h | 34 -- include/ruby/impl/arithmetic/off_t.h | 49 --- include/ruby/impl/arithmetic/pid_t.h | 34 -- include/ruby/impl/arithmetic/short.h | 54 --- include/ruby/impl/arithmetic/size_t.h | 51 --- include/ruby/impl/arithmetic/st_data_t.h | 59 --- include/ruby/impl/arithmetic/uid_t.h | 34 -- include/ruby/impl/assume.h | 90 ----- include/ruby/impl/attr/alloc_size.h | 32 -- include/ruby/impl/attr/artificial.h | 46 --- include/ruby/impl/attr/cold.h | 37 -- include/ruby/impl/attr/const.h | 46 --- include/ruby/impl/attr/constexpr.h | 85 ----- include/ruby/impl/attr/deprecated.h | 59 --- include/ruby/impl/attr/diagnose_if.h | 42 --- include/ruby/impl/attr/enum_extensibility.h | 32 -- include/ruby/impl/attr/error.h | 32 -- include/ruby/impl/attr/flag_enum.h | 33 -- include/ruby/impl/attr/forceinline.h | 40 -- include/ruby/impl/attr/format.h | 38 -- include/ruby/impl/attr/maybe_unused.h | 38 -- include/ruby/impl/attr/noalias.h | 58 --- include/ruby/impl/attr/nodiscard.h | 45 --- include/ruby/impl/attr/noexcept.h | 91 ----- include/ruby/impl/attr/noinline.h | 35 -- include/ruby/impl/attr/nonnull.h | 32 -- include/ruby/impl/attr/noreturn.h | 52 --- include/ruby/impl/attr/pure.h | 43 --- include/ruby/impl/attr/restrict.h | 45 --- include/ruby/impl/attr/returns_nonnull.h | 37 -- include/ruby/impl/attr/warning.h | 32 -- include/ruby/impl/attr/weakref.h | 32 -- include/ruby/impl/cast.h | 53 --- include/ruby/impl/compiler_is.h | 45 --- include/ruby/impl/compiler_is/apple.h | 41 --- include/ruby/impl/compiler_is/clang.h | 38 -- include/ruby/impl/compiler_is/gcc.h | 46 --- include/ruby/impl/compiler_is/intel.h | 41 --- include/ruby/impl/compiler_is/msvc.h | 57 --- include/ruby/impl/compiler_is/sunpro.h | 55 --- include/ruby/impl/compiler_since.h | 61 --- include/ruby/impl/config.h | 131 ------- include/ruby/impl/constant_p.h | 37 -- include/ruby/impl/core.h | 35 -- include/ruby/impl/core/rarray.h | 275 -------------- include/ruby/impl/core/rbasic.h | 85 ----- include/ruby/impl/core/rbignum.h | 51 --- include/ruby/impl/core/rclass.h | 47 --- include/ruby/impl/core/rdata.h | 174 --------- include/ruby/impl/core/rfile.h | 36 -- include/ruby/impl/core/rhash.h | 62 ---- include/ruby/impl/core/rmatch.h | 73 ---- include/ruby/impl/core/robject.h | 97 ----- include/ruby/impl/core/rregexp.h | 84 ----- include/ruby/impl/core/rstring.h | 215 ----------- include/ruby/impl/core/rstruct.h | 73 ---- include/ruby/impl/core/rtypeddata.h | 184 ---------- include/ruby/impl/ctype.h | 203 ---------- include/ruby/impl/dllexport.h | 92 ----- include/ruby/impl/dosish.h | 63 ---- include/ruby/impl/error.h | 74 ---- include/ruby/impl/eval.h | 50 --- include/ruby/impl/event.h | 75 ---- include/ruby/impl/fl_type.h | 469 ------------------------ include/ruby/impl/gc.h | 35 -- include/ruby/impl/glob.h | 35 -- include/ruby/impl/globals.h | 159 -------- include/ruby/impl/has/attribute.h | 164 --------- include/ruby/impl/has/builtin.h | 105 ------ include/ruby/impl/has/c_attribute.h | 38 -- include/ruby/impl/has/cpp_attribute.h | 79 ---- include/ruby/impl/has/declspec_attribute.h | 48 --- include/ruby/impl/has/extension.h | 33 -- include/ruby/impl/has/feature.h | 31 -- include/ruby/impl/has/warning.h | 31 -- include/ruby/impl/intern/array.h | 78 ---- include/ruby/impl/intern/bignum.h | 105 ------ include/ruby/impl/intern/class.h | 57 --- include/ruby/impl/intern/compar.h | 34 -- include/ruby/impl/intern/complex.h | 60 --- include/ruby/impl/intern/cont.h | 40 -- include/ruby/impl/intern/dir.h | 33 -- include/ruby/impl/intern/enum.h | 33 -- include/ruby/impl/intern/enumerator.h | 79 ---- include/ruby/impl/intern/error.h | 82 ----- include/ruby/impl/intern/eval.h | 59 --- include/ruby/impl/intern/file.h | 44 --- include/ruby/impl/intern/gc.h | 57 --- include/ruby/impl/intern/hash.h | 59 --- include/ruby/impl/intern/io.h | 70 ---- include/ruby/impl/intern/load.h | 39 -- include/ruby/impl/intern/marshal.h | 35 -- include/ruby/impl/intern/numeric.h | 42 --- include/ruby/impl/intern/object.h | 90 ----- include/ruby/impl/intern/parse.h | 64 ---- include/ruby/impl/intern/proc.h | 53 --- include/ruby/impl/intern/process.h | 46 --- include/ruby/impl/intern/random.h | 45 --- include/ruby/impl/intern/range.h | 35 -- include/ruby/impl/intern/rational.h | 46 --- include/ruby/impl/intern/re.h | 50 --- include/ruby/impl/intern/ruby.h | 37 -- include/ruby/impl/intern/select.h | 52 --- include/ruby/impl/intern/select/largesize.h | 103 ------ include/ruby/impl/intern/select/posix.h | 82 ----- include/ruby/impl/intern/select/win32.h | 124 ------- include/ruby/impl/intern/signal.h | 40 -- include/ruby/impl/intern/sprintf.h | 43 --- include/ruby/impl/intern/string.h | 326 ---------------- include/ruby/impl/intern/struct.h | 47 --- include/ruby/impl/intern/thread.h | 76 ---- include/ruby/impl/intern/time.h | 52 --- include/ruby/impl/intern/variable.h | 83 ----- include/ruby/impl/intern/vm.h | 77 ---- include/ruby/impl/interpreter.h | 94 ----- include/ruby/impl/iterator.h | 65 ---- include/ruby/impl/memory.h | 286 --------------- include/ruby/impl/method.h | 39 -- include/ruby/impl/module.h | 39 -- include/ruby/impl/newobj.h | 73 ---- include/ruby/impl/rgengc.h | 199 ---------- include/ruby/impl/scan_args.h | 394 -------------------- include/ruby/impl/special_consts.h | 204 ----------- include/ruby/impl/static_assert.h | 77 ---- include/ruby/impl/stdalign.h | 124 ------- include/ruby/impl/stdbool.h | 51 --- include/ruby/impl/symbol.h | 114 ------ include/ruby/impl/token_paste.h | 75 ---- include/ruby/impl/value.h | 66 ---- include/ruby/impl/value_type.h | 354 ------------------ include/ruby/impl/variable.h | 62 ---- include/ruby/impl/warning_push.h | 91 ----- include/ruby/impl/xmalloc.h | 201 ---------- include/ruby/internal/anyargs.h | 375 +++++++++++++++++++ include/ruby/internal/arithmetic.h | 38 ++ include/ruby/internal/arithmetic/char.h | 58 +++ include/ruby/internal/arithmetic/double.h | 39 ++ include/ruby/internal/arithmetic/fixnum.h | 44 +++ include/ruby/internal/arithmetic/gid_t.h | 34 ++ include/ruby/internal/arithmetic/int.h | 163 ++++++++ include/ruby/internal/arithmetic/intptr_t.h | 42 +++ include/ruby/internal/arithmetic/long.h | 244 ++++++++++++ include/ruby/internal/arithmetic/long_long.h | 53 +++ include/ruby/internal/arithmetic/mode_t.h | 34 ++ include/ruby/internal/arithmetic/off_t.h | 49 +++ include/ruby/internal/arithmetic/pid_t.h | 34 ++ include/ruby/internal/arithmetic/short.h | 54 +++ include/ruby/internal/arithmetic/size_t.h | 51 +++ include/ruby/internal/arithmetic/st_data_t.h | 59 +++ include/ruby/internal/arithmetic/uid_t.h | 34 ++ include/ruby/internal/assume.h | 90 +++++ include/ruby/internal/attr/alloc_size.h | 32 ++ include/ruby/internal/attr/artificial.h | 46 +++ include/ruby/internal/attr/cold.h | 37 ++ include/ruby/internal/attr/const.h | 46 +++ include/ruby/internal/attr/constexpr.h | 85 +++++ include/ruby/internal/attr/deprecated.h | 59 +++ include/ruby/internal/attr/diagnose_if.h | 42 +++ include/ruby/internal/attr/enum_extensibility.h | 32 ++ include/ruby/internal/attr/error.h | 32 ++ include/ruby/internal/attr/flag_enum.h | 33 ++ include/ruby/internal/attr/forceinline.h | 40 ++ include/ruby/internal/attr/format.h | 38 ++ include/ruby/internal/attr/maybe_unused.h | 38 ++ include/ruby/internal/attr/noalias.h | 58 +++ include/ruby/internal/attr/nodiscard.h | 45 +++ include/ruby/internal/attr/noexcept.h | 91 +++++ include/ruby/internal/attr/noinline.h | 35 ++ include/ruby/internal/attr/nonnull.h | 32 ++ include/ruby/internal/attr/noreturn.h | 52 +++ include/ruby/internal/attr/pure.h | 43 +++ include/ruby/internal/attr/restrict.h | 45 +++ include/ruby/internal/attr/returns_nonnull.h | 37 ++ include/ruby/internal/attr/warning.h | 32 ++ include/ruby/internal/attr/weakref.h | 32 ++ include/ruby/internal/cast.h | 53 +++ include/ruby/internal/compiler_is.h | 45 +++ include/ruby/internal/compiler_is/apple.h | 41 +++ include/ruby/internal/compiler_is/clang.h | 38 ++ include/ruby/internal/compiler_is/gcc.h | 46 +++ include/ruby/internal/compiler_is/intel.h | 41 +++ include/ruby/internal/compiler_is/msvc.h | 57 +++ include/ruby/internal/compiler_is/sunpro.h | 55 +++ include/ruby/internal/compiler_since.h | 61 +++ include/ruby/internal/config.h | 131 +++++++ include/ruby/internal/constant_p.h | 37 ++ include/ruby/internal/core.h | 35 ++ include/ruby/internal/core/rarray.h | 275 ++++++++++++++ include/ruby/internal/core/rbasic.h | 85 +++++ include/ruby/internal/core/rbignum.h | 51 +++ include/ruby/internal/core/rclass.h | 47 +++ include/ruby/internal/core/rdata.h | 174 +++++++++ include/ruby/internal/core/rfile.h | 36 ++ include/ruby/internal/core/rhash.h | 62 ++++ include/ruby/internal/core/rmatch.h | 73 ++++ include/ruby/internal/core/robject.h | 97 +++++ include/ruby/internal/core/rregexp.h | 84 +++++ include/ruby/internal/core/rstring.h | 215 +++++++++++ include/ruby/internal/core/rstruct.h | 73 ++++ include/ruby/internal/core/rtypeddata.h | 184 ++++++++++ include/ruby/internal/ctype.h | 203 ++++++++++ include/ruby/internal/dllexport.h | 92 +++++ include/ruby/internal/dosish.h | 63 ++++ include/ruby/internal/error.h | 74 ++++ include/ruby/internal/eval.h | 50 +++ include/ruby/internal/event.h | 75 ++++ include/ruby/internal/fl_type.h | 469 ++++++++++++++++++++++++ include/ruby/internal/gc.h | 35 ++ include/ruby/internal/glob.h | 35 ++ include/ruby/internal/globals.h | 159 ++++++++ include/ruby/internal/has/attribute.h | 164 +++++++++ include/ruby/internal/has/builtin.h | 105 ++++++ include/ruby/internal/has/c_attribute.h | 38 ++ include/ruby/internal/has/cpp_attribute.h | 79 ++++ include/ruby/internal/has/declspec_attribute.h | 48 +++ include/ruby/internal/has/extension.h | 33 ++ include/ruby/internal/has/feature.h | 31 ++ include/ruby/internal/has/warning.h | 31 ++ include/ruby/internal/intern/array.h | 78 ++++ include/ruby/internal/intern/bignum.h | 105 ++++++ include/ruby/internal/intern/class.h | 57 +++ include/ruby/internal/intern/compar.h | 34 ++ include/ruby/internal/intern/complex.h | 60 +++ include/ruby/internal/intern/cont.h | 40 ++ include/ruby/internal/intern/dir.h | 33 ++ include/ruby/internal/intern/enum.h | 33 ++ include/ruby/internal/intern/enumerator.h | 79 ++++ include/ruby/internal/intern/error.h | 82 +++++ include/ruby/internal/intern/eval.h | 59 +++ include/ruby/internal/intern/file.h | 44 +++ include/ruby/internal/intern/gc.h | 57 +++ include/ruby/internal/intern/hash.h | 59 +++ include/ruby/internal/intern/io.h | 70 ++++ include/ruby/internal/intern/load.h | 39 ++ include/ruby/internal/intern/marshal.h | 35 ++ include/ruby/internal/intern/numeric.h | 42 +++ include/ruby/internal/intern/object.h | 90 +++++ include/ruby/internal/intern/parse.h | 64 ++++ include/ruby/internal/intern/proc.h | 53 +++ include/ruby/internal/intern/process.h | 46 +++ include/ruby/internal/intern/random.h | 45 +++ include/ruby/internal/intern/range.h | 35 ++ include/ruby/internal/intern/rational.h | 46 +++ include/ruby/internal/intern/re.h | 50 +++ include/ruby/internal/intern/ruby.h | 37 ++ include/ruby/internal/intern/select.h | 52 +++ include/ruby/internal/intern/select/largesize.h | 103 ++++++ include/ruby/internal/intern/select/posix.h | 82 +++++ include/ruby/internal/intern/select/win32.h | 124 +++++++ include/ruby/internal/intern/signal.h | 40 ++ include/ruby/internal/intern/sprintf.h | 43 +++ include/ruby/internal/intern/string.h | 326 ++++++++++++++++ include/ruby/internal/intern/struct.h | 47 +++ include/ruby/internal/intern/thread.h | 76 ++++ include/ruby/internal/intern/time.h | 52 +++ include/ruby/internal/intern/variable.h | 83 +++++ include/ruby/internal/intern/vm.h | 77 ++++ include/ruby/internal/interpreter.h | 94 +++++ include/ruby/internal/iterator.h | 65 ++++ include/ruby/internal/memory.h | 286 +++++++++++++++ include/ruby/internal/method.h | 39 ++ include/ruby/internal/module.h | 39 ++ include/ruby/internal/newobj.h | 73 ++++ include/ruby/internal/rgengc.h | 199 ++++++++++ include/ruby/internal/scan_args.h | 394 ++++++++++++++++++++ include/ruby/internal/special_consts.h | 204 +++++++++++ include/ruby/internal/static_assert.h | 77 ++++ include/ruby/internal/stdalign.h | 124 +++++++ include/ruby/internal/stdbool.h | 51 +++ include/ruby/internal/symbol.h | 114 ++++++ include/ruby/internal/token_paste.h | 75 ++++ include/ruby/internal/value.h | 66 ++++ include/ruby/internal/value_type.h | 354 ++++++++++++++++++ include/ruby/internal/variable.h | 62 ++++ include/ruby/internal/warning_push.h | 91 +++++ include/ruby/internal/xmalloc.h | 201 ++++++++++ 286 files changed, 11622 insertions(+), 11622 deletions(-) delete mode 100644 include/ruby/impl/anyargs.h delete mode 100644 include/ruby/impl/arithmetic.h delete mode 100644 include/ruby/impl/arithmetic/char.h delete mode 100644 include/ruby/impl/arithmetic/double.h delete mode 100644 include/ruby/impl/arithmetic/fixnum.h delete mode 100644 include/ruby/impl/arithmetic/gid_t.h delete mode 100644 include/ruby/impl/arithmetic/int.h delete mode 100644 include/ruby/impl/arithmetic/intptr_t.h delete mode 100644 include/ruby/impl/arithmetic/long.h delete mode 100644 include/ruby/impl/arithmetic/long_long.h delete mode 100644 include/ruby/impl/arithmetic/mode_t.h delete mode 100644 include/ruby/impl/arithmetic/off_t.h delete mode 100644 include/ruby/impl/arithmetic/pid_t.h delete mode 100644 include/ruby/impl/arithmetic/short.h delete mode 100644 include/ruby/impl/arithmetic/size_t.h delete mode 100644 include/ruby/impl/arithmetic/st_data_t.h delete mode 100644 include/ruby/impl/arithmetic/uid_t.h delete mode 100644 include/ruby/impl/assume.h delete mode 100644 include/ruby/impl/attr/alloc_size.h delete mode 100644 include/ruby/impl/attr/artificial.h delete mode 100644 include/ruby/impl/attr/cold.h delete mode 100644 include/ruby/impl/attr/const.h delete mode 100644 include/ruby/impl/attr/constexpr.h delete mode 100644 include/ruby/impl/attr/deprecated.h delete mode 100644 include/ruby/impl/attr/diagnose_if.h delete mode 100644 include/ruby/impl/attr/enum_extensibility.h delete mode 100644 include/ruby/impl/attr/error.h delete mode 100644 include/ruby/impl/attr/flag_enum.h delete mode 100644 include/ruby/impl/attr/forceinline.h delete mode 100644 include/ruby/impl/attr/format.h delete mode 100644 include/ruby/impl/attr/maybe_unused.h delete mode 100644 include/ruby/impl/attr/noalias.h delete mode 100644 include/ruby/impl/attr/nodiscard.h delete mode 100644 include/ruby/impl/attr/noexcept.h delete mode 100644 include/ruby/impl/attr/noinline.h delete mode 100644 include/ruby/impl/attr/nonnull.h delete mode 100644 include/ruby/impl/attr/noreturn.h delete mode 100644 include/ruby/impl/attr/pure.h delete mode 100644 include/ruby/impl/attr/restrict.h delete mode 100644 include/ruby/impl/attr/returns_nonnull.h delete mode 100644 include/ruby/impl/attr/warning.h delete mode 100644 include/ruby/impl/attr/weakref.h delete mode 100644 include/ruby/impl/cast.h delete mode 100644 include/ruby/impl/compiler_is.h delete mode 100644 include/ruby/impl/compiler_is/apple.h delete mode 100644 include/ruby/impl/compiler_is/clang.h delete mode 100644 include/ruby/impl/compiler_is/gcc.h delete mode 100644 include/ruby/impl/compiler_is/intel.h delete mode 100644 include/ruby/impl/compiler_is/msvc.h delete mode 100644 include/ruby/impl/compiler_is/sunpro.h delete mode 100644 include/ruby/impl/compiler_since.h delete mode 100644 include/ruby/impl/config.h delete mode 100644 include/ruby/impl/constant_p.h delete mode 100644 include/ruby/impl/core.h delete mode 100644 include/ruby/impl/core/rarray.h delete mode 100644 include/ruby/impl/core/rbasic.h delete mode 100644 include/ruby/impl/core/rbignum.h delete mode 100644 include/ruby/impl/core/rclass.h delete mode 100644 include/ruby/impl/core/rdata.h delete mode 100644 include/ruby/impl/core/rfile.h delete mode 100644 include/ruby/impl/core/rhash.h delete mode 100644 include/ruby/impl/core/rmatch.h delete mode 100644 include/ruby/impl/core/robject.h delete mode 100644 include/ruby/impl/core/rregexp.h delete mode 100644 include/ruby/impl/core/rstring.h delete mode 100644 include/ruby/impl/core/rstruct.h delete mode 100644 include/ruby/impl/core/rtypeddata.h delete mode 100644 include/ruby/impl/ctype.h delete mode 100644 include/ruby/impl/dllexport.h delete mode 100644 include/ruby/impl/dosish.h delete mode 100644 include/ruby/impl/error.h delete mode 100644 include/ruby/impl/eval.h delete mode 100644 include/ruby/impl/event.h delete mode 100644 include/ruby/impl/fl_type.h delete mode 100644 include/ruby/impl/gc.h delete mode 100644 include/ruby/impl/glob.h delete mode 100644 include/ruby/impl/globals.h delete mode 100644 include/ruby/impl/has/attribute.h delete mode 100644 include/ruby/impl/has/builtin.h delete mode 100644 include/ruby/impl/has/c_attribute.h delete mode 100644 include/ruby/impl/has/cpp_attribute.h delete mode 100644 include/ruby/impl/has/declspec_attribute.h delete mode 100644 include/ruby/impl/has/extension.h delete mode 100644 include/ruby/impl/has/feature.h delete mode 100644 include/ruby/impl/has/warning.h delete mode 100644 include/ruby/impl/intern/array.h delete mode 100644 include/ruby/impl/intern/bignum.h delete mode 100644 include/ruby/impl/intern/class.h delete mode 100644 include/ruby/impl/intern/compar.h delete mode 100644 include/ruby/impl/intern/complex.h delete mode 100644 include/ruby/impl/intern/cont.h delete mode 100644 include/ruby/impl/intern/dir.h delete mode 100644 include/ruby/impl/intern/enum.h delete mode 100644 include/ruby/impl/intern/enumerator.h delete mode 100644 include/ruby/impl/intern/error.h delete mode 100644 include/ruby/impl/intern/eval.h delete mode 100644 include/ruby/impl/intern/file.h delete mode 100644 include/ruby/impl/intern/gc.h delete mode 100644 include/ruby/impl/intern/hash.h delete mode 100644 include/ruby/impl/intern/io.h delete mode 100644 include/ruby/impl/intern/load.h delete mode 100644 include/ruby/impl/intern/marshal.h delete mode 100644 include/ruby/impl/intern/numeric.h delete mode 100644 include/ruby/impl/intern/object.h delete mode 100644 include/ruby/impl/intern/parse.h delete mode 100644 include/ruby/impl/intern/proc.h delete mode 100644 include/ruby/impl/intern/process.h delete mode 100644 include/ruby/impl/intern/random.h delete mode 100644 include/ruby/impl/intern/range.h delete mode 100644 include/ruby/impl/intern/rational.h delete mode 100644 include/ruby/impl/intern/re.h delete mode 100644 include/ruby/impl/intern/ruby.h delete mode 100644 include/ruby/impl/intern/select.h delete mode 100644 include/ruby/impl/intern/select/largesize.h delete mode 100644 include/ruby/impl/intern/select/posix.h delete mode 100644 include/ruby/impl/intern/select/win32.h delete mode 100644 include/ruby/impl/intern/signal.h delete mode 100644 include/ruby/impl/intern/sprintf.h delete mode 100644 include/ruby/impl/intern/string.h delete mode 100644 include/ruby/impl/intern/struct.h delete mode 100644 include/ruby/impl/intern/thread.h delete mode 100644 include/ruby/impl/intern/time.h delete mode 100644 include/ruby/impl/intern/variable.h delete mode 100644 include/ruby/impl/intern/vm.h delete mode 100644 include/ruby/impl/interpreter.h delete mode 100644 include/ruby/impl/iterator.h delete mode 100644 include/ruby/impl/memory.h delete mode 100644 include/ruby/impl/method.h delete mode 100644 include/ruby/impl/module.h delete mode 100644 include/ruby/impl/newobj.h delete mode 100644 include/ruby/impl/rgengc.h delete mode 100644 include/ruby/impl/scan_args.h delete mode 100644 include/ruby/impl/special_consts.h delete mode 100644 include/ruby/impl/static_assert.h delete mode 100644 include/ruby/impl/stdalign.h delete mode 100644 include/ruby/impl/stdbool.h delete mode 100644 include/ruby/impl/symbol.h delete mode 100644 include/ruby/impl/token_paste.h delete mode 100644 include/ruby/impl/value.h delete mode 100644 include/ruby/impl/value_type.h delete mode 100644 include/ruby/impl/variable.h delete mode 100644 include/ruby/impl/warning_push.h delete mode 100644 include/ruby/impl/xmalloc.h create mode 100644 include/ruby/internal/anyargs.h create mode 100644 include/ruby/internal/arithmetic.h create mode 100644 include/ruby/internal/arithmetic/char.h create mode 100644 include/ruby/internal/arithmetic/double.h create mode 100644 include/ruby/internal/arithmetic/fixnum.h create mode 100644 include/ruby/internal/arithmetic/gid_t.h create mode 100644 include/ruby/internal/arithmetic/int.h create mode 100644 include/ruby/internal/arithmetic/intptr_t.h create mode 100644 include/ruby/internal/arithmetic/long.h create mode 100644 include/ruby/internal/arithmetic/long_long.h create mode 100644 include/ruby/internal/arithmetic/mode_t.h create mode 100644 include/ruby/internal/arithmetic/off_t.h create mode 100644 include/ruby/internal/arithmetic/pid_t.h create mode 100644 include/ruby/internal/arithmetic/short.h create mode 100644 include/ruby/internal/arithmetic/size_t.h create mode 100644 include/ruby/internal/arithmetic/st_data_t.h create mode 100644 include/ruby/internal/arithmetic/uid_t.h create mode 100644 include/ruby/internal/assume.h create mode 100644 include/ruby/internal/attr/alloc_size.h create mode 100644 include/ruby/internal/attr/artificial.h create mode 100644 include/ruby/internal/attr/cold.h create mode 100644 include/ruby/internal/attr/const.h create mode 100644 include/ruby/internal/attr/constexpr.h create mode 100644 include/ruby/internal/attr/deprecated.h create mode 100644 include/ruby/internal/attr/diagnose_if.h create mode 100644 include/ruby/internal/attr/enum_extensibility.h create mode 100644 include/ruby/internal/attr/error.h create mode 100644 include/ruby/internal/attr/flag_enum.h create mode 100644 include/ruby/internal/attr/forceinline.h create mode 100644 include/ruby/internal/attr/format.h create mode 100644 include/ruby/internal/attr/maybe_unused.h create mode 100644 include/ruby/internal/attr/noalias.h create mode 100644 include/ruby/internal/attr/nodiscard.h create mode 100644 include/ruby/internal/attr/noexcept.h create mode 100644 include/ruby/internal/attr/noinline.h create mode 100644 include/ruby/internal/attr/nonnull.h create mode 100644 include/ruby/internal/attr/noreturn.h create mode 100644 include/ruby/internal/attr/pure.h create mode 100644 include/ruby/internal/attr/restrict.h create mode 100644 include/ruby/internal/attr/returns_nonnull.h create mode 100644 include/ruby/internal/attr/warning.h create mode 100644 include/ruby/internal/attr/weakref.h create mode 100644 include/ruby/internal/cast.h create mode 100644 include/ruby/internal/compiler_is.h create mode 100644 include/ruby/internal/compiler_is/apple.h create mode 100644 include/ruby/internal/compiler_is/clang.h create mode 100644 include/ruby/internal/compiler_is/gcc.h create mode 100644 include/ruby/internal/compiler_is/intel.h create mode 100644 include/ruby/internal/compiler_is/msvc.h create mode 100644 include/ruby/internal/compiler_is/sunpro.h create mode 100644 include/ruby/internal/compiler_since.h create mode 100644 include/ruby/internal/config.h create mode 100644 include/ruby/internal/constant_p.h create mode 100644 include/ruby/internal/core.h create mode 100644 include/ruby/internal/core/rarray.h create mode 100644 include/ruby/internal/core/rbasic.h create mode 100644 include/ruby/internal/core/rbignum.h create mode 100644 include/ruby/internal/core/rclass.h create mode 100644 include/ruby/internal/core/rdata.h create mode 100644 include/ruby/internal/core/rfile.h create mode 100644 include/ruby/internal/core/rhash.h create mode 100644 include/ruby/internal/core/rmatch.h create mode 100644 include/ruby/internal/core/robject.h create mode 100644 include/ruby/internal/core/rregexp.h create mode 100644 include/ruby/internal/core/rstring.h create mode 100644 include/ruby/internal/core/rstruct.h create mode 100644 include/ruby/internal/core/rtypeddata.h create mode 100644 include/ruby/internal/ctype.h create mode 100644 include/ruby/internal/dllexport.h create mode 100644 include/ruby/internal/dosish.h create mode 100644 include/ruby/internal/error.h create mode 100644 include/ruby/internal/eval.h create mode 100644 include/ruby/internal/event.h create mode 100644 include/ruby/internal/fl_type.h create mode 100644 include/ruby/internal/gc.h create mode 100644 include/ruby/internal/glob.h create mode 100644 include/ruby/internal/globals.h create mode 100644 include/ruby/internal/has/attribute.h create mode 100644 include/ruby/internal/has/builtin.h create mode 100644 include/ruby/internal/has/c_attribute.h create mode 100644 include/ruby/internal/has/cpp_attribute.h create mode 100644 include/ruby/internal/has/declspec_attribute.h create mode 100644 include/ruby/internal/has/extension.h create mode 100644 include/ruby/internal/has/feature.h create mode 100644 include/ruby/internal/has/warning.h create mode 100644 include/ruby/internal/intern/array.h create mode 100644 include/ruby/internal/intern/bignum.h create mode 100644 include/ruby/internal/intern/class.h create mode 100644 include/ruby/internal/intern/compar.h create mode 100644 include/ruby/internal/intern/complex.h create mode 100644 include/ruby/internal/intern/cont.h create mode 100644 include/ruby/internal/intern/dir.h create mode 100644 include/ruby/internal/intern/enum.h create mode 100644 include/ruby/internal/intern/enumerator.h create mode 100644 include/ruby/internal/intern/error.h create mode 100644 include/ruby/internal/intern/eval.h create mode 100644 include/ruby/internal/intern/file.h create mode 100644 include/ruby/internal/intern/gc.h create mode 100644 include/ruby/internal/intern/hash.h create mode 100644 include/ruby/internal/intern/io.h create mode 100644 include/ruby/internal/intern/load.h create mode 100644 include/ruby/internal/intern/marshal.h create mode 100644 include/ruby/internal/intern/numeric.h create mode 100644 include/ruby/internal/intern/object.h create mode 100644 include/ruby/internal/intern/parse.h create mode 100644 include/ruby/internal/intern/proc.h create mode 100644 include/ruby/internal/intern/process.h create mode 100644 include/ruby/internal/intern/random.h create mode 100644 include/ruby/internal/intern/range.h create mode 100644 include/ruby/internal/intern/rational.h create mode 100644 include/ruby/internal/intern/re.h create mode 100644 include/ruby/internal/intern/ruby.h create mode 100644 include/ruby/internal/intern/select.h create mode 100644 include/ruby/internal/intern/select/largesize.h create mode 100644 include/ruby/internal/intern/select/posix.h create mode 100644 include/ruby/internal/intern/select/win32.h create mode 100644 include/ruby/internal/intern/signal.h create mode 100644 include/ruby/internal/intern/sprintf.h create mode 100644 include/ruby/internal/intern/string.h create mode 100644 include/ruby/internal/intern/struct.h create mode 100644 include/ruby/internal/intern/thread.h create mode 100644 include/ruby/internal/intern/time.h create mode 100644 include/ruby/internal/intern/variable.h create mode 100644 include/ruby/internal/intern/vm.h create mode 100644 include/ruby/internal/interpreter.h create mode 100644 include/ruby/internal/iterator.h create mode 100644 include/ruby/internal/memory.h create mode 100644 include/ruby/internal/method.h create mode 100644 include/ruby/internal/module.h create mode 100644 include/ruby/internal/newobj.h create mode 100644 include/ruby/internal/rgengc.h create mode 100644 include/ruby/internal/scan_args.h create mode 100644 include/ruby/internal/special_consts.h create mode 100644 include/ruby/internal/static_assert.h create mode 100644 include/ruby/internal/stdalign.h create mode 100644 include/ruby/internal/stdbool.h create mode 100644 include/ruby/internal/symbol.h create mode 100644 include/ruby/internal/token_paste.h create mode 100644 include/ruby/internal/value.h create mode 100644 include/ruby/internal/value_type.h create mode 100644 include/ruby/internal/variable.h create mode 100644 include/ruby/internal/warning_push.h create mode 100644 include/ruby/internal/xmalloc.h diff --git a/include/ruby/impl/anyargs.h b/include/ruby/impl/anyargs.h deleted file mode 100644 index 78c979eac0..0000000000 --- a/include/ruby/impl/anyargs.h +++ /dev/null @@ -1,375 +0,0 @@ -#ifndef RBIMPL_ANYARGS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ANYARGS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Function overloads to issue warnings around #ANYARGS. - * - * For instance ::rb_define_method takes a pointer to #ANYARGS -ed functions, - * which in fact varies 18 different prototypes. We still need to preserve - * #ANYARGS for storages but why not check the consistencies if possible. With - * those complex macro overlays defined in this header file, use of a function - * pointer gets checked against the corresponding arity argument. - * - * ### Q&A ### - * - * - Q: Where did the magic number "18" came from in the description above? - * - * - A: Count the case branch of `vm_method.c:call_cfunc_invoker_func()`. Note - * also that the 18 branches has lasted for at least 25 years. See also - * commit 200e0ee2fd3c1c006c528874a88f684447215524. - * - * - Q: What is this `__weakref__` thing? - * - * - A: That is a kind of function overloading mechanism that GCC provides. In - * this case for instance `rb_define_method_00` is an alias of - * ::rb_define_method, with a strong type. - * - * - Q: What is this `__transparent_union__` thing? - * - * A: That is another kind of function overloading mechanism that GCC - * provides. In this case the attributed function pointer is either - * `VALUE(*)(int,VALUE*,VALUE)` or `VALUE(*)(int,const VALUE*,VALUE)`. - * - * This is better than `void*` or #ANYARGS because we can reject all other - * possibilities than the two. - * - * - Q: What does this #rb_define_method macro mean? - * - * - A: It selects appropriate alias of the ::rb_define_method function, - * depending on the last (arity) argument. - * - * - Q: Why the special case for ::rb_f_notimplement ? - * - * - A: Function pointer to ::rb_f_notimplement is special cased in - * `vm_method.c:rb_add_method_cfunc()`. That should be handled by the - * `__builtin_choose_expr` chain inside of #rb_define_method macro - * expansion. In order to do so, comparison like - * `(func == rb_f_notimplement)` is inappropriate for - * `__builtin_choose_expr`'s expression (which must be a compile-time - * integer constant but the address of ::rb_f_notimplement is not fixed - * until the linker). Instead we are using - * `__builtin_types_compatible_p`, and in doing so we need to distinguish - * ::rb_f_notimplement from others, by type. - */ -#include "ruby/impl/attr/maybe_unused.h" -#include "ruby/impl/attr/nonnull.h" -#include "ruby/impl/attr/weakref.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/config.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/intern/class.h" -#include "ruby/impl/intern/vm.h" -#include "ruby/impl/method.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/stdarg.h" - -#if defined(__cplusplus) -# include "ruby/backward/cxxanyargs.hpp" - -#elif defined(_WIN32) || defined(__CYGWIN__) -# /* Skip due to [Bug #16134] */ - -#elif ! RBIMPL_HAS_ATTRIBUTE(transparent_union) -# /* :TODO: improve here, please find a way to support. */ - -#elif ! defined(HAVE_VA_ARGS_MACRO) -# /* :TODO: improve here, please find a way to support. */ - -#else -# /** @cond INTERNAL_MACRO */ -# if ! defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P) -# define RBIMPL_CFUNC_IS_rb_f_notimplement(f) 0 -# else -# define RBIMPL_CFUNC_IS_rb_f_notimplement(f) \ - __builtin_types_compatible_p( \ - __typeof__(f), \ - __typeof__(rb_f_notimplement)) -# endif - -# if ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) -# define RBIMPL_ANYARGS_DISPATCH(expr, truthy, falsy) (falsy) -# else -# define RBIMPL_ANYARGS_DISPATCH(expr, truthy, falsy) \ - __builtin_choose_expr( \ - __builtin_choose_expr( \ - __builtin_constant_p(expr), \ - (expr), 0), \ - (truthy), (falsy)) -# endif - -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_singleton_method_m2, rb_define_singleton_method_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_singleton_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_singleton_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_singleton_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_singleton_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_singleton_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_singleton_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_singleton_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_singleton_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_singleton_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_singleton_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_singleton_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_singleton_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_singleton_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_singleton_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_singleton_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_singleton_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_singleton_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_protected_method_m2, rb_define_protected_method_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_protected_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_protected_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_protected_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_protected_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_protected_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_protected_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_protected_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_protected_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_protected_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_protected_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_protected_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_protected_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_protected_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_protected_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_protected_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_protected_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_protected_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_private_method_m2, rb_define_private_method_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_private_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_private_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_private_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_private_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_private_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_private_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_private_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_private_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_private_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_private_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_private_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_private_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_private_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_private_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_private_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_private_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_private_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_module_function_m2, rb_define_module_function_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_module_function_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_module_function_00, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_module_function_01, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_module_function_02, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_module_function_03, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_module_function_04, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_module_function_05, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_module_function_06, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_module_function_07, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_module_function_08, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_module_function_09, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_module_function_10, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_module_function_11, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_module_function_12, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_module_function_13, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_module_function_14, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_module_function_15, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_global_function_m2, rb_define_global_function_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_global_function_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_global_function_00, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_global_function_01, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_global_function_02, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_global_function_03, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_global_function_04, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_global_function_05, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_global_function_06, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_global_function_07, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_global_function_08, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_global_function_09, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_global_function_10, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_global_function_11, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_global_function_12, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_global_function_13, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_global_function_14, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_global_function_15, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_method_id_m2, rb_define_method_id_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_method_id_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_method_id_00, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_method_id_01, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_method_id_02, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_method_id_03, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_method_id_04, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_method_id_05, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_method_id_06, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_method_id_07, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_method_id_08, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_method_id_09, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_method_id_10, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_method_id_11, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_method_id_12, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_method_id_13, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_method_id_14, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_method_id_15, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_method_m2, rb_define_method_m3) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_method_m2(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_method_m1(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_method_00(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_method_01(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_method_02(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_method_03(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_method_04(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_method_05(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_method_06(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_method_07(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_method_08(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_method_09(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_method_10(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_method_11(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_method_12(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_method_13(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_method_14(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_singleton_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_15(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_protected_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_15(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_private_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_15(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_module_function_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_15(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_global_function_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_15(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_method_id_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_15(n)) -# define RBIMPL_ANYARGS_DISPATCH_rb_define_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_method_15(n)) -# define RBIMPL_ANYARGS_ATTRSET(sym) RBIMPL_ATTR_MAYBE_UNUSED() RBIMPL_ATTR_NONNULL() RBIMPL_ATTR_WEAKREF(sym) -# define RBIMPL_ANYARGS_DECL(sym, ...) \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m3(__VA_ARGS__, VALUE(*)(ANYARGS), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m2(__VA_ARGS__, VALUE(*)(VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m1(__VA_ARGS__, VALUE(*)(int, union { VALUE *x; const VALUE *y; } __attribute__((__transparent_union__)), VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _00(__VA_ARGS__, VALUE(*)(VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _01(__VA_ARGS__, VALUE(*)(VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _02(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _03(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _04(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _05(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _06(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _07(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _08(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _09(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _10(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _11(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _12(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _13(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _14(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ -RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _15(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); -RBIMPL_ANYARGS_DECL(rb_define_singleton_method, VALUE, const char *) -RBIMPL_ANYARGS_DECL(rb_define_protected_method, VALUE, const char *) -RBIMPL_ANYARGS_DECL(rb_define_private_method, VALUE, const char *) -RBIMPL_ANYARGS_DECL(rb_define_module_function, VALUE, const char *) -RBIMPL_ANYARGS_DECL(rb_define_global_function, const char *) -RBIMPL_ANYARGS_DECL(rb_define_method_id, VALUE, ID) -RBIMPL_ANYARGS_DECL(rb_define_method, VALUE, const char *) -/** @endcond */ - -/** - * @brief Defines klass\#mid. - * @see ::rb_define_method - * @param klass Where the method lives. - * @param mid Name of the defining method. - * @param func Implementation of klass\#mid. - * @param arity Arity of klass\#mid. - */ -#define rb_define_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_method((arity), (func))((klass), (mid), (func), (arity)) - -/** - * @brief Defines klass\#mid. - * @see ::rb_define_method_id - * @param klass Where the method lives. - * @param mid Name of the defining method. - * @param func Implementation of klass\#mid. - * @param arity Arity of klass\#mid. - */ -#define rb_define_method_id(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_method_id((arity), (func))((klass), (mid), (func), (arity)) - -/** - * @brief Defines obj.mid. - * @see ::rb_define_singleton_method - * @param obj Where the method lives. - * @param mid Name of the defining method. - * @param func Implementation of obj.mid. - * @param arity Arity of obj.mid. - */ -#define rb_define_singleton_method(obj, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method((arity), (func))((obj), (mid), (func), (arity)) - -/** - * @brief Defines klass\#mid and make it protected. - * @see ::rb_define_protected_method - * @param klass Where the method lives. - * @param mid Name of the defining method. - * @param func Implementation of klass\#mid. - * @param arity Arity of klass\#mid. - */ -#define rb_define_protected_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method((arity), (func))((klass), (mid), (func), (arity)) - -/** - * @brief Defines klass\#mid and make it private. - * @see ::rb_define_private_method - * @param klass Where the method lives. - * @param mid Name of the defining method. - * @param func Implementation of klass\#mid. - * @param arity Arity of klass\#mid. - */ -#define rb_define_private_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_private_method((arity), (func))((klass), (mid), (func), (arity)) - -/** - * @brief Defines mod\#mid and make it a module function. - * @see ::rb_define_module_function - * @param mod Where the method lives. - * @param mid Name of the defining method. - * @param func Implementation of mod\#mid. - * @param arity Arity of mod\#mid. - */ -#define rb_define_module_function(mod, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_module_function((arity), (func))((mod), (mid), (func), (arity)) - -/** - * @brief Defines ::rb_mKerbel \#mid. - * @see ::rb_define_gobal_function - * @param mid Name of the defining method. - * @param func Implementation of ::rb_mKernel \#mid. - * @param arity Arity of ::rb_mKernel \#mid. - */ -#define rb_define_global_function(mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_global_function((arity), (func))((mid), (func), (arity)) - -#endif /* __cplusplus */ - -/** - * This macro is to properly cast a function parameter of *_define_method - * family. It has been around since 1.x era so you can maximize backwards - * compatibility by using it. - * - * ```CXX - * rb_define_method(klass, "method", RUBY_METHOD_FUNC(func), arity); - * ``` - * - * @param func A pointer to a function that implements a method. - */ -#if ! defined(RUBY_DEVEL) -# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func)) - -#elif ! RUBY_DEVEL -# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func)) - -#elif ! defined(rb_define_method) -# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func)) - -#else -# define RUBY_METHOD_FUNC(func) (func) - -#endif - -#endif /* RBIMPL_ANYARGS_H */ diff --git a/include/ruby/impl/arithmetic.h b/include/ruby/impl/arithmetic.h deleted file mode 100644 index f93fa581cd..0000000000 --- a/include/ruby/impl/arithmetic.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Conversion between C's arithmtic types and Ruby's numeric types. - */ -#include "ruby/impl/arithmetic/char.h" -#include "ruby/impl/arithmetic/double.h" -#include "ruby/impl/arithmetic/fixnum.h" -#include "ruby/impl/arithmetic/gid_t.h" -#include "ruby/impl/arithmetic/int.h" -#include "ruby/impl/arithmetic/intptr_t.h" -#include "ruby/impl/arithmetic/long.h" -#include "ruby/impl/arithmetic/long_long.h" -#include "ruby/impl/arithmetic/mode_t.h" -#include "ruby/impl/arithmetic/off_t.h" -#include "ruby/impl/arithmetic/pid_t.h" -#include "ruby/impl/arithmetic/short.h" -#include "ruby/impl/arithmetic/size_t.h" -#include "ruby/impl/arithmetic/st_data_t.h" -#include "ruby/impl/arithmetic/uid_t.h" -#endif /* RBIMPL_ARITHMETIC_H */ diff --git a/include/ruby/impl/arithmetic/char.h b/include/ruby/impl/arithmetic/char.h deleted file mode 100644 index 138ba63f58..0000000000 --- a/include/ruby/impl/arithmetic/char.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_CHAR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_CHAR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `char` and Ruby's. - */ -#include "ruby/impl/arithmetic/int.h" /* NUM2INT is here, but */ -#include "ruby/impl/arithmetic/long.h" /* INT2FIX is here.*/ -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/core/rstring.h" -#include "ruby/impl/value_type.h" - -#define RB_NUM2CHR rb_num2char_inline -#define NUM2CHR RB_NUM2CHR -#define CHR2FIX RB_CHR2FIX - -/** @cond INTERNAL_MACRO */ -#define RB_CHR2FIX RB_CHR2FIX -/** @endcond */ - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -RBIMPL_ATTR_ARTIFICIAL() -static inline VALUE -RB_CHR2FIX(unsigned char c) -{ - return RB_INT2FIX(c); -} - -static inline char -rb_num2char_inline(VALUE x) -{ - if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1)) - return RSTRING_PTR(x)[0]; - else - return RBIMPL_CAST((char)RB_NUM2INT(x)); -} - -#endif /* RBIMPL_ARITHMETIC_CHAR_H */ diff --git a/include/ruby/impl/arithmetic/double.h b/include/ruby/impl/arithmetic/double.h deleted file mode 100644 index 2c3426ae6b..0000000000 --- a/include/ruby/impl/arithmetic/double.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_DOUBLE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_DOUBLE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `double` and Ruby's. - */ -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -#define NUM2DBL rb_num2dbl -#define RFLOAT_VALUE rb_float_value -#define DBL2NUM rb_float_new - -RBIMPL_SYMBOL_EXPORT_BEGIN() -double rb_num2dbl(VALUE); -RBIMPL_ATTR_PURE() -double rb_float_value(VALUE); -VALUE rb_float_new(double); -VALUE rb_float_new_in_heap(double); -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_ARITHMETIC_DOUBLE_H */ diff --git a/include/ruby/impl/arithmetic/fixnum.h b/include/ruby/impl/arithmetic/fixnum.h deleted file mode 100644 index 68544b760b..0000000000 --- a/include/ruby/impl/arithmetic/fixnum.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_FIXNUM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_FIXNUM_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Handling of integers formerly known as Fixnums. - */ -#include "ruby/backward/2/limits.h" - -#define FIXABLE RB_FIXABLE -#define FIXNUM_MAX RUBY_FIXNUM_MAX -#define FIXNUM_MIN RUBY_FIXNUM_MIN -#define NEGFIXABLE RB_NEGFIXABLE -#define POSFIXABLE RB_POSFIXABLE - -/* - * FIXABLE can be applied to anything, from double to intmax_t. The problem is - * double. On a 64bit system RUBY_FIXNUM_MAX is 4,611,686,018,427,387,903, - * which is not representable by a double. The nearest value that a double can - * represent is 4,611,686,018,427,387,904, which is not fixable. The - * seemingly-stragne "< FIXNUM_MAX + 1" expression below is due to this. - */ -#define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1) -#define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN) -#define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_)) -#define RUBY_FIXNUM_MAX (LONG_MAX / 2) -#define RUBY_FIXNUM_MIN (LONG_MIN / 2) - -#endif /* RBIMPL_ARITHMETIC_FIXNUM_H */ diff --git a/include/ruby/impl/arithmetic/gid_t.h b/include/ruby/impl/arithmetic/gid_t.h deleted file mode 100644 index 2d4a230a1f..0000000000 --- a/include/ruby/impl/arithmetic/gid_t.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_GID_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_GID_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `gid_t` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/long.h" - -#ifndef GIDT2NUM -# define GIDT2NUM RB_LONG2NUM -#endif - -#ifndef NUM2GIDT -# define NUM2GIDT RB_NUM2LONG -#endif - -#endif /* RBIMPL_ARITHMETIC_GID_T_H */ diff --git a/include/ruby/impl/arithmetic/int.h b/include/ruby/impl/arithmetic/int.h deleted file mode 100644 index 374d10540b..0000000000 --- a/include/ruby/impl/arithmetic/int.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_INT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_INT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `int` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/fixnum.h" -#include "ruby/impl/arithmetic/intptr_t.h" -#include "ruby/impl/arithmetic/long.h" -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/compiler_is.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/special_consts.h" -#include "ruby/impl/value.h" -#include "ruby/impl/warning_push.h" -#include "ruby/assert.h" - -#define RB_INT2NUM rb_int2num_inline -#define RB_NUM2INT rb_num2int_inline -#define RB_UINT2NUM rb_uint2num_inline - -#define FIX2INT RB_FIX2INT -#define FIX2UINT RB_FIX2UINT -#define INT2NUM RB_INT2NUM -#define NUM2INT RB_NUM2INT -#define NUM2UINT RB_NUM2UINT -#define UINT2NUM RB_UINT2NUM - -/** @cond INTERNAL_MACRO */ -#define RB_FIX2INT RB_FIX2INT -#define RB_NUM2UINT RB_NUM2UINT -#define RB_FIX2UINT RB_FIX2UINT -/** @endcond */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() -long rb_num2int(VALUE); -long rb_fix2int(VALUE); -unsigned long rb_num2uint(VALUE); -unsigned long rb_fix2uint(VALUE); -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_ARTIFICIAL() -static inline int -RB_FIX2INT(VALUE x) -{ - /* "FIX2INT raises a TypeError if passed nil", says rubyspec. Not sure if - * that is a desired behaviour but just preserve backwards compatilibily. - */ -#if 0 - RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); -#endif - long ret; - - if /* constexpr */ (sizeof(int) < sizeof(long)) { - ret = rb_fix2int(x); - } - else { - ret = RB_FIX2LONG(x); - } - - return RBIMPL_CAST((int)ret); -} - -static inline int -rb_num2int_inline(VALUE x) -{ - long ret; - - if /* constexpr */ (sizeof(int) == sizeof(long)) { - ret = RB_NUM2LONG(x); - } - else if (RB_FIXNUM_P(x)) { - ret = rb_fix2int(x); - } - else { - ret = rb_num2int(x); - } - - return RBIMPL_CAST((int)ret); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline unsigned int -RB_NUM2UINT(VALUE x) -{ - unsigned long ret; - - if /* constexpr */ (sizeof(int) < sizeof(long)) { - ret = rb_num2uint(x); - } - else { - ret = RB_NUM2ULONG(x); - } - - return RBIMPL_CAST((unsigned int)ret); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline unsigned int -RB_FIX2UINT(VALUE x) -{ -#if 0 /* Ditto for RB_FIX2INT. */ - RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); -#endif - unsigned long ret; - - if /* constexpr */ (sizeof(int) < sizeof(long)) { - ret = rb_fix2uint(x); - } - else { - ret = RB_FIX2ULONG(x); - } - - return RBIMPL_CAST((unsigned int)ret); -} - -RBIMPL_WARNING_PUSH() -#if RBIMPL_COMPILER_IS(GCC) -RBIMPL_WARNING_IGNORED(-Wtype-limits) /* We can ignore them here. */ -#elif RBIMPL_HAS_WARNING("-Wtautological-constant-out-of-range-compare") -RBIMPL_WARNING_IGNORED(-Wtautological-constant-out-of-range-compare) -#endif - -static inline VALUE -rb_int2num_inline(int v) -{ - if (RB_FIXABLE(v)) - return RB_INT2FIX(v); - else - return rb_int2big(v); -} - -static inline VALUE -rb_uint2num_inline(unsigned int v) -{ - if (RB_POSFIXABLE(v)) - return RB_LONG2FIX(v); - else - return rb_uint2big(v); -} - -RBIMPL_WARNING_POP() - -#endif /* RBIMPL_ARITHMETIC_INT_H */ diff --git a/include/ruby/impl/arithmetic/intptr_t.h b/include/ruby/impl/arithmetic/intptr_t.h deleted file mode 100644 index 2bbbf652db..0000000000 --- a/include/ruby/impl/arithmetic/intptr_t.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_INTPTR_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_INTPTR_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `intptr_t` and Ruby's. - */ -#include "ruby/impl/config.h" - -#ifdef HAVE_STDINT_H -# include -#endif - -#include "ruby/impl/value.h" -#include "ruby/impl/dllexport.h" - -#define rb_int_new rb_int2inum -#define rb_uint_new rb_uint2inum - -RBIMPL_SYMBOL_EXPORT_BEGIN() -VALUE rb_int2big(intptr_t i); -VALUE rb_int2inum(intptr_t i); -VALUE rb_uint2big(uintptr_t i); -VALUE rb_uint2inum(uintptr_t i); -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_ARITHMETIC_INTPTR_T_H */ diff --git a/include/ruby/impl/arithmetic/long.h b/include/ruby/impl/arithmetic/long.h deleted file mode 100644 index d429974eaf..0000000000 --- a/include/ruby/impl/arithmetic/long.h +++ /dev/null @@ -1,244 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_LONG_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_LONG_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `long` and Ruby's. - * - * ### Q&A ### - * - * - Q: Why are INT2FIX etc. here, not in `int.h`? - * - * - A: Because they are in fact handling `long`. It seems someone did not - * understand the difference of `int` and `long` when they designed those - * macros. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/fixnum.h" /* FIXABLE */ -#include "ruby/impl/arithmetic/intptr_t.h" /* rb_int2big etc.*/ -#include "ruby/impl/assume.h" -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/cold.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/special_consts.h" /* FIXNUM_FLAG */ -#include "ruby/impl/value.h" -#include "ruby/assert.h" - -#define FIX2LONG RB_FIX2LONG -#define FIX2ULONG RB_FIX2ULONG -#define INT2FIX RB_INT2FIX -#define LONG2FIX RB_INT2FIX -#define LONG2NUM RB_LONG2NUM -#define NUM2LONG RB_NUM2LONG -#define NUM2ULONG RB_NUM2ULONG -#define RB_FIX2LONG rb_fix2long -#define RB_FIX2ULONG rb_fix2ulong -#define RB_LONG2FIX RB_INT2FIX -#define RB_LONG2NUM rb_long2num_inline -#define RB_NUM2LONG rb_num2long_inline -#define RB_NUM2ULONG rb_num2ulong_inline -#define RB_ULONG2NUM rb_ulong2num_inline -#define ULONG2NUM RB_ULONG2NUM -#define rb_fix_new RB_INT2FIX -#define rb_long2int rb_long2int_inline - -/** @cond INTERNAL_MACRO */ -#define RB_INT2FIX RB_INT2FIX -/** @endcond */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -RBIMPL_ATTR_NORETURN() -RBIMPL_ATTR_COLD() -void rb_out_of_int(SIGNED_VALUE num); - -long rb_num2long(VALUE num); -unsigned long rb_num2ulong(VALUE num); -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -RBIMPL_ATTR_ARTIFICIAL() -static inline VALUE -RB_INT2FIX(long i) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(i)); - - /* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully - * defined. Also it can be compiled into a single LEA instruction. */ - const unsigned long j = i; - const unsigned long k = 2 * j + RUBY_FIXNUM_FLAG; - const long l = k; - const SIGNED_VALUE m = l; /* Sign extend */ - const VALUE n = m; - - RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(n)); - return n; -} - -static inline int -rb_long2int_inline(long n) -{ - int i = RBIMPL_CAST((int)n); - - if /* constexpr */ (sizeof(long) <= sizeof(int)) { - RBIMPL_ASSUME(i == n); - } - - if (i != n) - rb_out_of_int(n); - - return i; -} - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -static inline long -rbimpl_fix2long_by_idiv(VALUE x) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); - - /* :NOTE: VALUE can be wider than long. (x-1)/2 never overflows because - * RB_FIXNUM_P(x) holds. Also it has no portability issue like y>>1 - * below. */ - const SIGNED_VALUE y = x - RUBY_FIXNUM_FLAG; - const SIGNED_VALUE z = y / 2; - const long w = RBIMPL_CAST((long)z); - - RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w)); - return w; -} - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -static inline long -rbimpl_fix2long_by_shift(VALUE x) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); - - /* :NOTE: VALUE can be wider than long. If right shift is arithmetic, this - * is noticeably faster than above. */ - const SIGNED_VALUE y = x; - const SIGNED_VALUE z = y >> 1; - const long w = RBIMPL_CAST((long)z); - - RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w)); - return w; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -static inline bool -rbimpl_right_shift_is_arithmetic_p(void) -{ - return (-1 >> 1) == -1; -} - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -static inline long -rb_fix2long(VALUE x) -{ - if /* constexpr */ (rbimpl_right_shift_is_arithmetic_p()) { - return rbimpl_fix2long_by_shift(x); - } - else { - return rbimpl_fix2long_by_idiv(x); - } -} - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -static inline unsigned long -rb_fix2ulong(VALUE x) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); - return rb_fix2long(x); -} - -static inline long -rb_num2long_inline(VALUE x) -{ - if (RB_FIXNUM_P(x)) - return RB_FIX2LONG(x); - else - return rb_num2long(x); -} - -static inline unsigned long -rb_num2ulong_inline(VALUE x) -{ - /* This (negative fixnum would become a large unsigned long while negative - * bignum is an exception) has been THE behaviour of NUM2ULONG since the - * beginning. It is strange, but we can no longer change how it works at - * this moment. We have to get by with it. See also: - * https://bugs.ruby-lang.org/issues/9089 */ - if (RB_FIXNUM_P(x)) - return RB_FIX2ULONG(x); - else - return rb_num2ulong(x); -} - -static inline VALUE -rb_long2num_inline(long v) -{ - if (RB_FIXABLE(v)) - return RB_LONG2FIX(v); - else - return rb_int2big(v); -} - -static inline VALUE -rb_ulong2num_inline(unsigned long v) -{ - if (RB_POSFIXABLE(v)) - return RB_LONG2FIX(v); - else - return rb_uint2big(v); -} - -/** - * @cond INTERNAL_MACRO - * - * Following overload is necessary because sometimes INT2FIX is used as a enum - * value (e.g. `enum { FOO = INT2FIX(0) };`). THIS IS NG in theory because a - * VALUE does not fit into an enum (which must be a signed int). But we cannot - * break existing codes. - */ -#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 -# /* C++ can write constexpr as enum values. */ - -#elif ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) -# undef INT2FIX -# define INT2FIX(i) (RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG) - -#else -# undef INT2FIX -# define INT2FIX(i) \ - __builtin_choose_expr( \ - __builtin_constant_p(i), \ - RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG, \ - RB_INT2FIX(i)) -#endif -/** @endcond */ - -#endif /* RBIMPL_ARITHMETIC_LONG_H */ diff --git a/include/ruby/impl/arithmetic/long_long.h b/include/ruby/impl/arithmetic/long_long.h deleted file mode 100644 index 3469421f0e..0000000000 --- a/include/ruby/impl/arithmetic/long_long.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_LONG_LONG_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_LONG_LONG_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `long long` and Ruby's. - */ -#include "ruby/impl/value.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/special_consts.h" -#include "ruby/backward/2/long_long.h" - -#define RB_LL2NUM rb_ll2inum -#define RB_ULL2NUM rb_ull2inum -#define LL2NUM RB_LL2NUM -#define ULL2NUM RB_ULL2NUM -#define RB_NUM2LL rb_num2ll_inline -#define RB_NUM2ULL rb_num2ull -#define NUM2LL RB_NUM2LL -#define NUM2ULL RB_NUM2ULL - -RBIMPL_SYMBOL_EXPORT_BEGIN() -VALUE rb_ll2inum(LONG_LONG); -VALUE rb_ull2inum(unsigned LONG_LONG); -LONG_LONG rb_num2ll(VALUE); -unsigned LONG_LONG rb_num2ull(VALUE); -RBIMPL_SYMBOL_EXPORT_END() - -static inline LONG_LONG -rb_num2ll_inline(VALUE x) -{ - if (RB_FIXNUM_P(x)) - return RB_FIX2LONG(x); - else - return rb_num2ll(x); -} - -#endif /* RBIMPL_ARITHMETIC_LONG_LONG_H */ diff --git a/include/ruby/impl/arithmetic/mode_t.h b/include/ruby/impl/arithmetic/mode_t.h deleted file mode 100644 index 81ae129924..0000000000 --- a/include/ruby/impl/arithmetic/mode_t.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_MODE_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_MODE_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `mode_t` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/int.h" - -#ifndef NUM2MODET -# define NUM2MODET RB_NUM2INT -#endif - -#ifndef MODET2NUM -# define MODET2NUM RB_INT2NUM -#endif - -#endif /* RBIMPL_ARITHMETIC_MODE_T_H */ diff --git a/include/ruby/impl/arithmetic/off_t.h b/include/ruby/impl/arithmetic/off_t.h deleted file mode 100644 index 2abada5441..0000000000 --- a/include/ruby/impl/arithmetic/off_t.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_OFF_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_OFF_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `off_t` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/int.h" -#include "ruby/impl/arithmetic/long.h" -#include "ruby/impl/arithmetic/long_long.h" -#include "ruby/backward/2/long_long.h" - -#ifdef OFFT2NUM -# /* take that. */ -#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG -# define OFFT2NUM RB_LL2NUM -#elif SIZEOF_OFF_T == SIZEOF_LONG -# define OFFT2NUM RB_LONG2NUM -#else -# define OFFT2NUM RB_INT2NUM -#endif - -#ifdef NUM2OFFT -# /* take that. */ -#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG -# define NUM2OFFT RB_NUM2LL -#elif SIZEOF_OFF_T == SIZEOF_LONG -# define NUM2OFFT RB_NUM2LONG -#else -# define NUM2OFFT RB_NUM2INT -#endif - -#endif /* RBIMPL_ARITHMETIC_OFF_T_H */ diff --git a/include/ruby/impl/arithmetic/pid_t.h b/include/ruby/impl/arithmetic/pid_t.h deleted file mode 100644 index 7af279a698..0000000000 --- a/include/ruby/impl/arithmetic/pid_t.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_PID_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_PID_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `pid_t` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/long.h" - -#ifndef PIDT2NUM -# define PIDT2NUM RB_LONG2NUM -#endif - -#ifndef NUM2PIDT -# define NUM2PIDT RB_NUM2LONG -#endif - -#endif /* RBIMPL_ARITHMETIC_PID_T_H */ diff --git a/include/ruby/impl/arithmetic/short.h b/include/ruby/impl/arithmetic/short.h deleted file mode 100644 index d952e5ba99..0000000000 --- a/include/ruby/impl/arithmetic/short.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_SHORT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_SHORT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `short` and Ruby's. - * - * Shyouhei wonders: why there is no SHORT2NUM, given there are both - * #USHORT2NUM and #CHR2FIX? - */ -#include "ruby/impl/value.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/special_consts.h" - -#define RB_NUM2SHORT rb_num2short_inline -#define RB_NUM2USHORT rb_num2ushort -#define NUM2SHORT RB_NUM2SHORT -#define NUM2USHORT RB_NUM2USHORT -#define USHORT2NUM RB_INT2FIX -#define RB_FIX2SHORT rb_fix2short -#define FIX2SHORT RB_FIX2SHORT - -RBIMPL_SYMBOL_EXPORT_BEGIN() -short rb_num2short(VALUE); -unsigned short rb_num2ushort(VALUE); -short rb_fix2short(VALUE); -unsigned short rb_fix2ushort(VALUE); -RBIMPL_SYMBOL_EXPORT_END() - -static inline short -rb_num2short_inline(VALUE x) -{ - if (RB_FIXNUM_P(x)) - return rb_fix2short(x); - else - return rb_num2short(x); -} - -#endif /* RBIMPL_ARITHMETIC_SOHRT_H */ diff --git a/include/ruby/impl/arithmetic/size_t.h b/include/ruby/impl/arithmetic/size_t.h deleted file mode 100644 index 661e18ed41..0000000000 --- a/include/ruby/impl/arithmetic/size_t.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_SIZE_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_SIZE_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `size_t` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/int.h" -#include "ruby/impl/arithmetic/long.h" -#include "ruby/impl/arithmetic/long_long.h" -#include "ruby/backward/2/long_long.h" - -#if SIZEOF_SIZE_T == SIZEOF_LONG_LONG -# define SIZET2NUM RB_ULL2NUM -# define SSIZET2NUM RB_LL2NUM -#elif SIZEOF_SIZE_T == SIZEOF_LONG -# define SIZET2NUM RB_ULONG2NUM -# define SSIZET2NUM RB_LONG2NUM -#else -# define SIZET2NUM RB_UINT2NUM -# define SSIZET2NUM RB_INT2NUM -#endif - -#if SIZEOF_SIZE_T == SIZEOF_LONG_LONG -# define NUM2SIZET RB_NUM2ULL -# define NUM2SSIZET RB_NUM2LL -#elif SIZEOF_SIZE_T == SIZEOF_LONG -# define NUM2SIZET RB_NUM2ULONG -# define NUM2SSIZET RB_NUM2LONG -#else -# define NUM2SIZET RB_NUM2UINT -# define NUM2SSIZET RB_NUM2INT -#endif - -#endif /* RBIMPL_ARITHMETIC_SIZE_T_H */ diff --git a/include/ruby/impl/arithmetic/st_data_t.h b/include/ruby/impl/arithmetic/st_data_t.h deleted file mode 100644 index 148816c265..0000000000 --- a/include/ruby/impl/arithmetic/st_data_t.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef RBIMPL_ARITHMERIC_ST_DATA_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMERIC_ST_DATA_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `st_data_t` and Ruby's. - */ -#include "ruby/impl/arithmetic/fixnum.h" -#include "ruby/impl/arithmetic/long.h" -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/value.h" -#include "ruby/assert.h" -#include "ruby/st.h" - -#define ST2FIX RB_ST2FIX -/** @cond INTERNAL_MACRO */ -#define RB_ST2FIX RB_ST2FIX -/** @endcond */ - -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) -RBIMPL_ATTR_ARTIFICIAL() -/* See also [ruby-core:84395] [Bug #14218] [ruby-core:82687] [Bug #13877] */ -static inline VALUE -RB_ST2FIX(st_data_t i) -{ - SIGNED_VALUE x = i; - - if (x >= 0) { - x &= RUBY_FIXNUM_MAX; - } - else { - x |= RUBY_FIXNUM_MIN; - } - - RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(x)); - unsigned long y = RBIMPL_CAST((unsigned long)x); - return RB_LONG2FIX(y); -} - -#endif /* RBIMPL_ARITHMERIC_ST_DATA_T_H */ diff --git a/include/ruby/impl/arithmetic/uid_t.h b/include/ruby/impl/arithmetic/uid_t.h deleted file mode 100644 index 8ea42f5c92..0000000000 --- a/include/ruby/impl/arithmetic/uid_t.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RBIMPL_ARITHMETIC_UID_T_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ARITHMETIC_UID_T_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Arithmetic conversion between C's `uid_t` and Ruby's. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/arithmetic/long.h" - -#ifndef UIDT2NUM -# define UIDT2NUM RB_LONG2NUM -#endif - -#ifndef NUM2UIDT -# define NUM2UIDT RB_NUM2LONG -#endif - -#endif /* RBIMPL_ARITHMETIC_UID_T_H */ diff --git a/include/ruby/impl/assume.h b/include/ruby/impl/assume.h deleted file mode 100644 index fa4a89514a..0000000000 --- a/include/ruby/impl/assume.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef RBIMPL_ASSUME_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ASSUME_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ASSUME / #RBIMPL_UNREACHABLE. - * - * These macros must be defined at once because: - * - * - #RBIMPL_ASSUME could fallback to #RBIMPL_UNREACHABLE. - * - #RBIMPL_UNREACHABLE could fallback to #RBIMPL_ASSUME. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/builtin.h" -#include "ruby/impl/warning_push.h" - -/** @cond INTERNAL_MACRO */ -#if RBIMPL_COMPILER_SINCE(MSVC, 13, 10, 0) -# define RBIMPL_HAVE___ASSUME - -#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) -# define RBIMPL_HAVE___ASSUME -#endif -/** @endcond */ - -/** Wraps (or simulates) `__builtin_unreachable`. */ -#if RBIMPL_HAS_BUILTIN(__builtin_unreachable) -# define RBIMPL_UNREACHABLE_RETURN(_) __builtin_unreachable() - -#elif defined(RBIMPL_HAVE___ASSUME) -# define RBIMPL_UNREACHABLE_RETURN(_) return (__assume(0), (_)) - -#else -# define RBIMPL_UNREACHABLE_RETURN(_) return (_) -#endif - -/** Wraps (or simulates) `__builtin_unreachable`. */ -#if RBIMPL_HAS_BUILTIN(__builtin_unreachable) -# define RBIMPL_UNREACHABLE __builtin_unreachable - -#elif defined(RBIMPL_HAVE___ASSUME) -# define RBIMPL_UNREACHABLE() __assume(0) -#endif - -/** Wraps (or simulates) `__assume`. */ -#if RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) -# /* icc warnings are false positives. Ignore them. */ -# /* "warning #2261: __assume expression with side effects discarded" */ -# define RBIMPL_ASSUME(expr) \ - RBIMPL_WARNING_PUSH() \ - RBIMPL_WARNING_IGNORED(2261) \ - __assume(expr) \ - RBIMPL_WARNING_POP() - -#elif defined(RBIMPL_HAVE___ASSUME) -# define RBIMPL_ASSUME __assume - -#elif RBIMPL_HAS_BUILTIN(__builtin_assume) -# define RBIMPL_ASSUME __builtin_assume - -#elif ! defined(RBIMPL_UNREACHABLE) -# define RBIMPL_ASSUME(_) RBIMPL_CAST((void)(_)) - -#else -# define RBIMPL_ASSUME(_) \ - (RB_LIKELY(!!(_)) ? RBIMPL_CAST((void)0) : RBIMPL_UNREACHABLE()) -#endif - -#if ! defined(RBIMPL_UNREACHABLE) -# define RBIMPL_UNREACHABLE() RBIMPL_ASSUME(0) -#endif - -#endif /* RBIMPL_ASSUME_H */ diff --git a/include/ruby/impl/attr/alloc_size.h b/include/ruby/impl/attr/alloc_size.h deleted file mode 100644 index 9dd79f15fc..0000000000 --- a/include/ruby/impl/attr/alloc_size.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RBIMPL_ATTR_ALLOC_SIZE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_ALLOC_SIZE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_ALLOC_SIZE. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((alloc_size))` */ -#if RBIMPL_HAS_ATTRIBUTE(alloc_size) -# define RBIMPL_ATTR_ALLOC_SIZE(tuple) __attribute__((__alloc_size__ tuple)) -#else -# define RBIMPL_ATTR_ALLOC_SIZE(tuple) /* void */ -#endif - -#endif /* RBIMPL_ATTR_ALLOC_SIZE_H */ diff --git a/include/ruby/impl/attr/artificial.h b/include/ruby/impl/attr/artificial.h deleted file mode 100644 index 7c9dc3e175..0000000000 --- a/include/ruby/impl/attr/artificial.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef RBIMPL_ATTR_ARTIFICIAL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_ARTIFICIAL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_ARTIFICIAL. - * - * ### Q&A ### - * - * - Q: What is this attribute? I don't get what GCC manual is talking about. - * - * - A: In short it is an attribute to manipulate GDB backtraces. The - * attribute makes the best sense when it comes with - * __attribute__((always_inline)). When a function annotated with this - * attribute gets inlined, and when you somehow look at a backtrace which - * includes such inlined call site, then the backtrace shows the caller - * and not the callee. This is handy for instance when an identical - * function is inlined more than once in a single big function. On such - * case it gets vital to know where the inlining happened in the callee. - * See also https://stackoverflow.com/a/21936099 - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((artificial))` */ -#if RBIMPL_HAS_ATTRIBUTE(artificial) -# define RBIMPL_ATTR_ARTIFICIAL() __attribute__((__artificial__)) -#else -# define RBIMPL_ATTR_ARTIFICIAL() /* void */ -#endif - -#endif /* RBIMPL_ATTR_ARTIFICIAL_H */ diff --git a/include/ruby/impl/attr/cold.h b/include/ruby/impl/attr/cold.h deleted file mode 100644 index 85877b6136..0000000000 --- a/include/ruby/impl/attr/cold.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RBIMPL_ATTR_COLD_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_COLD_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_COLD. - */ -#include "ruby/impl/compiler_is.h" -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((cold))` */ -#if RBIMPL_COMPILER_IS(SunPro) -# /* Recent SunPro has __has_attribute, and is borken. */ -# /* It reports it has attribute cold, reality isn't (warnings issued). */ -# define RBIMPL_ATTR_COLD() /* void */ -#elif RBIMPL_HAS_ATTRIBUTE(cold) -# define RBIMPL_ATTR_COLD() __attribute__((__cold__)) -#else -# define RBIMPL_ATTR_COLD() /* void */ -#endif - -#endif /* RBIMPL_ATTR_COLD_H */ diff --git a/include/ruby/impl/attr/const.h b/include/ruby/impl/attr/const.h deleted file mode 100644 index 85892ea464..0000000000 --- a/include/ruby/impl/attr/const.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef RBIMPL_ATTR_CONST_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_CONST_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_CONST. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/declspec_attribute.h" - -/** Wraps (or simulates) `__attribute__((const))` */ -#if RBIMPL_HAS_ATTRIBUTE(const) -# define RBIMPL_ATTR_CONST() __attribute__((__const__)) -#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias) -# /* If a function can be a const, that is also a noalias. */ -# define RBIMPL_ATTR_CONST() __declspec(noalias) -#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_ATTR_CONST() _Pragma("no_side_effect") -#else -# define RBIMPL_ATTR_CONST() /* void */ -#endif - -/** Enables #RBIMPL_ATTR_CONST iff. #RUBY_NDEBUG. */ -#if RUBY_NDEBUG -# define RBIMPL_ATTR_CONST_ON_NDEBUG() RBIMPL_ATTR_CONST() -#else -# define RBIMPL_ATTR_CONST_ON_NDEBUG() /* void */ -#endif - -#endif /* RBIMPL_ATTR_CONST_H */ diff --git a/include/ruby/impl/attr/constexpr.h b/include/ruby/impl/attr/constexpr.h deleted file mode 100644 index 4b6cc81e3b..0000000000 --- a/include/ruby/impl/attr/constexpr.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef RBIMPL_ATTR_CONSTEXPR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_CONSTEXPR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief #RBIMPL_ATTR_CONSTEXPR. - */ -#include "ruby/impl/has/feature.h" -#include "ruby/impl/compiler_is.h" -#include "ruby/impl/token_paste.h" - -/** @cond INTERNAL_MACRO */ -#if ! defined(__cplusplus) -# /* Makes no sense. */ -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0 -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 - -#elif defined(__cpp_constexpr) -# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L) - -#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 00) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 00) - -#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 13, 0) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) - -#elif RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) - -#elif RBIMPL_HAS_FEATURE(cxx_relaxed_constexpr) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1 -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 1 - -#elif RBIMPL_HAS_FEATURE(cxx_constexpr) -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1 -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 - -#else -# /* :FIXME: icpc must have constexpr but don't know how to detect. */ -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0 -# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 -#endif -/** @endcond */ - -/** Wraps (or simulates) C++11 `constexpr`. */ -#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 -# define RBIMPL_ATTR_CONSTEXPR(_) constexpr - -#elif RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 -# define RBIMPL_ATTR_CONSTEXPR(_) RBIMPL_TOKEN_PASTE(RBIMPL_ATTR_CONSTEXPR_, _) -# define RBIMPL_ATTR_CONSTEXPR_CXX11 constexpr -# define RBIMPL_ATTR_CONSTEXPR_CXX14 /* void */ - -#else -# define RBIMPL_ATTR_CONSTEXPR(_) /* void */ -#endif - -/** Enables #RBIMPL_ATTR_CONSTEXPR iff. #RUBY_NDEBUG. */ -#if RUBY_NDEBUG -# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) RBIMPL_ATTR_CONSTEXPR(_) -#else -# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) /* void */ -#endif - -#endif /* RBIMPL_ATTR_CONSTEXPR_H */ diff --git a/include/ruby/impl/attr/deprecated.h b/include/ruby/impl/attr/deprecated.h deleted file mode 100644 index c603d58a1f..0000000000 --- a/include/ruby/impl/attr/deprecated.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef RBIMPL_ATTR_DEPRECATED_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_DEPRECATED_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_DEPRECATED. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/c_attribute.h" -#include "ruby/impl/has/cpp_attribute.h" -#include "ruby/impl/has/declspec_attribute.h" -#include "ruby/impl/has/extension.h" - -/** Wraps (or simulates) `[[deprecated]]` */ -#if RBIMPL_HAS_EXTENSION(attribute_deprecated_with_message) -# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) - -#elif RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0) -# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) - -#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) -# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) - -#elif RBIMPL_HAS_ATTRIBUTE(deprecated) /* but not with message. */ -# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__)) - -#elif RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0) -# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated msg) - -#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(deprecated) -# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated) - -#elif RBIMPL_HAS_CPP_ATTRIBUTE(deprecated) -# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]] - -#elif RBIMPL_HAS_C_ATTRIBUTE(deprecated) -# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]] - -#else -# define RBIMPL_ATTR_DEPRECATED(msg) /* void */ -#endif - -#endif /* RBIMPL_ATTR_DEPRECATED_H */ diff --git a/include/ruby/impl/attr/diagnose_if.h b/include/ruby/impl/attr/diagnose_if.h deleted file mode 100644 index ba6e8626e3..0000000000 --- a/include/ruby/impl/attr/diagnose_if.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef RBIMPL_ATTR_DIAGNOSE_IF_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_DIAGNOSE_IF_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_DIAGNOSE_IF. - */ -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/warning_push.h" - -/** Wraps (or simulates) `__attribute__((diagnose_if))` */ -#if RBIMPL_COMPILER_BEFORE(Clang, 5, 0, 0) -# /* https://bugs.llvm.org/show_bug.cgi?id=34319 */ -# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */ - -#elif RBIMPL_HAS_ATTRIBUTE(diagnose_if) -# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) \ - RBIMPL_WARNING_PUSH() \ - RBIMPL_WARNING_IGNORED(-Wgcc-compat) \ - __attribute__((__diagnose_if__(_, __, ___))) \ - RBIMPL_WARNING_POP() - -#else -# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */ -#endif - -#endif /* RBIMPL_ATTR_DIAGNOSE_IF_H */ diff --git a/include/ruby/impl/attr/enum_extensibility.h b/include/ruby/impl/attr/enum_extensibility.h deleted file mode 100644 index d5d25e03d7..0000000000 --- a/include/ruby/impl/attr/enum_extensibility.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RBIMPL_ATTR_ENUM_EXTENSIBILITY_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_ENUM_EXTENSIBILITY_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief #RBIMPL_ATTR_ENUM_EXTENSIBILITY. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((enum_extensibility))` */ -#if RBIMPL_HAS_ATTRIBUTE(enum_extensibility) -# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) __attribute__((__enum_extensibility__(_))) -#else -# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) /* void */ -#endif - -#endif /* RBIMPL_ATTR_ENUM_EXTENSIBILITY_H */ diff --git a/include/ruby/impl/attr/error.h b/include/ruby/impl/attr/error.h deleted file mode 100644 index b46b306fb9..0000000000 --- a/include/ruby/impl/attr/error.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RBIMPL_ATTR_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_ERROR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_ERROR. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((error))` */ -#if RBIMPL_HAS_ATTRIBUTE(error) -# define RBIMPL_ATTR_ERROR(msg) __attribute__((__error__ msg)) -#else -# define RBIMPL_ATTR_ERROR(msg) /* void */ -#endif - -#endif /* RBIMPL_ATTR_ERROR_H */ diff --git a/include/ruby/impl/attr/flag_enum.h b/include/ruby/impl/attr/flag_enum.h deleted file mode 100644 index e769708d93..0000000000 --- a/include/ruby/impl/attr/flag_enum.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RBIMPL_ATTR_FLAG_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_FLAG_ENUM_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_FLAG_ENUM. - * @see https://clang.llvm.org/docs/AttributeReference.html#flag_enum - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((flag_enum)` */ -#if RBIMPL_HAS_ATTRIBUTE(flag_enum) -# define RBIMPL_ATTR_FLAG_ENUM() __attribute__((__flag_enum__)) -#else -# define RBIMPL_ATTR_FLAG_ENUM() /* void */ -#endif - -#endif /* RBIMPLATTR_FLAG_ENUM_H */ diff --git a/include/ruby/impl/attr/forceinline.h b/include/ruby/impl/attr/forceinline.h deleted file mode 100644 index 8d60a63437..0000000000 --- a/include/ruby/impl/attr/forceinline.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef RBIMPL_ATTR_FORCEINLINE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_FORCEINLINE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_FORCEINLINE. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/attribute.h" - -/** - * Wraps (or simulates) `__forceinline`. MSVC complains on declarations like - * `static inline __forceinline void foo()`. It seems MSVC's `inline` and - * `__forceinline` are mutually exclusive. We have to mimic that behaviour for - * non-MSVC compilers. - */ -#if RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0) -# define RBIMPL_ATTR_FORCEINLINE() __forceinline -#elif RBIMPL_HAS_ATTRIBUTE(always_inline) -# define RBIMPL_ATTR_FORCEINLINE() __attribute__((__always_inline__)) inline -#else -# define RBIMPL_ATTR_FORCEINLINE() inline -#endif - -#endif /* RBIMPL_ATTR_FORCEINLINE_H */ diff --git a/include/ruby/impl/attr/format.h b/include/ruby/impl/attr/format.h deleted file mode 100644 index 368c9f8797..0000000000 --- a/include/ruby/impl/attr/format.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef RBIMPL_ATTR_FORMAT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_FORMAT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_FORMAT. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((format))` */ -#if RBIMPL_HAS_ATTRIBUTE(format) -# define RBIMPL_ATTR_FORMAT(x, y, z) __attribute__((__format__(x, y, z))) -#else -# define RBIMPL_ATTR_FORMAT(x, y, z) /* void */ -#endif - -#if defined(__MINGW_PRINTF_FORMAT) -# define RBIMPL_PRINTF_FORMAT __MINGW_PRINTF_FORMAT -#else -# define RBIMPL_PRINTF_FORMAT __printf__ -#endif - -#endif /* RBIMPL_ATTR_FORMAT_H */ diff --git a/include/ruby/impl/attr/maybe_unused.h b/include/ruby/impl/attr/maybe_unused.h deleted file mode 100644 index d554603db5..0000000000 --- a/include/ruby/impl/attr/maybe_unused.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef RBIMPL_ATTR_MAYBE_UNUSED_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_MAYBE_UNUSED_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_MAYBE_UNUSED. - */ -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/c_attribute.h" -#include "ruby/impl/has/cpp_attribute.h" - -/** Wraps (or simulates) `[[maybe_unused]]` */ -#if RBIMPL_HAS_CPP_ATTRIBUTE(maybe_unused) -# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]] -#elif RBIMPL_HAS_C_ATTRIBUTE(maybe_unused) -# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]] -#elif RBIMPL_HAS_ATTRIBUTE(unused) -# define RBIMPL_ATTR_MAYBE_UNUSED() __attribute__((__unused__)) -#else -# define RBIMPL_ATTR_MAYBE_UNUSED() /* void */ -#endif - -#endif /* RBIMPL_ATTR_MAYBE_UNUSED */ diff --git a/include/ruby/impl/attr/noalias.h b/include/ruby/impl/attr/noalias.h deleted file mode 100644 index 0180d0c4ec..0000000000 --- a/include/ruby/impl/attr/noalias.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef RBIMPL_ATTR_NOALIAS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_NOALIAS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_NOALIAS. - * - * ### Q&A ### - * - * - Q: There are seemingly similar attributes named #RBIMPL_ATTR_CONST, - * #RBIMPL_ATTR_PURE, and #RBIMPL_ATTR_NOALIAS. What are the difference? - * - * - A: Allowed operations are different. - * - * - #RBIMPL_ATTR_CONST ... Functions attributed by this are not allowed to - * read/write _any_ pointers at all (there are exceptional situations - * when reading a pointer is possible but forget that; they are too - * exceptional to be useful). Just remember that everything pointer- - * related are NG. - * - * - #RBIMPL_ATTR_PURE ... Functions attributed by this can read any - * nonvolatile pointers, but no writes are allowed at all. The ability - * to read _any_ nonvolatile pointers makes it possible to mark ::VALUE- - * taking functions as being pure, as long as they are read-only. - * - * - #RBIMPL_ATTR_NOALIAS ... Can both read/write, but only through - * pointers passed to the function as parameters. This is a typical - * situation when you create a C++ non-static member function which only - * concerns `this`. No global variables are allowed to read/write. So - * this is not a super-set of being pure. If you want to read something, - * that has to be passed to the function as a pointer. ::VALUE -taking - * functions thus cannot be attributed as such. - */ -#include "ruby/impl/has/declspec_attribute.h" - -/** Wraps (or simulates) `__declspec((noalias))` */ -#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias) -# define RBIMPL_ATTR_NOALIAS() __declspec(noalias) -#else -# define RBIMPL_ATTR_NOALIAS() /* void */ -#endif - -#endif /* RBIMPL_ATTR_NOALIAS_H */ diff --git a/include/ruby/impl/attr/nodiscard.h b/include/ruby/impl/attr/nodiscard.h deleted file mode 100644 index ee3a1347df..0000000000 --- a/include/ruby/impl/attr/nodiscard.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef RBIMPL_ATTR_NODISCARD_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_NODISCARD_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_NODISCARD. - */ -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/c_attribute.h" -#include "ruby/impl/has/cpp_attribute.h" - -/** - * Wraps (or simulates) `[[nodiscard]]`. In C++ (at least since C++20) a - * nodiscard attribute can have a message why the result shall not be ignoed. - * However GCC attribute and SAL annotation cannot take them. - */ -#if RBIMPL_HAS_CPP_ATTRIBUTE(nodiscard) -# define RBIMPL_ATTR_NODISCARD() [[nodiscard]] -#elif RBIMPL_HAS_C_ATTRIBUTE(nodiscard) -# define RBIMPL_ATTR_NODISCARD() [[nodiscard]] -#elif RBIMPL_HAS_ATTRIBUTE(warn_unused_result) -# define RBIMPL_ATTR_NODISCARD() __attribute__((__warn_unused_result__)) -#elif defined(_Check_return_) -# /* Take SAL definition. */ -# define RBIMPL_ATTR_NODISCARD() _Check_return_ -#else -# define RBIMPL_ATTR_NODISCARD() /* void */ -#endif - -#endif /* RBIMPL_ATTR_NODISCARD_H */ diff --git a/include/ruby/impl/attr/noexcept.h b/include/ruby/impl/attr/noexcept.h deleted file mode 100644 index ac0ec4c10d..0000000000 --- a/include/ruby/impl/attr/noexcept.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef RBIMPL_ATTR_NOEXCEPT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_NOEXCEPT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_NOEXCEPT. - * - * This isn't actually an attribute in C++ but who cares... - * - * Mainly due to aesthetic reasons, this one is rarely used in the project. - * But can be handy on occasions, especially when a function's noexcept-ness - * depends on its calling functions. - * - * ### Q&A ### - * - * - Q: Can a function that raises Ruby exceptions be attributed `noexcept`? - * - * - A: Yes. `noexcept` is about C++ exceptions, not Ruby's. They don't - * interface each other. You can safely attribute a function that raises - * Ruby exceptions as `noexcept`. - * - * - Q: How, then, can I assert that a function I wrote doesn't raise any Ruby - * exceptions? - * - * - A: `__attribute__((__leaf__))` is for that purpose. A function attributed - * as leaf can still throw C++ exceptions, but not Ruby's. Note however, - * that it's extremely difficult -- if not impossible -- to assert that a - * function doesn't raise any Ruby exceptions at all. Use of that - * attribute is not recommended; mere mortals can't properly use that by - * hand. - * - * - Q: Does it make sense to attribute an inline function `noexcept`? - * - * - A: I thought so before. But no, I don't think they are useful any longer. - * - * - When an inline function attributed `noexcept` actually doesn't throw - * any exceptions at all: these days I don't see any difference in - * generated assembly by adding/removing this attribute. C++ compilers - * get smarter and smarter. Today they can infer if it actually throws - * or not without any annotations by humans (correct me if I'm wrong). - * - * - When an inline function attributed `noexcepr` actually _does_ throw an - * exception: they have to call `std::terminate` then (C++ standard - * mandates so). This means exception handling routines are actually - * enforced, not omitted. This doesn't impact runtime performance (The - * Itanium C++ ABI has zero-cost exception handling), but does impact on - * generated binary size. This is bad. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/feature.h" - -/** Wraps (or simulates) C++11 `noexcept` */ -#if ! defined(__cplusplus) -# /* Doesn't make sense. */ -# define RBIMPL_ATTR_NOEXCEPT(_) /* void */ - -#elif RBIMPL_HAS_FEATURE(cxx_noexcept) -# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) - -#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ -# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) - -#elif defined(__INTEL_CXX11_MODE__) -# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) - -#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0) -# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) - -#elif __cplusplus >= 201103L -# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) - -#else -# define RBIMPL_ATTR_NOEXCEPT(_) /* void */ -#endif - -#endif /* RBIMPL_ATTR_NOEXCEPT_H */ diff --git a/include/ruby/impl/attr/noinline.h b/include/ruby/impl/attr/noinline.h deleted file mode 100644 index c2cc007969..0000000000 --- a/include/ruby/impl/attr/noinline.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef RBIMPL_ATTR_NOINLINE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_NOINLINE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_NOINLINE. - */ -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/declspec_attribute.h" - -/** Wraps (or simulates) `__declspec(noinline)` */ -#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noinline) -# define RBIMPL_ATTR_NOINLINE() __declspec(noinline) -#elif RBIMPL_HAS_ATTRIBUTE(noinline) -# define RBIMPL_ATTR_NOINLINE() __attribute__((__noinline__)) -#else -# define RBIMPL_ATTR_NOINLINE() /* void */ -#endif - -#endif /* RBIMPL_ATTR_NOINLINE_H */ diff --git a/include/ruby/impl/attr/nonnull.h b/include/ruby/impl/attr/nonnull.h deleted file mode 100644 index a1d0320e1d..0000000000 --- a/include/ruby/impl/attr/nonnull.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RBIMPL_ATTR_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_NONNULL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_NONNULL. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((nonnull))` */ -#if RBIMPL_HAS_ATTRIBUTE(nonnull) -# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list)) -#else -# define RBIMPL_ATTR_NONNULL(list) /* void */ -#endif - -#endif /* RBIMPL_ATTR_NONNULL_H */ diff --git a/include/ruby/impl/attr/noreturn.h b/include/ruby/impl/attr/noreturn.h deleted file mode 100644 index 66a9b42947..0000000000 --- a/include/ruby/impl/attr/noreturn.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef RBIMPL_ATTR_NORETURN_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_NORETURN_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_NORETURN. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/cpp_attribute.h" -#include "ruby/impl/has/declspec_attribute.h" - -/** Wraps (or simulates) `[[noreturn]]` */ -#if RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_ATTR_NORETURN() _Pragma("does_not_return") - -#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn) -# define RBIMPL_ATTR_NORETURN() __declspec(noreturn) - -#elif RBIMPL_HAS_ATTRIBUTE(noreturn) -# define RBIMPL_ATTR_NORETURN() __attribute__((__noreturn__)) - -#elif RBIMPL_HAS_CPP_ATTRIBUTE(noreturn) -# define RBIMPL_ATTR_NORETURN() [[noreturn]] - -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112) -# define RBIMPL_ATTR_NORETURN() _Noreturn - -#elif defined(_Noreturn) -# /* glibc has this macro. */ -# define RBIMPL_ATTR_NORETURN() _Noreturn - -#else -# define RBIMPL_ATTR_NORETURN() /* void */ -#endif - -#endif /* RBIMPL_ATTR_NORETURN_H */ diff --git a/include/ruby/impl/attr/pure.h b/include/ruby/impl/attr/pure.h deleted file mode 100644 index a5bb51b76f..0000000000 --- a/include/ruby/impl/attr/pure.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef RBIMPL_ATTR_PURE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_PURE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_PURE. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/assert.h" - -/** Wraps (or simulates) `__attribute__((pure))` */ -#if RBIMPL_HAS_ATTRIBUTE(pure) -# define RBIMPL_ATTR_PURE() __attribute__((__pure__)) -#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_ATTR_PURE() _Pragma("does_not_write_global_data") -#else -# define RBIMPL_ATTR_PURE() /* void */ -#endif - -/** Enables #RBIMPL_ATTR_PURE iff. #RUBY_NDEBUG. */ -#if RUBY_NDEBUG -# define RBIMPL_ATTR_PURE_ON_NDEBUG() RBIMPL_ATTR_PURE() -#else -# define RBIMPL_ATTR_PURE_ON_NDEBUG() /* void */ -#endif - -#endif /* RBIMPL_ATTR_PURE_H */ diff --git a/include/ruby/impl/attr/restrict.h b/include/ruby/impl/attr/restrict.h deleted file mode 100644 index 518906f6da..0000000000 --- a/include/ruby/impl/attr/restrict.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef RBIMPL_ATTR_RESTRICT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_RESTRICT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_RESTRICT. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/token_paste.h" - -/* :FIXME: config.h includes conflicting `#define restrict`. MSVC can be - * detected using `RBIMPL_COMPILER_SINCE()`, but Clang & family cannot use - * `__has_declspec_attribute()` which involves macro substitution. */ - -/** Wraps (or simulates) `__declspec(restrict)` */ -#if RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0) -# define RBIMPL_ATTR_RESTRICT() __declspec(RBIMPL_TOKEN_PASTE(re, strict)) - -#elif RBIMPL_HAS_ATTRIBUTE(malloc) -# define RBIMPL_ATTR_RESTRICT() __attribute__((__malloc__)) - -#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_ATTR_RESTRICT() _Pragma("returns_new_memory") - -#else -# define RBIMPL_ATTR_RESTRICT() /* void */ -#endif - -#endif /* RBIMPL_ATTR_RESTRICT_H */ diff --git a/include/ruby/impl/attr/returns_nonnull.h b/include/ruby/impl/attr/returns_nonnull.h deleted file mode 100644 index f656d70c8c..0000000000 --- a/include/ruby/impl/attr/returns_nonnull.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RBIMPL_ATTR_RETURNS_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_RETURNS_NONNULL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_RETURNS_NONNULL. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((returns_nonnull))` */ -#if defined(_Ret_nonnull_) -# /* Take SAL definition. */ -# define RBIMPL_ATTR_RETURNS_NONNULL() _Ret_nonnull_ - -#elif RBIMPL_HAS_ATTRIBUTE(returns_nonnull) -# define RBIMPL_ATTR_RETURNS_NONNULL() __attribute__((__returns_nonnull__)) - -#else -# define RBIMPL_ATTR_RETURNS_NONNULL() /* void */ -#endif - -#endif /* RBIMPL_ATTR_RETURNS_NONNULL_H */ diff --git a/include/ruby/impl/attr/warning.h b/include/ruby/impl/attr/warning.h deleted file mode 100644 index e7585e0417..0000000000 --- a/include/ruby/impl/attr/warning.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RBIMPL_ATTR_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_WARNING_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_WARNING. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((warning))` */ -#if RBIMPL_HAS_ATTRIBUTE(warning) -# define RBIMPL_ATTR_WARNING(msg) __attribute__((__warning__ msg)) -#else -# define RBIMPL_ATTR_WARNING(msg) /* void */ -#endif - -#endif /* RBIMPL_ATTR_WARNING_H */ diff --git a/include/ruby/impl/attr/weakref.h b/include/ruby/impl/attr/weakref.h deleted file mode 100644 index 769ce017e0..0000000000 --- a/include/ruby/impl/attr/weakref.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RBIMPL_ATTR_WEAKREF_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ATTR_WEAKREF_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ATTR_WEAKREF. - */ -#include "ruby/impl/has/attribute.h" - -/** Wraps (or simulates) `__attribute__((weakref))` */ -#if RBIMPL_HAS_ATTRIBUTE(weakref) -# define RBIMPL_ATTR_WEAKREF(sym) __attribute__((__weakref__(# sym))) -#else -# define RBIMPL_ATTR_WEAKREF(sym) /* void */ -#endif - -#endif /* RBIMPL_ATTR_WEAKREF_H */ diff --git a/include/ruby/impl/cast.h b/include/ruby/impl/cast.h deleted file mode 100644 index 4524d63f17..0000000000 --- a/include/ruby/impl/cast.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef RBIMPL_CAST_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_CAST_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines RBIMPL_CAST. - * @cond INTERNAL_MACRO - * - * This casting macro makes sense only inside of other macros that are part of - * public headers. They could be used from C++, and C-style casts could issue - * warnings. Ruby internals are pure C so they should not bother. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/warning.h" -#include "ruby/impl/warning_push.h" - -#if ! defined(__cplusplus) -# define RBIMPL_CAST(expr) (expr) - -#elif RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) -# /* g++ has -Wold-style-cast since 1997 or so, but its _Pragma is broken. */ -# /* See https://gcc.godbolt.org/z/XWhU6J */ -# define RBIMPL_CAST(expr) (expr) -# pragma GCC diagnostic ignored "-Wold-style-cast" - -#elif RBIMPL_HAS_WARNING("-Wold-style-cast") -# define RBIMPL_CAST(expr) \ - RBIMPL_WARNING_PUSH() \ - RBIMPL_WARNING_IGNORED(-Wold-style-cast) \ - (expr) \ - RBIMPL_WARNING_POP() - -#else -# define RBIMPL_CAST(expr) (expr) -#endif -/** @endcond */ - -#endif /* RBIMPL_CAST_H */ diff --git a/include/ruby/impl/compiler_is.h b/include/ruby/impl/compiler_is.h deleted file mode 100644 index 3f34bc1a15..0000000000 --- a/include/ruby/impl/compiler_is.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS. - */ - -/** - * @brief Checks if the compiler is of given brand. - * @param cc Compiler brand, like `MSVC`. - * @retval true It is. - * @retval false It isn't. - */ -#define RBIMPL_COMPILER_IS(cc) RBIMPL_COMPILER_IS_ ## cc - -#include "ruby/impl/compiler_is/apple.h" -#include "ruby/impl/compiler_is/clang.h" -#include "ruby/impl/compiler_is/gcc.h" -#include "ruby/impl/compiler_is/intel.h" -#include "ruby/impl/compiler_is/msvc.h" -#include "ruby/impl/compiler_is/sunpro.h" -/* :TODO: Other possible compilers to support: - * - * - IBM XL: recent XL are clang-backended so some tweaks like we do for - * Apple's might be needed. - * - * - ARM's armclang: ditto, it can be clang-backended. */ - -#endif /* RBIMPL_COMPILER_IS_H */ diff --git a/include/ruby/impl/compiler_is/apple.h b/include/ruby/impl/compiler_is/apple.h deleted file mode 100644 index 5a5f558254..0000000000 --- a/include/ruby/impl/compiler_is/apple.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_APPLE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_APPLE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS_Apple. - * - * Apple ships clang. Problem is, its `__clang_major__` etc. are not the - * upstream LLVM version, but XCode's. We have to think Apple's is distinct - * from LLVM's, when it comes to compiler detection business in this header - * file. - */ -#if ! defined(__clang__) -# define RBIMPL_COMPILER_IS_Apple 0 - -#elif ! defined(__apple_build_version__) -# define RBIMPL_COMPILER_IS_Apple 0 - -#else -# define RBIMPL_COMPILER_IS_Apple 1 -# define RBIMPL_COMPILER_VERSION_MAJOR __clang_major__ -# define RBIMPL_COMPILER_VERSION_MINOR __clang_minor__ -# define RBIMPL_COMPILER_VERSION_PATCH __clang_patchlevel__ -#endif - -#endif /* RBIMPL_COMPILER_IS_APPLE_H */ diff --git a/include/ruby/impl/compiler_is/clang.h b/include/ruby/impl/compiler_is/clang.h deleted file mode 100644 index 40646750cb..0000000000 --- a/include/ruby/impl/compiler_is/clang.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_CLANG_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_CLANG_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS_Clang. - */ -#include "ruby/impl/compiler_is/apple.h" - -#if ! defined(__clang__) -# define RBIMPL_COMPILER_IS_Clang 0 - -#elif RBIMPL_COMPILER_IS(Apple) -# define RBIMPL_COMPILER_IS_Clang 0 - -#else -# define RBIMPL_COMPILER_IS_Clang 1 -# define RBIMPL_COMPILER_VERSION_MAJOR __clang_major__ -# define RBIMPL_COMPILER_VERSION_MINOR __clang_minor__ -# define RBIMPL_COMPILER_VERSION_PATCH __clang_patchlevel__ -#endif - -#endif /* RBIMPL_COMPILER_IS_CLANG_H */ diff --git a/include/ruby/impl/compiler_is/gcc.h b/include/ruby/impl/compiler_is/gcc.h deleted file mode 100644 index 06f0b2b9f6..0000000000 --- a/include/ruby/impl/compiler_is/gcc.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_GCC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_GCC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS_GCC. - */ -#include "ruby/impl/compiler_is/apple.h" -#include "ruby/impl/compiler_is/clang.h" -#include "ruby/impl/compiler_is/intel.h" - -#if ! defined(__GNUC__) -# define RBIMPL_COMPILER_IS_GCC 0 - -#elif RBIMPL_COMPILER_IS(Apple) -# define RBIMPL_COMPILER_IS_GCC 0 - -#elif RBIMPL_COMPILER_IS(Clang) -# define RBIMPL_COMPILER_IS_GCC 0 - -#elif RBIMPL_COMPILER_IS(Intel) -# define RBIMPL_COMPILER_IS_GCC 0 - -#else -# define RBIMPL_COMPILER_IS_GCC 1 -# define RBIMPL_COMPILER_VERSION_MAJOR __GNUC__ -# define RBIMPL_COMPILER_VERSION_MINOR __GNUC_MINOR__ -# define RBIMPL_COMPILER_VERSION_PATCH __GNUC_PATCHLEVEL__ -#endif - -#endif /* RBIMPL_COMPILER_IS_GCC_H */ diff --git a/include/ruby/impl/compiler_is/intel.h b/include/ruby/impl/compiler_is/intel.h deleted file mode 100644 index ada120485e..0000000000 --- a/include/ruby/impl/compiler_is/intel.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_INTEL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_INTEL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS_Intel. - */ -#if ! defined(__INTEL_COMPILER) -# define RBIMPL_COMPILER_IS_Intel 0 - -#elif ! defined(__INTEL_COMPILER_UPDATE) -# define RBIMPL_COMPILER_IS_Intel 1 -# /* __INTEL_COMPILER = XXYZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (__INTEL_COMPILER / 100) -# define RBIMPL_COMPILER_VERSION_MINOR (__INTEL_COMPILER % 100 / 10) -# define RBIMPL_COMPILER_VERSION_PATCH (__INTEL_COMPILER % 10) - -#else -# define RBIMPL_COMPILER_IS_Intel 1 -# /* __INTEL_COMPILER = XXYZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (__INTEL_COMPILER / 100) -# define RBIMPL_COMPILER_VERSION_MINOR (__INTEL_COMPILER % 100 / 10) -# define RBIMPL_COMPILER_VERSION_PATCH __INTEL_COMPILER_UPDATE -#endif - -#endif /* RBIMPL_COMPILER_IS_INTEL_H */ diff --git a/include/ruby/impl/compiler_is/msvc.h b/include/ruby/impl/compiler_is/msvc.h deleted file mode 100644 index f66050e9c4..0000000000 --- a/include/ruby/impl/compiler_is/msvc.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_MSVC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_MSVC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS_MSVC. - */ -#include "ruby/impl/compiler_is/clang.h" -#include "ruby/impl/compiler_is/intel.h" - -#if ! defined(_MSC_VER) -# define RBIMPL_COMPILER_IS_MSVC 0 - -#elif RBIMPL_COMPILER_IS(Clang) -# define RBIMPL_COMPILER_IS_MSVC 0 - -#elif RBIMPL_COMPILER_IS(Intel) -# define RBIMPL_COMPILER_IS_MSVC 0 - -#elif _MSC_VER >= 1400 -# define RBIMPL_COMPILER_IS_MSVC 1 -# /* _MSC_FULL_VER = XXYYZZZZZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 10000000) -# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_FULL_VER % 10000000 / 100000) -# define RBIMPL_COMPILER_VERSION_PATCH (_MSC_FULL_VER % 100000) - -#elif defined(_MSC_FULL_VER) -# define RBIMPL_COMPILER_IS_MSVC 1 -# /* _MSC_FULL_VER = XXYYZZZZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 1000000) -# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_FULL_VER % 1000000 / 10000) -# define RBIMPL_COMPILER_VERSION_PATCH (_MSC_FULL_VER % 10000) - -#else -# define RBIMPL_COMPILER_IS_MSVC 1 -# /* _MSC_VER = XXYY */ -# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_VER / 100) -# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_VER % 100) -# define RBIMPL_COMPILER_VERSION_PATCH 0 -#endif - -#endif /* RBIMPL_COMPILER_IS_MSVC_H */ diff --git a/include/ruby/impl/compiler_is/sunpro.h b/include/ruby/impl/compiler_is/sunpro.h deleted file mode 100644 index 2eb7b892f2..0000000000 --- a/include/ruby/impl/compiler_is/sunpro.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef RBIMPL_COMPILER_IS_SUNPRO_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_IS_SUNPRO_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_IS_SunPro. - */ -#if ! (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) -# define RBIMPL_COMPILER_IS_SunPro 0 - -#elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x5100 -# define RBIMPL_COMPILER_IS_SunPro 1 -# /* __SUNPRO_C = 0xXYYZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_C >> 12) -# define RBIMPL_COMPILER_VERSION_MINOR ((__SUNPRO_C >> 8 & 0xF) * 10 + (__SUNPRO_C >> 4 & 0xF)) -# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_C & 0xF) - -#elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5100 -# define RBIMPL_COMPILER_IS_SunPro 1 -# /* __SUNPRO_CC = 0xXYYZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_CC >> 12) -# define RBIMPL_COMPILER_VERSION_MINOR ((__SUNPRO_CC >> 8 & 0xF) * 10 + (__SUNPRO_CC >> 4 & 0xF)) -# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_CC & 0xF) - -#elif defined(__SUNPRO_C) -# define RBIMPL_COMPILER_IS_SunPro 1 -# /* __SUNPRO_C = 0xXYZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_C >> 8) -# define RBIMPL_COMPILER_VERSION_MINOR (__SUNPRO_C >> 4 & 0xF) -# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_C & 0xF) - -#else -# define RBIMPL_COMPILER_IS_SunPro 1 -# /* __SUNPRO_CC = 0xXYZ */ -# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_CC >> 8) -# define RBIMPL_COMPILER_VERSION_MINOR (__SUNPRO_CC >> 4 & 0xF) -# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_CC & 0xF) -#endif - -#endif /* RBIMPL_COMPILER_IS_SUNPRO_H */ diff --git a/include/ruby/impl/compiler_since.h b/include/ruby/impl/compiler_since.h deleted file mode 100644 index bdc6cac526..0000000000 --- a/include/ruby/impl/compiler_since.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef RBIMPL_COMPILER_SINCE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_COMPILER_SINCE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_COMPILER_SINCE. - */ -#include "ruby/impl/compiler_is.h" - -/** - * @brief Checks if the compiler is of given brand and is newer than or equal - * to the passed version. - * @param cc Compiler brand, like `MSVC`. - * @param x Major version. - * @param y Minor version. - * @param z Patchlevel. - * @retval true cc >= x.y.z. - * @retval false oherwise. - */ -#define RBIMPL_COMPILER_SINCE(cc, x, y, z) \ - (RBIMPL_COMPILER_IS(cc) && \ - ((RBIMPL_COMPILER_VERSION_MAJOR > (x)) || \ - ((RBIMPL_COMPILER_VERSION_MAJOR == (x)) && \ - ((RBIMPL_COMPILER_VERSION_MINOR > (y)) || \ - ((RBIMPL_COMPILER_VERSION_MINOR == (y)) && \ - (RBIMPL_COMPILER_VERSION_PATCH >= (z))))))) - -/** - * @brief Checks if the compiler is of given brand and is older than the - * passed version. - * @param cc Compiler brand, like `MSVC`. - * @param x Major version. - * @param y Minor version. - * @param z Patchlevel. - * @retval true cc < x.y.z. - * @retval false oherwise. - */ -#define RBIMPL_COMPILER_BEFORE(cc, x, y, z) \ - (RBIMPL_COMPILER_IS(cc) && \ - ((RBIMPL_COMPILER_VERSION_MAJOR < (x)) || \ - ((RBIMPL_COMPILER_VERSION_MAJOR == (x)) && \ - ((RBIMPL_COMPILER_VERSION_MINOR < (y)) || \ - ((RBIMPL_COMPILER_VERSION_MINOR == (y)) && \ - (RBIMPL_COMPILER_VERSION_PATCH < (z))))))) - -#endif /* RBIMPL_COMPILER_SINCE_H */ diff --git a/include/ruby/impl/config.h b/include/ruby/impl/config.h deleted file mode 100644 index e6c4d12488..0000000000 --- a/include/ruby/impl/config.h +++ /dev/null @@ -1,131 +0,0 @@ -#ifndef RBIMPL_CONFIG_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_CONFIG_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Thin wrapper to ruby/config.h - */ -#include "ruby/config.h" - -#ifdef RUBY_EXTCONF_H -# include RUBY_EXTCONF_H -#endif - -#include "ruby/impl/compiler_since.h" - -#if defined(__cplusplus) -#/* __builtin_choose_expr and __builtin_types_compatible aren't available -# * on C++. See https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */ -# undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P -# undef HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P - -# undef HAVE_PROTOTYPES -# define HAVE_PROTOTYPES 1 - -# undef HAVE_STDARG_PROTOTYPES -# define HAVE_STDARG_PROTOTYPES 1 - -/* HAVE_VA_ARGS_MACRO is for C. C++ situations might be different. */ -# undef HAVE_VA_ARGS_MACRO -# if __cplusplus >= 201103L -# define HAVE_VA_ARGS_MACRO -# elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ -# define HAVE_VA_ARGS_MACRO -# elif defined(__INTEL_CXX11_MODE__) -# define HAVE_VA_ARGS_MACRO -# elif RBIMPL_COMPILER_SINCE(MSVC, 16, 0, 0) -# define HAVE_VA_ARGS_MACRO -# else -# /* NG, not known. */ -# endif -#endif - -#if RBIMPL_COMPILER_BEFORE(GCC, 4, 9, 0) -# /* See https://bugs.ruby-lang.org/issues/14221 */ -# undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P -#endif - -#if RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0) -# /* GCC 4.9.2 reportedly has this feature and is broken. The function is not -# * officially documented below. Seems we should not use it. -# * https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Other-Builtins.html */ -# undef HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN -#endif - -#ifndef STRINGIZE0 -# define STRINGIZE(expr) STRINGIZE0(expr) -# define STRINGIZE0(expr) #expr -#endif - -#ifdef AC_APPLE_UNIVERSAL_BUILD -# undef WORDS_BIGENDIAN -# ifdef __BIG_ENDIAN__ -# define WORDS_BIGENDIAN -# endif -#endif - -#ifndef DLEXT_MAXLEN -# define DLEXT_MAXLEN 4 -#endif - -#ifndef RUBY_PLATFORM -# define RUBY_PLATFORM "unknown-unknown" -#endif - -#ifdef UNALIGNED_WORD_ACCESS -# /* Take that. */ -#elif defined(__i386) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(__i386__) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(_M_IX86) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(__x86_64) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(__x86_64__) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(_M_AMD64) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(__powerpc64__) -# define UNALIGNED_WORD_ACCESS 1 -#elif defined(__mc68020__) -# define UNALIGNED_WORD_ACCESS 1 -#else -# define UNALIGNED_WORD_ACCESS 0 -#endif - -/* Detection of __VA_OPT__ */ -#if ! defined(HAVE_VA_ARGS_MACRO) -# undef HAVE___VA_OPT__ - -#else -# /* Idea taken from: https://stackoverflow.com/a/48045656 */ -# define RBIMPL_TEST3(q, w, e, ...) e -# define RBIMPL_TEST2(...) RBIMPL_TEST3(__VA_OPT__(,),1,0,0) -# define RBIMPL_TEST1() RBIMPL_TEST2("ruby") -# if RBIMPL_TEST1() -# define HAVE___VA_OPT__ -# else -# undef HAVE___VA_OPT__ -# endif -# undef RBIMPL_TEST1 -# undef RBIMPL_TEST2 -# undef RBIMPL_TEST3 -#endif /* HAVE_VA_ARGS_MACRO */ - -#endif /* RBIMPL_CONFIG_H */ diff --git a/include/ruby/impl/constant_p.h b/include/ruby/impl/constant_p.h deleted file mode 100644 index bfc8d05580..0000000000 --- a/include/ruby/impl/constant_p.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RBIMPL_CONSTANT_P_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_CONSTANT_P_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_CONSTANT_P. - * - * Note that __builtin_constant_p can be applicable inside of inline functions, - * according to GCC manual. Clang lacks that feature, though. - * - * @see https://bugs.llvm.org/show_bug.cgi?id=4898 - * @see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html - */ -#include "ruby/impl/has/builtin.h" - -#if RBIMPL_HAS_BUILTIN(__builtin_constant_p) -# define RBIMPL_CONSTANT_P(expr) __builtin_constant_p(expr) -#else -# define RBIMPL_CONSTANT_P(expr) 0 -#endif - -#endif /* RBIMPL_CONSTANT_P_H */ diff --git a/include/ruby/impl/core.h b/include/ruby/impl/core.h deleted file mode 100644 index a9c8c080db..0000000000 --- a/include/ruby/impl/core.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef RBIMPL_CORE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_CORE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Core data structures, definitions and manupulations. - */ -#include "ruby/impl/core/rarray.h" -#include "ruby/impl/core/rbasic.h" -#include "ruby/impl/core/rbignum.h" -#include "ruby/impl/core/rclass.h" -#include "ruby/impl/core/rdata.h" -#include "ruby/impl/core/rfile.h" -#include "ruby/impl/core/rhash.h" -#include "ruby/impl/core/robject.h" -#include "ruby/impl/core/rregexp.h" -#include "ruby/impl/core/rstring.h" -#include "ruby/impl/core/rstruct.h" -#include "ruby/impl/core/rtypeddata.h" -#endif /* RBIMPL_CORE_H */ diff --git a/include/ruby/impl/core/rarray.h b/include/ruby/impl/core/rarray.h deleted file mode 100644 index 04f8f0dd49..0000000000 --- a/include/ruby/impl/core/rarray.h +++ /dev/null @@ -1,275 +0,0 @@ -#ifndef RBIMPL_RARRAY_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RARRAY_H -/** - * @file - * @author Ruby developers - * @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/impl/core/rbasic.h b/include/ruby/impl/core/rbasic.h deleted file mode 100644 index 751b30c24c..0000000000 --- a/include/ruby/impl/core/rbasic.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef RBIMPL_RBASIC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RBASIC_H -/** - * @file - * @author Ruby developers - * @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/impl/core/rbignum.h b/include/ruby/impl/core/rbignum.h deleted file mode 100644 index 9a77456ba3..0000000000 --- a/include/ruby/impl/core/rbignum.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef RBIMPL_RBIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RBIGNUM_H -/** - * @file - * @author Ruby developers - * @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/impl/core/rclass.h b/include/ruby/impl/core/rclass.h deleted file mode 100644 index c9864e2436..0000000000 --- a/include/ruby/impl/core/rclass.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef RBIMPL_RCLASS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RCLASS_H -/** - * @file - * @author Ruby developers - * @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/impl/core/rdata.h b/include/ruby/impl/core/rdata.h deleted file mode 100644 index 4a0b09498c..0000000000 --- a/include/ruby/impl/core/rdata.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef RBIMPL_RDATA_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RDATA_H -/** - * @file - * @author Ruby developers - * @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 -#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/impl/core/rfile.h b/include/ruby/impl/core/rfile.h deleted file mode 100644 index 4f3ff3f8af..0000000000 --- a/include/ruby/impl/core/rfile.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef RBIMPL_RFILE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RFILE_H -/** - * @file - * @author Ruby developers - * @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/impl/core/rhash.h b/include/ruby/impl/core/rhash.h deleted file mode 100644 index a4be7a3a11..0000000000 --- a/include/ruby/impl/core/rhash.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef RBIMPL_RHASH_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RHASH_H -/** - * @file - * @author Ruby developers - * @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 -#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/impl/core/rmatch.h b/include/ruby/impl/core/rmatch.h deleted file mode 100644 index 9474b82e4c..0000000000 --- a/include/ruby/impl/core/rmatch.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef RBIMPL_RMATCH_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RMATCH_H -/** - * @file - * @author Ruby developers - * @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/impl/core/robject.h b/include/ruby/impl/core/robject.h deleted file mode 100644 index 5a65bc1d0a..0000000000 --- a/include/ruby/impl/core/robject.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef RBIMPL_ROBJECT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ROBJECT_H -/** - * @file - * @author Ruby developers - * @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 -#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/impl/core/rregexp.h b/include/ruby/impl/core/rregexp.h deleted file mode 100644 index eff7bcc6e9..0000000000 --- a/include/ruby/impl/core/rregexp.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RREGEXP_H -/** - * @file - * @author Ruby developers - * @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 */ diff --git a/include/ruby/impl/core/rstring.h b/include/ruby/impl/core/rstring.h deleted file mode 100644 index 683635c5ac..0000000000 --- a/include/ruby/impl/core/rstring.h +++ /dev/null @@ -1,215 +0,0 @@ -#ifndef RBIMPL_RSTRING_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RSTRING_H -/** - * @file - * @author Ruby developers - * @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 */ diff --git a/include/ruby/impl/core/rstruct.h b/include/ruby/impl/core/rstruct.h deleted file mode 100644 index 9f873adad2..0000000000 --- a/include/ruby/impl/core/rstruct.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RSTRUCT_H -/** - * @file - * @author Ruby developers - * @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 */ diff --git a/include/ruby/impl/core/rtypeddata.h b/include/ruby/impl/core/rtypeddata.h deleted file mode 100644 index 49e55dcf91..0000000000 --- a/include/ruby/impl/core/rtypeddata.h +++ /dev/null @@ -1,184 +0,0 @@ -#ifndef RBIMPL_RTYPEDDATA_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RTYPEDDATA_H -/** - * @file - * @author Ruby developers - * @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 -#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 */ diff --git a/include/ruby/impl/ctype.h b/include/ruby/impl/ctype.h deleted file mode 100644 index 7a8f032c58..0000000000 --- a/include/ruby/impl/ctype.h +++ /dev/null @@ -1,203 +0,0 @@ -#ifndef RBIMPL_CTYPE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_CTYPE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Our own, locale independent, character handling routines. - */ -#include "ruby/impl/config.h" - -#ifdef STDC_HEADERS -# include -#endif - -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/dllexport.h" - -#ifndef ISPRINT -# define ISASCII rb_isascii -# define ISPRINT rb_isprint -# define ISGRAPH rb_isgraph -# define ISSPACE rb_isspace -# define ISUPPER rb_isupper -# define ISLOWER rb_islower -# define ISALNUM rb_isalnum -# define ISALPHA rb_isalpha -# define ISDIGIT rb_isdigit -# define ISXDIGIT rb_isxdigit -# define ISBLANK rb_isblank -# define ISCNTRL rb_iscntrl -# define ISPUNCT rb_ispunct -#endif - -#define TOUPPER rb_toupper -#define TOLOWER rb_tolower -#define STRCASECMP st_locale_insensitive_strcasecmp -#define STRNCASECMP st_locale_insensitive_strncasecmp -#define STRTOUL ruby_strtoul - -RBIMPL_SYMBOL_EXPORT_BEGIN() -/* locale insensitive functions */ -int st_locale_insensitive_strcasecmp(const char *s1, const char *s2); -int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n); -unsigned long ruby_strtoul(const char *str, char **endptr, int base); -RBIMPL_SYMBOL_EXPORT_END() - -/* - * We are making the functions below to return `int` instead of `bool`. They - * have been as such since their birth at 5f237d79033b2109afb768bc889611fa9630. - */ - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isascii(int c) -{ - return '\0' <= c && c <= '\x7f'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isupper(int c) -{ - return 'A' <= c && c <= 'Z'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_islower(int c) -{ - return 'a' <= c && c <= 'z'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isalpha(int c) -{ - return rb_isupper(c) || rb_islower(c); -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isdigit(int c) -{ - return '0' <= c && c <= '9'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isalnum(int c) -{ - return rb_isalpha(c) || rb_isdigit(c); -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isxdigit(int c) -{ - return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isblank(int c) -{ - return c == ' ' || c == '\t'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isspace(int c) -{ - return c == ' ' || ('\t' <= c && c <= '\r'); -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_iscntrl(int c) -{ - return ('\0' <= c && c < ' ') || c == '\x7f'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isprint(int c) -{ - return ' ' <= c && c <= '\x7e'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_ispunct(int c) -{ - return !rb_isalnum(c); -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_isgraph(int c) -{ - return '!' <= c && c <= '\x7e'; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_tolower(int c) -{ - return rb_isupper(c) ? (c|0x20) : c; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline int -rb_toupper(int c) -{ - return rb_islower(c) ? (c&0x5f) : c; -} - -#endif /* RBIMPL_CTYPE_H */ diff --git a/include/ruby/impl/dllexport.h b/include/ruby/impl/dllexport.h deleted file mode 100644 index ae1589d811..0000000000 --- a/include/ruby/impl/dllexport.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef RBIMPL_DLLEXPORT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_DLLEXPORT_H -/** - * @file - * @author Ruby developers - * @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 Tewaking visibility of C variables/functions. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/compiler_is.h" - -/* For MinGW, we need __declspec(dllimport) for RUBY_EXTERN on MJIT. - mswin's RUBY_EXTERN already has that. See also: win32/Makefile.sub */ -#undef RUBY_EXTERN -#if defined(MJIT_HEADER) && defined(_WIN32) -# define RUBY_EXTERN extern __declspec(dllimport) -#elif defined(RUBY_EXPORT) -# define RUBY_EXTERN extern -#elif defined(_WIN32) -# define RUBY_EXTERN extern __declspec(dllimport) -#else -# define RUBY_EXTERN extern -#endif - -#ifndef RUBY_SYMBOL_EXPORT_BEGIN -# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */ -#endif - -#ifndef RUBY_SYMBOL_EXPORT_END -# define RUBY_SYMBOL_EXPORT_END /* end */ -#endif - -#ifndef RUBY_FUNC_EXPORTED -# define RUBY_FUNC_EXPORTED /* void */ -#endif - -/* These macros are used for functions which are exported only for MJIT - and NOT ensured to be exported in future versions. */ - -#if ! defined(MJIT_HEADER) -# define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED -#elif ! RBIMPL_COMPILER_IS(MSVC) -# define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED -#else -# define MJIT_FUNC_EXPORTED static -#endif - -#define MJIT_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN -#define MJIT_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END - -/* On mswin, MJIT header transformation can't be used since cl.exe can't output - preprocessed output preserving macros. So this `MJIT_STATIC` is needed - to force non-static function to static on MJIT header to avoid symbol conflict. */ -#ifdef MJIT_HEADER -# define MJIT_STATIC static -#else -# define MJIT_STATIC -#endif - -/** Shortcut macro equivalent to `RUBY_SYMBOL_EXPORT_BEGIN extern "C" {`. - * \@shyouhei finds it handy. */ -#if defined(__DOXYGEN__) -# define RBIMPL_SYMBOL_EXPORT_BEGIN() /* void */ -#elif defined(__cplusplus) -# define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN extern "C" { -#else -# define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN -#endif - -/** Counterpart of #RBIMPL_SYMBOL_EXPORT_BEGIN */ -#if defined(__DOXYGEN__) -# define RBIMPL_SYMBOL_EXPORT_END() /* void */ -#elif defined(__cplusplus) -# define RBIMPL_SYMBOL_EXPORT_END() } RUBY_SYMBOL_EXPORT_END -#else -# define RBIMPL_SYMBOL_EXPORT_END() RUBY_SYMBOL_EXPORT_END -#endif -#endif /* RBIMPL_DLLEXPORT_H */ diff --git a/include/ruby/impl/dosish.h b/include/ruby/impl/dosish.h deleted file mode 100644 index eb71e36505..0000000000 --- a/include/ruby/impl/dosish.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef RBIMPL_DOSISH_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_DOSISH_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Support for so-called dosish systems. - */ -#ifdef __CYGWIN__ -#undef _WIN32 -#endif - -#if defined(_WIN32) -/* - DOSISH mean MS-Windows style filesystem. - But you should use more precise macros like DOSISH_DRIVE_LETTER, PATH_SEP, - ENV_IGNORECASE or CASEFOLD_FILESYSTEM. - */ -#define DOSISH 1 -# define DOSISH_DRIVE_LETTER -#endif - -#ifdef _WIN32 -#include "ruby/win32.h" -#endif - -#if defined(DOSISH) -#define PATH_SEP ";" -#else -#define PATH_SEP ":" -#endif - -#define PATH_SEP_CHAR PATH_SEP[0] - -#define PATH_ENV "PATH" - -#if defined(DOSISH) -#define ENV_IGNORECASE -#endif - -#ifndef CASEFOLD_FILESYSTEM -# if defined DOSISH -# define CASEFOLD_FILESYSTEM 1 -# else -# define CASEFOLD_FILESYSTEM 0 -# endif -#endif - -#endif /* RBIMPL_DOSISH_H */ diff --git a/include/ruby/impl/error.h b/include/ruby/impl/error.h deleted file mode 100644 index a7458f8e1b..0000000000 --- a/include/ruby/impl/error.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef RBIMPL_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ERROR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Declares ::rb_raise(). - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/attributes.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -VALUE rb_errinfo(void); -void rb_set_errinfo(VALUE); - -/* for rb_readwrite_sys_fail first argument */ -enum rb_io_wait_readwrite {RB_IO_WAIT_READABLE, RB_IO_WAIT_WRITABLE}; -#define RB_IO_WAIT_READABLE RB_IO_WAIT_READABLE -#define RB_IO_WAIT_WRITABLE RB_IO_WAIT_WRITABLE - -PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3); -PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2); -COLDFUNC PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2); -NORETURN(void rb_bug_errno(const char*, int)); -NORETURN(void rb_sys_fail(const char*)); -NORETURN(void rb_sys_fail_str(VALUE)); -NORETURN(void rb_mod_sys_fail(VALUE, const char*)); -NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE)); -NORETURN(void rb_readwrite_sys_fail(enum rb_io_wait_readwrite, const char*)); -NORETURN(void rb_iter_break(void)); -NORETURN(void rb_iter_break_value(VALUE)); -NORETURN(void rb_exit(int)); -NORETURN(void rb_notimplement(void)); -VALUE rb_syserr_new(int, const char *); -VALUE rb_syserr_new_str(int n, VALUE arg); -NORETURN(void rb_syserr_fail(int, const char*)); -NORETURN(void rb_syserr_fail_str(int, VALUE)); -NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*)); -NORETURN(void rb_mod_syserr_fail_str(VALUE, int, VALUE)); -NORETURN(void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite, int, const char*)); -NORETURN(void rb_unexpected_type(VALUE,int)); - -VALUE *rb_ruby_verbose_ptr(void); -VALUE *rb_ruby_debug_ptr(void); -#define ruby_verbose (*rb_ruby_verbose_ptr()) -#define ruby_debug (*rb_ruby_debug_ptr()) - -/* reports if `-W' specified */ -PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); -PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4); -PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2); -/* reports always */ -COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2); -PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_ERROR_H */ diff --git a/include/ruby/impl/eval.h b/include/ruby/impl/eval.h deleted file mode 100644 index ea59b4c6fd..0000000000 --- a/include/ruby/impl/eval.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef RBIMPL_EVAL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_EVAL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Declares ::rb_eval_string(). - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -VALUE rb_eval_string(const char*); -VALUE rb_eval_string_protect(const char*, int*); -VALUE rb_eval_string_wrap(const char*, int*); -VALUE rb_funcall(VALUE, ID, int, ...); -VALUE rb_funcallv(VALUE, ID, int, const VALUE*); -VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE*, int); -VALUE rb_funcallv_public(VALUE, ID, int, const VALUE*); -VALUE rb_funcallv_public_kw(VALUE, ID, int, const VALUE*, int); -#define rb_funcall2 rb_funcallv -#define rb_funcall3 rb_funcallv_public -VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*); -VALUE rb_funcall_passing_block_kw(VALUE, ID, int, const VALUE*, int); -VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE*, VALUE); -VALUE rb_funcall_with_block_kw(VALUE, ID, int, const VALUE*, VALUE, int); -VALUE rb_call_super(int, const VALUE*); -VALUE rb_call_super_kw(int, const VALUE*, int); -VALUE rb_current_receiver(void); -int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *); -VALUE rb_extract_keywords(VALUE *orighash); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_EVAL_H */ diff --git a/include/ruby/impl/event.h b/include/ruby/impl/event.h deleted file mode 100644 index 7af74261b0..0000000000 --- a/include/ruby/impl/event.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef RBIMPL_EVENT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_EVENT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Debugging and tracing APIs. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* traditional set_trace_func events */ -#define RUBY_EVENT_NONE 0x0000 -#define RUBY_EVENT_LINE 0x0001 -#define RUBY_EVENT_CLASS 0x0002 -#define RUBY_EVENT_END 0x0004 -#define RUBY_EVENT_CALL 0x0008 -#define RUBY_EVENT_RETURN 0x0010 -#define RUBY_EVENT_C_CALL 0x0020 -#define RUBY_EVENT_C_RETURN 0x0040 -#define RUBY_EVENT_RAISE 0x0080 -#define RUBY_EVENT_ALL 0x00ff - -/* for TracePoint extended events */ -#define RUBY_EVENT_B_CALL 0x0100 -#define RUBY_EVENT_B_RETURN 0x0200 -#define RUBY_EVENT_THREAD_BEGIN 0x0400 -#define RUBY_EVENT_THREAD_END 0x0800 -#define RUBY_EVENT_FIBER_SWITCH 0x1000 -#define RUBY_EVENT_SCRIPT_COMPILED 0x2000 -#define RUBY_EVENT_TRACEPOINT_ALL 0xffff - -/* special events */ -#define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 - -/* internal events */ -#define RUBY_INTERNAL_EVENT_SWITCH 0x040000 -#define RUBY_EVENT_SWITCH 0x040000 /* obsolete name. this macro is for compatibility */ - /* 0x080000 */ -#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 -#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 -#define RUBY_INTERNAL_EVENT_GC_START 0x400000 -#define RUBY_INTERNAL_EVENT_GC_END_MARK 0x800000 -#define RUBY_INTERNAL_EVENT_GC_END_SWEEP 0x1000000 -#define RUBY_INTERNAL_EVENT_GC_ENTER 0x2000000 -#define RUBY_INTERNAL_EVENT_GC_EXIT 0x4000000 -#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x7f00000 -#define RUBY_INTERNAL_EVENT_MASK 0xffff0000 - -typedef uint32_t rb_event_flag_t; -typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass); - -#define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1 -void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); -int rb_remove_event_hook(rb_event_hook_func_t func); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_EVENT_H */ diff --git a/include/ruby/impl/fl_type.h b/include/ruby/impl/fl_type.h deleted file mode 100644 index cca1bad391..0000000000 --- a/include/ruby/impl/fl_type.h +++ /dev/null @@ -1,469 +0,0 @@ -#ifndef RBIMPL_FL_TYPE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_FL_TYPE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines enum ::ruby_fl_type. - */ -#include "ruby/impl/config.h" /* for ENUM_OVER_INT */ -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/flag_enum.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/core/rbasic.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/special_consts.h" -#include "ruby/impl/stdbool.h" -#include "ruby/impl/value.h" -#include "ruby/impl/value_type.h" -#include "ruby/assert.h" -#include "ruby/defines.h" - -/** @cond INTERNAL_MACRO */ -#ifdef ENUM_OVER_INT -# define RBIMPL_WIDER_ENUM 1 -#elif SIZEOF_INT * CHAR_BIT > 12+19+1 -# define RBIMPL_WIDER_ENUM 1 -#else -# define RBIMPL_WIDER_ENUM 0 -#endif -/** @endcond */ - -#define FL_SINGLETON RBIMPL_CAST((VALUE)RUBY_FL_SINGLETON) -#define FL_WB_PROTECTED RBIMPL_CAST((VALUE)RUBY_FL_WB_PROTECTED) -#define FL_PROMOTED0 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED0) -#define FL_PROMOTED1 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED1) -#define FL_FINALIZE RBIMPL_CAST((VALUE)RUBY_FL_FINALIZE) -#define FL_TAINT RBIMPL_CAST((VALUE)RUBY_FL_TAINT) -#define FL_UNTRUSTED RBIMPL_CAST((VALUE)RUBY_FL_UNTRUSTED) -#define FL_SEEN_OBJ_ID RBIMPL_CAST((VALUE)RUBY_FL_SEEN_OBJ_ID) -#define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR) -#define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE) - -#define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT) - -#define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0) -#define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1) -#define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2) -#define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3) -#define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4) -#define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5) -#define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6) -#define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7) -#define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8) -#define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9) -#define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10) -#define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11) -#define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12) -#define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13) -#define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14) -#define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15) -#define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16) -#define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17) -#define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18) -#define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19) - -#define ELTS_SHARED RUBY_ELTS_SHARED -#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED -#define RB_OBJ_FREEZE rb_obj_freeze_inline - -/** @cond INTERNAL_MACRO */ -#define RB_FL_ABLE RB_FL_ABLE -#define RB_FL_ALL RB_FL_ALL -#define RB_FL_ALL_RAW RB_FL_ALL_RAW -#define RB_FL_ANY RB_FL_ANY -#define RB_FL_ANY_RAW RB_FL_ANY_RAW -#define RB_FL_REVERSE RB_FL_REVERSE -#define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW -#define RB_FL_SET RB_FL_SET -#define RB_FL_SET_RAW RB_FL_SET_RAW -#define RB_FL_TEST RB_FL_TEST -#define RB_FL_TEST_RAW RB_FL_TEST_RAW -#define RB_FL_UNSET RB_FL_UNSET -#define RB_FL_UNSET_RAW RB_FL_UNSET_RAW -#define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW -#define RB_OBJ_FROZEN RB_OBJ_FROZEN -#define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW -#define RB_OBJ_INFECT RB_OBJ_INFECT -#define RB_OBJ_INFECT_RAW RB_OBJ_INFECT_RAW -#define RB_OBJ_TAINT RB_OBJ_TAINT -#define RB_OBJ_TAINTABLE RB_OBJ_TAINTABLE -#define RB_OBJ_TAINTED RB_OBJ_TAINTED -#define RB_OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW -#define RB_OBJ_TAINT_RAW RB_OBJ_TAINT_RAW -#define RB_OBJ_UNTRUST RB_OBJ_UNTRUST -#define RB_OBJ_UNTRUSTED RB_OBJ_UNTRUSTED -/** @endcond */ - -/** - * @defgroup deprecated_macros deprecated macro APIs - * @{ - * These macros are deprecated. Prefer their `RB_`-prefixed versions. - */ -#define FL_ABLE RB_FL_ABLE -#define FL_ALL RB_FL_ALL -#define FL_ALL_RAW RB_FL_ALL_RAW -#define FL_ANY RB_FL_ANY -#define FL_ANY_RAW RB_FL_ANY_RAW -#define FL_REVERSE RB_FL_REVERSE -#define FL_REVERSE_RAW RB_FL_REVERSE_RAW -#define FL_SET RB_FL_SET -#define FL_SET_RAW RB_FL_SET_RAW -#define FL_TEST RB_FL_TEST -#define FL_TEST_RAW RB_FL_TEST_RAW -#define FL_UNSET RB_FL_UNSET -#define FL_UNSET_RAW RB_FL_UNSET_RAW -#define OBJ_FREEZE RB_OBJ_FREEZE -#define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW -#define OBJ_FROZEN RB_OBJ_FROZEN -#define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW -#define OBJ_INFECT RB_OBJ_INFECT -#define OBJ_INFECT_RAW RB_OBJ_INFECT_RAW -#define OBJ_TAINT RB_OBJ_TAINT -#define OBJ_TAINTABLE RB_OBJ_TAINTABLE -#define OBJ_TAINTED RB_OBJ_TAINTED -#define OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW -#define OBJ_TAINT_RAW RB_OBJ_TAINT_RAW -#define OBJ_UNTRUST RB_OBJ_UNTRUST -#define OBJ_UNTRUSTED RB_OBJ_UNTRUSTED -/** @} */ - -/* This is an enum because GDB wants it (rather than a macro) */ -enum ruby_fl_ushift { RUBY_FL_USHIFT = 12 }; - -/* > The expression that defines the value of an enumeration constant shall be - * > an integer constant expression that has a value representable as an `int`. - * - * -- ISO/IEC 9899:2018 section 6.7.2.2 - * - * So ENUM_OVER_INT situation is an extension to the standard. Note however - * that we do not support 16 bit `int` environment. */ -RB_GNUC_EXTENSION -enum -RBIMPL_ATTR_FLAG_ENUM() -ruby_fl_type { - RUBY_FL_WB_PROTECTED = (1<<5), - RUBY_FL_PROMOTED0 = (1<<5), - RUBY_FL_PROMOTED1 = (1<<6), - RUBY_FL_PROMOTED = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1, - RUBY_FL_FINALIZE = (1<<7), - RUBY_FL_TAINT = (1<<8), - RUBY_FL_UNTRUSTED = RUBY_FL_TAINT, - RUBY_FL_SEEN_OBJ_ID = (1<<9), - RUBY_FL_EXIVAR = (1<<10), - RUBY_FL_FREEZE = (1<<11), - -#define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n)) - RBIMPL_FL_USER_N(0), - RBIMPL_FL_USER_N(1), - RBIMPL_FL_USER_N(2), - RBIMPL_FL_USER_N(3), - RBIMPL_FL_USER_N(4), - RBIMPL_FL_USER_N(5), - RBIMPL_FL_USER_N(6), - RBIMPL_FL_USER_N(7), - RBIMPL_FL_USER_N(8), - RBIMPL_FL_USER_N(9), - RBIMPL_FL_USER_N(10), - RBIMPL_FL_USER_N(11), - RBIMPL_FL_USER_N(12), - RBIMPL_FL_USER_N(13), - RBIMPL_FL_USER_N(14), - RBIMPL_FL_USER_N(15), - RBIMPL_FL_USER_N(16), - RBIMPL_FL_USER_N(17), - RBIMPL_FL_USER_N(18), -#if ENUM_OVER_INT - RBIMPL_FL_USER_N(19), -#else -# define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19)) -#endif -#undef RBIMPL_FL_USER_N -#undef RBIMPL_WIDER_ENUM - - RUBY_ELTS_SHARED = RUBY_FL_USER2, - RUBY_FL_SINGLETON = RUBY_FL_USER0, -}; - -enum { RUBY_FL_DUPPED = RUBY_T_MASK | RUBY_FL_EXIVAR | RUBY_FL_TAINT }; - -RBIMPL_SYMBOL_EXPORT_BEGIN() -void rb_obj_infect(VALUE victim, VALUE carrier); -void rb_freeze_singleton_class(VALUE klass); -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -RBIMPL_ATTR_FORCEINLINE() -static bool -RB_FL_ABLE(VALUE obj) -{ - if (RB_SPECIAL_CONST_P(obj)) { - return false; - } - else if (RB_TYPE_P(obj, RUBY_T_NODE)) { - return false; - } - else { - return true; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline VALUE -RB_FL_TEST_RAW(VALUE obj, VALUE flags) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); - return RBASIC(obj)->flags & flags; -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline VALUE -RB_FL_TEST(VALUE obj, VALUE flags) -{ - if (RB_FL_ABLE(obj)) { - return RB_FL_TEST_RAW(obj, flags); - } - else { - return RBIMPL_VALUE_NULL; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FL_ANY_RAW(VALUE obj, VALUE flags) -{ - return RB_FL_TEST_RAW(obj, flags); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FL_ANY(VALUE obj, VALUE flags) -{ - return RB_FL_TEST(obj, flags); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FL_ALL_RAW(VALUE obj, VALUE flags) -{ - return RB_FL_TEST_RAW(obj, flags) == flags; -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FL_ALL(VALUE obj, VALUE flags) -{ - return RB_FL_TEST(obj, flags) == flags; -} - -RBIMPL_ATTR_NOALIAS() -RBIMPL_ATTR_ARTIFICIAL() -static inline void -rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags) -{ - obj->flags |= flags; -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_FL_SET_RAW(VALUE obj, VALUE flags) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); - rbimpl_fl_set_raw_raw(RBASIC(obj), flags); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_FL_SET(VALUE obj, VALUE flags) -{ - if (RB_FL_ABLE(obj)) { - RB_FL_SET_RAW(obj, flags); - } -} - -RBIMPL_ATTR_NOALIAS() -RBIMPL_ATTR_ARTIFICIAL() -static inline void -rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags) -{ - obj->flags &= ~flags; -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_FL_UNSET_RAW(VALUE obj, VALUE flags) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); - rbimpl_fl_unset_raw_raw(RBASIC(obj), flags); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_FL_UNSET(VALUE obj, VALUE flags) -{ - if (RB_FL_ABLE(obj)) { - RB_FL_UNSET_RAW(obj, flags); - } -} - -RBIMPL_ATTR_NOALIAS() -RBIMPL_ATTR_ARTIFICIAL() -static inline void -rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags) -{ - obj->flags ^= flags; -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_FL_REVERSE_RAW(VALUE obj, VALUE flags) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); - rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_FL_REVERSE(VALUE obj, VALUE flags) -{ - if (RB_FL_ABLE(obj)) { - RB_FL_REVERSE_RAW(obj, flags); - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_OBJ_TAINTABLE(VALUE obj) -{ - if (! RB_FL_ABLE(obj)) { - return false; - } - else if (RB_TYPE_P(obj, RUBY_T_BIGNUM)) { - return false; - } - else if (RB_TYPE_P(obj, RUBY_T_FLOAT)) { - return false; - } - else { - return true; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline VALUE -RB_OBJ_TAINTED_RAW(VALUE obj) -{ - return RB_FL_TEST_RAW(obj, RUBY_FL_TAINT); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_OBJ_TAINTED(VALUE obj) -{ - return RB_FL_ANY(obj, RUBY_FL_TAINT); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_OBJ_TAINT_RAW(VALUE obj) -{ - RB_FL_SET_RAW(obj, RUBY_FL_TAINT); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_OBJ_TAINT(VALUE obj) -{ - if (RB_OBJ_TAINTABLE(obj)) { - RB_OBJ_TAINT_RAW(obj); - } -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_OBJ_INFECT_RAW(VALUE dst, VALUE src) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_OBJ_TAINTABLE(dst)); - RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(src)); - RB_FL_SET_RAW(dst, RB_OBJ_TAINTED_RAW(src)); -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_OBJ_INFECT(VALUE dst, VALUE src) -{ - if (RB_OBJ_TAINTABLE(dst) && RB_FL_ABLE(src)) { - RB_OBJ_INFECT_RAW(dst, src); - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -/* It is intentional not to return bool here. There is a place in ruby core - * (namely class.c:singleton_class_of()) where return value of this function is - * verbatimly passed to RB_FL_SET_RAW. */ -static inline VALUE -RB_OBJ_FROZEN_RAW(VALUE obj) -{ - return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_OBJ_FROZEN(VALUE obj) -{ - if (! RB_FL_ABLE(obj)) { - return true; - } - else { - return RB_OBJ_FROZEN_RAW(obj); - } -} - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -RB_OBJ_FREEZE_RAW(VALUE obj) -{ - RB_FL_SET_RAW(obj, RUBY_FL_FREEZE); -} - -static inline void -rb_obj_freeze_inline(VALUE x) -{ - if (RB_FL_ABLE(x)) { - RB_OBJ_FREEZE_RAW(x); - if (RBASIC_CLASS(x) && !(RBASIC(x)->flags & RUBY_FL_SINGLETON)) { - rb_freeze_singleton_class(x); - } - } -} - -#endif /* RBIMPL_FL_TYPE_H */ diff --git a/include/ruby/impl/gc.h b/include/ruby/impl/gc.h deleted file mode 100644 index 029bbe4fc2..0000000000 --- a/include/ruby/impl/gc.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef RBIMPL_GC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_GC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Registering values to the GC. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -void rb_global_variable(VALUE*); -void rb_gc_register_mark_object(VALUE); -void rb_gc_register_address(VALUE*); -void rb_gc_unregister_address(VALUE*); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_GC_H */ diff --git a/include/ruby/impl/glob.h b/include/ruby/impl/glob.h deleted file mode 100644 index 2764b94d02..0000000000 --- a/include/ruby/impl/glob.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef RBIMPL_GLOB_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_GLOB_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Declares ::rb_glob(). - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -typedef int ruby_glob_func(const char*,VALUE, void*); -void rb_glob(const char*,void(*)(const char*,VALUE,void*),VALUE); -int ruby_glob(const char*,int,ruby_glob_func*,VALUE); -int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_GLOB_H */ diff --git a/include/ruby/impl/globals.h b/include/ruby/impl/globals.h deleted file mode 100644 index cfffd0504d..0000000000 --- a/include/ruby/impl/globals.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef RBIMPL_GLOBALS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_GLOBALS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Ruby-level global variables / constants, visible from C. - */ -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/fl_type.h" -#include "ruby/impl/special_consts.h" -#include "ruby/impl/value.h" -#include "ruby/impl/value_type.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -#define RUBY_INTEGER_UNIFICATION 1 - -RUBY_EXTERN VALUE rb_mKernel; -RUBY_EXTERN VALUE rb_mComparable; -RUBY_EXTERN VALUE rb_mEnumerable; -RUBY_EXTERN VALUE rb_mErrno; -RUBY_EXTERN VALUE rb_mFileTest; -RUBY_EXTERN VALUE rb_mGC; -RUBY_EXTERN VALUE rb_mMath; -RUBY_EXTERN VALUE rb_mProcess; -RUBY_EXTERN VALUE rb_mWaitReadable; -RUBY_EXTERN VALUE rb_mWaitWritable; - -RUBY_EXTERN VALUE rb_cBasicObject; -RUBY_EXTERN VALUE rb_cObject; -RUBY_EXTERN VALUE rb_cArray; -RUBY_EXTERN VALUE rb_cBinding; -RUBY_EXTERN VALUE rb_cClass; -RUBY_EXTERN VALUE rb_cCont; -RUBY_EXTERN VALUE rb_cData; -RUBY_EXTERN VALUE rb_cDir; -RUBY_EXTERN VALUE rb_cEncoding; -RUBY_EXTERN VALUE rb_cEnumerator; -RUBY_EXTERN VALUE rb_cFalseClass; -RUBY_EXTERN VALUE rb_cFile; -RUBY_EXTERN VALUE rb_cComplex; -RUBY_EXTERN VALUE rb_cFloat; -RUBY_EXTERN VALUE rb_cHash; -RUBY_EXTERN VALUE rb_cIO; -RUBY_EXTERN VALUE rb_cInteger; -RUBY_EXTERN VALUE rb_cMatch; -RUBY_EXTERN VALUE rb_cMethod; -RUBY_EXTERN VALUE rb_cModule; -RUBY_EXTERN VALUE rb_cNameErrorMesg; -RUBY_EXTERN VALUE rb_cNilClass; -RUBY_EXTERN VALUE rb_cNumeric; -RUBY_EXTERN VALUE rb_cProc; -RUBY_EXTERN VALUE rb_cRandom; -RUBY_EXTERN VALUE rb_cRange; -RUBY_EXTERN VALUE rb_cRational; -RUBY_EXTERN VALUE rb_cRegexp; -RUBY_EXTERN VALUE rb_cStat; -RUBY_EXTERN VALUE rb_cString; -RUBY_EXTERN VALUE rb_cStruct; -RUBY_EXTERN VALUE rb_cSymbol; -RUBY_EXTERN VALUE rb_cThread; -RUBY_EXTERN VALUE rb_cTime; -RUBY_EXTERN VALUE rb_cTrueClass; -RUBY_EXTERN VALUE rb_cUnboundMethod; - -RUBY_EXTERN VALUE rb_eException; -RUBY_EXTERN VALUE rb_eStandardError; -RUBY_EXTERN VALUE rb_eSystemExit; -RUBY_EXTERN VALUE rb_eInterrupt; -RUBY_EXTERN VALUE rb_eSignal; -RUBY_EXTERN VALUE rb_eFatal; -RUBY_EXTERN VALUE rb_eArgError; -RUBY_EXTERN VALUE rb_eEOFError; -RUBY_EXTERN VALUE rb_eIndexError; -RUBY_EXTERN VALUE rb_eStopIteration; -RUBY_EXTERN VALUE rb_eKeyError; -RUBY_EXTERN VALUE rb_eRangeError; -RUBY_EXTERN VALUE rb_eIOError; -RUBY_EXTERN VALUE rb_eRuntimeError; -RUBY_EXTERN VALUE rb_eFrozenError; -RUBY_EXTERN VALUE rb_eSecurityError; -RUBY_EXTERN VALUE rb_eSystemCallError; -RUBY_EXTERN VALUE rb_eThreadError; -RUBY_EXTERN VALUE rb_eTypeError; -RUBY_EXTERN VALUE rb_eZeroDivError; -RUBY_EXTERN VALUE rb_eNotImpError; -RUBY_EXTERN VALUE rb_eNoMemError; -RUBY_EXTERN VALUE rb_eNoMethodError; -RUBY_EXTERN VALUE rb_eFloatDomainError; -RUBY_EXTERN VALUE rb_eLocalJumpError; -RUBY_EXTERN VALUE rb_eSysStackError; -RUBY_EXTERN VALUE rb_eRegexpError; -RUBY_EXTERN VALUE rb_eEncodingError; -RUBY_EXTERN VALUE rb_eEncCompatError; -RUBY_EXTERN VALUE rb_eNoMatchingPatternError; - -RUBY_EXTERN VALUE rb_eScriptError; -RUBY_EXTERN VALUE rb_eNameError; -RUBY_EXTERN VALUE rb_eSyntaxError; -RUBY_EXTERN VALUE rb_eLoadError; - -RUBY_EXTERN VALUE rb_eMathDomainError; - -RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr; - -RBIMPL_ATTR_PURE() -static inline VALUE -rb_class_of(VALUE obj) -{ - if (! RB_SPECIAL_CONST_P(obj)) { - return RBASIC_CLASS(obj); - } - else if (obj == RUBY_Qfalse) { - return rb_cFalseClass; - } - else if (obj == RUBY_Qnil) { - return rb_cNilClass; - } - else if (obj == RUBY_Qtrue) { - return rb_cTrueClass; - } - else if (RB_FIXNUM_P(obj)) { - return rb_cInteger; - } - else if (RB_STATIC_SYM_P(obj)) { - return rb_cSymbol; - } - else if (RB_FLONUM_P(obj)) { - return rb_cFloat; - } - -#if RUBY_NDEBUG - RBIMPL_UNREACHABLE_RETURN(Qfalse); -#else - RUBY_ASSERT_FAIL(rb_class_of); -#endif -} - -#define CLASS_OF rb_class_of - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_GLOBALS_H */ diff --git a/include/ruby/impl/has/attribute.h b/include/ruby/impl/has/attribute.h deleted file mode 100644 index af51b93298..0000000000 --- a/include/ruby/impl/has/attribute.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef RBIMPL_HAS_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_ATTRIBUTE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_ATTRIBUTE. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/token_paste.h" - -#if defined(__has_attribute) -# if __has_attribute(pure) || RBIMPL_COMPILER_IS(GCC) -# /* FreeBSD's defines its own *broken* version of -# * __has_attribute. Cygwin copied that content to be a victim of the -# * broken-ness. We don't take them into account. */ -# define RBIMPL_HAVE___HAS_ATTRIBUTE 1 -# endif -#endif - -/** Wraps (or simulates) `__has_attribute`. */ -#if defined(RBIMPL_HAVE___HAS_ATTRIBUTE) -# define RBIMPL_HAS_ATTRIBUTE(_) __has_attribute(_) - -#elif RBIMPL_COMPILER_IS(GCC) -# /* GCC <= 4 lack __has_attribute predefined macro, while have attributes -# * themselves. We can simulate the macro like the following: */ -# define RBIMPL_HAS_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _) -# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_alloc_size RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_artificial RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0) -# define RBIMPL_HAS_ATTRIBUTE_cdecl RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_cold RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(GCC, 2, 6, 0) -# define RBIMPL_HAS_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0) -# define RBIMPL_HAS_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_error RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_format RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_hot RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_leaf RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) -# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) -# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) -# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_undefined RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0) -# define RBIMPL_HAS_ATTRIBUTE_nonnull RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(GCC, 2, 5, 0) -# define RBIMPL_HAS_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(GCC, 2,96, 0) -# define RBIMPL_HAS_ATTRIBUTE_returns_nonnull RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(GCC, 4, 1, 0) -# define RBIMPL_HAS_ATTRIBUTE_stdcall RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_unused RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result RBIMPL_COMPILER_SINCE(GCC, 3, 4, 0) -# define RBIMPL_HAS_ATTRIBUTE_warning RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) -# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# /* Note that "0, 0, 0" might be inaccurate. */ - -#elif RBIMPL_COMPILER_IS(SunPro) -# /* Oracle Solaris Studio 12.4 (cc version 5.11) introduced __has_attribute. -# * Before that, following attributes were available. */ -# /* See https://docs.oracle.com/cd/F24633_01/index.html */ -# define RBIMPL_HAS_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _) -# define RBIMPL_HAS_ATTRIBUTE_alias RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_constructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_destructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_packed RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_HAS_ATTRIBUTE_vector_size RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) -# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) - -#elif defined (_MSC_VER) -# define RBIMPL_HAS_ATTRIBUTE(_) 0 -# /* Fallback below doesn't work: see win32/Makefile.sub */ - -#else -# /* Take config.h definition when available. */ -# define RBIMPL_HAS_ATTRIBUTE(_) (RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _)+0) -# ifdef ALWAYS_INLINE -# define RBIMPL_HAS_ATTRIBUTE_always_inline 1 -# endif -# ifdef FUNC_CDECL -# define RBIMPL_HAS_ATTRIBUTE_cdecl 1 -# endif -# ifdef CONSTFUNC -# define RBIMPL_HAS_ATTRIBUTE_const 1 -# endif -# ifdef DEPRECATED -# define RBIMPL_HAS_ATTRIBUTE_deprecated 1 -# endif -# ifdef ERRORFUNC -# define RBIMPL_HAS_ATTRIBUTE_error 1 -# endif -# ifdef FUNC_FASTCALL -# define RBIMPL_HAS_ATTRIBUTE_fastcall 1 -# endif -# ifdef PUREFUNC -# define RBIMPL_HAS_ATTRIBUTE_pure 1 -# endif -# ifdef NO_ADDRESS_SAFETY_ANALYSIS -# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis 1 -# endif -# ifdef NO_SANITIZE -# define RBIMPL_HAS_ATTRIBUTE_no_sanitize 1 -# endif -# ifdef NO_SANITIZE_ADDRESS -# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address 1 -# endif -# ifdef NOINLINE -# define RBIMPL_HAS_ATTRIBUTE_noinline 1 -# endif -# ifdef RBIMPL_FUNC_NONNULL -# define RBIMPL_HAS_ATTRIBUTE_nonnull 1 -# endif -# ifdef NORETURN -# define RBIMPL_HAS_ATTRIBUTE_noreturn 1 -# endif -# ifdef FUNC_OPTIMIZED -# define RBIMPL_HAS_ATTRIBUTE_optimize 1 -# endif -# ifdef FUNC_STDCALL -# define RBIMPL_HAS_ATTRIBUTE_stdcall 1 -# endif -# ifdef MAYBE_UNUSED -# define RBIMPL_HAS_ATTRIBUTE_unused 1 -# endif -# ifdef WARN_UNUSED_RESULT -# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result 1 -# endif -# ifdef WARNINGFUNC -# define RBIMPL_HAS_ATTRIBUTE_warning 1 -# endif -# ifdef WEAK -# define RBIMPL_HAS_ATTRIBUTE_weak 1 -# endif -#endif - -#endif /* RBIMPL_HAS_ATTRIBUTE_H */ diff --git a/include/ruby/impl/has/builtin.h b/include/ruby/impl/has/builtin.h deleted file mode 100644 index 46f587c2cf..0000000000 --- a/include/ruby/impl/has/builtin.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef RBIMPL_HAS_BUILTIN_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_BUILTIN_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_BUILTIN. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/token_paste.h" - -#if defined(__has_builtin) -# if RBIMPL_COMPILER_IS(Intel) -# /* :TODO: Intel C Compiler has __has_builtin (since 19.1 maybe?), and is -# * reportedly broken. We have to skip them. However the situation can -# * change. They might improve someday. We need to revisit here later. */ -# elif RBIMPL_COMPILER_IS(GCC) && ! __has_builtin(__builtin_alloca) -# /* FreeBSD's defines its own *broken* version of -# * __has_builtin. Cygwin copied that content to be a victim of the -# * broken-ness. We don't take them into account. */ -# else -# define RBIMPL_HAVE___HAS_BUILTIN 1 -# endif -#endif - -/** Wraps (or simulates) `__has_builtin`. */ -#if defined(RBIMPL_HAVE___HAS_BUILTIN) -# define RBIMPL_HAS_BUILTIN(_) __has_builtin(_) - -#elif RBIMPL_COMPILER_IS(GCC) -# /* :FIXME: Historically GCC has had tons of builtins, but it implemented -# * __has_builtin only since GCC 10. This section can be made more -# * granular. */ -# /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970 */ -# define RBIMPL_HAS_BUILTIN(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_BUILTIN_, _) -# define RBIMPL_HAS_BUILTIN___builtin_add_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) -# define RBIMPL_HAS_BUILTIN___builtin_alloca RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) -# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align RBIMPL_COMPILER_SINCE(GCC, 6, 1, 0) -# /* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 for bswap16. */ -# define RBIMPL_HAS_BUILTIN___builtin_bswap16 RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) -# define RBIMPL_HAS_BUILTIN___builtin_bswap32 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_bswap64 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_clz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_clzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_clzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_constant_p RBIMPL_COMPILER_SINCE(GCC, 2,95, 3) -# define RBIMPL_HAS_BUILTIN___builtin_ctz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_ctzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_ctzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_expect RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0) -# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) -# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0) -# define RBIMPL_HAS_BUILTIN___builtin_popcount RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_popcountl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_popcountll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) -# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) -# define RBIMPL_HAS_BUILTIN___builtin_unreachable RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0) -# /* Note that "0, 0, 0" might be inaccurate. */ - -#elif RBIMPL_COMPILER_IS(MSVC) -# /* MSVC has UNREACHABLE, but that is not __builtin_unreachable. */ -# define RBIMPL_HAS_BUILTIN(_) 0 - -#else -# /* Take config.h definition when available */ -# define RBIMPL_HAS_BUILTIN(_) (RBIMPL_TOKEN_PASTE(RBIMPL_HAS_BUILTIN_, _)+0) -# define RBIMPL_HAS_BUILTIN___builtin_add_overflow HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW -# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN -# define RBIMPL_HAS_BUILTIN___builtin_assume_aligned HAVE_BUILTIN___BUILTIN_ASSUME_ALIGNED -# define RBIMPL_HAS_BUILTIN___builtin_bswap16 HAVE_BUILTIN___BUILTIN_BSWAP16 -# define RBIMPL_HAS_BUILTIN___builtin_bswap32 HAVE_BUILTIN___BUILTIN_BSWAP32 -# define RBIMPL_HAS_BUILTIN___builtin_bswap64 HAVE_BUILTIN___BUILTIN_BSWAP64 -# define RBIMPL_HAS_BUILTIN___builtin_clz HAVE_BUILTIN___BUILTIN_CLZ -# define RBIMPL_HAS_BUILTIN___builtin_clzl HAVE_BUILTIN___BUILTIN_CLZL -# define RBIMPL_HAS_BUILTIN___builtin_clzll HAVE_BUILTIN___BUILTIN_CLZLL -# define RBIMPL_HAS_BUILTIN___builtin_constant_p HAVE_BUILTIN___BUILTIN_CONSTANT_P -# define RBIMPL_HAS_BUILTIN___builtin_ctz HAVE_BUILTIN___BUILTIN_CTZ -# define RBIMPL_HAS_BUILTIN___builtin_ctzll HAVE_BUILTIN___BUILTIN_CTZLL -# define RBIMPL_HAS_BUILTIN___builtin_expect HAVE_BUILTIN___BUILTIN_EXPECT -# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW -# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P -# define RBIMPL_HAS_BUILTIN___builtin_popcount HAVE_BUILTIN___BUILTIN_POPCOUNT -# define RBIMPL_HAS_BUILTIN___builtin_popcountll HAVE_BUILTIN___BUILTIN_POPCOUNTLL -# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW -# if defined(UNREACHABLE) -# define RBIMPL_HAS_BUILTIN___builtin_unreachable 1 -# endif -#endif - -#endif /* RBIMPL_HAS_BUILTIN_H */ diff --git a/include/ruby/impl/has/c_attribute.h b/include/ruby/impl/has/c_attribute.h deleted file mode 100644 index b7eb94d22a..0000000000 --- a/include/ruby/impl/has/c_attribute.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef RBIMPL_HAS_C_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_C_ATTRIBUTE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_C_ATTRIBUTE. - */ - -/** Wraps (or simulates) `__has_c_attribute`. */ -#if defined(__cplusplus) -# /* Makes no sense. */ -# define RBIMPL_HAS_C_ATTRIBUTE(_) 0 - -#elif defined(__has_c_attribute) -# define RBIMPL_HAS_C_ATTRIBUTE(_) __has_c_attribute(_) - -#else -# /* As of writing everything that lacks __has_c_attribute also completely -# * lacks C2x attributes as well. Might change in future? */ -# define RBIMPL_HAS_C_ATTRIBUTE(_) 0 -#endif - -#endif /* RBIMPL_HAS_C_ATTRIBUTE_H */ diff --git a/include/ruby/impl/has/cpp_attribute.h b/include/ruby/impl/has/cpp_attribute.h deleted file mode 100644 index 12847a11d6..0000000000 --- a/include/ruby/impl/has/cpp_attribute.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef RBIMPL_HAS_CPP_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_CPP_ATTRIBUTE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_CPP_ATTRIBUTE. - */ -#include "ruby/impl/compiler_is.h" -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/token_paste.h" - -/** @cond INTERNAL_MACRO */ -#if defined(__has_cpp_attribute) -# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) __has_cpp_attribute(_) - -#elif RBIMPL_COMPILER_IS(MSVC) -# /* MSVC has never updated its __cplusplus since forever (unless specified -# * explicitly by a compiler flag). They also lack __has_cpp_attribute until -# * 2019. However, they do have attributes since 2015 or so. */ -# /* https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance */ -# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_CPP_ATTRIBUTE_, _) -# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_carries_dependency 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_fallthrough 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_maybe_unused 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_nodiscard 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0) - -#elif RBIMPL_COMPILER_BEFORE(Clang, 3, 6, 0) -# /* Clang 3.6.0 introduced __has_cpp_attribute. Prior to that following -# * attributes were already there. */ -# /* https://clang.llvm.org/cxx_status.html */ -# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_CPP_ATTRIBUTE_, _) -# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(Clang, 3, 3, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(Clang, 3, 4, 0) - -#elif RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0) -# /* GCC 5+ have __has_cpp_attribute, while 4.x had following attributes. */ -# /* https://gcc.gnu.org/projects/cxx-status.html */ -# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_CPP_ATTRIBUTE_, _) -# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) -# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) - -#else -# /* :FIXME: -# * Candidate compilers to list here: -# * - icpc: They have __INTEL_CXX11_MODE__. -# * - SunPro: Seems they support C++11. -# */ -# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) 0 -#endif -/** @endcond */ - -/** Wraps (or simulates) `__has_cpp_attribute`. */ -#if ! defined(__cplusplus) -# /* Makes no sense. */ -# define RBIMPL_HAS_CPP_ATTRIBUTE(_) 0 -#else -# /* GCC needs workarounds. See https://gcc.godbolt.org/z/jdz3pa */ -# define RBIMPL_HAS_CPP_ATTRIBUTE(_) \ - ((RBIMPL_HAS_CPP_ATTRIBUTE0(_) <= __cplusplus) ? RBIMPL_HAS_CPP_ATTRIBUTE0(_) : 0) -#endif - -#endif /* RBIMPL_HAS_CPP_ATTRIBUTE_H */ diff --git a/include/ruby/impl/has/declspec_attribute.h b/include/ruby/impl/has/declspec_attribute.h deleted file mode 100644 index ba6ad98fce..0000000000 --- a/include/ruby/impl/has/declspec_attribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_DECLSPEC_ATTRIBUTE. - */ -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/token_paste.h" - -/** Wraps (or simulates) `__has_declspec_attribute`. */ -#if defined(__has_declspec_attribute) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) __has_declspec_attribute(_) -#else -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_DECLSPEC_ATTRIBUTE_, _) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_align RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_empty_bases RBIMPL_COMPILER_SINCE(MSVC,19, 0, 23918) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noalias RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(MSVC,11, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) -# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_restrict RBIMPL_COMPILER_SINCE(MSVC,14, 0, 0) -# /* Note that "8, 0, 0" might be inaccurate. */ -# if ! defined(__cplusplus) -# /* Clang has this in both C/C++, but MSVC has this in C++ only.*/ -# undef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow -# endif -#endif - -#endif /* RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H */ diff --git a/include/ruby/impl/has/extension.h b/include/ruby/impl/has/extension.h deleted file mode 100644 index 02a48bc74c..0000000000 --- a/include/ruby/impl/has/extension.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RBIMPL_HAS_EXTENSION_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_EXTENSION_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_EXTENSION. - */ -#include "ruby/impl/has/feature.h" - -/** Wraps (or simulates) `__has_extension`. */ -#if defined(__has_extension) -# define RBIMPL_HAS_EXTENSION(_) __has_extension(_) -#else -# /* Pre-3.0 clang had __has_feature but not __has_extension. */ -# define RBIMPL_HAS_EXTENSION(_) RBIMPL_HAS_FEATURE(_) -#endif - -#endif /* RBIMPL_HAS_EXTENSION_H */ diff --git a/include/ruby/impl/has/feature.h b/include/ruby/impl/has/feature.h deleted file mode 100644 index b827590c00..0000000000 --- a/include/ruby/impl/has/feature.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef RBIMPL_HAS_FEATURE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_FEATURE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_FEATURE. - */ - -/** Wraps (or simulates) `__has_feature`. */ -#if defined(__has_feature) -# define RBIMPL_HAS_FEATURE(_) __has_feature(_) -#else -# define RBIMPL_HAS_FEATURE(_) 0 -#endif - -#endif /* RBIMPL_HAS_FEATURE_H */ diff --git a/include/ruby/impl/has/warning.h b/include/ruby/impl/has/warning.h deleted file mode 100644 index 03975ecc2f..0000000000 --- a/include/ruby/impl/has/warning.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef RBIMPL_HAS_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_HAS_WARNING_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_HAS_WARNING. - */ - -/** Wraps (or simulates) `__has_warning`. */ -#if defined(__has_warning) -# define RBIMPL_HAS_WARNING(_) __has_warning(_) -#else -# define RBIMPL_HAS_WARNING(_) 0 -#endif - -#endif /* RBIMPL_HAS_WARNING_H */ diff --git a/include/ruby/impl/intern/array.h b/include/ruby/impl/intern/array.h deleted file mode 100644 index bfa12191c4..0000000000 --- a/include/ruby/impl/intern/array.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef RBIMPL_INTERN_ARRAY_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_ARRAY_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cArray. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* array.c */ -void rb_mem_clear(VALUE*, long); -VALUE rb_assoc_new(VALUE, VALUE); -VALUE rb_check_array_type(VALUE); -VALUE rb_ary_new(void); -VALUE rb_ary_new_capa(long capa); -VALUE rb_ary_new_from_args(long n, ...); -VALUE rb_ary_new_from_values(long n, const VALUE *elts); -VALUE rb_ary_tmp_new(long); -void rb_ary_free(VALUE); -void rb_ary_modify(VALUE); -VALUE rb_ary_freeze(VALUE); -VALUE rb_ary_shared_with_p(VALUE, VALUE); -VALUE rb_ary_aref(int, const VALUE*, VALUE); -VALUE rb_ary_subseq(VALUE, long, long); -void rb_ary_store(VALUE, long, VALUE); -VALUE rb_ary_dup(VALUE); -VALUE rb_ary_resurrect(VALUE ary); -VALUE rb_ary_to_ary(VALUE); -VALUE rb_ary_to_s(VALUE); -VALUE rb_ary_cat(VALUE, const VALUE *, long); -VALUE rb_ary_push(VALUE, VALUE); -VALUE rb_ary_pop(VALUE); -VALUE rb_ary_shift(VALUE); -VALUE rb_ary_unshift(VALUE, VALUE); -VALUE rb_ary_entry(VALUE, long); -VALUE rb_ary_each(VALUE); -VALUE rb_ary_join(VALUE, VALUE); -VALUE rb_ary_reverse(VALUE); -VALUE rb_ary_rotate(VALUE, long); -VALUE rb_ary_sort(VALUE); -VALUE rb_ary_sort_bang(VALUE); -VALUE rb_ary_delete(VALUE, VALUE); -VALUE rb_ary_delete_at(VALUE, long); -VALUE rb_ary_clear(VALUE); -VALUE rb_ary_plus(VALUE, VALUE); -VALUE rb_ary_concat(VALUE, VALUE); -VALUE rb_ary_assoc(VALUE, VALUE); -VALUE rb_ary_rassoc(VALUE, VALUE); -VALUE rb_ary_includes(VALUE, VALUE); -VALUE rb_ary_cmp(VALUE, VALUE); -VALUE rb_ary_replace(VALUE copy, VALUE orig); -VALUE rb_get_values_at(VALUE, long, int, const VALUE*, VALUE(*)(VALUE,long)); -VALUE rb_ary_resize(VALUE ary, long len); -#define rb_ary_new2 rb_ary_new_capa -#define rb_ary_new3 rb_ary_new_from_args -#define rb_ary_new4 rb_ary_new_from_values - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_ARRAY_H */ diff --git a/include/ruby/impl/intern/bignum.h b/include/ruby/impl/intern/bignum.h deleted file mode 100644 index 5af4c0ae42..0000000000 --- a/include/ruby/impl/intern/bignum.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef RBIMPL_INTERN_BIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_BIGNUM_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to so-called rb_cBignum. - */ -#include "ruby/impl/config.h" - -#ifdef STDC_HEADERS -# include -#endif - -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/long_long.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* bignum.c */ -VALUE rb_big_new(size_t, int); -int rb_bigzero_p(VALUE x); -VALUE rb_big_clone(VALUE); -void rb_big_2comp(VALUE); -VALUE rb_big_norm(VALUE); -void rb_big_resize(VALUE big, size_t len); -VALUE rb_cstr_to_inum(const char*, int, int); -VALUE rb_str_to_inum(VALUE, int, int); -VALUE rb_cstr2inum(const char*, int); -VALUE rb_str2inum(VALUE, int); -VALUE rb_big2str(VALUE, int); -long rb_big2long(VALUE); -#define rb_big2int(x) rb_big2long(x) -unsigned long rb_big2ulong(VALUE); -#define rb_big2uint(x) rb_big2ulong(x) -#if HAVE_LONG_LONG -LONG_LONG rb_big2ll(VALUE); -unsigned LONG_LONG rb_big2ull(VALUE); -#endif /* HAVE_LONG_LONG */ -void rb_big_pack(VALUE val, unsigned long *buf, long num_longs); -VALUE rb_big_unpack(unsigned long *buf, long num_longs); -int rb_uv_to_utf8(char[6],unsigned long); -VALUE rb_dbl2big(double); -double rb_big2dbl(VALUE); -VALUE rb_big_cmp(VALUE, VALUE); -VALUE rb_big_eq(VALUE, VALUE); -VALUE rb_big_eql(VALUE, VALUE); -VALUE rb_big_plus(VALUE, VALUE); -VALUE rb_big_minus(VALUE, VALUE); -VALUE rb_big_mul(VALUE, VALUE); -VALUE rb_big_div(VALUE, VALUE); -VALUE rb_big_idiv(VALUE, VALUE); -VALUE rb_big_modulo(VALUE, VALUE); -VALUE rb_big_divmod(VALUE, VALUE); -VALUE rb_big_pow(VALUE, VALUE); -VALUE rb_big_and(VALUE, VALUE); -VALUE rb_big_or(VALUE, VALUE); -VALUE rb_big_xor(VALUE, VALUE); -VALUE rb_big_lshift(VALUE, VALUE); -VALUE rb_big_rshift(VALUE, VALUE); - -/* For rb_integer_pack and rb_integer_unpack: */ -/* "MS" in MSWORD and MSBYTE means "most significant" */ -/* "LS" in LSWORD and LSBYTE means "least significant" */ -#define INTEGER_PACK_MSWORD_FIRST 0x01 -#define INTEGER_PACK_LSWORD_FIRST 0x02 -#define INTEGER_PACK_MSBYTE_FIRST 0x10 -#define INTEGER_PACK_LSBYTE_FIRST 0x20 -#define INTEGER_PACK_NATIVE_BYTE_ORDER 0x40 -#define INTEGER_PACK_2COMP 0x80 -#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION 0x400 -/* For rb_integer_unpack: */ -#define INTEGER_PACK_FORCE_BIGNUM 0x100 -#define INTEGER_PACK_NEGATIVE 0x200 -/* Combinations: */ -#define INTEGER_PACK_LITTLE_ENDIAN \ - (INTEGER_PACK_LSWORD_FIRST | \ - INTEGER_PACK_LSBYTE_FIRST) -#define INTEGER_PACK_BIG_ENDIAN \ - (INTEGER_PACK_MSWORD_FIRST | \ - INTEGER_PACK_MSBYTE_FIRST) -int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags); -VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags); -size_t rb_absint_size(VALUE val, int *nlz_bits_ret); -size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret); -int rb_absint_singlebit_p(VALUE val); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_BIGNUM_H */ diff --git a/include/ruby/impl/intern/class.h b/include/ruby/impl/intern/class.h deleted file mode 100644 index 7a1cadd5b4..0000000000 --- a/include/ruby/impl/intern/class.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef RBIMPL_INTERN_CLASS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_CLASS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cClass/::rb_cModule. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/stdarg.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* class.c */ -VALUE rb_class_new(VALUE); -VALUE rb_mod_init_copy(VALUE, VALUE); -VALUE rb_singleton_class_clone(VALUE); -void rb_singleton_class_attached(VALUE,VALUE); -void rb_check_inheritable(VALUE); -VALUE rb_define_class_id(ID, VALUE); -VALUE rb_define_class_id_under(VALUE, ID, VALUE); -VALUE rb_module_new(void); -VALUE rb_define_module_id(ID); -VALUE rb_define_module_id_under(VALUE, ID); -VALUE rb_mod_included_modules(VALUE); -VALUE rb_mod_include_p(VALUE, VALUE); -VALUE rb_mod_ancestors(VALUE); -VALUE rb_class_instance_methods(int, const VALUE*, VALUE); -VALUE rb_class_public_instance_methods(int, const VALUE*, VALUE); -VALUE rb_class_protected_instance_methods(int, const VALUE*, VALUE); -VALUE rb_class_private_instance_methods(int, const VALUE*, VALUE); -VALUE rb_obj_singleton_methods(int, const VALUE*, VALUE); -void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int); -void rb_undef(VALUE, ID); -void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int); -void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int); -void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int); -VALUE rb_singleton_class(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_CLASS_H */ diff --git a/include/ruby/impl/intern/compar.h b/include/ruby/impl/intern/compar.h deleted file mode 100644 index c762dc1e24..0000000000 --- a/include/ruby/impl/intern/compar.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RBIMPL_INTERN_COMPAR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_COMPAR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_mComparable. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* compar.c */ -int rb_cmpint(VALUE, VALUE, VALUE); -NORETURN(void rb_cmperr(VALUE, VALUE)); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_COMPAR_H */ diff --git a/include/ruby/impl/intern/complex.h b/include/ruby/impl/intern/complex.h deleted file mode 100644 index c3841cfdb6..0000000000 --- a/include/ruby/impl/intern/complex.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef RBIMPL_INTERN_COMPLEX_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_COMPLEX_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cComplex. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/impl/arithmetic/long.h" /* INT2FIX is here. */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* complex.c */ -VALUE rb_complex_raw(VALUE, VALUE); -#define rb_complex_raw1(x) rb_complex_raw((x), INT2FIX(0)) -#define rb_complex_raw2(x,y) rb_complex_raw((x), (y)) -VALUE rb_complex_new(VALUE, VALUE); -#define rb_complex_new1(x) rb_complex_new((x), INT2FIX(0)) -#define rb_complex_new2(x,y) rb_complex_new((x), (y)) -VALUE rb_complex_new_polar(VALUE abs, VALUE arg); -DEPRECATED_BY(rb_complex_new_polar, VALUE rb_complex_polar(VALUE abs, VALUE arg)); -VALUE rb_complex_real(VALUE z); -VALUE rb_complex_imag(VALUE z); -VALUE rb_complex_plus(VALUE x, VALUE y); -VALUE rb_complex_minus(VALUE x, VALUE y); -VALUE rb_complex_mul(VALUE x, VALUE y); -VALUE rb_complex_div(VALUE x, VALUE y); -VALUE rb_complex_uminus(VALUE z); -VALUE rb_complex_conjugate(VALUE z); -VALUE rb_complex_abs(VALUE z); -VALUE rb_complex_arg(VALUE z); -VALUE rb_complex_pow(VALUE base, VALUE exp); -VALUE rb_dbl_complex_new(double real, double imag); -#define rb_complex_add rb_complex_plus -#define rb_complex_sub rb_complex_minus -#define rb_complex_nagate rb_complex_uminus - -VALUE rb_Complex(VALUE, VALUE); -#define rb_Complex1(x) rb_Complex((x), INT2FIX(0)) -#define rb_Complex2(x,y) rb_Complex((x), (y)) - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_COMPLEX_H */ diff --git a/include/ruby/impl/intern/cont.h b/include/ruby/impl/intern/cont.h deleted file mode 100644 index 16c3cf8be1..0000000000 --- a/include/ruby/impl/intern/cont.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef RBIMPL_INTERN_CONT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_CONT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to rb_cFiber. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/impl/iterator.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* cont.c */ -VALUE rb_fiber_new(rb_block_call_func_t, VALUE); -VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv); -VALUE rb_fiber_resume_kw(VALUE fib, int argc, const VALUE *argv, int kw_splat); -VALUE rb_fiber_yield(int argc, const VALUE *argv); -VALUE rb_fiber_yield_kw(int argc, const VALUE *argv, int kw_splat); -VALUE rb_fiber_current(void); -VALUE rb_fiber_alive_p(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_CONT_H */ diff --git a/include/ruby/impl/intern/dir.h b/include/ruby/impl/intern/dir.h deleted file mode 100644 index 6fcf274a28..0000000000 --- a/include/ruby/impl/intern/dir.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RBIMPL_INTERN_DIR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_DIR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cDir. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* dir.c */ -VALUE rb_dir_getwd(void); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_DIR_H */ diff --git a/include/ruby/impl/intern/enum.h b/include/ruby/impl/intern/enum.h deleted file mode 100644 index ef6fffe444..0000000000 --- a/include/ruby/impl/intern/enum.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RBIMPL_INTERN_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_ENUM_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_mEnumerable. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* enum.c */ -VALUE rb_enum_values_pack(int, const VALUE*); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_ENUM_H */ diff --git a/include/ruby/impl/intern/enumerator.h b/include/ruby/impl/intern/enumerator.h deleted file mode 100644 index 8f64b58de2..0000000000 --- a/include/ruby/impl/intern/enumerator.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef RBIMPL_INTERN_ENUMERATOR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_ENUMERATOR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cEnumerator. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/intern/eval.h" /* rb_frame_this_func */ -#include "ruby/impl/iterator.h" /* rb_block_given_p */ -#include "ruby/impl/symbol.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -typedef VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE); - -typedef struct { - VALUE begin; - VALUE end; - VALUE step; - int exclude_end; -} rb_arithmetic_sequence_components_t; - -/* enumerator.c */ -VALUE rb_enumeratorize(VALUE, VALUE, int, const VALUE *); -VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *); -VALUE rb_enumeratorize_with_size_kw(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *, int); -int rb_arithmetic_sequence_extract(VALUE, rb_arithmetic_sequence_components_t *); - -RBIMPL_SYMBOL_EXPORT_END() - -#ifndef RUBY_EXPORT -# define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \ - rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn)) -# define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat) \ - rb_enumeratorize_with_size_kw(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn), kw_splat) -#endif - -#define SIZED_ENUMERATOR(obj, argc, argv, size_fn) \ - rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()), \ - (argc), (argv), (size_fn)) - -#define SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) \ - rb_enumeratorize_with_size_kw((obj), ID2SYM(rb_frame_this_func()), \ - (argc), (argv), (size_fn), (kw_splat)) - -#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \ - if (!rb_block_given_p()) \ - return SIZED_ENUMERATOR(obj, argc, argv, size_fn); \ - } while (0) - -#define RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) do { \ - if (!rb_block_given_p()) \ - return SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat); \ - } while (0) - -#define RETURN_ENUMERATOR(obj, argc, argv) \ - RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0) - -#define RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) \ - RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat) - -#endif /* RBIMPL_INTERN_ENUMERATOR_H */ diff --git a/include/ruby/impl/intern/error.h b/include/ruby/impl/intern/error.h deleted file mode 100644 index 0cc5e1c858..0000000000 --- a/include/ruby/impl/intern/error.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef RBIMPL_INTERN_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_ERROR_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_eException. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/impl/fl_type.h" -#include "ruby/backward/2/assume.h" -#include "ruby/backward/2/attributes.h" - -#define UNLIMITED_ARGUMENTS (-1) -#define rb_exc_new2 rb_exc_new_cstr -#define rb_exc_new3 rb_exc_new_str -#define rb_check_trusted rb_check_trusted -#define rb_check_trusted_inline rb_check_trusted -#define rb_check_arity rb_check_arity - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* error.c */ -VALUE rb_exc_new(VALUE, const char*, long); -VALUE rb_exc_new_cstr(VALUE, const char*); -VALUE rb_exc_new_str(VALUE, VALUE); -PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2); -PRINTF_ARGS(NORETURN(void rb_loaderror_with_path(VALUE path, const char*, ...)), 2, 3); -PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3); -PRINTF_ARGS(NORETURN(void rb_name_error_str(VALUE, const char*, ...)), 2, 3); -PRINTF_ARGS(NORETURN(void rb_frozen_error_raise(VALUE, const char*, ...)), 2, 3); -NORETURN(void rb_invalid_str(const char*, const char*)); -NORETURN(void rb_error_frozen(const char*)); -NORETURN(void rb_error_frozen_object(VALUE)); -void rb_error_untrusted(VALUE); -void rb_check_frozen(VALUE); -void rb_check_trusted(VALUE); -void rb_check_copyable(VALUE obj, VALUE orig); -NORETURN(MJIT_STATIC void rb_error_arity(int, int, int)); -RBIMPL_SYMBOL_EXPORT_END() - -/* Does anyone use this? Remain not deleted for compatibility. */ -#define rb_check_frozen_internal(obj) do { \ - VALUE frozen_obj = (obj); \ - if (RB_UNLIKELY(RB_OBJ_FROZEN(frozen_obj))) { \ - rb_error_frozen_object(frozen_obj); \ - } \ - } while (0) - -static inline void -rb_check_frozen_inline(VALUE obj) -{ - if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) { - rb_error_frozen_object(obj); - } -} -#define rb_check_frozen rb_check_frozen_inline - -static inline int -rb_check_arity(int argc, int min, int max) -{ - if ((argc < min) || (max != UNLIMITED_ARGUMENTS && argc > max)) - rb_error_arity(argc, min, max); - return argc; -} - -#endif /* RBIMPL_INTERN_ERROR_H */ diff --git a/include/ruby/impl/intern/eval.h b/include/ruby/impl/intern/eval.h deleted file mode 100644 index 75374df6be..0000000000 --- a/include/ruby/impl/intern/eval.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef RBIMPL_INTERN_EVAL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_EVAL_H -/** - * @file - * @author Ruby developers - * @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 Pre-1.9 era evaluator APIs (now considered miscellaneous). - */ -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* eval.c */ -RBIMPL_ATTR_NORETURN() -void rb_exc_raise(VALUE); - -RBIMPL_ATTR_NORETURN() -void rb_exc_fatal(VALUE); - -RBIMPL_ATTR_NORETURN() -VALUE rb_f_exit(int, const VALUE*); - -RBIMPL_ATTR_NORETURN() -VALUE rb_f_abort(int, const VALUE*); - -RBIMPL_ATTR_NORETURN() -void rb_interrupt(void); -ID rb_frame_this_func(void); - -RBIMPL_ATTR_NORETURN() -void rb_jump_tag(int); -void rb_obj_call_init(VALUE, int, const VALUE*); -void rb_obj_call_init_kw(VALUE, int, const VALUE*, int); -VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); -ID rb_frame_callee(void); -VALUE rb_make_exception(int, const VALUE*); - -/* eval_jump.c */ -void rb_set_end_proc(void (*)(VALUE), VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_EVAL_H */ diff --git a/include/ruby/impl/intern/file.h b/include/ruby/impl/intern/file.h deleted file mode 100644 index ed8e50cba6..0000000000 --- a/include/ruby/impl/intern/file.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef RBIMPL_INTERN_FILE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_FILE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cFile. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* file.c */ -VALUE rb_file_s_expand_path(int, const VALUE *); -VALUE rb_file_expand_path(VALUE, VALUE); -VALUE rb_file_s_absolute_path(int, const VALUE *); -VALUE rb_file_absolute_path(VALUE, VALUE); -VALUE rb_file_dirname(VALUE fname); -int rb_find_file_ext_safe(VALUE*, const char* const*, int); /* Remove in 3.0 */ -VALUE rb_find_file_safe(VALUE, int); /* Remove in 3.0 */ -int rb_find_file_ext(VALUE*, const char* const*); -VALUE rb_find_file(VALUE); -VALUE rb_file_directory_p(VALUE,VALUE); -VALUE rb_str_encode_ospath(VALUE); -int rb_is_absolute_path(const char *); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_FILE_H */ diff --git a/include/ruby/impl/intern/gc.h b/include/ruby/impl/intern/gc.h deleted file mode 100644 index a75785cc49..0000000000 --- a/include/ruby/impl/intern/gc.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef RBIMPL_INTERN_GC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_GC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_mGC. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/attributes.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* gc.c */ -COLDFUNC NORETURN(void rb_memerror(void)); -PUREFUNC(int rb_during_gc(void)); -void rb_gc_mark_locations(const VALUE*, const VALUE*); -void rb_mark_tbl(struct st_table*); -void rb_mark_tbl_no_pin(struct st_table*); -void rb_mark_set(struct st_table*); -void rb_mark_hash(struct st_table*); -void rb_gc_update_tbl_refs(st_table *ptr); -void rb_gc_mark_maybe(VALUE); -void rb_gc_mark(VALUE); -void rb_gc_mark_movable(VALUE); -VALUE rb_gc_location(VALUE); -void rb_gc_force_recycle(VALUE); -void rb_gc(void); -void rb_gc_copy_finalizer(VALUE,VALUE); -VALUE rb_gc_enable(void); -VALUE rb_gc_disable(void); -VALUE rb_gc_start(void); -VALUE rb_define_finalizer(VALUE, VALUE); -VALUE rb_undefine_finalizer(VALUE); -size_t rb_gc_count(void); -size_t rb_gc_stat(VALUE); -VALUE rb_gc_latest_gc_info(VALUE); -void rb_gc_adjust_memory_usage(ssize_t); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_GC_H */ diff --git a/include/ruby/impl/intern/hash.h b/include/ruby/impl/intern/hash.h deleted file mode 100644 index 3f0a930131..0000000000 --- a/include/ruby/impl/intern/hash.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef RBIMPL_INTERN_HASH_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_HASH_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cHash. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/st.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* hash.c */ -void rb_st_foreach_safe(struct st_table *, int (*)(st_data_t, st_data_t, st_data_t), st_data_t); -#define st_foreach_safe rb_st_foreach_safe -VALUE rb_check_hash_type(VALUE); -void rb_hash_foreach(VALUE, int (*)(VALUE, VALUE, VALUE), VALUE); -VALUE rb_hash(VALUE); -VALUE rb_hash_new(void); -VALUE rb_hash_dup(VALUE); -VALUE rb_hash_freeze(VALUE); -VALUE rb_hash_aref(VALUE, VALUE); -VALUE rb_hash_lookup(VALUE, VALUE); -VALUE rb_hash_lookup2(VALUE, VALUE, VALUE); -VALUE rb_hash_fetch(VALUE, VALUE); -VALUE rb_hash_aset(VALUE, VALUE, VALUE); -VALUE rb_hash_clear(VALUE); -VALUE rb_hash_delete_if(VALUE); -VALUE rb_hash_delete(VALUE,VALUE); -VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone); -void rb_hash_bulk_insert(long, const VALUE *, VALUE); -typedef VALUE rb_hash_update_func(VALUE newkey, VALUE oldkey, VALUE value); -VALUE rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func); -struct st_table *rb_hash_tbl(VALUE, const char *file, int line); -int rb_path_check(const char*); -int rb_env_path_tainted(void); -VALUE rb_env_clear(void); -VALUE rb_hash_size(VALUE); -void rb_hash_free(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_HASH_H */ diff --git a/include/ruby/impl/intern/io.h b/include/ruby/impl/intern/io.h deleted file mode 100644 index 6b0133dddf..0000000000 --- a/include/ruby/impl/intern/io.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef RBIMPL_INTERN_IO_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_IO_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cIO. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* io.c */ -#define rb_defout rb_stdout -RUBY_EXTERN VALUE rb_fs; -RUBY_EXTERN VALUE rb_output_fs; -RUBY_EXTERN VALUE rb_rs; -RUBY_EXTERN VALUE rb_default_rs; -RUBY_EXTERN VALUE rb_output_rs; -VALUE rb_io_write(VALUE, VALUE); -VALUE rb_io_gets(VALUE); -VALUE rb_io_getbyte(VALUE); -VALUE rb_io_ungetc(VALUE, VALUE); -VALUE rb_io_ungetbyte(VALUE, VALUE); -VALUE rb_io_close(VALUE); -VALUE rb_io_flush(VALUE); -VALUE rb_io_eof(VALUE); -VALUE rb_io_binmode(VALUE); -VALUE rb_io_ascii8bit_binmode(VALUE); -VALUE rb_io_addstr(VALUE, VALUE); -VALUE rb_io_printf(int, const VALUE*, VALUE); -VALUE rb_io_print(int, const VALUE*, VALUE); -VALUE rb_io_puts(int, const VALUE*, VALUE); -VALUE rb_io_fdopen(int, int, const char*); -VALUE rb_io_get_io(VALUE); -VALUE rb_file_open(const char*, const char*); -VALUE rb_file_open_str(VALUE, const char*); -VALUE rb_gets(void); -void rb_write_error(const char*); -void rb_write_error2(const char*, long); -void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds); -int rb_pipe(int *pipes); -int rb_reserved_fd_p(int fd); -int rb_cloexec_open(const char *pathname, int flags, mode_t mode); -int rb_cloexec_dup(int oldfd); -int rb_cloexec_dup2(int oldfd, int newfd); -int rb_cloexec_pipe(int fildes[2]); -int rb_cloexec_fcntl_dupfd(int fd, int minfd); -#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd) -void rb_update_max_fd(int fd); -void rb_fd_fix_cloexec(int fd); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_IO_H */ diff --git a/include/ruby/impl/intern/load.h b/include/ruby/impl/intern/load.h deleted file mode 100644 index d165237bfc..0000000000 --- a/include/ruby/impl/intern/load.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RBIMPL_INTERN_LOAD_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_LOAD_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_f_require(). - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* load.c */ -void rb_load(VALUE, int); -void rb_load_protect(VALUE, int, int*); -int rb_provided(const char*); -int rb_feature_provided(const char *, const char **); -void rb_provide(const char*); -VALUE rb_f_require(VALUE, VALUE); -VALUE rb_require_string(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_LOAD_H */ diff --git a/include/ruby/impl/intern/marshal.h b/include/ruby/impl/intern/marshal.h deleted file mode 100644 index 88473ba4e3..0000000000 --- a/include/ruby/impl/intern/marshal.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef RBIMPL_INTERN_MARSHAL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_MARSHAL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to rb_mMarshal. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* marshal.c */ -VALUE rb_marshal_dump(VALUE, VALUE); -VALUE rb_marshal_load(VALUE); -void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE)); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_MARSHAL_H */ diff --git a/include/ruby/impl/intern/numeric.h b/include/ruby/impl/intern/numeric.h deleted file mode 100644 index fa4b1daa74..0000000000 --- a/include/ruby/impl/intern/numeric.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef RBIMPL_INTERN_NUMERIC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_NUMERIC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cNumeric. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/attributes.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* numeric.c */ -NORETURN(void rb_num_zerodiv(void)); -#define RB_NUM_COERCE_FUNCS_NEED_OPID 1 -VALUE rb_num_coerce_bin(VALUE, VALUE, ID); -VALUE rb_num_coerce_cmp(VALUE, VALUE, ID); -VALUE rb_num_coerce_relop(VALUE, VALUE, ID); -VALUE rb_num_coerce_bit(VALUE, VALUE, ID); -VALUE rb_num2fix(VALUE); -VALUE rb_fix2str(VALUE, int); -CONSTFUNC(VALUE rb_dbl_cmp(double, double)); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_NUMERIC_H */ diff --git a/include/ruby/impl/intern/object.h b/include/ruby/impl/intern/object.h deleted file mode 100644 index 808836fbda..0000000000 --- a/include/ruby/impl/intern/object.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef RBIMPL_INTERN_OBJECT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_OBJECT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cObject. - */ -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -#define RB_OBJ_INIT_COPY(obj, orig) \ - ((obj) != (orig) && (rb_obj_init_copy((obj), (orig)), 1)) -#define OBJ_INIT_COPY(obj, orig) RB_OBJ_INIT_COPY(obj, orig) - -VALUE rb_class_new_instance_pass_kw(int, const VALUE *, VALUE); -VALUE rb_class_new_instance(int, const VALUE*, VALUE); -VALUE rb_class_new_instance_kw(int, const VALUE*, VALUE, int); - -/* object.c */ -int rb_eql(VALUE, VALUE); -VALUE rb_any_to_s(VALUE); -VALUE rb_inspect(VALUE); -VALUE rb_obj_is_instance_of(VALUE, VALUE); -VALUE rb_obj_is_kind_of(VALUE, VALUE); -VALUE rb_obj_alloc(VALUE); -VALUE rb_obj_clone(VALUE); -VALUE rb_obj_dup(VALUE); -VALUE rb_obj_init_copy(VALUE,VALUE); -VALUE rb_obj_taint(VALUE); - -RBIMPL_ATTR_PURE() -VALUE rb_obj_tainted(VALUE); -VALUE rb_obj_untaint(VALUE); -VALUE rb_obj_untrust(VALUE); - -RBIMPL_ATTR_PURE() -VALUE rb_obj_untrusted(VALUE); -VALUE rb_obj_trust(VALUE); -VALUE rb_obj_freeze(VALUE); - -RBIMPL_ATTR_PURE() -VALUE rb_obj_frozen_p(VALUE); - -VALUE rb_obj_id(VALUE); -VALUE rb_memory_id(VALUE); -VALUE rb_obj_class(VALUE); - -RBIMPL_ATTR_PURE() -VALUE rb_class_real(VALUE); - -RBIMPL_ATTR_PURE() -VALUE rb_class_inherited_p(VALUE, VALUE); -VALUE rb_class_superclass(VALUE); -VALUE rb_class_get_superclass(VALUE); -VALUE rb_convert_type(VALUE,int,const char*,const char*); -VALUE rb_check_convert_type(VALUE,int,const char*,const char*); -VALUE rb_check_to_integer(VALUE, const char *); -VALUE rb_check_to_float(VALUE); -VALUE rb_to_int(VALUE); -VALUE rb_check_to_int(VALUE); -VALUE rb_Integer(VALUE); -VALUE rb_to_float(VALUE); -VALUE rb_Float(VALUE); -VALUE rb_String(VALUE); -VALUE rb_Array(VALUE); -VALUE rb_Hash(VALUE); -double rb_cstr_to_dbl(const char*, int); -double rb_str_to_dbl(VALUE, int); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_OBJECT_H */ diff --git a/include/ruby/impl/intern/parse.h b/include/ruby/impl/intern/parse.h deleted file mode 100644 index cc6424f539..0000000000 --- a/include/ruby/impl/intern/parse.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef RBIMPL_INTERN_PARSE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_PARSE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cSymbol. - */ -#include "ruby/impl/attr/const.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* parse.y */ -ID rb_id_attrset(ID); - -RBIMPL_ATTR_CONST() -int rb_is_const_id(ID); - -RBIMPL_ATTR_CONST() -int rb_is_global_id(ID); - -RBIMPL_ATTR_CONST() -int rb_is_instance_id(ID); - -RBIMPL_ATTR_CONST() -int rb_is_attrset_id(ID); - -RBIMPL_ATTR_CONST() -int rb_is_class_id(ID); - -RBIMPL_ATTR_CONST() -int rb_is_local_id(ID); - -RBIMPL_ATTR_CONST() -int rb_is_junk_id(ID); -int rb_symname_p(const char*); -int rb_sym_interned_p(VALUE); -VALUE rb_backref_get(void); -void rb_backref_set(VALUE); -VALUE rb_lastline_get(void); -void rb_lastline_set(VALUE); - -/* symbol.c */ -VALUE rb_sym_all_symbols(void); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_PARSE_H */ diff --git a/include/ruby/impl/intern/proc.h b/include/ruby/impl/intern/proc.h deleted file mode 100644 index 7ee864d9a3..0000000000 --- a/include/ruby/impl/intern/proc.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef RBIMPL_INTERN_PROC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_PROC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cProc. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/iterator.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* proc.c */ -VALUE rb_block_proc(void); -VALUE rb_block_lambda(void); -VALUE rb_proc_new(rb_block_call_func_t, VALUE); -VALUE rb_obj_is_proc(VALUE); -VALUE rb_proc_call(VALUE, VALUE); -VALUE rb_proc_call_kw(VALUE, VALUE, int); -VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE); -VALUE rb_proc_call_with_block_kw(VALUE, int argc, const VALUE *argv, VALUE, int); -int rb_proc_arity(VALUE); -VALUE rb_proc_lambda_p(VALUE); -VALUE rb_binding_new(void); -VALUE rb_obj_method(VALUE, VALUE); -VALUE rb_obj_is_method(VALUE); -VALUE rb_method_call(int, const VALUE*, VALUE); -VALUE rb_method_call_kw(int, const VALUE*, VALUE, int); -VALUE rb_method_call_with_block(int, const VALUE *, VALUE, VALUE); -VALUE rb_method_call_with_block_kw(int, const VALUE *, VALUE, VALUE, int); -int rb_mod_method_arity(VALUE, ID); -int rb_obj_method_arity(VALUE, ID); -VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_PROC_H */ diff --git a/include/ruby/impl/intern/process.h b/include/ruby/impl/intern/process.h deleted file mode 100644 index bbbea1f86a..0000000000 --- a/include/ruby/impl/intern/process.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef RBIMPL_INTERN_PROCESS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_PROCESS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_mProcess. - */ -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/config.h" /* rb_pid_t is defined here. */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* process.c */ -void rb_last_status_set(int status, rb_pid_t pid); -VALUE rb_last_status_get(void); -int rb_proc_exec(const char*); - -RBIMPL_ATTR_NORETURN() -VALUE rb_f_exec(int, const VALUE*); -rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags); -void rb_syswait(rb_pid_t pid); -rb_pid_t rb_spawn(int, const VALUE*); -rb_pid_t rb_spawn_err(int, const VALUE*, char*, size_t); -VALUE rb_proc_times(VALUE); -VALUE rb_detach_process(rb_pid_t pid); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_PROCESS_H */ diff --git a/include/ruby/impl/intern/random.h b/include/ruby/impl/intern/random.h deleted file mode 100644 index 2f054cd688..0000000000 --- a/include/ruby/impl/intern/random.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef RBIMPL_INTERN_RANDOM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_RANDOM_H -/** - * @file - * @author Ruby developers - * @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 MT19937 backended pseudo random number generator. - * @see Matsumoto, M., Nishimura, T., "Mersenne Twister: A 623- - * dimensionally equidistributed uniform pseudorandom number - * generator", ACM Trans. on Modeling and Computer Simulation, 8 - * (1): pp 3-30, 1998. https://doi.org/10.1145/272991.272995 - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* random.c */ -unsigned int rb_genrand_int32(void); -double rb_genrand_real(void); -void rb_reset_random_seed(void); -VALUE rb_random_bytes(VALUE rnd, long n); -VALUE rb_random_int(VALUE rnd, VALUE max); -unsigned int rb_random_int32(VALUE rnd); -double rb_random_real(VALUE rnd); -unsigned long rb_random_ulong_limited(VALUE rnd, unsigned long limit); -unsigned long rb_genrand_ulong_limited(unsigned long i); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_RANDOM_H */ diff --git a/include/ruby/impl/intern/range.h b/include/ruby/impl/intern/range.h deleted file mode 100644 index 0841baa0d5..0000000000 --- a/include/ruby/impl/intern/range.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef RBIMPL_INTERN_RANGE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_RANGE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cRange. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* range.c */ -VALUE rb_range_new(VALUE, VALUE, int); -VALUE rb_range_beg_len(VALUE, long*, long*, long, int); -int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_RANGE_H */ diff --git a/include/ruby/impl/intern/rational.h b/include/ruby/impl/intern/rational.h deleted file mode 100644 index d56a6ec752..0000000000 --- a/include/ruby/impl/intern/rational.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef RBIMPL_INTERN_RATIONAL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_RATIONAL_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cRational. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/impl/arithmetic/long.h" /* INT2FIX is here. */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* rational.c */ -VALUE rb_rational_raw(VALUE, VALUE); -#define rb_rational_raw1(x) rb_rational_raw((x), INT2FIX(1)) -#define rb_rational_raw2(x,y) rb_rational_raw((x), (y)) -VALUE rb_rational_new(VALUE, VALUE); -#define rb_rational_new1(x) rb_rational_new((x), INT2FIX(1)) -#define rb_rational_new2(x,y) rb_rational_new((x), (y)) -VALUE rb_Rational(VALUE, VALUE); -#define rb_Rational1(x) rb_Rational((x), INT2FIX(1)) -#define rb_Rational2(x,y) rb_Rational((x), (y)) -VALUE rb_rational_num(VALUE rat); -VALUE rb_rational_den(VALUE rat); -VALUE rb_flt_rationalize_with_prec(VALUE, VALUE); -VALUE rb_flt_rationalize(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_RATIONAL_H */ diff --git a/include/ruby/impl/intern/re.h b/include/ruby/impl/intern/re.h deleted file mode 100644 index 4392cef1a2..0000000000 --- a/include/ruby/impl/intern/re.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef RBIMPL_INTERN_RE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_RE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cRegexp. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* re.c */ -#define rb_memcmp memcmp -int rb_memcicmp(const void*,const void*,long); -void rb_match_busy(VALUE); -VALUE rb_reg_nth_defined(int, VALUE); -VALUE rb_reg_nth_match(int, VALUE); -int rb_reg_backref_number(VALUE match, VALUE backref); -VALUE rb_reg_last_match(VALUE); -VALUE rb_reg_match_pre(VALUE); -VALUE rb_reg_match_post(VALUE); -VALUE rb_reg_match_last(VALUE); -#define HAVE_RB_REG_NEW_STR 1 -VALUE rb_reg_new_str(VALUE, int); -VALUE rb_reg_new(const char *, long, int); -VALUE rb_reg_alloc(void); -VALUE rb_reg_init_str(VALUE re, VALUE s, int options); -VALUE rb_reg_match(VALUE, VALUE); -VALUE rb_reg_match2(VALUE); -int rb_reg_options(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_RE_H */ diff --git a/include/ruby/impl/intern/ruby.h b/include/ruby/impl/intern/ruby.h deleted file mode 100644 index bbfda510d5..0000000000 --- a/include/ruby/impl/intern/ruby.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RBIMPL_INTERN_RUBY_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_RUBY_H -/** - * @file - * @author Ruby developers - * @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 Process-global APIs. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* ruby.c */ -#define rb_argv rb_get_argv() -RUBY_EXTERN VALUE rb_argv0; -VALUE rb_get_argv(void); -void *rb_load_file(const char*); -void *rb_load_file_str(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_RUBY_H */ diff --git a/include/ruby/impl/intern/select.h b/include/ruby/impl/intern/select.h deleted file mode 100644 index 09244dcce5..0000000000 --- a/include/ruby/impl/intern/select.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef RBIMPL_INTERN_SELECT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_SELECT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs to provide ::rb_fd_select(). - * @note Functions and structs defined in this header file are not - * necessarily ruby-specific. They don't need ::VALUE etc. - */ -#include "ruby/impl/config.h" - -#ifdef HAVE_SYS_TYPES_H -# include /* for NFDBITS (BSD Net/2) */ -#endif - -#include "ruby/impl/dllexport.h" - -/* thread.c */ -#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT) -# include "ruby/impl/intern/select/largesize.h" -#elif defined(_WIN32) -# include "ruby/impl/intern/select/win32.h" -# define rb_fd_resize(n, f) ((void)(f)) -#else -# include "ruby/impl/intern/select/posix.h" -# define rb_fd_resize(n, f) ((void)(f)) -#endif - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -struct timeval; - -int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_SELECT_H */ diff --git a/include/ruby/impl/intern/select/largesize.h b/include/ruby/impl/intern/select/largesize.h deleted file mode 100644 index c5f321f1dc..0000000000 --- a/include/ruby/impl/intern/select/largesize.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef RBIMPL_INTERN_SELECT_LARGESIZE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_SELECT_LARGESIZE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs to provide ::rb_fd_select(). - * - * Several Unix platforms support file descriptors bigger than FD_SETSIZE in - * `select(2)` system call. - * - * - Linux 2.2.12 (?) - * - * - NetBSD 1.2 (src/sys/kern/sys_generic.c:1.25) - * `select(2)` documents how to allocate fd_set dynamically. - * http://netbsd.gw.com/cgi-bin/man-cgi?select++NetBSD-4.0 - * - * - FreeBSD 2.2 (src/sys/kern/sys_generic.c:1.19) - * - * - OpenBSD 2.0 (src/sys/kern/sys_generic.c:1.4) - * `select(2)` documents how to allocate fd_set dynamically. - * http://www.openbsd.org/cgi-bin/man.cgi?query=select&manpath=OpenBSD+4.4 - * - * - HP-UX documents how to allocate fd_set dynamically. - * http://docs.hp.com/en/B2355-60105/select.2.html - * - * - Solaris 8 has `select_large_fdset` - * - * - Mac OS X 10.7 (Lion) - * `select(2)` returns `EINVAL` if `nfds` is greater than `FD_SET_SIZE` and - * `_DARWIN_UNLIMITED_SELECT` (or `_DARWIN_C_SOURCE`) isn't defined. - * http://developer.apple.com/library/mac/#releasenotes/Darwin/SymbolVariantsRelNotes/_index.html - * - * When `fd_set` is not big enough to hold big file descriptors, it should be - * allocated dynamically. Note that this assumes `fd_set` is structured as - * bitmap. - * - * `rb_fd_init` allocates the memory. - * `rb_fd_term` frees the memory. - * `rb_fd_set` may re-allocate bitmap. - * - * So `rb_fd_set` doesn't reject file descriptors bigger than `FD_SETSIZE`. - */ -#include "ruby/impl/attr/nonnull.h" -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/dllexport.h" - -/**@cond INTERNAL_MACRO */ -#define rb_fd_ptr rb_fd_ptr -#define rb_fd_max rb_fd_max -/** @endcond */ - -struct timeval; - -typedef struct { - int maxfd; - fd_set *fdset; -} rb_fdset_t; - -RBIMPL_SYMBOL_EXPORT_BEGIN() -void rb_fd_init(rb_fdset_t *); -void rb_fd_term(rb_fdset_t *); -void rb_fd_zero(rb_fdset_t *); -void rb_fd_set(int, rb_fdset_t *); -void rb_fd_clr(int, rb_fdset_t *); -int rb_fd_isset(int, const rb_fdset_t *); -void rb_fd_copy(rb_fdset_t *, const fd_set *, int); -void rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src); -int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_NONNULL(()) -RBIMPL_ATTR_PURE() -/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */ -static inline fd_set * -rb_fd_ptr(const rb_fdset_t *f) -{ - return f->fdset; -} - -RBIMPL_ATTR_NONNULL(()) -RBIMPL_ATTR_PURE() -static inline int -rb_fd_max(const rb_fdset_t *f) -{ - return f->maxfd; -} - -#endif /* RBIMPL_INTERN_SELECT_LARGESIZE_H */ diff --git a/include/ruby/impl/intern/select/posix.h b/include/ruby/impl/intern/select/posix.h deleted file mode 100644 index a2ac51df92..0000000000 --- a/include/ruby/impl/intern/select/posix.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef RBIMPL_INTERN_SELECT_POSIX_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_SELECT_POSIX_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs to provide ::rb_fd_select(). - */ -#include "ruby/impl/config.h" - -#ifdef HAVE_SYS_SELECT_H -# include /* for select(2) (modern POSIX) */ -#endif - -#ifdef HAVE_UNISTD_H -# include /* for select(2) (archaic UNIX) */ -#endif - -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/attr/const.h" - -typedef fd_set rb_fdset_t; - -#define rb_fd_zero FD_ZERO -#define rb_fd_set FD_SET -#define rb_fd_clr FD_CLR -#define rb_fd_isset FD_ISSET -#define rb_fd_init FD_ZERO -#define rb_fd_select select -/**@cond INTERNAL_MACRO */ -#define rb_fd_copy rb_fd_copy -#define rb_fd_dup rb_fd_dup -#define rb_fd_ptr rb_fd_ptr -#define rb_fd_max rb_fd_max -/** @endcond */ - -static inline void -rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int n) -{ - *dst = *src; -} - -static inline void -rb_fd_dup(rb_fdset_t *dst, const fd_set *src, int n) -{ - *dst = *src; -} - -RBIMPL_ATTR_PURE() -/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */ -static inline fd_set * -rb_fd_ptr(rb_fdset_t *f) -{ - return f; -} - -RBIMPL_ATTR_CONST() -static inline int -rb_fd_max(const rb_fdset_t *f) -{ - return FD_SETSIZE; -} - -/* :FIXME: What are these? They don't exist for shibling implementations. */ -#define rb_fd_init_copy(d, s) (*(d) = *(s)) -#define rb_fd_term(f) ((void)(f)) - -#endif /* RBIMPL_INTERN_SELECT_POSIX_H */ diff --git a/include/ruby/impl/intern/select/win32.h b/include/ruby/impl/intern/select/win32.h deleted file mode 100644 index 0a1da61e63..0000000000 --- a/include/ruby/impl/intern/select/win32.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef RBIMPL_INTERN_SELECT_WIN32_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_SELECT_WIN32_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs to provide ::rb_fd_select(). - */ -#include "ruby/impl/dosish.h" /* for rb_w32_select */ -#include "ruby/impl/attr/nonnull.h" -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/attr/noalias.h" -#include "ruby/impl/dllexport.h" -#include "ruby/assert.h" - -/**@cond INTERNAL_MACRO */ -#define rb_fd_zero rb_fd_zero -#define rb_fd_clr rb_fd_clr -#define rb_fd_isset rb_fd_isset -#define rb_fd_copy rb_fd_copy -#define rb_fd_dup rb_fd_dup -#define rb_fd_ptr rb_fd_ptr -#define rb_fd_max rb_fd_max -/** @endcond */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -struct timeval; - -typedef struct { - int capa; - fd_set *fdset; -} rb_fdset_t; - -void rb_fd_init(rb_fdset_t *); -void rb_fd_term(rb_fdset_t *); -void rb_fd_set(int, rb_fdset_t *); -void rb_w32_fd_copy(rb_fdset_t *, const fd_set *, int); -void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src); - -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_NONNULL(()) -RBIMPL_ATTR_NOALIAS() -static inline void -rb_fd_zero(rb_fdset_t *f) -{ - f->fdset->fd_count = 0; -} - -RBIMPL_ATTR_NONNULL(()) -static inline void -rb_fd_clr(int n, rb_fdset_t *f) -{ - rb_w32_fdclr(n, f->fdset); -} - -RBIMPL_ATTR_NONNULL(()) -static inline int -rb_fd_isset(int n, rb_fdset_t *f) -{ - return rb_w32_fdisset(n, f->fdset); -} - -RBIMPL_ATTR_NONNULL(()) -static inline void -rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int n) -{ - rb_w32_fd_copy(dst, src, n); -} - -RBIMPL_ATTR_NONNULL(()) -static inline void -rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src) -{ - rb_w32_fd_dup(dst, src); -} - -static inline int -rb_fd_select(int n, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout) -{ - return rb_w32_select( - n, - rfds ? rfds->fdset : NULL, - wfds ? wfds->fdset : NULL, - efds ? efds->fdset : NULL, - timeout); -} - -RBIMPL_ATTR_NONNULL(()) -RBIMPL_ATTR_PURE() -/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */ -static inline fd_set * -rb_fd_ptr(const rb_fdset_t *f) -{ - return f->fdset; -} - -RBIMPL_ATTR_NONNULL(()) -RBIMPL_ATTR_PURE() -static inline int -rb_fd_max(const rb_fdset_t *f) -{ - const fd_set *p = f->fdset; - - RBIMPL_ASSERT_OR_ASSUME(p); - return p->fd_count; -} - -#endif /* RBIMPL_INTERN_SELECT_WIN32_H */ diff --git a/include/ruby/impl/intern/signal.h b/include/ruby/impl/intern/signal.h deleted file mode 100644 index 43ce470c2e..0000000000 --- a/include/ruby/impl/intern/signal.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef RBIMPL_INTERN_SIGNAL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_SIGNAL_H -/** - * @file - * @author Ruby developers - * @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 Signal handling APIs. - */ -#include "ruby/impl/config.h" /* POSIX_SIGNAL / RETSIGTYPE */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* signal.c */ -VALUE rb_f_kill(int, const VALUE*); -#ifdef POSIX_SIGNAL -#define posix_signal ruby_posix_signal -RETSIGTYPE (*posix_signal(int, RETSIGTYPE (*)(int)))(int); -#endif -const char *ruby_signal_name(int); -void ruby_default_signal(int); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_SIGNAL_H */ diff --git a/include/ruby/impl/intern/sprintf.h b/include/ruby/impl/intern/sprintf.h deleted file mode 100644 index c2b1818cdf..0000000000 --- a/include/ruby/impl/intern/sprintf.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef RBIMPL_INTERN_SPRINTF_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_SPRINTF_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Our own private printf(3). - */ -#include "ruby/impl/attr/format.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* sprintf.c */ -VALUE rb_f_sprintf(int, const VALUE*); - -RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2) -VALUE rb_sprintf(const char*, ...); -VALUE rb_vsprintf(const char*, va_list); - -RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3) -VALUE rb_str_catf(VALUE, const char*, ...); -VALUE rb_str_vcatf(VALUE, const char*, va_list); -VALUE rb_str_format(int, const VALUE *, VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_SPRINTF_H */ diff --git a/include/ruby/impl/intern/string.h b/include/ruby/impl/intern/string.h deleted file mode 100644 index ba4107c79f..0000000000 --- a/include/ruby/impl/intern/string.h +++ /dev/null @@ -1,326 +0,0 @@ -#ifndef RBIMPL_INTERN_STRING_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_STRING_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cString. - */ -#include "ruby/impl/config.h" - -#ifdef STDC_HEADERS -# include -#endif - -#ifdef HAVE_STRING_H -# include -#endif - -#ifdef HAVE_STDINT_H -# include -#endif - -#include "ruby/impl/attr/nonnull.h" -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/constant_p.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/impl/variable.h" /* rb_gvar_setter_t */ -#include "ruby/st.h" /* st_index_t */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* string.c */ -VALUE rb_str_new(const char*, long); -VALUE rb_str_new_cstr(const char*); -VALUE rb_str_new_shared(VALUE); -VALUE rb_str_new_frozen(VALUE); -VALUE rb_str_new_with_class(VALUE, const char*, long); -VALUE rb_tainted_str_new_cstr(const char*); -VALUE rb_tainted_str_new(const char*, long); -VALUE rb_external_str_new(const char*, long); -VALUE rb_external_str_new_cstr(const char*); -VALUE rb_locale_str_new(const char*, long); -VALUE rb_locale_str_new_cstr(const char*); -VALUE rb_filesystem_str_new(const char*, long); -VALUE rb_filesystem_str_new_cstr(const char*); -VALUE rb_str_buf_new(long); -VALUE rb_str_buf_new_cstr(const char*); -VALUE rb_str_buf_new2(const char*); -VALUE rb_str_tmp_new(long); -VALUE rb_usascii_str_new(const char*, long); -VALUE rb_usascii_str_new_cstr(const char*); -VALUE rb_utf8_str_new(const char*, long); -VALUE rb_utf8_str_new_cstr(const char*); -VALUE rb_str_new_static(const char *, long); -VALUE rb_usascii_str_new_static(const char *, long); -VALUE rb_utf8_str_new_static(const char *, long); -void rb_str_free(VALUE); -void rb_str_shared_replace(VALUE, VALUE); -VALUE rb_str_buf_append(VALUE, VALUE); -VALUE rb_str_buf_cat(VALUE, const char*, long); -VALUE rb_str_buf_cat2(VALUE, const char*); -VALUE rb_str_buf_cat_ascii(VALUE, const char*); -VALUE rb_obj_as_string(VALUE); -VALUE rb_check_string_type(VALUE); -void rb_must_asciicompat(VALUE); -VALUE rb_str_dup(VALUE); -VALUE rb_str_resurrect(VALUE str); -VALUE rb_str_locktmp(VALUE); -VALUE rb_str_unlocktmp(VALUE); -VALUE rb_str_dup_frozen(VALUE); -#define rb_str_dup_frozen rb_str_new_frozen -VALUE rb_str_plus(VALUE, VALUE); -VALUE rb_str_times(VALUE, VALUE); -long rb_str_sublen(VALUE, long); -VALUE rb_str_substr(VALUE, long, long); -VALUE rb_str_subseq(VALUE, long, long); -char *rb_str_subpos(VALUE, long, long*); -void rb_str_modify(VALUE); -void rb_str_modify_expand(VALUE, long); -VALUE rb_str_freeze(VALUE); -void rb_str_set_len(VALUE, long); -VALUE rb_str_resize(VALUE, long); -VALUE rb_str_cat(VALUE, const char*, long); -VALUE rb_str_cat_cstr(VALUE, const char*); -VALUE rb_str_cat2(VALUE, const char*); -VALUE rb_str_append(VALUE, VALUE); -VALUE rb_str_concat(VALUE, VALUE); -st_index_t rb_memhash(const void *ptr, long len); -st_index_t rb_hash_start(st_index_t); -st_index_t rb_hash_uint32(st_index_t, uint32_t); -st_index_t rb_hash_uint(st_index_t, st_index_t); -st_index_t rb_hash_end(st_index_t); -#define rb_hash_uint32(h, i) st_hash_uint32((h), (i)) -#define rb_hash_uint(h, i) st_hash_uint((h), (i)) -#define rb_hash_end(h) st_hash_end(h) -st_index_t rb_str_hash(VALUE); -int rb_str_hash_cmp(VALUE,VALUE); -int rb_str_comparable(VALUE, VALUE); -int rb_str_cmp(VALUE, VALUE); -VALUE rb_str_equal(VALUE str1, VALUE str2); -VALUE rb_str_drop_bytes(VALUE, long); -void rb_str_update(VALUE, long, long, VALUE); -VALUE rb_str_replace(VALUE, VALUE); -VALUE rb_str_inspect(VALUE); -VALUE rb_str_dump(VALUE); -VALUE rb_str_split(VALUE, const char*); -rb_gvar_setter_t rb_str_setter; -VALUE rb_str_intern(VALUE); -VALUE rb_sym_to_s(VALUE); -long rb_str_strlen(VALUE); -VALUE rb_str_length(VALUE); -long rb_str_offset(VALUE, long); -RBIMPL_ATTR_PURE() -size_t rb_str_capacity(VALUE); -VALUE rb_str_ellipsize(VALUE, long); -VALUE rb_str_scrub(VALUE, VALUE); -VALUE rb_str_succ(VALUE); - -RBIMPL_ATTR_NONNULL(()) -static inline long -rbimpl_strlen(const char *str) -{ - return RBIMPL_CAST((long)strlen(str)); -} - -static inline VALUE -rbimpl_str_new(const char *str, long len) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_str_new(str, len); - } - else if /* constexpr */ (! RBIMPL_CONSTANT_P(len)) { - return rb_str_new(str, len); - } - else { - return rb_str_new_static(str, len); - } -} - -static inline VALUE -rbimpl_str_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_str_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - return rb_str_new_static(str, len); - } -} - -static inline VALUE -rbimpl_usascii_str_new(const char *str, long len) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_usascii_str_new(str, len); - } - else if /* constexpr */ (! RBIMPL_CONSTANT_P(len)) { - return rb_usascii_str_new(str, len); - } - else { - return rb_usascii_str_new_static(str, len); - } -} - -static inline VALUE -rbimpl_utf8_str_new(const char *str, long len) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_utf8_str_new(str, len); - } - else if /* constexpr */ (! RBIMPL_CONSTANT_P(len)) { - return rb_utf8_str_new(str, len); - } - else { - return rb_utf8_str_new_static(str, len); - } -} - -static inline VALUE -rbimpl_tainted_str_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_tainted_str_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - return rb_tainted_str_new(str, len); - } -} - -static inline VALUE -rbimpl_usascii_str_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_usascii_str_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - return rb_usascii_str_new_static(str, len); - } -} - -static inline VALUE -rbimpl_utf8_str_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_utf8_str_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - return rb_utf8_str_new_static(str, len); - } -} - -static inline VALUE -rbimpl_external_str_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_external_str_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - return rb_external_str_new(str, len); - } -} - -static inline VALUE -rbimpl_locale_str_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_locale_str_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - return rb_locale_str_new(str, len); - } -} - -static inline VALUE -rbimpl_str_buf_new_cstr(const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_str_buf_new_cstr(str); - } - else { - long len = rbimpl_strlen(str); - VALUE buf = rb_str_buf_new(len); - return rb_str_buf_cat(buf, str, len); - } -} - -static inline VALUE -rbimpl_str_cat_cstr(VALUE buf, const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_str_cat_cstr(buf, str); - } - else { - long len = rbimpl_strlen(str); - return rb_str_cat(buf, str, len); - } -} - -static inline VALUE -rbimpl_exc_new_cstr(VALUE exc, const char *str) -{ - if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { - return rb_exc_new_cstr(exc, str); - } - else { - long len = rbimpl_strlen(str); - return rb_exc_new(exc, str, len); - } -} - -#define rb_str_new rbimpl_str_new -#define rb_str_new_cstr rbimpl_str_new_cstr -#define rb_usascii_str_new rbimpl_usascii_str_new -#define rb_utf8_str_new rbimpl_utf8_str_new -#define rb_tainted_str_new_cstr rbimpl_tainted_str_new_cstr -#define rb_usascii_str_new_cstr rbimpl_usascii_str_new_cstr -#define rb_utf8_str_new_cstr rbimpl_utf8_str_new_cstr -#define rb_external_str_new_cstr rbimpl_external_str_new_cstr -#define rb_locale_str_new_cstr rbimpl_locale_str_new_cstr -#define rb_str_buf_new_cstr rbimpl_str_buf_new_cstr -#define rb_str_cat_cstr rbimpl_str_cat_cstr -#define rb_exc_new_cstr rbimpl_exc_new_cstr -#define rb_str_new2 rb_str_new_cstr -#define rb_str_new3 rb_str_new_shared -#define rb_str_new4 rb_str_new_frozen -#define rb_str_new5 rb_str_new_with_class -#define rb_tainted_str_new2 rb_tainted_str_new_cstr -#define rb_str_buf_new2 rb_str_buf_new_cstr -#define rb_usascii_str_new2 rb_usascii_str_new_cstr -#define rb_str_buf_cat rb_str_cat -#define rb_str_buf_cat2 rb_str_cat_cstr -#define rb_str_cat2 rb_str_cat_cstr -#define rb_strlen_lit(str) (sizeof(str "") - 1) -#define rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str)) -#define rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str)) -#define rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str)) -#define rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc)) -#define rb_str_new_literal(str) rb_str_new_lit(str) -#define rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str) -#define rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str) -#define rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc) - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_STRING_H */ diff --git a/include/ruby/impl/intern/struct.h b/include/ruby/impl/intern/struct.h deleted file mode 100644 index 18d1058d9f..0000000000 --- a/include/ruby/impl/intern/struct.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef RBIMPL_INTERN_STRUCT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_STRUCT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cStruct. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/intern/vm.h" /* rb_alloc_func_t */ -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* struct.c */ -VALUE rb_struct_new(VALUE, ...); -VALUE rb_struct_define(const char*, ...); -VALUE rb_struct_define_under(VALUE, const char*, ...); -VALUE rb_struct_alloc(VALUE, VALUE); -VALUE rb_struct_initialize(VALUE, VALUE); -VALUE rb_struct_aref(VALUE, VALUE); -VALUE rb_struct_aset(VALUE, VALUE, VALUE); -VALUE rb_struct_getmember(VALUE, ID); -VALUE rb_struct_s_members(VALUE); -VALUE rb_struct_members(VALUE); -VALUE rb_struct_size(VALUE s); -VALUE rb_struct_alloc_noinit(VALUE); -VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...); -VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, ...); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_STRUCT_H */ diff --git a/include/ruby/impl/intern/thread.h b/include/ruby/impl/intern/thread.h deleted file mode 100644 index 38784fcca3..0000000000 --- a/include/ruby/impl/intern/thread.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef RBIMPL_INTERN_THREAD_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_THREAD_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cThread. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -struct timeval; - -/* thread.c */ -void rb_thread_schedule(void); -void rb_thread_wait_fd(int); -int rb_thread_fd_writable(int); -void rb_thread_fd_close(int); -int rb_thread_alone(void); -void rb_thread_sleep(int); -void rb_thread_sleep_forever(void); -void rb_thread_sleep_deadly(void); -VALUE rb_thread_stop(void); -VALUE rb_thread_wakeup(VALUE); -VALUE rb_thread_wakeup_alive(VALUE); -VALUE rb_thread_run(VALUE); -VALUE rb_thread_kill(VALUE); -VALUE rb_thread_create(VALUE (*)(void *), void*); -void rb_thread_wait_for(struct timeval); -VALUE rb_thread_current(void); -VALUE rb_thread_main(void); -VALUE rb_thread_local_aref(VALUE, ID); -VALUE rb_thread_local_aset(VALUE, ID, VALUE); -void rb_thread_atfork(void); -void rb_thread_atfork_before_exec(void); -VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); -VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE); -VALUE rb_exec_recursive_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); -VALUE rb_exec_recursive_paired_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE); - -typedef void rb_unblock_function_t(void *); -typedef VALUE rb_blocking_function_t(void *); -void rb_thread_check_ints(void); -int rb_thread_interrupted(VALUE thval); - -#define RUBY_UBF_IO RBIMPL_CAST((rb_unblock_function_t *)-1) -#define RUBY_UBF_PROCESS RBIMPL_CAST((rb_unblock_function_t *)-1) -VALUE rb_mutex_new(void); -VALUE rb_mutex_locked_p(VALUE mutex); -VALUE rb_mutex_trylock(VALUE mutex); -VALUE rb_mutex_lock(VALUE mutex); -VALUE rb_mutex_unlock(VALUE mutex); -VALUE rb_mutex_sleep(VALUE self, VALUE timeout); -VALUE rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_THREAD_H */ diff --git a/include/ruby/impl/intern/time.h b/include/ruby/impl/intern/time.h deleted file mode 100644 index b49802ccf4..0000000000 --- a/include/ruby/impl/intern/time.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef RBIMPL_INTERN_TIME_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_TIME_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cTime. - */ -#include "ruby/impl/config.h" - -#ifdef HAVE_TIME_H -# include /* for time_t */ -#endif - -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -struct timespec; -struct timeval; - -/* time.c */ -void rb_timespec_now(struct timespec *); -VALUE rb_time_new(time_t, long); -VALUE rb_time_nano_new(time_t, long); -VALUE rb_time_timespec_new(const struct timespec *, int); -VALUE rb_time_num_new(VALUE, VALUE); -struct timeval rb_time_interval(VALUE num); -struct timeval rb_time_timeval(VALUE time); -struct timespec rb_time_timespec(VALUE time); -struct timespec rb_time_timespec_interval(VALUE num); -VALUE rb_time_utc_offset(VALUE time); -VALUE rb_time_succ(VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_TIME_H */ diff --git a/include/ruby/impl/intern/variable.h b/include/ruby/impl/intern/variable.h deleted file mode 100644 index d8de93a8d6..0000000000 --- a/include/ruby/impl/intern/variable.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef RBIMPL_INTERN_VARIABLE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_VARIABLE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to names inside of a Ruby program. - */ -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/st.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* variable.c */ -VALUE rb_mod_name(VALUE); -VALUE rb_class_path(VALUE); -VALUE rb_class_path_cached(VALUE); -void rb_set_class_path(VALUE, VALUE, const char*); -void rb_set_class_path_string(VALUE, VALUE, VALUE); -VALUE rb_path_to_class(VALUE); -VALUE rb_path2class(const char*); -VALUE rb_class_name(VALUE); -VALUE rb_autoload_load(VALUE, ID); -VALUE rb_autoload_p(VALUE, ID); -VALUE rb_f_trace_var(int, const VALUE*); -VALUE rb_f_untrace_var(int, const VALUE*); -VALUE rb_f_global_variables(void); -void rb_alias_variable(ID, ID); -void rb_copy_generic_ivar(VALUE,VALUE); -void rb_free_generic_ivar(VALUE); -VALUE rb_ivar_get(VALUE, ID); -VALUE rb_ivar_set(VALUE, ID, VALUE); -VALUE rb_ivar_defined(VALUE, ID); -void rb_ivar_foreach(VALUE, int (*)(ID, VALUE, st_data_t), st_data_t); -st_index_t rb_ivar_count(VALUE); -VALUE rb_attr_get(VALUE, ID); -VALUE rb_obj_instance_variables(VALUE); -VALUE rb_obj_remove_instance_variable(VALUE, VALUE); -void *rb_mod_const_at(VALUE, void*); -void *rb_mod_const_of(VALUE, void*); -VALUE rb_const_list(void*); -VALUE rb_mod_constants(int, const VALUE *, VALUE); -VALUE rb_mod_remove_const(VALUE, VALUE); -int rb_const_defined(VALUE, ID); -int rb_const_defined_at(VALUE, ID); -int rb_const_defined_from(VALUE, ID); -VALUE rb_const_get(VALUE, ID); -VALUE rb_const_get_at(VALUE, ID); -VALUE rb_const_get_from(VALUE, ID); -void rb_const_set(VALUE, ID, VALUE); -VALUE rb_const_remove(VALUE, ID); -#if 0 /* EXPERIMENTAL: remove if no problem */ -RBIMPL_ATTR_NORETURN() -VALUE rb_mod_const_missing(VALUE,VALUE); -#endif -VALUE rb_cvar_defined(VALUE, ID); -void rb_cvar_set(VALUE, ID, VALUE); -VALUE rb_cvar_get(VALUE, ID); -void rb_cv_set(VALUE, const char*, VALUE); -VALUE rb_cv_get(VALUE, const char*); -void rb_define_class_variable(VALUE, const char*, VALUE); -VALUE rb_mod_class_variables(int, const VALUE*, VALUE); -VALUE rb_mod_remove_cvar(VALUE, VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_VARIABLE_H */ diff --git a/include/ruby/impl/intern/vm.h b/include/ruby/impl/intern/vm.h deleted file mode 100644 index 1fc8423dde..0000000000 --- a/include/ruby/impl/intern/vm.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef RBIMPL_INTERN_VM_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERN_VM_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Public APIs related to ::rb_cRubyVM. - */ -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/* vm.c */ -int rb_sourceline(void); -const char *rb_sourcefile(void); -int rb_frame_method_id_and_class(ID *idp, VALUE *klassp); - -/* vm_eval.c */ -VALUE rb_check_funcall(VALUE, ID, int, const VALUE*); -VALUE rb_check_funcall_kw(VALUE, ID, int, const VALUE*, int); -void rb_remove_method(VALUE, const char*); -void rb_remove_method_id(VALUE, ID); - -VALUE rb_eval_cmd_kw(VALUE, VALUE, int); -VALUE rb_apply(VALUE, ID, VALUE); - -VALUE rb_obj_instance_eval(int, const VALUE*, VALUE); -VALUE rb_obj_instance_exec(int, const VALUE*, VALUE); -VALUE rb_mod_module_eval(int, const VALUE*, VALUE); -VALUE rb_mod_module_exec(int, const VALUE*, VALUE); - -/* vm_method.c */ -#define HAVE_RB_DEFINE_ALLOC_FUNC 1 -typedef VALUE (*rb_alloc_func_t)(VALUE); -void rb_define_alloc_func(VALUE, rb_alloc_func_t); -void rb_undef_alloc_func(VALUE); -rb_alloc_func_t rb_get_alloc_func(VALUE); -void rb_clear_constant_cache(void); -void rb_clear_method_cache_by_class(VALUE); -void rb_alias(VALUE, ID, ID); -void rb_attr(VALUE,ID,int,int,int); -int rb_method_boundp(VALUE, ID, int); -int rb_method_basic_definition_p(VALUE, ID); - -int rb_obj_respond_to(VALUE, ID, int); -int rb_respond_to(VALUE, ID); - -RBIMPL_ATTR_NORETURN() -VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker); -#if !defined(RUBY_EXPORT) && defined(_WIN32) -RUBY_EXTERN VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE, VALUE marker); -#define rb_f_notimplement (*rb_f_notimplement_) -#endif - -/* vm_backtrace.c */ -void rb_backtrace(void); -VALUE rb_make_backtrace(void); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERN_VM_H */ diff --git a/include/ruby/impl/interpreter.h b/include/ruby/impl/interpreter.h deleted file mode 100644 index 23b70b2926..0000000000 --- a/include/ruby/impl/interpreter.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef RBIMPL_INTERPRETER_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_INTERPRETER_H -/** - * @file - * @author Ruby developers - * @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 Interpreter embedding APIs. - */ -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -/** - * @defgroup embed CRuby Embedding APIs - * CRuby interpreter APIs. These are APIs to embed MRI interpreter into your - * program. - * These functions are not a part of Ruby extension library API. - * Extension libraries of Ruby should not depend on these functions. - * @{ - */ - -/** @defgroup ruby1 ruby(1) implementation - * A part of the implementation of ruby(1) command. - * Other programs that embed Ruby interpreter do not always need to use these - * functions. - * @{ - */ - -void ruby_sysinit(int *argc, char ***argv); -void ruby_init(void); -void* ruby_options(int argc, char** argv); -int ruby_executable_node(void *n, int *status); -int ruby_run_node(void *n); - -/* version.c */ -void ruby_show_version(void); -#ifndef ruby_show_copyright -void ruby_show_copyright(void); -#endif - -/*! A convenience macro to call ruby_init_stack(). Must be placed just after - * variable declarations */ -#define RUBY_INIT_STACK \ - VALUE variable_in_this_stack_frame; \ - ruby_init_stack(&variable_in_this_stack_frame); -/*! @} */ - -void ruby_init_stack(volatile VALUE*); - -int ruby_setup(void); -int ruby_cleanup(volatile int); - -void ruby_finalize(void); - -RBIMPL_ATTR_NORETURN() -void ruby_stop(int); - -void ruby_set_stack_size(size_t); -int ruby_stack_check(void); -size_t ruby_stack_length(VALUE**); - -int ruby_exec_node(void *n); - -void ruby_script(const char* name); -void ruby_set_script_name(VALUE name); - -void ruby_prog_init(void); -void ruby_set_argv(int, char**); -void *ruby_process_options(int, char**); -void ruby_init_loadpath(void); -void ruby_incpush(const char*); -void ruby_sig_finalize(void); - -/*! @} */ - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_INTERPRETER_H */ diff --git a/include/ruby/impl/iterator.h b/include/ruby/impl/iterator.h deleted file mode 100644 index 980c6ebf7f..0000000000 --- a/include/ruby/impl/iterator.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef RBIMPL_ITERATOR_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_ITERATOR_H -/** - * @file - * @author Ruby developers - * @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 Block related APIs. - */ -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -#define RB_BLOCK_CALL_FUNC_STRICT 1 -#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1 -#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) \ - VALUE yielded_arg, VALUE callback_arg, int argc, const VALUE *argv, VALUE blockarg -typedef VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); -typedef rb_block_call_func *rb_block_call_func_t; - -VALUE rb_each(VALUE); -VALUE rb_yield(VALUE); -VALUE rb_yield_values(int n, ...); -VALUE rb_yield_values2(int n, const VALUE *argv); -VALUE rb_yield_values_kw(int n, const VALUE *argv, int kw_splat); -VALUE rb_yield_splat(VALUE); -VALUE rb_yield_splat_kw(VALUE, int); -VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); /* rb_block_call_func */ -int rb_keyword_given_p(void); -int rb_block_given_p(void); -void rb_need_block(void); -VALUE rb_iterate(VALUE(*)(VALUE),VALUE,rb_block_call_func_t,VALUE); -VALUE rb_block_call(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE); -VALUE rb_block_call_kw(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE,int); -VALUE rb_rescue(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE); -VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...); -VALUE rb_vrescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,va_list); -VALUE rb_ensure(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE),VALUE); -VALUE rb_catch(const char*,rb_block_call_func_t,VALUE); -VALUE rb_catch_obj(VALUE,rb_block_call_func_t,VALUE); - -RBIMPL_ATTR_NORETURN() -void rb_throw(const char*,VALUE); - -RBIMPL_ATTR_NORETURN() -void rb_throw_obj(VALUE,VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_ITERATOR_H */ diff --git a/include/ruby/impl/memory.h b/include/ruby/impl/memory.h deleted file mode 100644 index 8525cff96c..0000000000 --- a/include/ruby/impl/memory.h +++ /dev/null @@ -1,286 +0,0 @@ -#ifndef RBIMPL_MEMORY_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_MEMORY_H -/** - * @file - * @author Ruby developers - * @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 Memory management stuff. - */ -#include "ruby/impl/config.h" - -#ifdef STDC_HEADERS -# include -#endif - -#ifdef HAVE_STRING_H -# include -#endif - -#ifdef HAVE_STDINT_H -# include -#endif - -#ifdef HAVE_ALLOCA_H -# include -#endif - -#if defined(_MSC_VER) && defined(_WIN64) -# include -# pragma intrinsic(_umul128) -#endif - -#include "ruby/impl/attr/alloc_size.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/attr/noalias.h" -#include "ruby/impl/attr/nonnull.h" -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/attr/restrict.h" -#include "ruby/impl/attr/returns_nonnull.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/has/builtin.h" -#include "ruby/impl/stdalign.h" -#include "ruby/impl/stdbool.h" -#include "ruby/impl/xmalloc.h" -#include "ruby/backward/2/limits.h" -#include "ruby/backward/2/long_long.h" -#include "ruby/backward/2/assume.h" -#include "ruby/defines.h" - -/* Make alloca work the best possible way. */ -#if defined(alloca) -# /* Take that. */ -#elif RBIMPL_HAS_BUILTIN(__builtin_alloca) -# define alloca __builtin_alloca -#elif defined(_AIX) -# pragma alloca -#elif defined(__cplusplus) -extern "C" void *alloca(size_t); -#else -extern void *alloca(); -#endif - -#if defined(HAVE_INT128_T) && SIZEOF_SIZE_T <= 8 -# define DSIZE_T uint128_t -#elif SIZEOF_SIZE_T * 2 <= SIZEOF_LONG_LONG -# define DSIZE_T unsigned LONG_LONG -#endif - -#ifdef C_ALLOCA -# define RUBY_ALLOCV_LIMIT 0 -#else -# define RUBY_ALLOCV_LIMIT 1024 -#endif - -#ifdef __GNUC__ -#define RB_GC_GUARD(v) \ - (*__extension__ ({ \ - volatile VALUE *rb_gc_guarded_ptr = &(v); \ - __asm__("" : : "m"(rb_gc_guarded_ptr)); \ - rb_gc_guarded_ptr; \ - })) -#elif defined _MSC_VER -#define RB_GC_GUARD(v) (*rb_gc_guarded_ptr(&(v))) -#else -#define HAVE_RB_GC_GUARDED_PTR_VAL 1 -#define RB_GC_GUARD(v) (*rb_gc_guarded_ptr_val(&(v),(v))) -#endif - -/* Casts needed because void* is NOT compaible with others in C++. */ -#define RB_ALLOC_N(type,n) RBIMPL_CAST((type *)ruby_xmalloc2((n), sizeof(type))) -#define RB_ALLOC(type) RBIMPL_CAST((type *)ruby_xmalloc(sizeof(type))) -#define RB_ZALLOC_N(type,n) RBIMPL_CAST((type *)ruby_xcalloc((n), sizeof(type))) -#define RB_ZALLOC(type) (RB_ZALLOC_N(type, 1)) -#define RB_REALLOC_N(var,type,n) \ - ((var) = RBIMPL_CAST((type *)ruby_xrealloc2((void *)(var), (n), sizeof(type)))) - -/* I don't know why but __builtin_alloca_with_align's second argument - takes bits rather than bytes. */ -#if RBIMPL_HAS_BUILTIN(__builtin_alloca_with_align) -# define ALLOCA_N(type, n) \ - RBIMPL_CAST((type *) \ - __builtin_alloca_with_align( \ - rbimpl_size_mul_or_raise(sizeof(type), (n)), \ - RUBY_ALIGNOF(type) * CHAR_BIT)) -#else -# define ALLOCA_N(type,n) \ - RBIMPL_CAST((type *)alloca(rbimpl_size_mul_or_raise(sizeof(type), (n)))) -#endif - -/* allocates _n_ bytes temporary buffer and stores VALUE including it - * in _v_. _n_ may be evaluated twice. */ -#define RB_ALLOCV(v, n) \ - ((n) < RUBY_ALLOCV_LIMIT ? \ - ((v) = 0, alloca(n)) : \ - rb_alloc_tmp_buffer(&(v), (n))) -#define RB_ALLOCV_N(type, v, n) \ - RBIMPL_CAST((type *) \ - (((size_t)(n) < RUBY_ALLOCV_LIMIT / sizeof(type)) ? \ - ((v) = 0, alloca((n) * sizeof(type))) : \ - rb_alloc_tmp_buffer2(&(v), (n), sizeof(type)))) -#define RB_ALLOCV_END(v) rb_free_tmp_buffer(&(v)) - -#define MEMZERO(p,type,n) memset((p), 0, rbimpl_size_mul_or_raise(sizeof(type), (n))) -#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) -#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) -#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) - -#define ALLOC_N RB_ALLOC_N -#define ALLOC RB_ALLOC -#define ZALLOC_N RB_ZALLOC_N -#define ZALLOC RB_ZALLOC -#define REALLOC_N RB_REALLOC_N -#define ALLOCV RB_ALLOCV -#define ALLOCV_N RB_ALLOCV_N -#define ALLOCV_END RB_ALLOCV_END - -/* Expecting this struct to be eliminated by function inlinings */ -struct rbimpl_size_mul_overflow_tag { - bool left; - size_t right; -}; - -RBIMPL_SYMBOL_EXPORT_BEGIN() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((2)) -void *rb_alloc_tmp_buffer(volatile VALUE *store, long len); - -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((2,3)) -void *rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t len,size_t count); - -void rb_free_tmp_buffer(volatile VALUE *store); - -RBIMPL_ATTR_NORETURN() -void ruby_malloc_size_overflow(size_t, size_t); - -#ifdef HAVE_RB_GC_GUARDED_PTR_VAL -volatile VALUE *rb_gc_guarded_ptr_val(volatile VALUE *ptr, VALUE val); -#endif -RBIMPL_SYMBOL_EXPORT_END() - -#ifdef _MSC_VER -# pragma optimize("", off) - -static inline volatile VALUE * -rb_gc_guarded_ptr(volatile VALUE *ptr) -{ - return ptr; -} - -# pragma optimize("", on) -#endif - -/* Does anyone use it? Just here for backwards compatibility. */ -static inline int -rb_mul_size_overflow(size_t a, size_t b, size_t max, size_t *c) -{ -#ifdef DSIZE_T - RB_GNUC_EXTENSION DSIZE_T da, db, c2; - da = a; - db = b; - c2 = da * db; - if (c2 > max) return 1; - *c = RBIMPL_CAST((size_t)c2); -#else - if (b != 0 && a > max / b) return 1; - *c = a * b; -#endif - return 0; -} - -#if RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0) -RBIMPL_ATTR_CONSTEXPR(CXX14) /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70507 */ -#elif RBIMPL_COMPILER_SINCE(Clang, 7, 0, 0) -RBIMPL_ATTR_CONSTEXPR(CXX14) /* https://bugs.llvm.org/show_bug.cgi?id=37633 */ -#endif -RBIMPL_ATTR_CONST() -static inline struct rbimpl_size_mul_overflow_tag -rbimpl_size_mul_overflow(size_t x, size_t y) -{ - struct rbimpl_size_mul_overflow_tag ret = { false, 0, }; - -#if RBIMPL_HAS_BUILTIN(__builtin_mul_overflow) - ret.left = __builtin_mul_overflow(x, y, &ret.right); - -#elif defined(DSIZE_T) - RB_GNUC_EXTENSION DSIZE_T dx = x; - RB_GNUC_EXTENSION DSIZE_T dy = y; - RB_GNUC_EXTENSION DSIZE_T dz = dx * dy; - ret.left = dz > SIZE_MAX; - ret.right = RBIMPL_CAST((size_t)dz); - -#elif defined(_MSC_VER) && defined(_WIN64) - unsigned __int64 dp = 0; - unsigned __int64 dz = _umul128(x, y, &dp); - ret.left = RBIMPL_CAST((bool)dp); - ret.right = RBIMPL_CAST((size_t)dz); - -#else - /* https://wiki.sei.cmu.edu/confluence/display/c/INT30-C.+Ensure+that+unsigned+integer+operations+do+not+wrap */ - ret.left = (y != 0) && (x > SIZE_MAX / y); - ret.right = x * y; -#endif - - return ret; -} - -static inline size_t -rbimpl_size_mul_or_raise(size_t x, size_t y) -{ - struct rbimpl_size_mul_overflow_tag size = - rbimpl_size_mul_overflow(x, y); - - if (RB_LIKELY(! size.left)) { - return size.right; - } - else { - ruby_malloc_size_overflow(x, y); - RBIMPL_UNREACHABLE_RETURN(0); - } -} - -static inline void * -rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize) -{ - return rb_alloc_tmp_buffer_with_count( - store, rbimpl_size_mul_or_raise(count, elsize), count); -} - -RBIMPL_ATTR_NOALIAS() -RBIMPL_ATTR_NONNULL((1)) -RBIMPL_ATTR_RETURNS_NONNULL() -/* At least since 2004, glibc's annotates memcpy to be - * __attribute__((__nonnull__(1, 2))). However it is safe to pass NULL to the - * source pointer, if n is 0. Let's wrap memcpy. */ -static inline void * -ruby_nonempty_memcpy(void *dest, const void *src, size_t n) -{ - if (n) { - return memcpy(dest, src, n); - } - else { - return dest; - } -} -#undef memcpy -#define memcpy ruby_nonempty_memcpy - -#endif /* RBIMPL_MEMORY_H */ diff --git a/include/ruby/impl/method.h b/include/ruby/impl/method.h deleted file mode 100644 index fd2d9af070..0000000000 --- a/include/ruby/impl/method.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RBIMPL_METHOD_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_METHOD_H -/** - * @file - * @author Ruby developers - * @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 Creation and modification of Ruby methods. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/backward/2/stdarg.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int); -void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int); -void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int); - -void rb_undef_method(VALUE,const char*); -void rb_define_alias(VALUE,const char*,const char*); -void rb_define_attr(VALUE,const char*,int,int); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_METHOD_H */ diff --git a/include/ruby/impl/module.h b/include/ruby/impl/module.h deleted file mode 100644 index 8dc1988b5b..0000000000 --- a/include/ruby/impl/module.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RBIMPL_MODULE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_MODULE_H -/** - * @file - * @author Ruby developers - * @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 Creation and modification of Ruby modules. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -VALUE rb_define_class(const char*,VALUE); -VALUE rb_define_module(const char*); -VALUE rb_define_class_under(VALUE, const char*, VALUE); -VALUE rb_define_module_under(VALUE, const char*); - -void rb_include_module(VALUE,VALUE); -void rb_extend_object(VALUE,VALUE); -void rb_prepend_module(VALUE,VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_MODULE_H */ diff --git a/include/ruby/impl/newobj.h b/include/ruby/impl/newobj.h deleted file mode 100644 index 0f7e9ba06c..0000000000 --- a/include/ruby/impl/newobj.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef RBIMPL_NEWOBJ_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_NEWOBJ_H -/** - * @file - * @author Ruby developers - * @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 #NEWOBJ. - */ -#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/special_consts.h" -#include "ruby/impl/value.h" -#include "ruby/assert.h" - -#define RB_NEWOBJ(obj,type) type *(obj) = RBIMPL_CAST((type *)rb_newobj()) -#define RB_NEWOBJ_OF(obj,type,klass,flags) type *(obj) = RBIMPL_CAST((type *)rb_newobj_of(klass, flags)) - -#define NEWOBJ RB_NEWOBJ -#define NEWOBJ_OF RB_NEWOBJ_OF /* core has special NEWOBJ_OF() in internal.h */ -#define OBJSETUP rb_obj_setup /* use NEWOBJ_OF instead of NEWOBJ()+OBJSETUP() */ -#define CLONESETUP rb_clone_setup -#define DUPSETUP rb_dup_setup - -RBIMPL_SYMBOL_EXPORT_BEGIN() -VALUE rb_newobj(void); -VALUE rb_newobj_of(VALUE, VALUE); -VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type); -VALUE rb_obj_class(VALUE); -VALUE rb_singleton_class_clone(VALUE); -void rb_singleton_class_attached(VALUE,VALUE); -void rb_copy_generic_ivar(VALUE,VALUE); -RBIMPL_SYMBOL_EXPORT_END() - -static inline void -rb_clone_setup(VALUE clone, VALUE obj) -{ - RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); - RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(clone)); - - const VALUE flags = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1 | RUBY_FL_FINALIZE; - rb_obj_setup(clone, rb_singleton_class_clone(obj), - RB_FL_TEST_RAW(obj, ~flags)); - rb_singleton_class_attached(RBASIC_CLASS(clone), clone); - if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(clone, obj); -} - -static inline void -rb_dup_setup(VALUE dup, VALUE obj) -{ - RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); - RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(dup)); - - rb_obj_setup(dup, rb_obj_class(obj), RB_FL_TEST_RAW(obj, RUBY_FL_DUPPED)); - if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(dup, obj); -} - -#endif /* RBIMPL_NEWOBJ_H */ diff --git a/include/ruby/impl/rgengc.h b/include/ruby/impl/rgengc.h deleted file mode 100644 index 34096455fb..0000000000 --- a/include/ruby/impl/rgengc.h +++ /dev/null @@ -1,199 +0,0 @@ -#ifndef RBIMPL_RGENGC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_RGENGC_H -/** - * @file - * @author Ruby developers - * @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 RGENGC write-barrier APIs. - * @see Sasada, K., "Gradual write-barrier insertion into a Ruby - * interpreter", in proceedings of the 2019 ACM SIGPLAN - * International Symposium on Memory Management (ISMM 2019), pp - * 115-121, 2019. https://doi.org/10.1145/3315573.3329986 - */ -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/special_consts.h" -#include "ruby/impl/stdbool.h" -#include "ruby/impl/value.h" -#include "ruby/assert.h" -#include "ruby/backward/2/attributes.h" - -#undef USE_RGENGC -#define USE_RGENGC 1 - -#ifndef USE_RINCGC -# define USE_RINCGC 1 -#endif - -#ifndef USE_RGENGC_LOGGING_WB_UNPROTECT -# define USE_RGENGC_LOGGING_WB_UNPROTECT 0 -#endif - -#ifndef RGENGC_WB_PROTECTED_ARRAY -# define RGENGC_WB_PROTECTED_ARRAY 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_HASH -# define RGENGC_WB_PROTECTED_HASH 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_STRUCT -# define RGENGC_WB_PROTECTED_STRUCT 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_STRING -# define RGENGC_WB_PROTECTED_STRING 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_OBJECT -# define RGENGC_WB_PROTECTED_OBJECT 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_REGEXP -# define RGENGC_WB_PROTECTED_REGEXP 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_CLASS -# define RGENGC_WB_PROTECTED_CLASS 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_FLOAT -# define RGENGC_WB_PROTECTED_FLOAT 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_COMPLEX -# define RGENGC_WB_PROTECTED_COMPLEX 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_RATIONAL -# define RGENGC_WB_PROTECTED_RATIONAL 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_BIGNUM -# define RGENGC_WB_PROTECTED_BIGNUM 1 -#endif - -#ifndef RGENGC_WB_PROTECTED_NODE_CREF -# define RGENGC_WB_PROTECTED_NODE_CREF 1 -#endif - -/** - * @name Write barrier (WB) interfaces: - * @{ - * - * @note The following core interfaces can be changed in the future. Please - * catch up if you want to insert WB into C-extensions correctly. - */ - -/** - * WB for new reference from `a' to `b'. Write `b' into `*slot'. `slot' is a - * pointer in `a'. - */ -#define RB_OBJ_WRITE(a, slot, b) \ - RBIMPL_CAST(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)) -/** - * WB for new reference from `a' to `b'. This doesn't write any values, but - * only a WB declaration. `oldv' is replaced value with `b' (not used in - * current Ruby). - */ -#define RB_OBJ_WRITTEN(a, oldv, b) \ - RBIMPL_CAST(rb_obj_written((VALUE)(a), (VALUE)(oldv), (VALUE)(b), __FILE__, __LINE__)) -/** @} */ - -#define OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW -#define OBJ_PROMOTED RB_OBJ_PROMOTED -#define OBJ_WB_UNPROTECT RB_OBJ_WB_UNPROTECT - -#define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__) -#define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \ - (RGENGC_WB_PROTECTED_##type ? OBJ_WB_UNPROTECT(obj) : obj) -#define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging - -/** @cond INTERNAL_MACRO */ -#define RB_OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW -#define RB_OBJ_PROMOTED RB_OBJ_PROMOTED -/** @endcond */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() -void rb_gc_writebarrier(VALUE a, VALUE b); -void rb_gc_writebarrier_unprotect(VALUE obj); -#if USE_RGENGC_LOGGING_WB_UNPROTECT -void rb_gc_unprotect_logging(void *objptr, const char *filename, int line); -#endif -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_OBJ_PROMOTED_RAW(VALUE obj) -{ - RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); - return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_OBJ_PROMOTED(VALUE obj) -{ - if (! RB_FL_ABLE(obj)) { - return false; - } - else { - return RB_OBJ_PROMOTED_RAW(obj); - } -} - -static inline VALUE -rb_obj_wb_unprotect(VALUE x, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) -{ -#if USE_RGENGC_LOGGING_WB_UNPROTECT - RGENGC_LOGGING_WB_UNPROTECT(RBIMPL_CAST((void *)x), filename, line); -#endif - rb_gc_writebarrier_unprotect(x); - return x; -} - -static inline VALUE -rb_obj_written(VALUE a, RB_UNUSED_VAR(VALUE oldv), VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) -{ -#if USE_RGENGC_LOGGING_WB_UNPROTECT - RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line); -#endif - - if (!RB_SPECIAL_CONST_P(b)) { - rb_gc_writebarrier(a, b); - } - - return a; -} - -static inline VALUE -rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) -{ -#ifdef RGENGC_LOGGING_WRITE - RGENGC_LOGGING_WRITE(a, slot, b, filename, line); -#endif - - *slot = b; - - rb_obj_written(a, RUBY_Qundef /* ignore `oldv' now */, b, filename, line); - return a; -} - -#endif /* RBIMPL_RGENGC_H */ diff --git a/include/ruby/impl/scan_args.h b/include/ruby/impl/scan_args.h deleted file mode 100644 index ca31786175..0000000000 --- a/include/ruby/impl/scan_args.h +++ /dev/null @@ -1,394 +0,0 @@ -#ifndef RBIMPL_SCAN_ARGS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_SCAN_ARGS_H -/** - * @file - * @author Ruby developers - * @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 Compile-time static implementation of ::rb_scan_args(). - * - * This is a beast. It statically analyses the argument spec string, and - * expands the assignment of variables into dedicated codes. - */ -#include "ruby/impl/attr/diagnose_if.h" -#include "ruby/impl/attr/error.h" -#include "ruby/impl/attr/forceinline.h" -#include "ruby/impl/attr/noreturn.h" -#include "ruby/impl/config.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/intern/array.h" /* rb_ary_new_from_values */ -#include "ruby/impl/intern/error.h" /* rb_error_arity */ -#include "ruby/impl/intern/hash.h" /* rb_hash_dup */ -#include "ruby/impl/intern/proc.h" /* rb_block_proc */ -#include "ruby/impl/iterator.h" /* rb_block_given_p / rb_keyword_given_p */ -#include "ruby/impl/static_assert.h" -#include "ruby/impl/stdbool.h" -#include "ruby/impl/value.h" -#include "ruby/assert.h" - -#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS 0 -#define RB_SCAN_ARGS_KEYWORDS 1 -#define RB_SCAN_ARGS_LAST_HASH_KEYWORDS 3 -#define RB_NO_KEYWORDS 0 -#define RB_PASS_KEYWORDS 1 -#define RB_PASS_CALLED_KEYWORDS rb_keyword_given_p() -/* rb_scan_args() format allows ':' for optional hash */ -#define HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1 - -RBIMPL_SYMBOL_EXPORT_BEGIN() -int rb_scan_args(int, const VALUE*, const char*, ...); -int rb_scan_args_kw(int, int, const VALUE*, const char*, ...); - -RBIMPL_ATTR_ERROR(("bad scan arg format")) -void rb_scan_args_bad_format(const char*); - -RBIMPL_ATTR_ERROR(("variable argument length doesn't match")) -void rb_scan_args_length_mismatch(const char*,int); - -RBIMPL_SYMBOL_EXPORT_END() - -/* If we could use constexpr the following macros could be inline functions - * ... but sadly we cannot. */ - -#define rb_scan_args_isdigit(c) (RBIMPL_CAST((unsigned char)((c)-'0'))<10) - -#define rb_scan_args_count_end(fmt, ofs, vari) \ - ((fmt)[ofs] ? -1 : (vari)) - -#define rb_scan_args_count_block(fmt, ofs, vari) \ - ((fmt)[ofs]!='&' ? \ - rb_scan_args_count_end(fmt, ofs, vari) : \ - rb_scan_args_count_end(fmt, (ofs)+1, (vari)+1)) - -#define rb_scan_args_count_hash(fmt, ofs, vari) \ - ((fmt)[ofs]!=':' ? \ - rb_scan_args_count_block(fmt, ofs, vari) : \ - rb_scan_args_count_block(fmt, (ofs)+1, (vari)+1)) - -#define rb_scan_args_count_trail(fmt, ofs, vari) \ - (!rb_scan_args_isdigit((fmt)[ofs]) ? \ - rb_scan_args_count_hash(fmt, ofs, vari) : \ - rb_scan_args_count_hash(fmt, (ofs)+1, (vari)+((fmt)[ofs]-'0'))) - -#define rb_scan_args_count_var(fmt, ofs, vari) \ - ((fmt)[ofs]!='*' ? \ - rb_scan_args_count_trail(fmt, ofs, vari) : \ - rb_scan_args_count_trail(fmt, (ofs)+1, (vari)+1)) - -#define rb_scan_args_count_opt(fmt, ofs, vari) \ - (!rb_scan_args_isdigit((fmt)[ofs]) ? \ - rb_scan_args_count_var(fmt, ofs, vari) : \ - rb_scan_args_count_var(fmt, (ofs)+1, (vari)+(fmt)[ofs]-'0')) - -#define rb_scan_args_count_lead(fmt, ofs, vari) \ - (!rb_scan_args_isdigit((fmt)[ofs]) ? \ - rb_scan_args_count_var(fmt, ofs, vari) : \ - rb_scan_args_count_opt(fmt, (ofs)+1, (vari)+(fmt)[ofs]-'0')) - -#define rb_scan_args_count(fmt) rb_scan_args_count_lead(fmt, 0, 0) - -#if RBIMPL_HAS_ATTRIBUTE(diagnose_if) -# /* Assertions done in the attribute. */ -# define rb_scan_args_verify(fmt, varc) RBIMPL_ASSERT_NOTHING -#else -# /* At one sight it _seems_ the expressions below could be written using -# * static assrtions. The reality is no, they don't. Because fmt is a string -# * literal, any operations against fmt cannot produce the "integer constant -# * expression"s, as defined in ISO/IEC 9899:2018 section 6.6 paragraph #6. -# * Static assertions need such integer constant expressions as defined in -# * ISO/IEC 9899:2018 section 6.7.10 paragraph #3. -# * -# * GCC nonetheless constant-folds this into no-op, though. */ -# define rb_scan_args_verify(fmt, varc) \ - (sizeof(char[1-2*(rb_scan_args_count(fmt)<0)])!=1 ? \ - rb_scan_args_bad_format(fmt) : \ - sizeof(char[1-2*(rb_scan_args_count(fmt)!=(varc))])!=1 ? \ - rb_scan_args_length_mismatch(fmt, varc) : \ - RBIMPL_ASSERT_NOTHING) -#endif - -static inline bool -rb_scan_args_keyword_p(int kw_flag, VALUE last) -{ - switch (kw_flag) { - case RB_SCAN_ARGS_PASS_CALLED_KEYWORDS: - return !! rb_keyword_given_p(); - case RB_SCAN_ARGS_KEYWORDS: - return true; - case RB_SCAN_ARGS_LAST_HASH_KEYWORDS: - return RB_TYPE_P(last, T_HASH); - default: - return false; - } -} - -RBIMPL_ATTR_FORCEINLINE() -static bool -rb_scan_args_lead_p(const char *fmt) -{ - return rb_scan_args_isdigit(fmt[0]); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_n_lead(const char *fmt) -{ - return (rb_scan_args_lead_p(fmt) ? fmt[0]-'0' : 0); -} - -RBIMPL_ATTR_FORCEINLINE() -static bool -rb_scan_args_opt_p(const char *fmt) -{ - return (rb_scan_args_lead_p(fmt) && rb_scan_args_isdigit(fmt[1])); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_n_opt(const char *fmt) -{ - return (rb_scan_args_opt_p(fmt) ? fmt[1]-'0' : 0); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_var_idx(const char *fmt) -{ - return (!rb_scan_args_lead_p(fmt) ? 0 : !rb_scan_args_isdigit(fmt[1]) ? 1 : 2); -} - -RBIMPL_ATTR_FORCEINLINE() -static bool -rb_scan_args_f_var(const char *fmt) -{ - return (fmt[rb_scan_args_var_idx(fmt)]=='*'); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_trail_idx(const char *fmt) -{ - const int idx = rb_scan_args_var_idx(fmt); - return idx+(fmt[idx]=='*'); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_n_trail(const char *fmt) -{ - const int idx = rb_scan_args_trail_idx(fmt); - return (rb_scan_args_isdigit(fmt[idx]) ? fmt[idx]-'0' : 0); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_hash_idx(const char *fmt) -{ - const int idx = rb_scan_args_trail_idx(fmt); - return idx+rb_scan_args_isdigit(fmt[idx]); -} - -RBIMPL_ATTR_FORCEINLINE() -static bool -rb_scan_args_f_hash(const char *fmt) -{ - return (fmt[rb_scan_args_hash_idx(fmt)]==':'); -} - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_block_idx(const char *fmt) -{ - const int idx = rb_scan_args_hash_idx(fmt); - return idx+(fmt[idx]==':'); -} - -RBIMPL_ATTR_FORCEINLINE() -static bool -rb_scan_args_f_block(const char *fmt) -{ - return (fmt[rb_scan_args_block_idx(fmt)]=='&'); -} - -# if 0 -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_end_idx(const char *fmt) -{ - const int idx = rb_scan_args_block_idx(fmt); - return idx+(fmt[idx]=='&'); -} -# endif - -/* NOTE: Use `char *fmt` instead of `const char *fmt` because of clang's bug*/ -/* https://bugs.llvm.org/show_bug.cgi?id=38095 */ -# define rb_scan_args0(argc, argv, fmt, varc, vars) \ - rb_scan_args_set(RB_SCAN_ARGS_PASS_CALLED_KEYWORDS, argc, argv, \ - rb_scan_args_n_lead(fmt), \ - rb_scan_args_n_opt(fmt), \ - rb_scan_args_n_trail(fmt), \ - rb_scan_args_f_var(fmt), \ - rb_scan_args_f_hash(fmt), \ - rb_scan_args_f_block(fmt), \ - (rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc) -# define rb_scan_args_kw0(kw_flag, argc, argv, fmt, varc, vars) \ - rb_scan_args_set(kw_flag, argc, argv, \ - rb_scan_args_n_lead(fmt), \ - rb_scan_args_n_opt(fmt), \ - rb_scan_args_n_trail(fmt), \ - rb_scan_args_f_var(fmt), \ - rb_scan_args_f_hash(fmt), \ - rb_scan_args_f_block(fmt), \ - (rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc) - -RBIMPL_ATTR_FORCEINLINE() -static int -rb_scan_args_set(int kw_flag, int argc, const VALUE *argv, - int n_lead, int n_opt, int n_trail, - bool f_var, bool f_hash, bool f_block, - VALUE *vars[], RB_UNUSED_VAR(const char *fmt), RB_UNUSED_VAR(int varc)) - RBIMPL_ATTR_DIAGNOSE_IF(rb_scan_args_count(fmt) < 0, "bad scan arg format", "error") - RBIMPL_ATTR_DIAGNOSE_IF(rb_scan_args_count(fmt) != varc, "variable argument length doesn't match", "error") -{ - int i, argi = 0, vari = 0; - VALUE *var, hash = Qnil; -#define rb_scan_args_next_param() vars[vari++] - const int n_mand = n_lead + n_trail; - - if (f_hash && argc > 0) { - VALUE last = argv[argc - 1]; - if (rb_scan_args_keyword_p(kw_flag, last)) { - hash = rb_hash_dup(last); - argc--; - } - } - - if (argc < n_mand) { - goto argc_error; - } - - /* capture leading mandatory arguments */ - for (i = n_lead; i-- > 0; ) { - var = rb_scan_args_next_param(); - if (var) *var = argv[argi]; - argi++; - } - /* capture optional arguments */ - for (i = n_opt; i-- > 0; ) { - var = rb_scan_args_next_param(); - if (argi < argc - n_trail) { - if (var) *var = argv[argi]; - argi++; - } - else { - if (var) *var = Qnil; - } - } - /* capture variable length arguments */ - if (f_var) { - int n_var = argc - argi - n_trail; - - var = rb_scan_args_next_param(); - if (0 < n_var) { - if (var) *var = rb_ary_new_from_values(n_var, &argv[argi]); - argi += n_var; - } - else { - if (var) *var = rb_ary_new(); - } - } - /* capture trailing mandatory arguments */ - for (i = n_trail; i-- > 0; ) { - var = rb_scan_args_next_param(); - if (var) *var = argv[argi]; - argi++; - } - /* capture an option hash - phase 2: assignment */ - if (f_hash) { - var = rb_scan_args_next_param(); - if (var) *var = hash; - } - /* capture iterator block */ - if (f_block) { - var = rb_scan_args_next_param(); - if (rb_block_given_p()) { - *var = rb_block_proc(); - } - else { - *var = Qnil; - } - } - - if (argi < argc) { - argc_error: - rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt); - } - - return argc; -#undef rb_scan_args_next_param -} - -#if ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) -# /* skip */ - -#elif ! defined(HAVE_VA_ARGS_MACRO) -# /* skip */ - -#elif ! defined(__OPTIMIZE__) -# /* skip */ - -#elif defined(HAVE___VA_OPT__) -# define rb_scan_args(argc, argvp, fmt, ...) \ - __builtin_choose_expr( \ - __builtin_constant_p(fmt), \ - rb_scan_args0( \ - argc, argvp, fmt, \ - (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ - ((VALUE*[]){__VA_ARGS__})), \ - (rb_scan_args)(argc, argvp, fmt __VA_OPT__(, __VA_ARGS__))) -# define rb_scan_args_kw(kw_flag, argc, argvp, fmt, ...) \ - __builtin_choose_expr( \ - __builtin_constant_p(fmt), \ - rb_scan_args_kw0( \ - kw_flag, argc, argvp, fmt, \ - (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ - ((VALUE*[]){__VA_ARGS__})), \ - (rb_scan_args_kw)(kw_flag, argc, argvp, fmt __VA_OPT__(, __VA_ARGS__))) - -#elif defined(__STRICT_ANSI__) -# /* skip */ - -#elif defined(__GNUC__) -# define rb_scan_args(argc, argvp, fmt, ...) \ - __builtin_choose_expr( \ - __builtin_constant_p(fmt), \ - rb_scan_args0( \ - argc, argvp, fmt, \ - (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ - ((VALUE*[]){__VA_ARGS__})), \ - (rb_scan_args)(argc, argvp, fmt, __VA_ARGS__)) -# define rb_scan_args_kw(kw_flag, argc, argvp, fmt, ...) \ - __builtin_choose_expr( \ - __builtin_constant_p(fmt), \ - rb_scan_args_kw0( \ - kw_flag, argc, argvp, fmt, \ - (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ - ((VALUE*[]){__VA_ARGS__})), \ - (rb_scan_args_kw)(kw_flag, argc, argvp, fmt, __VA_ARGS__ /**/)) -#endif - -#endif /* RBIMPL_SCAN_ARGS_H */ diff --git a/include/ruby/impl/special_consts.h b/include/ruby/impl/special_consts.h deleted file mode 100644 index 5fb3b8eb94..0000000000 --- a/include/ruby/impl/special_consts.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef RBIMPL_SPECIAL_CONSTS_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_SPECIAL_CONSTS_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines enum ::ruby_special_consts. - * @see Sasada, K., "A Lighweight Representation of Floting-Point - * Numbers on Ruby Interpreter", in proceedings of 10th JSSST - * SIGPPL Workshop on Programming and Programming Languages - * (PPL2008), pp. 9-16, 2008. - */ -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/const.h" -#include "ruby/impl/attr/constexpr.h" -#include "ruby/impl/attr/enum_extensibility.h" -#include "ruby/impl/stdbool.h" -#include "ruby/impl/value.h" - -#if defined(USE_FLONUM) -# /* Take that. */ -#elif SIZEOF_VALUE >= SIZEOF_DOUBLE -# define USE_FLONUM 1 -#else -# define USE_FLONUM 0 -#endif - -#define RTEST RB_TEST - -#define FIXNUM_P RB_FIXNUM_P -#define IMMEDIATE_P RB_IMMEDIATE_P -#define NIL_P RB_NIL_P -#define SPECIAL_CONST_P RB_SPECIAL_CONST_P -#define STATIC_SYM_P RB_STATIC_SYM_P - -#define Qfalse RUBY_Qfalse -#define Qnil RUBY_Qnil -#define Qtrue RUBY_Qtrue -#define Qundef RUBY_Qundef - -/** @cond INTERNAL_MACRO */ -#define FIXNUM_FLAG RUBY_FIXNUM_FLAG -#define FLONUM_FLAG RUBY_FLONUM_FLAG -#define FLONUM_MASK RUBY_FLONUM_MASK -#define FLONUM_P RB_FLONUM_P -#define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK -#define SYMBOL_FLAG RUBY_SYMBOL_FLAG - -#define RB_FIXNUM_P RB_FIXNUM_P -#define RB_FLONUM_P RB_FLONUM_P -#define RB_IMMEDIATE_P RB_IMMEDIATE_P -#define RB_NIL_P RB_NIL_P -#define RB_SPECIAL_CONST_P RB_SPECIAL_CONST_P -#define RB_STATIC_SYM_P RB_STATIC_SYM_P -#define RB_TEST RB_TEST -/** @endcond */ - -/** special constants - i.e. non-zero and non-fixnum constants */ -enum -RBIMPL_ATTR_ENUM_EXTENSIBILITY(closed) -ruby_special_consts { -#if USE_FLONUM - RUBY_Qfalse = 0x00, /* ...0000 0000 */ - RUBY_Qtrue = 0x14, /* ...0001 0100 */ - RUBY_Qnil = 0x08, /* ...0000 1000 */ - RUBY_Qundef = 0x34, /* ...0011 0100 */ - RUBY_IMMEDIATE_MASK = 0x07, /* ...0000 0111 */ - RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ - RUBY_FLONUM_MASK = 0x03, /* ...0000 0011 */ - RUBY_FLONUM_FLAG = 0x02, /* ...xxxx xx10 */ - RUBY_SYMBOL_FLAG = 0x0c, /* ...xxxx 1100 */ -#else - RUBY_Qfalse = 0x00, /* ...0000 0000 */ - RUBY_Qtrue = 0x02, /* ...0000 0010 */ - RUBY_Qnil = 0x04, /* ...0000 0100 */ - RUBY_Qundef = 0x06, /* ...0000 0110 */ - RUBY_IMMEDIATE_MASK = 0x03, /* ...0000 0011 */ - RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ - RUBY_FLONUM_MASK = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */ - RUBY_FLONUM_FLAG = 0x02, /* ...0000 0010 */ - RUBY_SYMBOL_FLAG = 0x0e, /* ...0000 1110 */ -#endif - - RUBY_SPECIAL_SHIFT = 8 /** Least significant 8 bits are reserved. */ -}; - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -/* - * :NOTE: rbimpl_test HAS to be `__attribute__((const))` in order for clang to - * properly deduce `__builtin_assume()`. - */ -static inline bool -RB_TEST(VALUE obj) -{ - /* - * Qfalse: ....0000 0000 - * Qnil: ....0000 1000 - * ~Qnil: ....1111 0111 - * v ....xxxx xxxx - * ---------------------------- - * RTEST(v) ....xxxx 0xxx - * - * RTEST(v) can be 0 if and only if (v == Qfalse || v == Qnil). - */ - return obj & ~RUBY_Qnil; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_NIL_P(VALUE obj) -{ - return obj == RUBY_Qnil; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FIXNUM_P(VALUE obj) -{ - return obj & RUBY_FIXNUM_FLAG; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX14) -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_STATIC_SYM_P(VALUE obj) -{ - RBIMPL_ATTR_CONSTEXPR(CXX14) - const VALUE mask = ~(RBIMPL_VALUE_FULL << RUBY_SPECIAL_SHIFT); - return (obj & mask) == RUBY_SYMBOL_FLAG; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FLONUM_P(VALUE obj) -{ -#if USE_FLONUM - return (obj & RUBY_FLONUM_MASK) == RUBY_FLONUM_FLAG; -#else - return false; -#endif -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_IMMEDIATE_P(VALUE obj) -{ - return obj & RUBY_IMMEDIATE_MASK; -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_SPECIAL_CONST_P(VALUE obj) -{ - return RB_IMMEDIATE_P(obj) || ! RB_TEST(obj); -} - -RBIMPL_ATTR_CONST() -RBIMPL_ATTR_CONSTEXPR(CXX11) -/* This function is to mimic old rb_special_const_p macro but have anyone - * actually used its return value? Wasn't it just something no one needed? */ -static inline VALUE -rb_special_const_p(VALUE obj) -{ - return RB_SPECIAL_CONST_P(obj) * RUBY_Qtrue; -} - -/** - * @cond INTERNAL_MACRO - * See [ruby-dev:27513] for the following macros. - */ -#define RUBY_Qfalse RBIMPL_CAST((VALUE)RUBY_Qfalse) -#define RUBY_Qtrue RBIMPL_CAST((VALUE)RUBY_Qtrue) -#define RUBY_Qnil RBIMPL_CAST((VALUE)RUBY_Qnil) -#define RUBY_Qundef RBIMPL_CAST((VALUE)RUBY_Qundef) -/** @endcond */ - -#endif /* RBIMPL_SPECIAL_CONSTS_H */ diff --git a/include/ruby/impl/static_assert.h b/include/ruby/impl/static_assert.h deleted file mode 100644 index e7788ab31a..0000000000 --- a/include/ruby/impl/static_assert.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef RBIMPL_STATIC_ASSERT_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_STATIC_ASSERT_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_STATIC_ASSERT. - */ -#include -#include "ruby/impl/has/extension.h" -#include "ruby/impl/compiler_since.h" - -/** @cond INTERNAL_MACRO */ -#if defined(__cplusplus) && defined(__cpp_static_assert) -# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ -# define RBIMPL_STATIC_ASSERT0 static_assert - -#elif defined(__cplusplus) && RBIMPL_COMPILER_SINCE(MSVC, 16, 0, 0) -# define RBIMPL_STATIC_ASSERT0 static_assert - -#elif defined(__INTEL_CXX11_MODE__) -# define RBIMPL_STATIC_ASSERT0 static_assert - -#elif defined(__cplusplus) && __cplusplus >= 201103L -# define RBIMPL_STATIC_ASSERT0 static_assert - -#elif defined(__cplusplus) && RBIMPL_HAS_EXTENSION(cxx_static_assert) -# define RBIMPL_STATIC_ASSERT0 __extension__ static_assert - -#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ -# define RBIMPL_STATIC_ASSERT0 __extension__ static_assert - -#elif defined(__STDC_VERSION__) && RBIMPL_HAS_EXTENSION(c_static_assert) -# define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert - -#elif defined(__STDC_VERSION__) && RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) -# define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert - -#elif defined(static_assert) -# /* Take definition */ -# define RBIMPL_STATIC_ASSERT0 static_assert -#endif -/** @endcond */ - -/** - * @brief Wraps (or simulates) `static_assert` - * @param name Valid C/C++ identifier, describing the assertion. - * @param expr Expression to assert. - * @note `name` shall not be a string literal. - */ -#if defined(__DOXYGEN__) -# define RBIMPL_STATIC_ASSERT static_assert - -#elif defined(RBIMPL_STATIC_ASSERT0) -# define RBIMPL_STATIC_ASSERT(name, expr) \ - RBIMPL_STATIC_ASSERT0(expr, # name ": " # expr) - -#else -# define RBIMPL_STATIC_ASSERT(name, expr) \ - typedef int static_assert_ ## name ## _check[1 - 2 * !(expr)] -#endif - -#endif /* RBIMPL_STATIC_ASSERT_H */ diff --git a/include/ruby/impl/stdalign.h b/include/ruby/impl/stdalign.h deleted file mode 100644 index a3dcfb90ef..0000000000 --- a/include/ruby/impl/stdalign.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef RBIMPL_STDALIGN_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_STDALIGN_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_ALIGNAS / #RBIMPL_ALIGNOF - */ -#include "ruby/impl/config.h" - -#ifdef HAVE_STDALIGN_H -# include -#endif - -#include "ruby/impl/compiler_is.h" -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/feature.h" -#include "ruby/impl/has/extension.h" -#include "ruby/impl/has/attribute.h" -#include "ruby/impl/has/declspec_attribute.h" - -/** - * Wraps (or simulates) `alignas`. This is C++11's `alignas` and is _different_ - * from C11 `_Alignas`. For instance, - * - * ```CXX - * typedef struct alignas(128) foo { int foo } foo; - * ``` - * - * is a valid C++ while - * - * ```C - * typedef struct _Alignas(128) foo { int foo } foo; - * ``` - * - * is an invalid C because: - * - * - You cannot `struct _Alignas`. - * - A `typedef` cannot have alignments. - */ -#if defined(__cplusplus) && RBIMPL_HAS_FEATURE(cxx_alignas) -# define RBIMPL_ALIGNAS alignas - -#elif defined(__cplusplus) && (__cplusplus >= 201103L) -# define RBIMPL_ALIGNAS alignas - -#elif defined(__INTEL_CXX11_MODE__) -# define RBIMPL_ALIGNAS alignas - -#elif defined(__GXX_EXPERIMENTAL_CXX0X__) -# define RBIMPL_ALIGNAS alignas - -#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(align) -# define RBIMPL_ALIGNAS(_) __declspec(align(_)) - -#elif RBIMPL_HAS_ATTRIBUTE(aliged) -# define RBIMPL_ALIGNAS(_) __attribute__((__aligned__(_))) - -#else -# define RBIMPL_ALIGNAS(_) /* void */ -#endif - -/** - * Wraps (or simulates) `alignof`. Unlike #RBIMPL_ALIGNAS, we can safely say - * both C/C++ definitions are effective. - */ -#if defined(__cplusplus) && RBIMPL_HAS_EXTENSION(cxx_alignof) -# define RBIMPL_ALIGNOF __extension__ alignof - -#elif defined(__cplusplus) && (__cplusplus >= 201103L) -# define RBIMPL_ALIGNOF alignof - -#elif defined(__INTEL_CXX11_MODE__) -# define RBIMPL_ALIGNOF alignof - -#elif defined(__GXX_EXPERIMENTAL_CXX0X__) -# define RBIMPL_ALIGNOF alignof - -#elif defined(__STDC_VERSION__) && RBIMPL_HAS_EXTENSION(c_alignof) -# define RBIMPL_ALIGNOF __extension__ _Alignof - -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define RBIMPL_ALIGNOF _Alignof - -#elif RBIMPL_COMPILER_IS(MSVC) -# define RBIMPL_ALIGNOF __alignof - -#elif defined(__GNUC__) -# /* At least GCC 2.95 had this. */ -# define RBIMPL_ALIGNOF __extension__ __alignof__ - -#elif defined(__alignof_is_defined) || defined(__DOXYGEN__) -# /* OK, we can safely take definition. */ -# define RBIMPL_ALIGNOF alignof - -#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) -# /* According to their manual, Sun Studio 12 introduced __alignof__ for both -# * C/C++. */ -# define RBIMPL_ALIGNOF __alignof__ - -#elif 0 -# /* THIS IS NG, you cannot define a new type inside of offsetof. */ -# /* see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm */ -# define RBIMPL_ALIGNOF(T) offsetof(struct { char _; T t; }, t) - -#else -# error :FIXME: add your compiler here to obtain an alignment. -#endif - -#endif /* RBIMPL_STDALIGN_H */ diff --git a/include/ruby/impl/stdbool.h b/include/ruby/impl/stdbool.h deleted file mode 100644 index 36ccaa0c6f..0000000000 --- a/include/ruby/impl/stdbool.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef RBIMPL_STDBOOL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_STDBOOL_H -/** - * @file - * @author Ruby developers - * @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 C99 shim for - */ -#include "ruby/impl/config.h" - -#if defined(__bool_true_false_are_defined) -# /* Take that. */ - -#elif defined(__cplusplus) -# /* bool is a keyword in C++. */ -# if defined(HAVE_STDBOOL_H) && (__cplusplus >= 201103L) -# include -# endif -# -# ifndef __bool_true_false_are_defined -# define __bool_true_false_are_defined -# endif - -#elif defined(HAVE_STDBOOL_H) -# /* Take stdbool.h definition. */ -# include - -#else -typedef unsigned char _Bool; -# /* See also http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2229.htm */ -# define bool _Bool -# define true ((_Bool)+1) -# define false ((_Bool)+0) -# define __bool_true_false_are_defined -#endif - -#endif /* RBIMPL_STDBOOL_H */ diff --git a/include/ruby/impl/symbol.h b/include/ruby/impl/symbol.h deleted file mode 100644 index a7b2358894..0000000000 --- a/include/ruby/impl/symbol.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef RBIMPL_SYMBOL_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_SYMBOL_H -/** - * @file - * @author Ruby developers - * @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 #rb_intern - */ -#include "ruby/impl/config.h" - -#ifdef HAVE_STDDEF_H -# include -#endif - -#ifdef HAVE_STRING_H -# include -#endif - -#include "ruby/impl/attr/nonnull.h" -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/attr/noalias.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/constant_p.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/has/builtin.h" -#include "ruby/impl/value.h" - -#define RB_ID2SYM rb_id2sym -#define RB_SYM2ID rb_sym2id -#define ID2SYM RB_ID2SYM -#define SYM2ID RB_SYM2ID -#define CONST_ID_CACHE RUBY_CONST_ID_CACHE -#define CONST_ID RUBY_CONST_ID - -/** @cond INTERNAL_MACRO */ -#define rb_intern_const rb_intern_const -/** @endcond */ - -RBIMPL_SYMBOL_EXPORT_BEGIN() -ID rb_sym2id(VALUE); -VALUE rb_id2sym(ID); -ID rb_intern(const char*); -ID rb_intern2(const char*, long); -ID rb_intern_str(VALUE str); -const char *rb_id2name(ID); -ID rb_check_id(volatile VALUE *); -ID rb_to_id(VALUE); -VALUE rb_id2str(ID); -VALUE rb_sym2str(VALUE); -VALUE rb_to_symbol(VALUE name); -VALUE rb_check_symbol(volatile VALUE *namep); -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_PURE() -RBIMPL_ATTR_NONNULL(()) -static inline ID -rb_intern_const(const char *str) -{ - size_t len = strlen(str); - return rb_intern2(str, RBIMPL_CAST((long)len)); -} - -RBIMPL_ATTR_NOALIAS() -RBIMPL_ATTR_NONNULL(()) -static inline ID -rbimpl_intern_const(ID *ptr, const char *str) -{ - while (! *ptr) { - *ptr = rb_intern_const(str); - } - - return *ptr; -} - -/* Does anyone use it? Preserved for backward compat. */ -#define RUBY_CONST_ID_CACHE(result, str) \ - { \ - static ID rb_intern_id_cache; \ - rbimpl_intern_const(&rb_intern_id_cache, (str)); \ - result rb_intern_id_cache; \ - } -#define RUBY_CONST_ID(var, str) \ - do { \ - static ID rbimpl_id; \ - (var) = rbimpl_intern_const(&rbimpl_id, (str)); \ - } while (0) - -#if defined(HAVE_STMT_AND_DECL_IN_EXPR) -/* __builtin_constant_p and statement expression is available - * since gcc-2.7.2.3 at least. */ -#define rb_intern(str) \ - (RBIMPL_CONSTANT_P(str) ? \ - __extension__ ({ \ - static ID rbimpl_id; \ - rbimpl_intern_const(&rbimpl_id, (str)); \ - }) : \ - (rb_intern)(str)) -#endif - -#endif /* RBIMPL_SYMBOL_H */ diff --git a/include/ruby/impl/token_paste.h b/include/ruby/impl/token_paste.h deleted file mode 100644 index 473fd597f8..0000000000 --- a/include/ruby/impl/token_paste.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef RBIMPL_TOKEN_PASTE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_TOKEN_PASTE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines #RBIMPL_TOKEN_PASTE. - */ -#include "ruby/impl/config.h" -#include "ruby/impl/compiler_since.h" -#include "ruby/impl/has/warning.h" -#include "ruby/impl/warning_push.h" - -/* :TODO: add your compiler here. There are many compilers that can suppress - * warnings via pragmas, but not all of them accept such things inside of `#if` - * and variants' conditions. And such nitpicking behavours tend not be - * documented. Please improve this file when you are really sure about your - * compiler's behaviour. */ - -#if RBIMPL_COMPILER_SINCE(GCC, 4, 2, 0) -# /* GCC is one of such compiler who cannot write `_Pragma` inside of a `#if`. -# * Cannot but globally kill everything. This is of course a very bad thing. -# * If you know how to reroute this please tell us. */ -# /* https://gcc.godbolt.org/z/K2xr7X */ -# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) -# pragma GCC diagnostic ignored "-Wundef" -# /* > warning: "symbol" is not defined, evaluates to 0 [-Wundef] */ - -#elif RBIMPL_COMPILER_IS(Intel) -# /* Ditto for icc. */ -# /* https://gcc.godbolt.org/z/pTwDxE */ -# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) -# pragma warning(disable: 193) -# /* > warning #193: zero used for undefined preprocessing identifier */ - -#elif RBIMPL_COMPILER_BEFORE(MSVC, 19, 14, 26428) -# /* :FIXME: is 19.14 the exact version they supported this? */ -# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) -# pragma warning(disable: 4668) -# /* > warning C4668: 'symbol' is not defined as a preprocessor macro */ - -#elif RBIMPL_COMPILER_IS(MSVC) -# define RBIMPL_TOKEN_PASTE(x, y) \ - RBIMPL_WARNING_PUSH() \ - RBIMPL_WARNING_IGNORED(4668) \ - TOKEN_PASTE(x, y) \ - RBIMPL_WARNING_POP() - -#elif RBIMPL_HAS_WARNING("-Wundef") -# define RBIMPL_TOKEN_PASTE(x, y) \ - RBIMPL_WARNING_PUSH() \ - RBIMPL_WARNING_IGNORED(-Wundef) \ - TOKEN_PASTE(x, y) \ - RBIMPL_WARNING_POP() - -#else -# /* No way. */ -# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) -#endif - -#endif /* RBIMPL_TOKEN_PASTE_H */ diff --git a/include/ruby/impl/value.h b/include/ruby/impl/value.h deleted file mode 100644 index 905cc04187..0000000000 --- a/include/ruby/impl/value.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef RBIMPL_VALUE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_VALUE_H -/** - * @file - * @author Ruby developers - * @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 ::VALUE and ::ID. - */ -#include "ruby/impl/static_assert.h" -#include "ruby/backward/2/long_long.h" -#include "ruby/backward/2/limits.h" - -#if defined HAVE_UINTPTR_T && 0 -typedef uintptr_t VALUE; -typedef uintptr_t ID; -# define SIGNED_VALUE intptr_t -# define SIZEOF_VALUE SIZEOF_UINTPTR_T -# undef PRI_VALUE_PREFIX -# define RBIMPL_VALUE_NULL UINTPTR_C(0) -# define RBIMPL_VALUE_ONE UINTPTR_C(1) -# define RBIMPL_VALUE_FULL UINTPTR_MAX - -#elif SIZEOF_LONG == SIZEOF_VOIDP -typedef unsigned long VALUE; -typedef unsigned long ID; -# define SIGNED_VALUE long -# define SIZEOF_VALUE SIZEOF_LONG -# define PRI_VALUE_PREFIX "l" -# define RBIMPL_VALUE_NULL 0UL -# define RBIMPL_VALUE_ONE 1UL -# define RBIMPL_VALUE_FULL ULONG_MAX - -#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP -typedef unsigned LONG_LONG VALUE; -typedef unsigned LONG_LONG ID; -# define SIGNED_VALUE LONG_LONG -# define LONG_LONG_VALUE 1 -# define SIZEOF_VALUE SIZEOF_LONG_LONG -# define PRI_VALUE_PREFIX PRI_LL_PREFIX -# define RBIMPL_VALUE_NULL 0ULL -# define RBIMPL_VALUE_ONE 1ULL -# define RBIMPL_VALUE_FULL ULLONG_MAX - -#else -# error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<---- -#endif - -RBIMPL_STATIC_ASSERT(sizeof_int, SIZEOF_INT == sizeof(int)); -RBIMPL_STATIC_ASSERT(sizeof_long, SIZEOF_LONG == sizeof(long)); -RBIMPL_STATIC_ASSERT(sizeof_long_long, SIZEOF_LONG_LONG == sizeof(LONG_LONG)); -RBIMPL_STATIC_ASSERT(sizeof_voidp, SIZEOF_VOIDP == sizeof(void *)); -#endif /* RBIMPL_VALUE_H */ diff --git a/include/ruby/impl/value_type.h b/include/ruby/impl/value_type.h deleted file mode 100644 index be1b3559b6..0000000000 --- a/include/ruby/impl/value_type.h +++ /dev/null @@ -1,354 +0,0 @@ -#ifndef RBIMPL_VALUE_TYPE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_VALUE_TYPE_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines enum ::ruby_value_type. - */ -#include "ruby/impl/assume.h" -#include "ruby/impl/attr/artificial.h" -#include "ruby/impl/attr/cold.h" -#include "ruby/impl/attr/enum_extensibility.h" -#include "ruby/impl/attr/forceinline.h" -#include "ruby/impl/attr/pure.h" -#include "ruby/impl/cast.h" -#include "ruby/impl/constant_p.h" -#include "ruby/impl/core/rbasic.h" -#include "ruby/impl/dllexport.h" -#include "ruby/impl/has/builtin.h" -#include "ruby/impl/special_consts.h" -#include "ruby/impl/stdbool.h" -#include "ruby/impl/value.h" -#include "ruby/assert.h" - -#if defined(T_DATA) -/* - * :!BEWARE!: (Recent?) Solaris' have conflicting definition of - * T_DATA. Let us stop here. Please have a workaround like this: - * - * ```C - * #include // <- Include this one first. - * #undef T_DATA // <- ... and stick to RUBY_T_DATA forever. - * #include // <- OS-provided T_DATA introduced. - * ``` - * - * See also [ruby-core:4261] - */ -# error Bail out due to conflicting definition of T_DATA. -#endif - -#define T_ARRAY RUBY_T_ARRAY -#define T_BIGNUM RUBY_T_BIGNUM -#define T_CLASS RUBY_T_CLASS -#define T_COMPLEX RUBY_T_COMPLEX -#define T_DATA RUBY_T_DATA -#define T_FALSE RUBY_T_FALSE -#define T_FILE RUBY_T_FILE -#define T_FIXNUM RUBY_T_FIXNUM -#define T_FLOAT RUBY_T_FLOAT -#define T_HASH RUBY_T_HASH -#define T_ICLASS RUBY_T_ICLASS -#define T_IMEMO RUBY_T_IMEMO -#define T_MASK RUBY_T_MASK -#define T_MATCH RUBY_T_MATCH -#define T_MODULE RUBY_T_MODULE -#define T_MOVED RUBY_T_MOVED -#define T_NIL RUBY_T_NIL -#define T_NODE RUBY_T_NODE -#define T_NONE RUBY_T_NONE -#define T_OBJECT RUBY_T_OBJECT -#define T_RATIONAL RUBY_T_RATIONAL -#define T_REGEXP RUBY_T_REGEXP -#define T_STRING RUBY_T_STRING -#define T_STRUCT RUBY_T_STRUCT -#define T_SYMBOL RUBY_T_SYMBOL -#define T_TRUE RUBY_T_TRUE -#define T_UNDEF RUBY_T_UNDEF -#define T_ZOMBIE RUBY_T_ZOMBIE - -#define BUILTIN_TYPE RB_BUILTIN_TYPE -#define DYNAMIC_SYM_P RB_DYNAMIC_SYM_P -#define RB_INTEGER_TYPE_P rb_integer_type_p -#define SYMBOL_P RB_SYMBOL_P -#define rb_type_p RB_TYPE_P - -/** @cond INTERNAL_MACRO */ -#define RB_BUILTIN_TYPE RB_BUILTIN_TYPE -#define RB_DYNAMIC_SYM_P RB_DYNAMIC_SYM_P -#define RB_FLOAT_TYPE_P RB_FLOAT_TYPE_P -#define RB_SYMBOL_P RB_SYMBOL_P -#define RB_TYPE_P RB_TYPE_P -#define Check_Type Check_Type - -#if RUBY_NDEBUG -# define RBIMPL_ASSERT_TYPE(v, t) RBIMPL_ASSERT_OR_ASSUME(RB_TYPE_P((v), (t))) -#else -# define RBIMPL_ASSERT_TYPE Check_Type -#endif -/** @endcond */ - -#define TYPE(_) RBIMPL_CAST((int)rb_type(_)) - -/** C-level type of an object. */ -enum -RBIMPL_ATTR_ENUM_EXTENSIBILITY(closed) -ruby_value_type { - RUBY_T_NONE = 0x00, /**< Non-object (sweeped etc.) */ - - RUBY_T_OBJECT = 0x01, /**< @see struct ::RObject */ - RUBY_T_CLASS = 0x02, /**< @see struct ::RClass and ::rb_cClass */ - RUBY_T_MODULE = 0x03, /**< @see struct ::RClass and ::rb_cModule */ - RUBY_T_FLOAT = 0x04, /**< @see struct ::RFloat */ - RUBY_T_STRING = 0x05, /**< @see struct ::RString */ - RUBY_T_REGEXP = 0x06, /**< @see struct ::RRegexp */ - RUBY_T_ARRAY = 0x07, /**< @see struct ::RArray */ - RUBY_T_HASH = 0x08, /**< @see struct ::RHash */ - RUBY_T_STRUCT = 0x09, /**< @see struct ::RStruct */ - RUBY_T_BIGNUM = 0x0a, /**< @see struct ::RBignum */ - RUBY_T_FILE = 0x0b, /**< @see struct ::RFile */ - RUBY_T_DATA = 0x0c, /**< @see struct ::RTypedData */ - RUBY_T_MATCH = 0x0d, /**< @see struct ::RMatch */ - RUBY_T_COMPLEX = 0x0e, /**< @see struct ::RComplex */ - RUBY_T_RATIONAL = 0x0f, /**< @see struct ::RRational */ - - RUBY_T_NIL = 0x11, /**< @see ::RUBY_Qnil */ - RUBY_T_TRUE = 0x12, /**< @see ::RUBY_Qfalse */ - RUBY_T_FALSE = 0x13, /**< @see ::RUBY_Qtrue */ - RUBY_T_SYMBOL = 0x14, /**< @see struct ::RSymbol */ - RUBY_T_FIXNUM = 0x15, /**< Integers formerly known as Fixnums. */ - RUBY_T_UNDEF = 0x16, /**< @see ::RUBY_Qundef */ - - RUBY_T_IMEMO = 0x1a, /**< @see struct ::RIMemo */ - RUBY_T_NODE = 0x1b, /**< @see struct ::RNode */ - RUBY_T_ICLASS = 0x1c, /**< Hidden classes known as IClasses. */ - RUBY_T_ZOMBIE = 0x1d, /**< @see struct ::RZombie */ - RUBY_T_MOVED = 0x1e, /**< @see struct ::RMoved */ - - RUBY_T_MASK = 0x1f -}; - -RBIMPL_SYMBOL_EXPORT_BEGIN() -RBIMPL_ATTR_COLD() -void rb_check_type(VALUE obj, int t); -RBIMPL_SYMBOL_EXPORT_END() - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline enum ruby_value_type -RB_BUILTIN_TYPE(VALUE obj) -{ - RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); - - VALUE ret = RBASIC(obj)->flags & RUBY_T_MASK; - return RBIMPL_CAST((enum ruby_value_type)ret); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -static inline bool -rb_integer_type_p(VALUE obj) -{ - if (RB_FIXNUM_P(obj)) { - return true; - } - else if (RB_SPECIAL_CONST_P(obj)) { - return false; - } - else { - return RB_BUILTIN_TYPE(obj) == RUBY_T_BIGNUM; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -static inline enum ruby_value_type -rb_type(VALUE obj) -{ - if (! RB_SPECIAL_CONST_P(obj)) { - return RB_BUILTIN_TYPE(obj); - } - else if (obj == RUBY_Qfalse) { - return RUBY_T_FALSE; - } - else if (obj == RUBY_Qnil) { - return RUBY_T_NIL; - } - else if (obj == RUBY_Qtrue) { - return RUBY_T_TRUE; - } - else if (obj == RUBY_Qundef) { - return RUBY_T_UNDEF; - } - else if (RB_FIXNUM_P(obj)) { - return RUBY_T_FIXNUM; - } - else if (RB_STATIC_SYM_P(obj)) { - return RUBY_T_SYMBOL; - } - else { - RBIMPL_ASSUME(RB_FLONUM_P(obj)); - return RUBY_T_FLOAT; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_FLOAT_TYPE_P(VALUE obj) -{ - if (RB_FLONUM_P(obj)) { - return true; - } - else if (RB_SPECIAL_CONST_P(obj)) { - return false; - } - else { - return RB_BUILTIN_TYPE(obj) == RUBY_T_FLOAT; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_DYNAMIC_SYM_P(VALUE obj) -{ - if (RB_SPECIAL_CONST_P(obj)) { - return false; - } - else { - return RB_BUILTIN_TYPE(obj) == RUBY_T_SYMBOL; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_SYMBOL_P(VALUE obj) -{ - return RB_STATIC_SYM_P(obj) || RB_DYNAMIC_SYM_P(obj); -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -RBIMPL_ATTR_FORCEINLINE() -static bool -rbimpl_RB_TYPE_P_fastpath(VALUE obj, enum ruby_value_type t) -{ - if (t == RUBY_T_TRUE) { - return obj == RUBY_Qtrue; - } - else if (t == RUBY_T_FALSE) { - return obj == RUBY_Qfalse; - } - else if (t == RUBY_T_NIL) { - return obj == RUBY_Qnil; - } - else if (t == RUBY_T_UNDEF) { - return obj == RUBY_Qundef; - } - else if (t == RUBY_T_FIXNUM) { - return RB_FIXNUM_P(obj); - } - else if (t == RUBY_T_SYMBOL) { - return RB_SYMBOL_P(obj); - } - else if (t == RUBY_T_FLOAT) { - return RB_FLOAT_TYPE_P(obj); - } - else if (RB_SPECIAL_CONST_P(obj)) { - return false; - } - else if (t == RB_BUILTIN_TYPE(obj)) { - return true; - } - else { - return false; - } -} - -RBIMPL_ATTR_PURE_ON_NDEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline bool -RB_TYPE_P(VALUE obj, enum ruby_value_type t) -{ - if (RBIMPL_CONSTANT_P(t)) { - return rbimpl_RB_TYPE_P_fastpath(obj, t); - } - else { - return t == rb_type(obj); - } -} - -/** @cond INTERNAL_MACRO */ -/* Clang, unlike GCC, cannot propagate __builtin_constant_p beyond function - * boundary. */ -#if defined(__clang__) -# undef RB_TYPE_P -# define RB_TYPE_P(obj, t) \ - (RBIMPL_CONSTANT_P(t) ? \ - rbimpl_RB_TYPE_P_fastpath((obj), (t)) : \ - (RB_TYPE_P)((obj), (t))) -#endif - -/* clang 3.x (4.2 compatible) can't eliminate CSE of RB_BUILTIN_TYPE - * in inline function and caller function - * See also 8998c06461ea0bef11b3aeb30b6d2ab71c8762ba - */ -#if RBIMPL_COMPILER_BEFORE(Clang, 4, 0, 0) -# undef rb_integer_type_p -# define rb_integer_type_p(obj) \ - __extension__ ({ \ - const VALUE integer_type_obj = (obj); \ - (RB_FIXNUM_P(integer_type_obj) || \ - (!RB_SPECIAL_CONST_P(integer_type_obj) && \ - RB_BUILTIN_TYPE(integer_type_obj) == RUBY_T_BIGNUM)); \ - }) -#endif -/** @endcond */ - -RBIMPL_ATTR_PURE() -RBIMPL_ATTR_ARTIFICIAL() -/* Defined in ruby/impl/core/rtypeddata.h */ -static inline bool rbimpl_rtypeddata_p(VALUE obj); - -RBIMPL_ATTR_ARTIFICIAL() -static inline void -Check_Type(VALUE v, enum ruby_value_type t) -{ - if (RB_UNLIKELY(! RB_TYPE_P(v, t))) { - goto slowpath; - } - else if (t != RUBY_T_DATA) { - goto fastpath; - } - else if (rbimpl_rtypeddata_p(v)) { - /* The intention itself is not necessarily clear to me, but at least it - * is intentional to rule out typed data here. See commit - * a7c32bf81d3391cfb78cfda278f469717d0fb794. */ - goto slowpath; - } - else { - goto fastpath; - } - - fastpath: - return; - - slowpath: /* <- :TODO: mark this label as cold. */ - rb_check_type(v, t); -} - -#endif /* RBIMPL_VALUE_TYPE_H */ diff --git a/include/ruby/impl/variable.h b/include/ruby/impl/variable.h deleted file mode 100644 index 70aa43ea44..0000000000 --- a/include/ruby/impl/variable.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef RBIMPL_VARIABLE_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_VARIABLE_H -/** - * @file - * @author Ruby developers - * @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 C-function backended Ruby-global variables. - */ -#include "ruby/impl/dllexport.h" -#include "ruby/impl/value.h" -#include "ruby/impl/attr/noreturn.h" - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -typedef VALUE rb_gvar_getter_t(ID id, VALUE *data); -typedef void rb_gvar_setter_t(VALUE val, ID id, VALUE *data); -typedef void rb_gvar_marker_t(VALUE *var); - -rb_gvar_getter_t rb_gvar_undef_getter; -rb_gvar_setter_t rb_gvar_undef_setter; -rb_gvar_marker_t rb_gvar_undef_marker; - -rb_gvar_getter_t rb_gvar_val_getter; -rb_gvar_setter_t rb_gvar_val_setter; -rb_gvar_marker_t rb_gvar_val_marker; - -rb_gvar_getter_t rb_gvar_var_getter; -rb_gvar_setter_t rb_gvar_var_setter; -rb_gvar_marker_t rb_gvar_var_marker; - -RBIMPL_ATTR_NORETURN() -rb_gvar_setter_t rb_gvar_readonly_setter; - -void rb_define_variable(const char*,VALUE*); -void rb_define_virtual_variable(const char*,rb_gvar_getter_t*,rb_gvar_setter_t*); -void rb_define_hooked_variable(const char*,VALUE*,rb_gvar_getter_t*,rb_gvar_setter_t*); -void rb_define_readonly_variable(const char*,const VALUE*); -void rb_define_const(VALUE,const char*,VALUE); -void rb_define_global_const(const char*,VALUE); - -VALUE rb_gv_set(const char*, VALUE); -VALUE rb_gv_get(const char*); -VALUE rb_iv_get(VALUE, const char*); -VALUE rb_iv_set(VALUE, const char*, VALUE); - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_VARIABLE_H */ diff --git a/include/ruby/impl/warning_push.h b/include/ruby/impl/warning_push.h deleted file mode 100644 index e13e749b82..0000000000 --- a/include/ruby/impl/warning_push.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef RBIMPL_WARNING_PUSH_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_WARNING_PUSH_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Defines RBIMPL_WARNING_PUSH. - * @cond INTERNAL_MACRO - * - * ### Q&A ### - * - * Q: Why all the macros defined in this file are function-like macros? - * - * A: Sigh. This is because of Doxgen. Its `SKIP_FUNCTION_MACROS = YES` - * configuration setting requests us that if we want it to ignore these - * macros, then we have to do two things: (1) let them be defined as - * function-like macros, and (2) place them separately in their own line, - * like below: - * - * ```CXX - * // NG -- foo's type considered something like `unsigned int`. - * RBIMPL_WARNING_PUSH - * int foo(void); - * RBIMPL_WARNING_POP - * - * // OK -- the macros are ignored by Doxygen. - * RBIMPL_WARNING_PUSH() - * int foo(void); - * RBIMPL_WARNING_POP() - * ``` - */ -#include "ruby/impl/compiler_is.h" -#include "ruby/impl/compiler_since.h" - -#if RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0) -# /* Not sure exactly when but it seems VC++ 6.0 is a version with it.*/ -# define RBIMPL_WARNING_PUSH() __pragma(warning(push)) -# define RBIMPL_WARNING_POP() __pragma(warning(pop)) -# define RBIMPL_WARNING_ERROR(flag) __pragma(warning(error: flag)) -# define RBIMPL_WARNING_IGNORED(flag) __pragma(warning(disable: flag)) - -#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) -# define RBIMPL_WARNING_PUSH() __pragma(warning(push)) -# define RBIMPL_WARNING_POP() __pragma(warning(pop)) -# define RBIMPL_WARNING_ERROR(flag) __pragma(warning(error: flag)) -# define RBIMPL_WARNING_IGNORED(flag) __pragma(warning(disable: flag)) - -#elif RBIMPL_COMPILER_IS(Clang) || RBIMPL_COMPILER_IS(Apple) -# /* Not sure exactly when but it seems LLVM 2.6.0 is a version with it. */ -# define RBIMPL_WARNING_PRAGMA0(x) _Pragma(# x) -# define RBIMPL_WARNING_PRAGMA1(x) RBIMPL_WARNING_PRAGMA0(clang diagnostic x) -# define RBIMPL_WARNING_PRAGMA2(x, y) RBIMPL_WARNING_PRAGMA1(x # y) -# define RBIMPL_WARNING_PUSH() RBIMPL_WARNING_PRAGMA1(push) -# define RBIMPL_WARNING_POP() RBIMPL_WARNING_PRAGMA1(pop) -# define RBIMPL_WARNING_ERROR(flag) RBIMPL_WARNING_PRAGMA2(error, flag) -# define RBIMPL_WARNING_IGNORED(flag) RBIMPL_WARNING_PRAGMA2(ignored, flag) - -#elif RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) -# /* https://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Diagnostic-Pragmas.html */ -# define RBIMPL_WARNING_PRAGMA0(x) _Pragma(# x) -# define RBIMPL_WARNING_PRAGMA1(x) RBIMPL_WARNING_PRAGMA0(GCC diagnostic x) -# define RBIMPL_WARNING_PRAGMA2(x, y) RBIMPL_WARNING_PRAGMA1(x # y) -# define RBIMPL_WARNING_PUSH() RBIMPL_WARNING_PRAGMA1(push) -# define RBIMPL_WARNING_POP() RBIMPL_WARNING_PRAGMA1(pop) -# define RBIMPL_WARNING_ERROR(flag) RBIMPL_WARNING_PRAGMA2(error, flag) -# define RBIMPL_WARNING_IGNORED(flag) RBIMPL_WARNING_PRAGMA2(ignored, flag) - -#else -# /* :FIXME: improve here */ -# define RBIMPL_WARNING_PUSH() /* void */ -# define RBIMPL_WARNING_POP() /* void */ -# define RBIMPL_WARNING_ERROR(flag) /* void */ -# define RBIMPL_WARNING_IGNORED(flag) /* void */ -#endif /* _MSC_VER */ -/** @endcond */ - -#endif /* RBIMPL_WARNING_PUSH_H */ diff --git a/include/ruby/impl/xmalloc.h b/include/ruby/impl/xmalloc.h deleted file mode 100644 index 145a3e236f..0000000000 --- a/include/ruby/impl/xmalloc.h +++ /dev/null @@ -1,201 +0,0 @@ -#ifndef RBIMPL_XMALLOC_H /*-*-C++-*-vi:se ft=cpp:*/ -#define RBIMPL_XMALLOC_H -/** - * @file - * @author Ruby developers - * @copyright This file is a part of the programming language Ruby. - * Permission is hereby granted, to either redistribute and/or - * modify this file, provided that the conditions mentioned in the - * file COPYING are met. Consult the file for details. - * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are - * implementation details. Don't take them as canon. They could - * rapidly appear then vanish. The name (path) of this header file - * is also an implementation detail. Do not expect it to persist - * at the place it is now. Developers are free to move it anywhere - * anytime at will. - * @note To ruby-core: remember that this header can be possibly - * recursively included from extension libraries written in C++. - * Do not expect for instance `__VA_ARGS__` is always available. - * We assume C99 for ruby itself but we don't assume languages of - * extension libraries. They could be written in C++98. - * @brief Declares ::ruby_xmalloc(). - */ -#include "ruby/impl/config.h" - -#ifdef STDC_HEADERS -# include -#endif - -#ifdef HAVE_STDLIB_H -# include -#endif - -#include "ruby/impl/attr/alloc_size.h" -#include "ruby/impl/attr/nodiscard.h" -#include "ruby/impl/attr/noexcept.h" -#include "ruby/impl/attr/restrict.h" -#include "ruby/impl/attr/returns_nonnull.h" -#include "ruby/impl/dllexport.h" - -#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS -# define USE_GC_MALLOC_OBJ_INFO_DETAILS 0 -#endif - -#define xmalloc ruby_xmalloc -#define xmalloc2 ruby_xmalloc2 -#define xcalloc ruby_xcalloc -#define xrealloc ruby_xrealloc -#define xrealloc2 ruby_xrealloc2 -#define xfree ruby_xfree - -RBIMPL_SYMBOL_EXPORT_BEGIN() - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((1)) -void *ruby_xmalloc(size_t size) -RBIMPL_ATTR_NOEXCEPT(malloc(size)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((1,2)) -void *ruby_xmalloc2(size_t nelems, size_t elemsiz) -RBIMPL_ATTR_NOEXCEPT(malloc(nelems * elemsiz)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((1,2)) -void *ruby_xcalloc(size_t nelems, size_t elemsiz) -RBIMPL_ATTR_NOEXCEPT(calloc(nelems, elemsiz)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((2)) -void *ruby_xrealloc(void *ptr, size_t newsiz) -RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newsiz)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((2,3)) -void *ruby_xrealloc2(void *ptr, size_t newelems, size_t newsiz) -RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz)) -; - -void ruby_xfree(void *ptr) -RBIMPL_ATTR_NOEXCEPT(free(ptr)) -; - -#if USE_GC_MALLOC_OBJ_INFO_DETAILS || defined(__DOXYGEN) -# define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__) -# define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__) -# define ruby_xcalloc(s1, s2) ruby_xcalloc_with_location(s1, s2, __FILE__, __LINE__) -# define ruby_xrealloc(ptr, s1) ruby_xrealloc_with_location(ptr, s1, __FILE__, __LINE__) -# define ruby_xrealloc2(ptr, s1, s2) ruby_xrealloc2_with_location(ptr, s1, s2, __FILE__, __LINE__) - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((1)) -void *ruby_xmalloc_body(size_t size) -RBIMPL_ATTR_NOEXCEPT(malloc(size)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((1,2)) -void *ruby_xmalloc2_body(size_t nelems, size_t elemsiz) -RBIMPL_ATTR_NOEXCEPT(malloc(nelems * elemsiz)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RESTRICT() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((1,2)) -void *ruby_xcalloc_body(size_t nelems, size_t elemsiz) -RBIMPL_ATTR_NOEXCEPT(calloc(nelems, elemsiz)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((2)) -void *ruby_xrealloc_body(void *ptr, size_t newsiz) -RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newsiz)) -; - -RBIMPL_ATTR_NODISCARD() -RBIMPL_ATTR_RETURNS_NONNULL() -RBIMPL_ATTR_ALLOC_SIZE((2,3)) -void *ruby_xrealloc2_body(void *ptr, size_t newelems, size_t newsiz) -RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz)) -; - -RUBY_EXTERN const char *ruby_malloc_info_file; -RUBY_EXTERN int ruby_malloc_info_line; - -static inline void * -ruby_xmalloc_with_location(size_t s, const char *file, int line) -{ - void *ptr; - ruby_malloc_info_file = file; - ruby_malloc_info_line = line; - ptr = ruby_xmalloc_body(s); - ruby_malloc_info_file = NULL; - return ptr; -} - -static inline void * -ruby_xmalloc2_with_location(size_t s1, size_t s2, const char *file, int line) -{ - void *ptr; - ruby_malloc_info_file = file; - ruby_malloc_info_line = line; - ptr = ruby_xmalloc2_body(s1, s2); - ruby_malloc_info_file = NULL; - return ptr; -} - -static inline void * -ruby_xcalloc_with_location(size_t s1, size_t s2, const char *file, int line) -{ - void *ptr; - ruby_malloc_info_file = file; - ruby_malloc_info_line = line; - ptr = ruby_xcalloc_body(s1, s2); - ruby_malloc_info_file = NULL; - return ptr; -} - -static inline void * -ruby_xrealloc_with_location(void *ptr, size_t s, const char *file, int line) -{ - void *rptr; - ruby_malloc_info_file = file; - ruby_malloc_info_line = line; - rptr = ruby_xrealloc_body(ptr, s); - ruby_malloc_info_file = NULL; - return rptr; -} - -static inline void * -ruby_xrealloc2_with_location(void *ptr, size_t s1, size_t s2, const char *file, int line) -{ - void *rptr; - ruby_malloc_info_file = file; - ruby_malloc_info_line = line; - rptr = ruby_xrealloc2_body(ptr, s1, s2); - ruby_malloc_info_file = NULL; - return rptr; -} -#endif - -RBIMPL_SYMBOL_EXPORT_END() - -#endif /* RBIMPL_XMALLOC_H */ diff --git a/include/ruby/internal/anyargs.h b/include/ruby/internal/anyargs.h new file mode 100644 index 0000000000..78c979eac0 --- /dev/null +++ b/include/ruby/internal/anyargs.h @@ -0,0 +1,375 @@ +#ifndef RBIMPL_ANYARGS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ANYARGS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Function overloads to issue warnings around #ANYARGS. + * + * For instance ::rb_define_method takes a pointer to #ANYARGS -ed functions, + * which in fact varies 18 different prototypes. We still need to preserve + * #ANYARGS for storages but why not check the consistencies if possible. With + * those complex macro overlays defined in this header file, use of a function + * pointer gets checked against the corresponding arity argument. + * + * ### Q&A ### + * + * - Q: Where did the magic number "18" came from in the description above? + * + * - A: Count the case branch of `vm_method.c:call_cfunc_invoker_func()`. Note + * also that the 18 branches has lasted for at least 25 years. See also + * commit 200e0ee2fd3c1c006c528874a88f684447215524. + * + * - Q: What is this `__weakref__` thing? + * + * - A: That is a kind of function overloading mechanism that GCC provides. In + * this case for instance `rb_define_method_00` is an alias of + * ::rb_define_method, with a strong type. + * + * - Q: What is this `__transparent_union__` thing? + * + * A: That is another kind of function overloading mechanism that GCC + * provides. In this case the attributed function pointer is either + * `VALUE(*)(int,VALUE*,VALUE)` or `VALUE(*)(int,const VALUE*,VALUE)`. + * + * This is better than `void*` or #ANYARGS because we can reject all other + * possibilities than the two. + * + * - Q: What does this #rb_define_method macro mean? + * + * - A: It selects appropriate alias of the ::rb_define_method function, + * depending on the last (arity) argument. + * + * - Q: Why the special case for ::rb_f_notimplement ? + * + * - A: Function pointer to ::rb_f_notimplement is special cased in + * `vm_method.c:rb_add_method_cfunc()`. That should be handled by the + * `__builtin_choose_expr` chain inside of #rb_define_method macro + * expansion. In order to do so, comparison like + * `(func == rb_f_notimplement)` is inappropriate for + * `__builtin_choose_expr`'s expression (which must be a compile-time + * integer constant but the address of ::rb_f_notimplement is not fixed + * until the linker). Instead we are using + * `__builtin_types_compatible_p`, and in doing so we need to distinguish + * ::rb_f_notimplement from others, by type. + */ +#include "ruby/impl/attr/maybe_unused.h" +#include "ruby/impl/attr/nonnull.h" +#include "ruby/impl/attr/weakref.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/config.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/intern/class.h" +#include "ruby/impl/intern/vm.h" +#include "ruby/impl/method.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/stdarg.h" + +#if defined(__cplusplus) +# include "ruby/backward/cxxanyargs.hpp" + +#elif defined(_WIN32) || defined(__CYGWIN__) +# /* Skip due to [Bug #16134] */ + +#elif ! RBIMPL_HAS_ATTRIBUTE(transparent_union) +# /* :TODO: improve here, please find a way to support. */ + +#elif ! defined(HAVE_VA_ARGS_MACRO) +# /* :TODO: improve here, please find a way to support. */ + +#else +# /** @cond INTERNAL_MACRO */ +# if ! defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P) +# define RBIMPL_CFUNC_IS_rb_f_notimplement(f) 0 +# else +# define RBIMPL_CFUNC_IS_rb_f_notimplement(f) \ + __builtin_types_compatible_p( \ + __typeof__(f), \ + __typeof__(rb_f_notimplement)) +# endif + +# if ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# define RBIMPL_ANYARGS_DISPATCH(expr, truthy, falsy) (falsy) +# else +# define RBIMPL_ANYARGS_DISPATCH(expr, truthy, falsy) \ + __builtin_choose_expr( \ + __builtin_choose_expr( \ + __builtin_constant_p(expr), \ + (expr), 0), \ + (truthy), (falsy)) +# endif + +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_singleton_method_m2, rb_define_singleton_method_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_singleton_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_singleton_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_singleton_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_singleton_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_singleton_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_singleton_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_singleton_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_singleton_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_singleton_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_singleton_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_singleton_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_singleton_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_singleton_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_singleton_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_singleton_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_singleton_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_singleton_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_protected_method_m2, rb_define_protected_method_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_protected_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_protected_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_protected_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_protected_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_protected_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_protected_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_protected_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_protected_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_protected_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_protected_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_protected_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_protected_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_protected_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_protected_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_protected_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_protected_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_protected_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_private_method_m2, rb_define_private_method_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_private_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_private_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_private_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_private_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_private_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_private_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_private_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_private_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_private_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_private_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_private_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_private_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_private_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_private_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_private_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_private_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_private_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_module_function_m2, rb_define_module_function_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_module_function_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_module_function_00, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_module_function_01, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_module_function_02, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_module_function_03, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_module_function_04, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_module_function_05, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_module_function_06, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_module_function_07, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_module_function_08, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_module_function_09, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_module_function_10, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_module_function_11, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_module_function_12, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_module_function_13, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_module_function_14, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_module_function_15, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_global_function_m2, rb_define_global_function_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_global_function_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_global_function_00, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_global_function_01, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_global_function_02, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_global_function_03, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_global_function_04, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_global_function_05, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_global_function_06, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_global_function_07, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_global_function_08, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_global_function_09, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_global_function_10, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_global_function_11, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_global_function_12, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_global_function_13, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_global_function_14, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_global_function_15, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_method_id_m2, rb_define_method_id_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_method_id_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_method_id_00, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_method_id_01, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_method_id_02, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_method_id_03, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_method_id_04, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_method_id_05, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_method_id_06, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_method_id_07, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_method_id_08, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_method_id_09, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_method_id_10, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_method_id_11, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_method_id_12, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_method_id_13, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_method_id_14, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_method_id_15, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_m2(n) RBIMPL_ANYARGS_DISPATCH((n) == -2, rb_define_method_m2, rb_define_method_m3) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_m1(n) RBIMPL_ANYARGS_DISPATCH((n) == -1, rb_define_method_m1, RBIMPL_ANYARGS_DISPATCH_rb_define_method_m2(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_00(n) RBIMPL_ANYARGS_DISPATCH((n) == 0, rb_define_method_00, RBIMPL_ANYARGS_DISPATCH_rb_define_method_m1(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_01(n) RBIMPL_ANYARGS_DISPATCH((n) == 1, rb_define_method_01, RBIMPL_ANYARGS_DISPATCH_rb_define_method_00(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_02(n) RBIMPL_ANYARGS_DISPATCH((n) == 2, rb_define_method_02, RBIMPL_ANYARGS_DISPATCH_rb_define_method_01(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_03(n) RBIMPL_ANYARGS_DISPATCH((n) == 3, rb_define_method_03, RBIMPL_ANYARGS_DISPATCH_rb_define_method_02(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_04(n) RBIMPL_ANYARGS_DISPATCH((n) == 4, rb_define_method_04, RBIMPL_ANYARGS_DISPATCH_rb_define_method_03(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_05(n) RBIMPL_ANYARGS_DISPATCH((n) == 5, rb_define_method_05, RBIMPL_ANYARGS_DISPATCH_rb_define_method_04(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_06(n) RBIMPL_ANYARGS_DISPATCH((n) == 6, rb_define_method_06, RBIMPL_ANYARGS_DISPATCH_rb_define_method_05(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_07(n) RBIMPL_ANYARGS_DISPATCH((n) == 7, rb_define_method_07, RBIMPL_ANYARGS_DISPATCH_rb_define_method_06(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_08(n) RBIMPL_ANYARGS_DISPATCH((n) == 8, rb_define_method_08, RBIMPL_ANYARGS_DISPATCH_rb_define_method_07(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_09(n) RBIMPL_ANYARGS_DISPATCH((n) == 9, rb_define_method_09, RBIMPL_ANYARGS_DISPATCH_rb_define_method_08(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_10(n) RBIMPL_ANYARGS_DISPATCH((n) == 10, rb_define_method_10, RBIMPL_ANYARGS_DISPATCH_rb_define_method_09(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_11(n) RBIMPL_ANYARGS_DISPATCH((n) == 11, rb_define_method_11, RBIMPL_ANYARGS_DISPATCH_rb_define_method_10(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_12(n) RBIMPL_ANYARGS_DISPATCH((n) == 12, rb_define_method_12, RBIMPL_ANYARGS_DISPATCH_rb_define_method_11(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_13(n) RBIMPL_ANYARGS_DISPATCH((n) == 13, rb_define_method_13, RBIMPL_ANYARGS_DISPATCH_rb_define_method_12(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_14(n) RBIMPL_ANYARGS_DISPATCH((n) == 14, rb_define_method_14, RBIMPL_ANYARGS_DISPATCH_rb_define_method_13(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_15(n) RBIMPL_ANYARGS_DISPATCH((n) == 15, rb_define_method_15, RBIMPL_ANYARGS_DISPATCH_rb_define_method_14(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_singleton_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method_15(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_protected_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method_15(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_private_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_private_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_private_method_15(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_module_function(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_module_function_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_module_function_15(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_global_function(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_global_function_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_global_function_15(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method_id(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_method_id_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_method_id_15(n)) +# define RBIMPL_ANYARGS_DISPATCH_rb_define_method(n, f) RBIMPL_ANYARGS_DISPATCH(RBIMPL_CFUNC_IS_rb_f_notimplement(f), rb_define_method_m3, RBIMPL_ANYARGS_DISPATCH_rb_define_method_15(n)) +# define RBIMPL_ANYARGS_ATTRSET(sym) RBIMPL_ATTR_MAYBE_UNUSED() RBIMPL_ATTR_NONNULL() RBIMPL_ATTR_WEAKREF(sym) +# define RBIMPL_ANYARGS_DECL(sym, ...) \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m3(__VA_ARGS__, VALUE(*)(ANYARGS), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m2(__VA_ARGS__, VALUE(*)(VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _m1(__VA_ARGS__, VALUE(*)(int, union { VALUE *x; const VALUE *y; } __attribute__((__transparent_union__)), VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _00(__VA_ARGS__, VALUE(*)(VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _01(__VA_ARGS__, VALUE(*)(VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _02(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _03(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _04(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _05(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _06(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _07(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _08(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _09(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _10(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _11(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _12(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _13(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _14(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); \ +RBIMPL_ANYARGS_ATTRSET(sym) static void sym ## _15(__VA_ARGS__, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE), int); +RBIMPL_ANYARGS_DECL(rb_define_singleton_method, VALUE, const char *) +RBIMPL_ANYARGS_DECL(rb_define_protected_method, VALUE, const char *) +RBIMPL_ANYARGS_DECL(rb_define_private_method, VALUE, const char *) +RBIMPL_ANYARGS_DECL(rb_define_module_function, VALUE, const char *) +RBIMPL_ANYARGS_DECL(rb_define_global_function, const char *) +RBIMPL_ANYARGS_DECL(rb_define_method_id, VALUE, ID) +RBIMPL_ANYARGS_DECL(rb_define_method, VALUE, const char *) +/** @endcond */ + +/** + * @brief Defines klass\#mid. + * @see ::rb_define_method + * @param klass Where the method lives. + * @param mid Name of the defining method. + * @param func Implementation of klass\#mid. + * @param arity Arity of klass\#mid. + */ +#define rb_define_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_method((arity), (func))((klass), (mid), (func), (arity)) + +/** + * @brief Defines klass\#mid. + * @see ::rb_define_method_id + * @param klass Where the method lives. + * @param mid Name of the defining method. + * @param func Implementation of klass\#mid. + * @param arity Arity of klass\#mid. + */ +#define rb_define_method_id(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_method_id((arity), (func))((klass), (mid), (func), (arity)) + +/** + * @brief Defines obj.mid. + * @see ::rb_define_singleton_method + * @param obj Where the method lives. + * @param mid Name of the defining method. + * @param func Implementation of obj.mid. + * @param arity Arity of obj.mid. + */ +#define rb_define_singleton_method(obj, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_singleton_method((arity), (func))((obj), (mid), (func), (arity)) + +/** + * @brief Defines klass\#mid and make it protected. + * @see ::rb_define_protected_method + * @param klass Where the method lives. + * @param mid Name of the defining method. + * @param func Implementation of klass\#mid. + * @param arity Arity of klass\#mid. + */ +#define rb_define_protected_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_protected_method((arity), (func))((klass), (mid), (func), (arity)) + +/** + * @brief Defines klass\#mid and make it private. + * @see ::rb_define_private_method + * @param klass Where the method lives. + * @param mid Name of the defining method. + * @param func Implementation of klass\#mid. + * @param arity Arity of klass\#mid. + */ +#define rb_define_private_method(klass, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_private_method((arity), (func))((klass), (mid), (func), (arity)) + +/** + * @brief Defines mod\#mid and make it a module function. + * @see ::rb_define_module_function + * @param mod Where the method lives. + * @param mid Name of the defining method. + * @param func Implementation of mod\#mid. + * @param arity Arity of mod\#mid. + */ +#define rb_define_module_function(mod, mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_module_function((arity), (func))((mod), (mid), (func), (arity)) + +/** + * @brief Defines ::rb_mKerbel \#mid. + * @see ::rb_define_gobal_function + * @param mid Name of the defining method. + * @param func Implementation of ::rb_mKernel \#mid. + * @param arity Arity of ::rb_mKernel \#mid. + */ +#define rb_define_global_function(mid, func, arity) RBIMPL_ANYARGS_DISPATCH_rb_define_global_function((arity), (func))((mid), (func), (arity)) + +#endif /* __cplusplus */ + +/** + * This macro is to properly cast a function parameter of *_define_method + * family. It has been around since 1.x era so you can maximize backwards + * compatibility by using it. + * + * ```CXX + * rb_define_method(klass, "method", RUBY_METHOD_FUNC(func), arity); + * ``` + * + * @param func A pointer to a function that implements a method. + */ +#if ! defined(RUBY_DEVEL) +# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func)) + +#elif ! RUBY_DEVEL +# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func)) + +#elif ! defined(rb_define_method) +# define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func)) + +#else +# define RUBY_METHOD_FUNC(func) (func) + +#endif + +#endif /* RBIMPL_ANYARGS_H */ diff --git a/include/ruby/internal/arithmetic.h b/include/ruby/internal/arithmetic.h new file mode 100644 index 0000000000..f93fa581cd --- /dev/null +++ b/include/ruby/internal/arithmetic.h @@ -0,0 +1,38 @@ +#ifndef RBIMPL_ARITHMETIC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Conversion between C's arithmtic types and Ruby's numeric types. + */ +#include "ruby/impl/arithmetic/char.h" +#include "ruby/impl/arithmetic/double.h" +#include "ruby/impl/arithmetic/fixnum.h" +#include "ruby/impl/arithmetic/gid_t.h" +#include "ruby/impl/arithmetic/int.h" +#include "ruby/impl/arithmetic/intptr_t.h" +#include "ruby/impl/arithmetic/long.h" +#include "ruby/impl/arithmetic/long_long.h" +#include "ruby/impl/arithmetic/mode_t.h" +#include "ruby/impl/arithmetic/off_t.h" +#include "ruby/impl/arithmetic/pid_t.h" +#include "ruby/impl/arithmetic/short.h" +#include "ruby/impl/arithmetic/size_t.h" +#include "ruby/impl/arithmetic/st_data_t.h" +#include "ruby/impl/arithmetic/uid_t.h" +#endif /* RBIMPL_ARITHMETIC_H */ diff --git a/include/ruby/internal/arithmetic/char.h b/include/ruby/internal/arithmetic/char.h new file mode 100644 index 0000000000..138ba63f58 --- /dev/null +++ b/include/ruby/internal/arithmetic/char.h @@ -0,0 +1,58 @@ +#ifndef RBIMPL_ARITHMETIC_CHAR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_CHAR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `char` and Ruby's. + */ +#include "ruby/impl/arithmetic/int.h" /* NUM2INT is here, but */ +#include "ruby/impl/arithmetic/long.h" /* INT2FIX is here.*/ +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/core/rstring.h" +#include "ruby/impl/value_type.h" + +#define RB_NUM2CHR rb_num2char_inline +#define NUM2CHR RB_NUM2CHR +#define CHR2FIX RB_CHR2FIX + +/** @cond INTERNAL_MACRO */ +#define RB_CHR2FIX RB_CHR2FIX +/** @endcond */ + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RB_CHR2FIX(unsigned char c) +{ + return RB_INT2FIX(c); +} + +static inline char +rb_num2char_inline(VALUE x) +{ + if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1)) + return RSTRING_PTR(x)[0]; + else + return RBIMPL_CAST((char)RB_NUM2INT(x)); +} + +#endif /* RBIMPL_ARITHMETIC_CHAR_H */ diff --git a/include/ruby/internal/arithmetic/double.h b/include/ruby/internal/arithmetic/double.h new file mode 100644 index 0000000000..2c3426ae6b --- /dev/null +++ b/include/ruby/internal/arithmetic/double.h @@ -0,0 +1,39 @@ +#ifndef RBIMPL_ARITHMETIC_DOUBLE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_DOUBLE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `double` and Ruby's. + */ +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +#define NUM2DBL rb_num2dbl +#define RFLOAT_VALUE rb_float_value +#define DBL2NUM rb_float_new + +RBIMPL_SYMBOL_EXPORT_BEGIN() +double rb_num2dbl(VALUE); +RBIMPL_ATTR_PURE() +double rb_float_value(VALUE); +VALUE rb_float_new(double); +VALUE rb_float_new_in_heap(double); +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_ARITHMETIC_DOUBLE_H */ diff --git a/include/ruby/internal/arithmetic/fixnum.h b/include/ruby/internal/arithmetic/fixnum.h new file mode 100644 index 0000000000..68544b760b --- /dev/null +++ b/include/ruby/internal/arithmetic/fixnum.h @@ -0,0 +1,44 @@ +#ifndef RBIMPL_ARITHMETIC_FIXNUM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_FIXNUM_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Handling of integers formerly known as Fixnums. + */ +#include "ruby/backward/2/limits.h" + +#define FIXABLE RB_FIXABLE +#define FIXNUM_MAX RUBY_FIXNUM_MAX +#define FIXNUM_MIN RUBY_FIXNUM_MIN +#define NEGFIXABLE RB_NEGFIXABLE +#define POSFIXABLE RB_POSFIXABLE + +/* + * FIXABLE can be applied to anything, from double to intmax_t. The problem is + * double. On a 64bit system RUBY_FIXNUM_MAX is 4,611,686,018,427,387,903, + * which is not representable by a double. The nearest value that a double can + * represent is 4,611,686,018,427,387,904, which is not fixable. The + * seemingly-stragne "< FIXNUM_MAX + 1" expression below is due to this. + */ +#define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1) +#define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN) +#define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_)) +#define RUBY_FIXNUM_MAX (LONG_MAX / 2) +#define RUBY_FIXNUM_MIN (LONG_MIN / 2) + +#endif /* RBIMPL_ARITHMETIC_FIXNUM_H */ diff --git a/include/ruby/internal/arithmetic/gid_t.h b/include/ruby/internal/arithmetic/gid_t.h new file mode 100644 index 0000000000..2d4a230a1f --- /dev/null +++ b/include/ruby/internal/arithmetic/gid_t.h @@ -0,0 +1,34 @@ +#ifndef RBIMPL_ARITHMETIC_GID_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_GID_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `gid_t` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/long.h" + +#ifndef GIDT2NUM +# define GIDT2NUM RB_LONG2NUM +#endif + +#ifndef NUM2GIDT +# define NUM2GIDT RB_NUM2LONG +#endif + +#endif /* RBIMPL_ARITHMETIC_GID_T_H */ diff --git a/include/ruby/internal/arithmetic/int.h b/include/ruby/internal/arithmetic/int.h new file mode 100644 index 0000000000..374d10540b --- /dev/null +++ b/include/ruby/internal/arithmetic/int.h @@ -0,0 +1,163 @@ +#ifndef RBIMPL_ARITHMETIC_INT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_INT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `int` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/fixnum.h" +#include "ruby/impl/arithmetic/intptr_t.h" +#include "ruby/impl/arithmetic/long.h" +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/compiler_is.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" +#include "ruby/impl/value.h" +#include "ruby/impl/warning_push.h" +#include "ruby/assert.h" + +#define RB_INT2NUM rb_int2num_inline +#define RB_NUM2INT rb_num2int_inline +#define RB_UINT2NUM rb_uint2num_inline + +#define FIX2INT RB_FIX2INT +#define FIX2UINT RB_FIX2UINT +#define INT2NUM RB_INT2NUM +#define NUM2INT RB_NUM2INT +#define NUM2UINT RB_NUM2UINT +#define UINT2NUM RB_UINT2NUM + +/** @cond INTERNAL_MACRO */ +#define RB_FIX2INT RB_FIX2INT +#define RB_NUM2UINT RB_NUM2UINT +#define RB_FIX2UINT RB_FIX2UINT +/** @endcond */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() +long rb_num2int(VALUE); +long rb_fix2int(VALUE); +unsigned long rb_num2uint(VALUE); +unsigned long rb_fix2uint(VALUE); +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_ARTIFICIAL() +static inline int +RB_FIX2INT(VALUE x) +{ + /* "FIX2INT raises a TypeError if passed nil", says rubyspec. Not sure if + * that is a desired behaviour but just preserve backwards compatilibily. + */ +#if 0 + RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); +#endif + long ret; + + if /* constexpr */ (sizeof(int) < sizeof(long)) { + ret = rb_fix2int(x); + } + else { + ret = RB_FIX2LONG(x); + } + + return RBIMPL_CAST((int)ret); +} + +static inline int +rb_num2int_inline(VALUE x) +{ + long ret; + + if /* constexpr */ (sizeof(int) == sizeof(long)) { + ret = RB_NUM2LONG(x); + } + else if (RB_FIXNUM_P(x)) { + ret = rb_fix2int(x); + } + else { + ret = rb_num2int(x); + } + + return RBIMPL_CAST((int)ret); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline unsigned int +RB_NUM2UINT(VALUE x) +{ + unsigned long ret; + + if /* constexpr */ (sizeof(int) < sizeof(long)) { + ret = rb_num2uint(x); + } + else { + ret = RB_NUM2ULONG(x); + } + + return RBIMPL_CAST((unsigned int)ret); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline unsigned int +RB_FIX2UINT(VALUE x) +{ +#if 0 /* Ditto for RB_FIX2INT. */ + RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); +#endif + unsigned long ret; + + if /* constexpr */ (sizeof(int) < sizeof(long)) { + ret = rb_fix2uint(x); + } + else { + ret = RB_FIX2ULONG(x); + } + + return RBIMPL_CAST((unsigned int)ret); +} + +RBIMPL_WARNING_PUSH() +#if RBIMPL_COMPILER_IS(GCC) +RBIMPL_WARNING_IGNORED(-Wtype-limits) /* We can ignore them here. */ +#elif RBIMPL_HAS_WARNING("-Wtautological-constant-out-of-range-compare") +RBIMPL_WARNING_IGNORED(-Wtautological-constant-out-of-range-compare) +#endif + +static inline VALUE +rb_int2num_inline(int v) +{ + if (RB_FIXABLE(v)) + return RB_INT2FIX(v); + else + return rb_int2big(v); +} + +static inline VALUE +rb_uint2num_inline(unsigned int v) +{ + if (RB_POSFIXABLE(v)) + return RB_LONG2FIX(v); + else + return rb_uint2big(v); +} + +RBIMPL_WARNING_POP() + +#endif /* RBIMPL_ARITHMETIC_INT_H */ diff --git a/include/ruby/internal/arithmetic/intptr_t.h b/include/ruby/internal/arithmetic/intptr_t.h new file mode 100644 index 0000000000..2bbbf652db --- /dev/null +++ b/include/ruby/internal/arithmetic/intptr_t.h @@ -0,0 +1,42 @@ +#ifndef RBIMPL_ARITHMETIC_INTPTR_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_INTPTR_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `intptr_t` and Ruby's. + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_STDINT_H +# include +#endif + +#include "ruby/impl/value.h" +#include "ruby/impl/dllexport.h" + +#define rb_int_new rb_int2inum +#define rb_uint_new rb_uint2inum + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE rb_int2big(intptr_t i); +VALUE rb_int2inum(intptr_t i); +VALUE rb_uint2big(uintptr_t i); +VALUE rb_uint2inum(uintptr_t i); +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_ARITHMETIC_INTPTR_T_H */ diff --git a/include/ruby/internal/arithmetic/long.h b/include/ruby/internal/arithmetic/long.h new file mode 100644 index 0000000000..d429974eaf --- /dev/null +++ b/include/ruby/internal/arithmetic/long.h @@ -0,0 +1,244 @@ +#ifndef RBIMPL_ARITHMETIC_LONG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_LONG_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `long` and Ruby's. + * + * ### Q&A ### + * + * - Q: Why are INT2FIX etc. here, not in `int.h`? + * + * - A: Because they are in fact handling `long`. It seems someone did not + * understand the difference of `int` and `long` when they designed those + * macros. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/fixnum.h" /* FIXABLE */ +#include "ruby/impl/arithmetic/intptr_t.h" /* rb_int2big etc.*/ +#include "ruby/impl/assume.h" +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/cold.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" /* FIXNUM_FLAG */ +#include "ruby/impl/value.h" +#include "ruby/assert.h" + +#define FIX2LONG RB_FIX2LONG +#define FIX2ULONG RB_FIX2ULONG +#define INT2FIX RB_INT2FIX +#define LONG2FIX RB_INT2FIX +#define LONG2NUM RB_LONG2NUM +#define NUM2LONG RB_NUM2LONG +#define NUM2ULONG RB_NUM2ULONG +#define RB_FIX2LONG rb_fix2long +#define RB_FIX2ULONG rb_fix2ulong +#define RB_LONG2FIX RB_INT2FIX +#define RB_LONG2NUM rb_long2num_inline +#define RB_NUM2LONG rb_num2long_inline +#define RB_NUM2ULONG rb_num2ulong_inline +#define RB_ULONG2NUM rb_ulong2num_inline +#define ULONG2NUM RB_ULONG2NUM +#define rb_fix_new RB_INT2FIX +#define rb_long2int rb_long2int_inline + +/** @cond INTERNAL_MACRO */ +#define RB_INT2FIX RB_INT2FIX +/** @endcond */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +RBIMPL_ATTR_NORETURN() +RBIMPL_ATTR_COLD() +void rb_out_of_int(SIGNED_VALUE num); + +long rb_num2long(VALUE num); +unsigned long rb_num2ulong(VALUE num); +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RB_INT2FIX(long i) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(i)); + + /* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully + * defined. Also it can be compiled into a single LEA instruction. */ + const unsigned long j = i; + const unsigned long k = 2 * j + RUBY_FIXNUM_FLAG; + const long l = k; + const SIGNED_VALUE m = l; /* Sign extend */ + const VALUE n = m; + + RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(n)); + return n; +} + +static inline int +rb_long2int_inline(long n) +{ + int i = RBIMPL_CAST((int)n); + + if /* constexpr */ (sizeof(long) <= sizeof(int)) { + RBIMPL_ASSUME(i == n); + } + + if (i != n) + rb_out_of_int(n); + + return i; +} + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +static inline long +rbimpl_fix2long_by_idiv(VALUE x) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); + + /* :NOTE: VALUE can be wider than long. (x-1)/2 never overflows because + * RB_FIXNUM_P(x) holds. Also it has no portability issue like y>>1 + * below. */ + const SIGNED_VALUE y = x - RUBY_FIXNUM_FLAG; + const SIGNED_VALUE z = y / 2; + const long w = RBIMPL_CAST((long)z); + + RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w)); + return w; +} + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +static inline long +rbimpl_fix2long_by_shift(VALUE x) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); + + /* :NOTE: VALUE can be wider than long. If right shift is arithmetic, this + * is noticeably faster than above. */ + const SIGNED_VALUE y = x; + const SIGNED_VALUE z = y >> 1; + const long w = RBIMPL_CAST((long)z); + + RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w)); + return w; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +static inline bool +rbimpl_right_shift_is_arithmetic_p(void) +{ + return (-1 >> 1) == -1; +} + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +static inline long +rb_fix2long(VALUE x) +{ + if /* constexpr */ (rbimpl_right_shift_is_arithmetic_p()) { + return rbimpl_fix2long_by_shift(x); + } + else { + return rbimpl_fix2long_by_idiv(x); + } +} + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +static inline unsigned long +rb_fix2ulong(VALUE x) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x)); + return rb_fix2long(x); +} + +static inline long +rb_num2long_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return RB_FIX2LONG(x); + else + return rb_num2long(x); +} + +static inline unsigned long +rb_num2ulong_inline(VALUE x) +{ + /* This (negative fixnum would become a large unsigned long while negative + * bignum is an exception) has been THE behaviour of NUM2ULONG since the + * beginning. It is strange, but we can no longer change how it works at + * this moment. We have to get by with it. See also: + * https://bugs.ruby-lang.org/issues/9089 */ + if (RB_FIXNUM_P(x)) + return RB_FIX2ULONG(x); + else + return rb_num2ulong(x); +} + +static inline VALUE +rb_long2num_inline(long v) +{ + if (RB_FIXABLE(v)) + return RB_LONG2FIX(v); + else + return rb_int2big(v); +} + +static inline VALUE +rb_ulong2num_inline(unsigned long v) +{ + if (RB_POSFIXABLE(v)) + return RB_LONG2FIX(v); + else + return rb_uint2big(v); +} + +/** + * @cond INTERNAL_MACRO + * + * Following overload is necessary because sometimes INT2FIX is used as a enum + * value (e.g. `enum { FOO = INT2FIX(0) };`). THIS IS NG in theory because a + * VALUE does not fit into an enum (which must be a signed int). But we cannot + * break existing codes. + */ +#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 +# /* C++ can write constexpr as enum values. */ + +#elif ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# undef INT2FIX +# define INT2FIX(i) (RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG) + +#else +# undef INT2FIX +# define INT2FIX(i) \ + __builtin_choose_expr( \ + __builtin_constant_p(i), \ + RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG, \ + RB_INT2FIX(i)) +#endif +/** @endcond */ + +#endif /* RBIMPL_ARITHMETIC_LONG_H */ diff --git a/include/ruby/internal/arithmetic/long_long.h b/include/ruby/internal/arithmetic/long_long.h new file mode 100644 index 0000000000..3469421f0e --- /dev/null +++ b/include/ruby/internal/arithmetic/long_long.h @@ -0,0 +1,53 @@ +#ifndef RBIMPL_ARITHMETIC_LONG_LONG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_LONG_LONG_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `long long` and Ruby's. + */ +#include "ruby/impl/value.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" +#include "ruby/backward/2/long_long.h" + +#define RB_LL2NUM rb_ll2inum +#define RB_ULL2NUM rb_ull2inum +#define LL2NUM RB_LL2NUM +#define ULL2NUM RB_ULL2NUM +#define RB_NUM2LL rb_num2ll_inline +#define RB_NUM2ULL rb_num2ull +#define NUM2LL RB_NUM2LL +#define NUM2ULL RB_NUM2ULL + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE rb_ll2inum(LONG_LONG); +VALUE rb_ull2inum(unsigned LONG_LONG); +LONG_LONG rb_num2ll(VALUE); +unsigned LONG_LONG rb_num2ull(VALUE); +RBIMPL_SYMBOL_EXPORT_END() + +static inline LONG_LONG +rb_num2ll_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return RB_FIX2LONG(x); + else + return rb_num2ll(x); +} + +#endif /* RBIMPL_ARITHMETIC_LONG_LONG_H */ diff --git a/include/ruby/internal/arithmetic/mode_t.h b/include/ruby/internal/arithmetic/mode_t.h new file mode 100644 index 0000000000..81ae129924 --- /dev/null +++ b/include/ruby/internal/arithmetic/mode_t.h @@ -0,0 +1,34 @@ +#ifndef RBIMPL_ARITHMETIC_MODE_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_MODE_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `mode_t` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/int.h" + +#ifndef NUM2MODET +# define NUM2MODET RB_NUM2INT +#endif + +#ifndef MODET2NUM +# define MODET2NUM RB_INT2NUM +#endif + +#endif /* RBIMPL_ARITHMETIC_MODE_T_H */ diff --git a/include/ruby/internal/arithmetic/off_t.h b/include/ruby/internal/arithmetic/off_t.h new file mode 100644 index 0000000000..2abada5441 --- /dev/null +++ b/include/ruby/internal/arithmetic/off_t.h @@ -0,0 +1,49 @@ +#ifndef RBIMPL_ARITHMETIC_OFF_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_OFF_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `off_t` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/int.h" +#include "ruby/impl/arithmetic/long.h" +#include "ruby/impl/arithmetic/long_long.h" +#include "ruby/backward/2/long_long.h" + +#ifdef OFFT2NUM +# /* take that. */ +#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG +# define OFFT2NUM RB_LL2NUM +#elif SIZEOF_OFF_T == SIZEOF_LONG +# define OFFT2NUM RB_LONG2NUM +#else +# define OFFT2NUM RB_INT2NUM +#endif + +#ifdef NUM2OFFT +# /* take that. */ +#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG +# define NUM2OFFT RB_NUM2LL +#elif SIZEOF_OFF_T == SIZEOF_LONG +# define NUM2OFFT RB_NUM2LONG +#else +# define NUM2OFFT RB_NUM2INT +#endif + +#endif /* RBIMPL_ARITHMETIC_OFF_T_H */ diff --git a/include/ruby/internal/arithmetic/pid_t.h b/include/ruby/internal/arithmetic/pid_t.h new file mode 100644 index 0000000000..7af279a698 --- /dev/null +++ b/include/ruby/internal/arithmetic/pid_t.h @@ -0,0 +1,34 @@ +#ifndef RBIMPL_ARITHMETIC_PID_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_PID_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `pid_t` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/long.h" + +#ifndef PIDT2NUM +# define PIDT2NUM RB_LONG2NUM +#endif + +#ifndef NUM2PIDT +# define NUM2PIDT RB_NUM2LONG +#endif + +#endif /* RBIMPL_ARITHMETIC_PID_T_H */ diff --git a/include/ruby/internal/arithmetic/short.h b/include/ruby/internal/arithmetic/short.h new file mode 100644 index 0000000000..d952e5ba99 --- /dev/null +++ b/include/ruby/internal/arithmetic/short.h @@ -0,0 +1,54 @@ +#ifndef RBIMPL_ARITHMETIC_SHORT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_SHORT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `short` and Ruby's. + * + * Shyouhei wonders: why there is no SHORT2NUM, given there are both + * #USHORT2NUM and #CHR2FIX? + */ +#include "ruby/impl/value.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" + +#define RB_NUM2SHORT rb_num2short_inline +#define RB_NUM2USHORT rb_num2ushort +#define NUM2SHORT RB_NUM2SHORT +#define NUM2USHORT RB_NUM2USHORT +#define USHORT2NUM RB_INT2FIX +#define RB_FIX2SHORT rb_fix2short +#define FIX2SHORT RB_FIX2SHORT + +RBIMPL_SYMBOL_EXPORT_BEGIN() +short rb_num2short(VALUE); +unsigned short rb_num2ushort(VALUE); +short rb_fix2short(VALUE); +unsigned short rb_fix2ushort(VALUE); +RBIMPL_SYMBOL_EXPORT_END() + +static inline short +rb_num2short_inline(VALUE x) +{ + if (RB_FIXNUM_P(x)) + return rb_fix2short(x); + else + return rb_num2short(x); +} + +#endif /* RBIMPL_ARITHMETIC_SOHRT_H */ diff --git a/include/ruby/internal/arithmetic/size_t.h b/include/ruby/internal/arithmetic/size_t.h new file mode 100644 index 0000000000..661e18ed41 --- /dev/null +++ b/include/ruby/internal/arithmetic/size_t.h @@ -0,0 +1,51 @@ +#ifndef RBIMPL_ARITHMETIC_SIZE_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_SIZE_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `size_t` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/int.h" +#include "ruby/impl/arithmetic/long.h" +#include "ruby/impl/arithmetic/long_long.h" +#include "ruby/backward/2/long_long.h" + +#if SIZEOF_SIZE_T == SIZEOF_LONG_LONG +# define SIZET2NUM RB_ULL2NUM +# define SSIZET2NUM RB_LL2NUM +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define SIZET2NUM RB_ULONG2NUM +# define SSIZET2NUM RB_LONG2NUM +#else +# define SIZET2NUM RB_UINT2NUM +# define SSIZET2NUM RB_INT2NUM +#endif + +#if SIZEOF_SIZE_T == SIZEOF_LONG_LONG +# define NUM2SIZET RB_NUM2ULL +# define NUM2SSIZET RB_NUM2LL +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define NUM2SIZET RB_NUM2ULONG +# define NUM2SSIZET RB_NUM2LONG +#else +# define NUM2SIZET RB_NUM2UINT +# define NUM2SSIZET RB_NUM2INT +#endif + +#endif /* RBIMPL_ARITHMETIC_SIZE_T_H */ diff --git a/include/ruby/internal/arithmetic/st_data_t.h b/include/ruby/internal/arithmetic/st_data_t.h new file mode 100644 index 0000000000..148816c265 --- /dev/null +++ b/include/ruby/internal/arithmetic/st_data_t.h @@ -0,0 +1,59 @@ +#ifndef RBIMPL_ARITHMERIC_ST_DATA_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMERIC_ST_DATA_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `st_data_t` and Ruby's. + */ +#include "ruby/impl/arithmetic/fixnum.h" +#include "ruby/impl/arithmetic/long.h" +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/value.h" +#include "ruby/assert.h" +#include "ruby/st.h" + +#define ST2FIX RB_ST2FIX +/** @cond INTERNAL_MACRO */ +#define RB_ST2FIX RB_ST2FIX +/** @endcond */ + +RBIMPL_ATTR_CONST_ON_NDEBUG() +RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_ARTIFICIAL() +/* See also [ruby-core:84395] [Bug #14218] [ruby-core:82687] [Bug #13877] */ +static inline VALUE +RB_ST2FIX(st_data_t i) +{ + SIGNED_VALUE x = i; + + if (x >= 0) { + x &= RUBY_FIXNUM_MAX; + } + else { + x |= RUBY_FIXNUM_MIN; + } + + RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(x)); + unsigned long y = RBIMPL_CAST((unsigned long)x); + return RB_LONG2FIX(y); +} + +#endif /* RBIMPL_ARITHMERIC_ST_DATA_T_H */ diff --git a/include/ruby/internal/arithmetic/uid_t.h b/include/ruby/internal/arithmetic/uid_t.h new file mode 100644 index 0000000000..8ea42f5c92 --- /dev/null +++ b/include/ruby/internal/arithmetic/uid_t.h @@ -0,0 +1,34 @@ +#ifndef RBIMPL_ARITHMETIC_UID_T_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ARITHMETIC_UID_T_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Arithmetic conversion between C's `uid_t` and Ruby's. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/arithmetic/long.h" + +#ifndef UIDT2NUM +# define UIDT2NUM RB_LONG2NUM +#endif + +#ifndef NUM2UIDT +# define NUM2UIDT RB_NUM2LONG +#endif + +#endif /* RBIMPL_ARITHMETIC_UID_T_H */ diff --git a/include/ruby/internal/assume.h b/include/ruby/internal/assume.h new file mode 100644 index 0000000000..fa4a89514a --- /dev/null +++ b/include/ruby/internal/assume.h @@ -0,0 +1,90 @@ +#ifndef RBIMPL_ASSUME_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ASSUME_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ASSUME / #RBIMPL_UNREACHABLE. + * + * These macros must be defined at once because: + * + * - #RBIMPL_ASSUME could fallback to #RBIMPL_UNREACHABLE. + * - #RBIMPL_UNREACHABLE could fallback to #RBIMPL_ASSUME. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/builtin.h" +#include "ruby/impl/warning_push.h" + +/** @cond INTERNAL_MACRO */ +#if RBIMPL_COMPILER_SINCE(MSVC, 13, 10, 0) +# define RBIMPL_HAVE___ASSUME + +#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) +# define RBIMPL_HAVE___ASSUME +#endif +/** @endcond */ + +/** Wraps (or simulates) `__builtin_unreachable`. */ +#if RBIMPL_HAS_BUILTIN(__builtin_unreachable) +# define RBIMPL_UNREACHABLE_RETURN(_) __builtin_unreachable() + +#elif defined(RBIMPL_HAVE___ASSUME) +# define RBIMPL_UNREACHABLE_RETURN(_) return (__assume(0), (_)) + +#else +# define RBIMPL_UNREACHABLE_RETURN(_) return (_) +#endif + +/** Wraps (or simulates) `__builtin_unreachable`. */ +#if RBIMPL_HAS_BUILTIN(__builtin_unreachable) +# define RBIMPL_UNREACHABLE __builtin_unreachable + +#elif defined(RBIMPL_HAVE___ASSUME) +# define RBIMPL_UNREACHABLE() __assume(0) +#endif + +/** Wraps (or simulates) `__assume`. */ +#if RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) +# /* icc warnings are false positives. Ignore them. */ +# /* "warning #2261: __assume expression with side effects discarded" */ +# define RBIMPL_ASSUME(expr) \ + RBIMPL_WARNING_PUSH() \ + RBIMPL_WARNING_IGNORED(2261) \ + __assume(expr) \ + RBIMPL_WARNING_POP() + +#elif defined(RBIMPL_HAVE___ASSUME) +# define RBIMPL_ASSUME __assume + +#elif RBIMPL_HAS_BUILTIN(__builtin_assume) +# define RBIMPL_ASSUME __builtin_assume + +#elif ! defined(RBIMPL_UNREACHABLE) +# define RBIMPL_ASSUME(_) RBIMPL_CAST((void)(_)) + +#else +# define RBIMPL_ASSUME(_) \ + (RB_LIKELY(!!(_)) ? RBIMPL_CAST((void)0) : RBIMPL_UNREACHABLE()) +#endif + +#if ! defined(RBIMPL_UNREACHABLE) +# define RBIMPL_UNREACHABLE() RBIMPL_ASSUME(0) +#endif + +#endif /* RBIMPL_ASSUME_H */ diff --git a/include/ruby/internal/attr/alloc_size.h b/include/ruby/internal/attr/alloc_size.h new file mode 100644 index 0000000000..9dd79f15fc --- /dev/null +++ b/include/ruby/internal/attr/alloc_size.h @@ -0,0 +1,32 @@ +#ifndef RBIMPL_ATTR_ALLOC_SIZE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_ALLOC_SIZE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_ALLOC_SIZE. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((alloc_size))` */ +#if RBIMPL_HAS_ATTRIBUTE(alloc_size) +# define RBIMPL_ATTR_ALLOC_SIZE(tuple) __attribute__((__alloc_size__ tuple)) +#else +# define RBIMPL_ATTR_ALLOC_SIZE(tuple) /* void */ +#endif + +#endif /* RBIMPL_ATTR_ALLOC_SIZE_H */ diff --git a/include/ruby/internal/attr/artificial.h b/include/ruby/internal/attr/artificial.h new file mode 100644 index 0000000000..7c9dc3e175 --- /dev/null +++ b/include/ruby/internal/attr/artificial.h @@ -0,0 +1,46 @@ +#ifndef RBIMPL_ATTR_ARTIFICIAL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_ARTIFICIAL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_ARTIFICIAL. + * + * ### Q&A ### + * + * - Q: What is this attribute? I don't get what GCC manual is talking about. + * + * - A: In short it is an attribute to manipulate GDB backtraces. The + * attribute makes the best sense when it comes with + * __attribute__((always_inline)). When a function annotated with this + * attribute gets inlined, and when you somehow look at a backtrace which + * includes such inlined call site, then the backtrace shows the caller + * and not the callee. This is handy for instance when an identical + * function is inlined more than once in a single big function. On such + * case it gets vital to know where the inlining happened in the callee. + * See also https://stackoverflow.com/a/21936099 + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((artificial))` */ +#if RBIMPL_HAS_ATTRIBUTE(artificial) +# define RBIMPL_ATTR_ARTIFICIAL() __attribute__((__artificial__)) +#else +# define RBIMPL_ATTR_ARTIFICIAL() /* void */ +#endif + +#endif /* RBIMPL_ATTR_ARTIFICIAL_H */ diff --git a/include/ruby/internal/attr/cold.h b/include/ruby/internal/attr/cold.h new file mode 100644 index 0000000000..85877b6136 --- /dev/null +++ b/include/ruby/internal/attr/cold.h @@ -0,0 +1,37 @@ +#ifndef RBIMPL_ATTR_COLD_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_COLD_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_COLD. + */ +#include "ruby/impl/compiler_is.h" +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((cold))` */ +#if RBIMPL_COMPILER_IS(SunPro) +# /* Recent SunPro has __has_attribute, and is borken. */ +# /* It reports it has attribute cold, reality isn't (warnings issued). */ +# define RBIMPL_ATTR_COLD() /* void */ +#elif RBIMPL_HAS_ATTRIBUTE(cold) +# define RBIMPL_ATTR_COLD() __attribute__((__cold__)) +#else +# define RBIMPL_ATTR_COLD() /* void */ +#endif + +#endif /* RBIMPL_ATTR_COLD_H */ diff --git a/include/ruby/internal/attr/const.h b/include/ruby/internal/attr/const.h new file mode 100644 index 0000000000..85892ea464 --- /dev/null +++ b/include/ruby/internal/attr/const.h @@ -0,0 +1,46 @@ +#ifndef RBIMPL_ATTR_CONST_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_CONST_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_CONST. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/declspec_attribute.h" + +/** Wraps (or simulates) `__attribute__((const))` */ +#if RBIMPL_HAS_ATTRIBUTE(const) +# define RBIMPL_ATTR_CONST() __attribute__((__const__)) +#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias) +# /* If a function can be a const, that is also a noalias. */ +# define RBIMPL_ATTR_CONST() __declspec(noalias) +#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_ATTR_CONST() _Pragma("no_side_effect") +#else +# define RBIMPL_ATTR_CONST() /* void */ +#endif + +/** Enables #RBIMPL_ATTR_CONST iff. #RUBY_NDEBUG. */ +#if RUBY_NDEBUG +# define RBIMPL_ATTR_CONST_ON_NDEBUG() RBIMPL_ATTR_CONST() +#else +# define RBIMPL_ATTR_CONST_ON_NDEBUG() /* void */ +#endif + +#endif /* RBIMPL_ATTR_CONST_H */ diff --git a/include/ruby/internal/attr/constexpr.h b/include/ruby/internal/attr/constexpr.h new file mode 100644 index 0000000000..4b6cc81e3b --- /dev/null +++ b/include/ruby/internal/attr/constexpr.h @@ -0,0 +1,85 @@ +#ifndef RBIMPL_ATTR_CONSTEXPR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_CONSTEXPR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief #RBIMPL_ATTR_CONSTEXPR. + */ +#include "ruby/impl/has/feature.h" +#include "ruby/impl/compiler_is.h" +#include "ruby/impl/token_paste.h" + +/** @cond INTERNAL_MACRO */ +#if ! defined(__cplusplus) +# /* Makes no sense. */ +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0 +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 + +#elif defined(__cpp_constexpr) +# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L) + +#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 00) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 00) + +#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 13, 0) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) + +#elif RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) + +#elif RBIMPL_HAS_FEATURE(cxx_relaxed_constexpr) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1 +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 1 + +#elif RBIMPL_HAS_FEATURE(cxx_constexpr) +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 1 +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 + +#else +# /* :FIXME: icpc must have constexpr but don't know how to detect. */ +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 0 +# define RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 0 +#endif +/** @endcond */ + +/** Wraps (or simulates) C++11 `constexpr`. */ +#if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14 +# define RBIMPL_ATTR_CONSTEXPR(_) constexpr + +#elif RBIMPL_HAS_ATTR_CONSTEXPR_CXX11 +# define RBIMPL_ATTR_CONSTEXPR(_) RBIMPL_TOKEN_PASTE(RBIMPL_ATTR_CONSTEXPR_, _) +# define RBIMPL_ATTR_CONSTEXPR_CXX11 constexpr +# define RBIMPL_ATTR_CONSTEXPR_CXX14 /* void */ + +#else +# define RBIMPL_ATTR_CONSTEXPR(_) /* void */ +#endif + +/** Enables #RBIMPL_ATTR_CONSTEXPR iff. #RUBY_NDEBUG. */ +#if RUBY_NDEBUG +# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) RBIMPL_ATTR_CONSTEXPR(_) +#else +# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) /* void */ +#endif + +#endif /* RBIMPL_ATTR_CONSTEXPR_H */ diff --git a/include/ruby/internal/attr/deprecated.h b/include/ruby/internal/attr/deprecated.h new file mode 100644 index 0000000000..c603d58a1f --- /dev/null +++ b/include/ruby/internal/attr/deprecated.h @@ -0,0 +1,59 @@ +#ifndef RBIMPL_ATTR_DEPRECATED_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_DEPRECATED_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_DEPRECATED. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/c_attribute.h" +#include "ruby/impl/has/cpp_attribute.h" +#include "ruby/impl/has/declspec_attribute.h" +#include "ruby/impl/has/extension.h" + +/** Wraps (or simulates) `[[deprecated]]` */ +#if RBIMPL_HAS_EXTENSION(attribute_deprecated_with_message) +# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) + +#elif RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0) +# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) + +#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) +# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) + +#elif RBIMPL_HAS_ATTRIBUTE(deprecated) /* but not with message. */ +# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__)) + +#elif RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0) +# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated msg) + +#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(deprecated) +# define RBIMPL_ATTR_DEPRECATED(msg) __declspec(deprecated) + +#elif RBIMPL_HAS_CPP_ATTRIBUTE(deprecated) +# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]] + +#elif RBIMPL_HAS_C_ATTRIBUTE(deprecated) +# define RBIMPL_ATTR_DEPRECATED(msg) [[deprecated msg]] + +#else +# define RBIMPL_ATTR_DEPRECATED(msg) /* void */ +#endif + +#endif /* RBIMPL_ATTR_DEPRECATED_H */ diff --git a/include/ruby/internal/attr/diagnose_if.h b/include/ruby/internal/attr/diagnose_if.h new file mode 100644 index 0000000000..ba6e8626e3 --- /dev/null +++ b/include/ruby/internal/attr/diagnose_if.h @@ -0,0 +1,42 @@ +#ifndef RBIMPL_ATTR_DIAGNOSE_IF_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_DIAGNOSE_IF_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_DIAGNOSE_IF. + */ +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/warning_push.h" + +/** Wraps (or simulates) `__attribute__((diagnose_if))` */ +#if RBIMPL_COMPILER_BEFORE(Clang, 5, 0, 0) +# /* https://bugs.llvm.org/show_bug.cgi?id=34319 */ +# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */ + +#elif RBIMPL_HAS_ATTRIBUTE(diagnose_if) +# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) \ + RBIMPL_WARNING_PUSH() \ + RBIMPL_WARNING_IGNORED(-Wgcc-compat) \ + __attribute__((__diagnose_if__(_, __, ___))) \ + RBIMPL_WARNING_POP() + +#else +# define RBIMPL_ATTR_DIAGNOSE_IF(_, __, ___) /* void */ +#endif + +#endif /* RBIMPL_ATTR_DIAGNOSE_IF_H */ diff --git a/include/ruby/internal/attr/enum_extensibility.h b/include/ruby/internal/attr/enum_extensibility.h new file mode 100644 index 0000000000..d5d25e03d7 --- /dev/null +++ b/include/ruby/internal/attr/enum_extensibility.h @@ -0,0 +1,32 @@ +#ifndef RBIMPL_ATTR_ENUM_EXTENSIBILITY_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_ENUM_EXTENSIBILITY_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief #RBIMPL_ATTR_ENUM_EXTENSIBILITY. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((enum_extensibility))` */ +#if RBIMPL_HAS_ATTRIBUTE(enum_extensibility) +# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) __attribute__((__enum_extensibility__(_))) +#else +# define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_) /* void */ +#endif + +#endif /* RBIMPL_ATTR_ENUM_EXTENSIBILITY_H */ diff --git a/include/ruby/internal/attr/error.h b/include/ruby/internal/attr/error.h new file mode 100644 index 0000000000..b46b306fb9 --- /dev/null +++ b/include/ruby/internal/attr/error.h @@ -0,0 +1,32 @@ +#ifndef RBIMPL_ATTR_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_ERROR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_ERROR. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((error))` */ +#if RBIMPL_HAS_ATTRIBUTE(error) +# define RBIMPL_ATTR_ERROR(msg) __attribute__((__error__ msg)) +#else +# define RBIMPL_ATTR_ERROR(msg) /* void */ +#endif + +#endif /* RBIMPL_ATTR_ERROR_H */ diff --git a/include/ruby/internal/attr/flag_enum.h b/include/ruby/internal/attr/flag_enum.h new file mode 100644 index 0000000000..e769708d93 --- /dev/null +++ b/include/ruby/internal/attr/flag_enum.h @@ -0,0 +1,33 @@ +#ifndef RBIMPL_ATTR_FLAG_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_FLAG_ENUM_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_FLAG_ENUM. + * @see https://clang.llvm.org/docs/AttributeReference.html#flag_enum + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((flag_enum)` */ +#if RBIMPL_HAS_ATTRIBUTE(flag_enum) +# define RBIMPL_ATTR_FLAG_ENUM() __attribute__((__flag_enum__)) +#else +# define RBIMPL_ATTR_FLAG_ENUM() /* void */ +#endif + +#endif /* RBIMPLATTR_FLAG_ENUM_H */ diff --git a/include/ruby/internal/attr/forceinline.h b/include/ruby/internal/attr/forceinline.h new file mode 100644 index 0000000000..8d60a63437 --- /dev/null +++ b/include/ruby/internal/attr/forceinline.h @@ -0,0 +1,40 @@ +#ifndef RBIMPL_ATTR_FORCEINLINE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_FORCEINLINE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_FORCEINLINE. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/attribute.h" + +/** + * Wraps (or simulates) `__forceinline`. MSVC complains on declarations like + * `static inline __forceinline void foo()`. It seems MSVC's `inline` and + * `__forceinline` are mutually exclusive. We have to mimic that behaviour for + * non-MSVC compilers. + */ +#if RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0) +# define RBIMPL_ATTR_FORCEINLINE() __forceinline +#elif RBIMPL_HAS_ATTRIBUTE(always_inline) +# define RBIMPL_ATTR_FORCEINLINE() __attribute__((__always_inline__)) inline +#else +# define RBIMPL_ATTR_FORCEINLINE() inline +#endif + +#endif /* RBIMPL_ATTR_FORCEINLINE_H */ diff --git a/include/ruby/internal/attr/format.h b/include/ruby/internal/attr/format.h new file mode 100644 index 0000000000..368c9f8797 --- /dev/null +++ b/include/ruby/internal/attr/format.h @@ -0,0 +1,38 @@ +#ifndef RBIMPL_ATTR_FORMAT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_FORMAT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_FORMAT. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((format))` */ +#if RBIMPL_HAS_ATTRIBUTE(format) +# define RBIMPL_ATTR_FORMAT(x, y, z) __attribute__((__format__(x, y, z))) +#else +# define RBIMPL_ATTR_FORMAT(x, y, z) /* void */ +#endif + +#if defined(__MINGW_PRINTF_FORMAT) +# define RBIMPL_PRINTF_FORMAT __MINGW_PRINTF_FORMAT +#else +# define RBIMPL_PRINTF_FORMAT __printf__ +#endif + +#endif /* RBIMPL_ATTR_FORMAT_H */ diff --git a/include/ruby/internal/attr/maybe_unused.h b/include/ruby/internal/attr/maybe_unused.h new file mode 100644 index 0000000000..d554603db5 --- /dev/null +++ b/include/ruby/internal/attr/maybe_unused.h @@ -0,0 +1,38 @@ +#ifndef RBIMPL_ATTR_MAYBE_UNUSED_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_MAYBE_UNUSED_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_MAYBE_UNUSED. + */ +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/c_attribute.h" +#include "ruby/impl/has/cpp_attribute.h" + +/** Wraps (or simulates) `[[maybe_unused]]` */ +#if RBIMPL_HAS_CPP_ATTRIBUTE(maybe_unused) +# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]] +#elif RBIMPL_HAS_C_ATTRIBUTE(maybe_unused) +# define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]] +#elif RBIMPL_HAS_ATTRIBUTE(unused) +# define RBIMPL_ATTR_MAYBE_UNUSED() __attribute__((__unused__)) +#else +# define RBIMPL_ATTR_MAYBE_UNUSED() /* void */ +#endif + +#endif /* RBIMPL_ATTR_MAYBE_UNUSED */ diff --git a/include/ruby/internal/attr/noalias.h b/include/ruby/internal/attr/noalias.h new file mode 100644 index 0000000000..0180d0c4ec --- /dev/null +++ b/include/ruby/internal/attr/noalias.h @@ -0,0 +1,58 @@ +#ifndef RBIMPL_ATTR_NOALIAS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_NOALIAS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_NOALIAS. + * + * ### Q&A ### + * + * - Q: There are seemingly similar attributes named #RBIMPL_ATTR_CONST, + * #RBIMPL_ATTR_PURE, and #RBIMPL_ATTR_NOALIAS. What are the difference? + * + * - A: Allowed operations are different. + * + * - #RBIMPL_ATTR_CONST ... Functions attributed by this are not allowed to + * read/write _any_ pointers at all (there are exceptional situations + * when reading a pointer is possible but forget that; they are too + * exceptional to be useful). Just remember that everything pointer- + * related are NG. + * + * - #RBIMPL_ATTR_PURE ... Functions attributed by this can read any + * nonvolatile pointers, but no writes are allowed at all. The ability + * to read _any_ nonvolatile pointers makes it possible to mark ::VALUE- + * taking functions as being pure, as long as they are read-only. + * + * - #RBIMPL_ATTR_NOALIAS ... Can both read/write, but only through + * pointers passed to the function as parameters. This is a typical + * situation when you create a C++ non-static member function which only + * concerns `this`. No global variables are allowed to read/write. So + * this is not a super-set of being pure. If you want to read something, + * that has to be passed to the function as a pointer. ::VALUE -taking + * functions thus cannot be attributed as such. + */ +#include "ruby/impl/has/declspec_attribute.h" + +/** Wraps (or simulates) `__declspec((noalias))` */ +#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noalias) +# define RBIMPL_ATTR_NOALIAS() __declspec(noalias) +#else +# define RBIMPL_ATTR_NOALIAS() /* void */ +#endif + +#endif /* RBIMPL_ATTR_NOALIAS_H */ diff --git a/include/ruby/internal/attr/nodiscard.h b/include/ruby/internal/attr/nodiscard.h new file mode 100644 index 0000000000..ee3a1347df --- /dev/null +++ b/include/ruby/internal/attr/nodiscard.h @@ -0,0 +1,45 @@ +#ifndef RBIMPL_ATTR_NODISCARD_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_NODISCARD_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_NODISCARD. + */ +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/c_attribute.h" +#include "ruby/impl/has/cpp_attribute.h" + +/** + * Wraps (or simulates) `[[nodiscard]]`. In C++ (at least since C++20) a + * nodiscard attribute can have a message why the result shall not be ignoed. + * However GCC attribute and SAL annotation cannot take them. + */ +#if RBIMPL_HAS_CPP_ATTRIBUTE(nodiscard) +# define RBIMPL_ATTR_NODISCARD() [[nodiscard]] +#elif RBIMPL_HAS_C_ATTRIBUTE(nodiscard) +# define RBIMPL_ATTR_NODISCARD() [[nodiscard]] +#elif RBIMPL_HAS_ATTRIBUTE(warn_unused_result) +# define RBIMPL_ATTR_NODISCARD() __attribute__((__warn_unused_result__)) +#elif defined(_Check_return_) +# /* Take SAL definition. */ +# define RBIMPL_ATTR_NODISCARD() _Check_return_ +#else +# define RBIMPL_ATTR_NODISCARD() /* void */ +#endif + +#endif /* RBIMPL_ATTR_NODISCARD_H */ diff --git a/include/ruby/internal/attr/noexcept.h b/include/ruby/internal/attr/noexcept.h new file mode 100644 index 0000000000..ac0ec4c10d --- /dev/null +++ b/include/ruby/internal/attr/noexcept.h @@ -0,0 +1,91 @@ +#ifndef RBIMPL_ATTR_NOEXCEPT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_NOEXCEPT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_NOEXCEPT. + * + * This isn't actually an attribute in C++ but who cares... + * + * Mainly due to aesthetic reasons, this one is rarely used in the project. + * But can be handy on occasions, especially when a function's noexcept-ness + * depends on its calling functions. + * + * ### Q&A ### + * + * - Q: Can a function that raises Ruby exceptions be attributed `noexcept`? + * + * - A: Yes. `noexcept` is about C++ exceptions, not Ruby's. They don't + * interface each other. You can safely attribute a function that raises + * Ruby exceptions as `noexcept`. + * + * - Q: How, then, can I assert that a function I wrote doesn't raise any Ruby + * exceptions? + * + * - A: `__attribute__((__leaf__))` is for that purpose. A function attributed + * as leaf can still throw C++ exceptions, but not Ruby's. Note however, + * that it's extremely difficult -- if not impossible -- to assert that a + * function doesn't raise any Ruby exceptions at all. Use of that + * attribute is not recommended; mere mortals can't properly use that by + * hand. + * + * - Q: Does it make sense to attribute an inline function `noexcept`? + * + * - A: I thought so before. But no, I don't think they are useful any longer. + * + * - When an inline function attributed `noexcept` actually doesn't throw + * any exceptions at all: these days I don't see any difference in + * generated assembly by adding/removing this attribute. C++ compilers + * get smarter and smarter. Today they can infer if it actually throws + * or not without any annotations by humans (correct me if I'm wrong). + * + * - When an inline function attributed `noexcepr` actually _does_ throw an + * exception: they have to call `std::terminate` then (C++ standard + * mandates so). This means exception handling routines are actually + * enforced, not omitted. This doesn't impact runtime performance (The + * Itanium C++ ABI has zero-cost exception handling), but does impact on + * generated binary size. This is bad. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/feature.h" + +/** Wraps (or simulates) C++11 `noexcept` */ +#if ! defined(__cplusplus) +# /* Doesn't make sense. */ +# define RBIMPL_ATTR_NOEXCEPT(_) /* void */ + +#elif RBIMPL_HAS_FEATURE(cxx_noexcept) +# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ +# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif defined(__INTEL_CXX11_MODE__) +# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif RBIMPL_COMPILER_SINCE(MSVC, 19, 0, 0) +# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif __cplusplus >= 201103L +# define RBIMPL_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#else +# define RBIMPL_ATTR_NOEXCEPT(_) /* void */ +#endif + +#endif /* RBIMPL_ATTR_NOEXCEPT_H */ diff --git a/include/ruby/internal/attr/noinline.h b/include/ruby/internal/attr/noinline.h new file mode 100644 index 0000000000..c2cc007969 --- /dev/null +++ b/include/ruby/internal/attr/noinline.h @@ -0,0 +1,35 @@ +#ifndef RBIMPL_ATTR_NOINLINE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_NOINLINE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_NOINLINE. + */ +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/declspec_attribute.h" + +/** Wraps (or simulates) `__declspec(noinline)` */ +#if RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noinline) +# define RBIMPL_ATTR_NOINLINE() __declspec(noinline) +#elif RBIMPL_HAS_ATTRIBUTE(noinline) +# define RBIMPL_ATTR_NOINLINE() __attribute__((__noinline__)) +#else +# define RBIMPL_ATTR_NOINLINE() /* void */ +#endif + +#endif /* RBIMPL_ATTR_NOINLINE_H */ diff --git a/include/ruby/internal/attr/nonnull.h b/include/ruby/internal/attr/nonnull.h new file mode 100644 index 0000000000..a1d0320e1d --- /dev/null +++ b/include/ruby/internal/attr/nonnull.h @@ -0,0 +1,32 @@ +#ifndef RBIMPL_ATTR_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_NONNULL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_NONNULL. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((nonnull))` */ +#if RBIMPL_HAS_ATTRIBUTE(nonnull) +# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list)) +#else +# define RBIMPL_ATTR_NONNULL(list) /* void */ +#endif + +#endif /* RBIMPL_ATTR_NONNULL_H */ diff --git a/include/ruby/internal/attr/noreturn.h b/include/ruby/internal/attr/noreturn.h new file mode 100644 index 0000000000..66a9b42947 --- /dev/null +++ b/include/ruby/internal/attr/noreturn.h @@ -0,0 +1,52 @@ +#ifndef RBIMPL_ATTR_NORETURN_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_NORETURN_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_NORETURN. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/cpp_attribute.h" +#include "ruby/impl/has/declspec_attribute.h" + +/** Wraps (or simulates) `[[noreturn]]` */ +#if RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_ATTR_NORETURN() _Pragma("does_not_return") + +#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn) +# define RBIMPL_ATTR_NORETURN() __declspec(noreturn) + +#elif RBIMPL_HAS_ATTRIBUTE(noreturn) +# define RBIMPL_ATTR_NORETURN() __attribute__((__noreturn__)) + +#elif RBIMPL_HAS_CPP_ATTRIBUTE(noreturn) +# define RBIMPL_ATTR_NORETURN() [[noreturn]] + +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112) +# define RBIMPL_ATTR_NORETURN() _Noreturn + +#elif defined(_Noreturn) +# /* glibc has this macro. */ +# define RBIMPL_ATTR_NORETURN() _Noreturn + +#else +# define RBIMPL_ATTR_NORETURN() /* void */ +#endif + +#endif /* RBIMPL_ATTR_NORETURN_H */ diff --git a/include/ruby/internal/attr/pure.h b/include/ruby/internal/attr/pure.h new file mode 100644 index 0000000000..a5bb51b76f --- /dev/null +++ b/include/ruby/internal/attr/pure.h @@ -0,0 +1,43 @@ +#ifndef RBIMPL_ATTR_PURE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_PURE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_PURE. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/assert.h" + +/** Wraps (or simulates) `__attribute__((pure))` */ +#if RBIMPL_HAS_ATTRIBUTE(pure) +# define RBIMPL_ATTR_PURE() __attribute__((__pure__)) +#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_ATTR_PURE() _Pragma("does_not_write_global_data") +#else +# define RBIMPL_ATTR_PURE() /* void */ +#endif + +/** Enables #RBIMPL_ATTR_PURE iff. #RUBY_NDEBUG. */ +#if RUBY_NDEBUG +# define RBIMPL_ATTR_PURE_ON_NDEBUG() RBIMPL_ATTR_PURE() +#else +# define RBIMPL_ATTR_PURE_ON_NDEBUG() /* void */ +#endif + +#endif /* RBIMPL_ATTR_PURE_H */ diff --git a/include/ruby/internal/attr/restrict.h b/include/ruby/internal/attr/restrict.h new file mode 100644 index 0000000000..518906f6da --- /dev/null +++ b/include/ruby/internal/attr/restrict.h @@ -0,0 +1,45 @@ +#ifndef RBIMPL_ATTR_RESTRICT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_RESTRICT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_RESTRICT. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/token_paste.h" + +/* :FIXME: config.h includes conflicting `#define restrict`. MSVC can be + * detected using `RBIMPL_COMPILER_SINCE()`, but Clang & family cannot use + * `__has_declspec_attribute()` which involves macro substitution. */ + +/** Wraps (or simulates) `__declspec(restrict)` */ +#if RBIMPL_COMPILER_SINCE(MSVC, 14, 0, 0) +# define RBIMPL_ATTR_RESTRICT() __declspec(RBIMPL_TOKEN_PASTE(re, strict)) + +#elif RBIMPL_HAS_ATTRIBUTE(malloc) +# define RBIMPL_ATTR_RESTRICT() __attribute__((__malloc__)) + +#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_ATTR_RESTRICT() _Pragma("returns_new_memory") + +#else +# define RBIMPL_ATTR_RESTRICT() /* void */ +#endif + +#endif /* RBIMPL_ATTR_RESTRICT_H */ diff --git a/include/ruby/internal/attr/returns_nonnull.h b/include/ruby/internal/attr/returns_nonnull.h new file mode 100644 index 0000000000..f656d70c8c --- /dev/null +++ b/include/ruby/internal/attr/returns_nonnull.h @@ -0,0 +1,37 @@ +#ifndef RBIMPL_ATTR_RETURNS_NONNULL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_RETURNS_NONNULL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_RETURNS_NONNULL. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((returns_nonnull))` */ +#if defined(_Ret_nonnull_) +# /* Take SAL definition. */ +# define RBIMPL_ATTR_RETURNS_NONNULL() _Ret_nonnull_ + +#elif RBIMPL_HAS_ATTRIBUTE(returns_nonnull) +# define RBIMPL_ATTR_RETURNS_NONNULL() __attribute__((__returns_nonnull__)) + +#else +# define RBIMPL_ATTR_RETURNS_NONNULL() /* void */ +#endif + +#endif /* RBIMPL_ATTR_RETURNS_NONNULL_H */ diff --git a/include/ruby/internal/attr/warning.h b/include/ruby/internal/attr/warning.h new file mode 100644 index 0000000000..e7585e0417 --- /dev/null +++ b/include/ruby/internal/attr/warning.h @@ -0,0 +1,32 @@ +#ifndef RBIMPL_ATTR_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_WARNING_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_WARNING. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((warning))` */ +#if RBIMPL_HAS_ATTRIBUTE(warning) +# define RBIMPL_ATTR_WARNING(msg) __attribute__((__warning__ msg)) +#else +# define RBIMPL_ATTR_WARNING(msg) /* void */ +#endif + +#endif /* RBIMPL_ATTR_WARNING_H */ diff --git a/include/ruby/internal/attr/weakref.h b/include/ruby/internal/attr/weakref.h new file mode 100644 index 0000000000..769ce017e0 --- /dev/null +++ b/include/ruby/internal/attr/weakref.h @@ -0,0 +1,32 @@ +#ifndef RBIMPL_ATTR_WEAKREF_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ATTR_WEAKREF_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ATTR_WEAKREF. + */ +#include "ruby/impl/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((weakref))` */ +#if RBIMPL_HAS_ATTRIBUTE(weakref) +# define RBIMPL_ATTR_WEAKREF(sym) __attribute__((__weakref__(# sym))) +#else +# define RBIMPL_ATTR_WEAKREF(sym) /* void */ +#endif + +#endif /* RBIMPL_ATTR_WEAKREF_H */ diff --git a/include/ruby/internal/cast.h b/include/ruby/internal/cast.h new file mode 100644 index 0000000000..4524d63f17 --- /dev/null +++ b/include/ruby/internal/cast.h @@ -0,0 +1,53 @@ +#ifndef RBIMPL_CAST_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_CAST_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines RBIMPL_CAST. + * @cond INTERNAL_MACRO + * + * This casting macro makes sense only inside of other macros that are part of + * public headers. They could be used from C++, and C-style casts could issue + * warnings. Ruby internals are pure C so they should not bother. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/warning.h" +#include "ruby/impl/warning_push.h" + +#if ! defined(__cplusplus) +# define RBIMPL_CAST(expr) (expr) + +#elif RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) +# /* g++ has -Wold-style-cast since 1997 or so, but its _Pragma is broken. */ +# /* See https://gcc.godbolt.org/z/XWhU6J */ +# define RBIMPL_CAST(expr) (expr) +# pragma GCC diagnostic ignored "-Wold-style-cast" + +#elif RBIMPL_HAS_WARNING("-Wold-style-cast") +# define RBIMPL_CAST(expr) \ + RBIMPL_WARNING_PUSH() \ + RBIMPL_WARNING_IGNORED(-Wold-style-cast) \ + (expr) \ + RBIMPL_WARNING_POP() + +#else +# define RBIMPL_CAST(expr) (expr) +#endif +/** @endcond */ + +#endif /* RBIMPL_CAST_H */ diff --git a/include/ruby/internal/compiler_is.h b/include/ruby/internal/compiler_is.h new file mode 100644 index 0000000000..3f34bc1a15 --- /dev/null +++ b/include/ruby/internal/compiler_is.h @@ -0,0 +1,45 @@ +#ifndef RBIMPL_COMPILER_IS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS. + */ + +/** + * @brief Checks if the compiler is of given brand. + * @param cc Compiler brand, like `MSVC`. + * @retval true It is. + * @retval false It isn't. + */ +#define RBIMPL_COMPILER_IS(cc) RBIMPL_COMPILER_IS_ ## cc + +#include "ruby/impl/compiler_is/apple.h" +#include "ruby/impl/compiler_is/clang.h" +#include "ruby/impl/compiler_is/gcc.h" +#include "ruby/impl/compiler_is/intel.h" +#include "ruby/impl/compiler_is/msvc.h" +#include "ruby/impl/compiler_is/sunpro.h" +/* :TODO: Other possible compilers to support: + * + * - IBM XL: recent XL are clang-backended so some tweaks like we do for + * Apple's might be needed. + * + * - ARM's armclang: ditto, it can be clang-backended. */ + +#endif /* RBIMPL_COMPILER_IS_H */ diff --git a/include/ruby/internal/compiler_is/apple.h b/include/ruby/internal/compiler_is/apple.h new file mode 100644 index 0000000000..5a5f558254 --- /dev/null +++ b/include/ruby/internal/compiler_is/apple.h @@ -0,0 +1,41 @@ +#ifndef RBIMPL_COMPILER_IS_APPLE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_APPLE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS_Apple. + * + * Apple ships clang. Problem is, its `__clang_major__` etc. are not the + * upstream LLVM version, but XCode's. We have to think Apple's is distinct + * from LLVM's, when it comes to compiler detection business in this header + * file. + */ +#if ! defined(__clang__) +# define RBIMPL_COMPILER_IS_Apple 0 + +#elif ! defined(__apple_build_version__) +# define RBIMPL_COMPILER_IS_Apple 0 + +#else +# define RBIMPL_COMPILER_IS_Apple 1 +# define RBIMPL_COMPILER_VERSION_MAJOR __clang_major__ +# define RBIMPL_COMPILER_VERSION_MINOR __clang_minor__ +# define RBIMPL_COMPILER_VERSION_PATCH __clang_patchlevel__ +#endif + +#endif /* RBIMPL_COMPILER_IS_APPLE_H */ diff --git a/include/ruby/internal/compiler_is/clang.h b/include/ruby/internal/compiler_is/clang.h new file mode 100644 index 0000000000..40646750cb --- /dev/null +++ b/include/ruby/internal/compiler_is/clang.h @@ -0,0 +1,38 @@ +#ifndef RBIMPL_COMPILER_IS_CLANG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_CLANG_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS_Clang. + */ +#include "ruby/impl/compiler_is/apple.h" + +#if ! defined(__clang__) +# define RBIMPL_COMPILER_IS_Clang 0 + +#elif RBIMPL_COMPILER_IS(Apple) +# define RBIMPL_COMPILER_IS_Clang 0 + +#else +# define RBIMPL_COMPILER_IS_Clang 1 +# define RBIMPL_COMPILER_VERSION_MAJOR __clang_major__ +# define RBIMPL_COMPILER_VERSION_MINOR __clang_minor__ +# define RBIMPL_COMPILER_VERSION_PATCH __clang_patchlevel__ +#endif + +#endif /* RBIMPL_COMPILER_IS_CLANG_H */ diff --git a/include/ruby/internal/compiler_is/gcc.h b/include/ruby/internal/compiler_is/gcc.h new file mode 100644 index 0000000000..06f0b2b9f6 --- /dev/null +++ b/include/ruby/internal/compiler_is/gcc.h @@ -0,0 +1,46 @@ +#ifndef RBIMPL_COMPILER_IS_GCC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_GCC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS_GCC. + */ +#include "ruby/impl/compiler_is/apple.h" +#include "ruby/impl/compiler_is/clang.h" +#include "ruby/impl/compiler_is/intel.h" + +#if ! defined(__GNUC__) +# define RBIMPL_COMPILER_IS_GCC 0 + +#elif RBIMPL_COMPILER_IS(Apple) +# define RBIMPL_COMPILER_IS_GCC 0 + +#elif RBIMPL_COMPILER_IS(Clang) +# define RBIMPL_COMPILER_IS_GCC 0 + +#elif RBIMPL_COMPILER_IS(Intel) +# define RBIMPL_COMPILER_IS_GCC 0 + +#else +# define RBIMPL_COMPILER_IS_GCC 1 +# define RBIMPL_COMPILER_VERSION_MAJOR __GNUC__ +# define RBIMPL_COMPILER_VERSION_MINOR __GNUC_MINOR__ +# define RBIMPL_COMPILER_VERSION_PATCH __GNUC_PATCHLEVEL__ +#endif + +#endif /* RBIMPL_COMPILER_IS_GCC_H */ diff --git a/include/ruby/internal/compiler_is/intel.h b/include/ruby/internal/compiler_is/intel.h new file mode 100644 index 0000000000..ada120485e --- /dev/null +++ b/include/ruby/internal/compiler_is/intel.h @@ -0,0 +1,41 @@ +#ifndef RBIMPL_COMPILER_IS_INTEL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_INTEL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS_Intel. + */ +#if ! defined(__INTEL_COMPILER) +# define RBIMPL_COMPILER_IS_Intel 0 + +#elif ! defined(__INTEL_COMPILER_UPDATE) +# define RBIMPL_COMPILER_IS_Intel 1 +# /* __INTEL_COMPILER = XXYZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (__INTEL_COMPILER / 100) +# define RBIMPL_COMPILER_VERSION_MINOR (__INTEL_COMPILER % 100 / 10) +# define RBIMPL_COMPILER_VERSION_PATCH (__INTEL_COMPILER % 10) + +#else +# define RBIMPL_COMPILER_IS_Intel 1 +# /* __INTEL_COMPILER = XXYZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (__INTEL_COMPILER / 100) +# define RBIMPL_COMPILER_VERSION_MINOR (__INTEL_COMPILER % 100 / 10) +# define RBIMPL_COMPILER_VERSION_PATCH __INTEL_COMPILER_UPDATE +#endif + +#endif /* RBIMPL_COMPILER_IS_INTEL_H */ diff --git a/include/ruby/internal/compiler_is/msvc.h b/include/ruby/internal/compiler_is/msvc.h new file mode 100644 index 0000000000..f66050e9c4 --- /dev/null +++ b/include/ruby/internal/compiler_is/msvc.h @@ -0,0 +1,57 @@ +#ifndef RBIMPL_COMPILER_IS_MSVC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_MSVC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS_MSVC. + */ +#include "ruby/impl/compiler_is/clang.h" +#include "ruby/impl/compiler_is/intel.h" + +#if ! defined(_MSC_VER) +# define RBIMPL_COMPILER_IS_MSVC 0 + +#elif RBIMPL_COMPILER_IS(Clang) +# define RBIMPL_COMPILER_IS_MSVC 0 + +#elif RBIMPL_COMPILER_IS(Intel) +# define RBIMPL_COMPILER_IS_MSVC 0 + +#elif _MSC_VER >= 1400 +# define RBIMPL_COMPILER_IS_MSVC 1 +# /* _MSC_FULL_VER = XXYYZZZZZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 10000000) +# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_FULL_VER % 10000000 / 100000) +# define RBIMPL_COMPILER_VERSION_PATCH (_MSC_FULL_VER % 100000) + +#elif defined(_MSC_FULL_VER) +# define RBIMPL_COMPILER_IS_MSVC 1 +# /* _MSC_FULL_VER = XXYYZZZZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_FULL_VER / 1000000) +# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_FULL_VER % 1000000 / 10000) +# define RBIMPL_COMPILER_VERSION_PATCH (_MSC_FULL_VER % 10000) + +#else +# define RBIMPL_COMPILER_IS_MSVC 1 +# /* _MSC_VER = XXYY */ +# define RBIMPL_COMPILER_VERSION_MAJOR (_MSC_VER / 100) +# define RBIMPL_COMPILER_VERSION_MINOR (_MSC_VER % 100) +# define RBIMPL_COMPILER_VERSION_PATCH 0 +#endif + +#endif /* RBIMPL_COMPILER_IS_MSVC_H */ diff --git a/include/ruby/internal/compiler_is/sunpro.h b/include/ruby/internal/compiler_is/sunpro.h new file mode 100644 index 0000000000..2eb7b892f2 --- /dev/null +++ b/include/ruby/internal/compiler_is/sunpro.h @@ -0,0 +1,55 @@ +#ifndef RBIMPL_COMPILER_IS_SUNPRO_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_IS_SUNPRO_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_IS_SunPro. + */ +#if ! (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) +# define RBIMPL_COMPILER_IS_SunPro 0 + +#elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x5100 +# define RBIMPL_COMPILER_IS_SunPro 1 +# /* __SUNPRO_C = 0xXYYZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_C >> 12) +# define RBIMPL_COMPILER_VERSION_MINOR ((__SUNPRO_C >> 8 & 0xF) * 10 + (__SUNPRO_C >> 4 & 0xF)) +# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_C & 0xF) + +#elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5100 +# define RBIMPL_COMPILER_IS_SunPro 1 +# /* __SUNPRO_CC = 0xXYYZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_CC >> 12) +# define RBIMPL_COMPILER_VERSION_MINOR ((__SUNPRO_CC >> 8 & 0xF) * 10 + (__SUNPRO_CC >> 4 & 0xF)) +# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_CC & 0xF) + +#elif defined(__SUNPRO_C) +# define RBIMPL_COMPILER_IS_SunPro 1 +# /* __SUNPRO_C = 0xXYZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_C >> 8) +# define RBIMPL_COMPILER_VERSION_MINOR (__SUNPRO_C >> 4 & 0xF) +# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_C & 0xF) + +#else +# define RBIMPL_COMPILER_IS_SunPro 1 +# /* __SUNPRO_CC = 0xXYZ */ +# define RBIMPL_COMPILER_VERSION_MAJOR (__SUNPRO_CC >> 8) +# define RBIMPL_COMPILER_VERSION_MINOR (__SUNPRO_CC >> 4 & 0xF) +# define RBIMPL_COMPILER_VERSION_PATCH (__SUNPRO_CC & 0xF) +#endif + +#endif /* RBIMPL_COMPILER_IS_SUNPRO_H */ diff --git a/include/ruby/internal/compiler_since.h b/include/ruby/internal/compiler_since.h new file mode 100644 index 0000000000..bdc6cac526 --- /dev/null +++ b/include/ruby/internal/compiler_since.h @@ -0,0 +1,61 @@ +#ifndef RBIMPL_COMPILER_SINCE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_COMPILER_SINCE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_COMPILER_SINCE. + */ +#include "ruby/impl/compiler_is.h" + +/** + * @brief Checks if the compiler is of given brand and is newer than or equal + * to the passed version. + * @param cc Compiler brand, like `MSVC`. + * @param x Major version. + * @param y Minor version. + * @param z Patchlevel. + * @retval true cc >= x.y.z. + * @retval false oherwise. + */ +#define RBIMPL_COMPILER_SINCE(cc, x, y, z) \ + (RBIMPL_COMPILER_IS(cc) && \ + ((RBIMPL_COMPILER_VERSION_MAJOR > (x)) || \ + ((RBIMPL_COMPILER_VERSION_MAJOR == (x)) && \ + ((RBIMPL_COMPILER_VERSION_MINOR > (y)) || \ + ((RBIMPL_COMPILER_VERSION_MINOR == (y)) && \ + (RBIMPL_COMPILER_VERSION_PATCH >= (z))))))) + +/** + * @brief Checks if the compiler is of given brand and is older than the + * passed version. + * @param cc Compiler brand, like `MSVC`. + * @param x Major version. + * @param y Minor version. + * @param z Patchlevel. + * @retval true cc < x.y.z. + * @retval false oherwise. + */ +#define RBIMPL_COMPILER_BEFORE(cc, x, y, z) \ + (RBIMPL_COMPILER_IS(cc) && \ + ((RBIMPL_COMPILER_VERSION_MAJOR < (x)) || \ + ((RBIMPL_COMPILER_VERSION_MAJOR == (x)) && \ + ((RBIMPL_COMPILER_VERSION_MINOR < (y)) || \ + ((RBIMPL_COMPILER_VERSION_MINOR == (y)) && \ + (RBIMPL_COMPILER_VERSION_PATCH < (z))))))) + +#endif /* RBIMPL_COMPILER_SINCE_H */ diff --git a/include/ruby/internal/config.h b/include/ruby/internal/config.h new file mode 100644 index 0000000000..e6c4d12488 --- /dev/null +++ b/include/ruby/internal/config.h @@ -0,0 +1,131 @@ +#ifndef RBIMPL_CONFIG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_CONFIG_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Thin wrapper to ruby/config.h + */ +#include "ruby/config.h" + +#ifdef RUBY_EXTCONF_H +# include RUBY_EXTCONF_H +#endif + +#include "ruby/impl/compiler_since.h" + +#if defined(__cplusplus) +#/* __builtin_choose_expr and __builtin_types_compatible aren't available +# * on C++. See https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */ +# undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P +# undef HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P + +# undef HAVE_PROTOTYPES +# define HAVE_PROTOTYPES 1 + +# undef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 + +/* HAVE_VA_ARGS_MACRO is for C. C++ situations might be different. */ +# undef HAVE_VA_ARGS_MACRO +# if __cplusplus >= 201103L +# define HAVE_VA_ARGS_MACRO +# elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ +# define HAVE_VA_ARGS_MACRO +# elif defined(__INTEL_CXX11_MODE__) +# define HAVE_VA_ARGS_MACRO +# elif RBIMPL_COMPILER_SINCE(MSVC, 16, 0, 0) +# define HAVE_VA_ARGS_MACRO +# else +# /* NG, not known. */ +# endif +#endif + +#if RBIMPL_COMPILER_BEFORE(GCC, 4, 9, 0) +# /* See https://bugs.ruby-lang.org/issues/14221 */ +# undef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P +#endif + +#if RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0) +# /* GCC 4.9.2 reportedly has this feature and is broken. The function is not +# * officially documented below. Seems we should not use it. +# * https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Other-Builtins.html */ +# undef HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN +#endif + +#ifndef STRINGIZE0 +# define STRINGIZE(expr) STRINGIZE0(expr) +# define STRINGIZE0(expr) #expr +#endif + +#ifdef AC_APPLE_UNIVERSAL_BUILD +# undef WORDS_BIGENDIAN +# ifdef __BIG_ENDIAN__ +# define WORDS_BIGENDIAN +# endif +#endif + +#ifndef DLEXT_MAXLEN +# define DLEXT_MAXLEN 4 +#endif + +#ifndef RUBY_PLATFORM +# define RUBY_PLATFORM "unknown-unknown" +#endif + +#ifdef UNALIGNED_WORD_ACCESS +# /* Take that. */ +#elif defined(__i386) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(__i386__) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(_M_IX86) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(__x86_64) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(__x86_64__) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(_M_AMD64) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(__powerpc64__) +# define UNALIGNED_WORD_ACCESS 1 +#elif defined(__mc68020__) +# define UNALIGNED_WORD_ACCESS 1 +#else +# define UNALIGNED_WORD_ACCESS 0 +#endif + +/* Detection of __VA_OPT__ */ +#if ! defined(HAVE_VA_ARGS_MACRO) +# undef HAVE___VA_OPT__ + +#else +# /* Idea taken from: https://stackoverflow.com/a/48045656 */ +# define RBIMPL_TEST3(q, w, e, ...) e +# define RBIMPL_TEST2(...) RBIMPL_TEST3(__VA_OPT__(,),1,0,0) +# define RBIMPL_TEST1() RBIMPL_TEST2("ruby") +# if RBIMPL_TEST1() +# define HAVE___VA_OPT__ +# else +# undef HAVE___VA_OPT__ +# endif +# undef RBIMPL_TEST1 +# undef RBIMPL_TEST2 +# undef RBIMPL_TEST3 +#endif /* HAVE_VA_ARGS_MACRO */ + +#endif /* RBIMPL_CONFIG_H */ diff --git a/include/ruby/internal/constant_p.h b/include/ruby/internal/constant_p.h new file mode 100644 index 0000000000..bfc8d05580 --- /dev/null +++ b/include/ruby/internal/constant_p.h @@ -0,0 +1,37 @@ +#ifndef RBIMPL_CONSTANT_P_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_CONSTANT_P_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_CONSTANT_P. + * + * Note that __builtin_constant_p can be applicable inside of inline functions, + * according to GCC manual. Clang lacks that feature, though. + * + * @see https://bugs.llvm.org/show_bug.cgi?id=4898 + * @see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html + */ +#include "ruby/impl/has/builtin.h" + +#if RBIMPL_HAS_BUILTIN(__builtin_constant_p) +# define RBIMPL_CONSTANT_P(expr) __builtin_constant_p(expr) +#else +# define RBIMPL_CONSTANT_P(expr) 0 +#endif + +#endif /* RBIMPL_CONSTANT_P_H */ diff --git a/include/ruby/internal/core.h b/include/ruby/internal/core.h new file mode 100644 index 0000000000..a9c8c080db --- /dev/null +++ b/include/ruby/internal/core.h @@ -0,0 +1,35 @@ +#ifndef RBIMPL_CORE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_CORE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Core data structures, definitions and manupulations. + */ +#include "ruby/impl/core/rarray.h" +#include "ruby/impl/core/rbasic.h" +#include "ruby/impl/core/rbignum.h" +#include "ruby/impl/core/rclass.h" +#include "ruby/impl/core/rdata.h" +#include "ruby/impl/core/rfile.h" +#include "ruby/impl/core/rhash.h" +#include "ruby/impl/core/robject.h" +#include "ruby/impl/core/rregexp.h" +#include "ruby/impl/core/rstring.h" +#include "ruby/impl/core/rstruct.h" +#include "ruby/impl/core/rtypeddata.h" +#endif /* RBIMPL_CORE_H */ 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 + * @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 + * @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 + * @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 + * @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 + * @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 +#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 + * @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 + * @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 +#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 + * @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 + * @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 +#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 + * @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 */ diff --git a/include/ruby/internal/core/rstring.h b/include/ruby/internal/core/rstring.h new file mode 100644 index 0000000000..683635c5ac --- /dev/null +++ b/include/ruby/internal/core/rstring.h @@ -0,0 +1,215 @@ +#ifndef RBIMPL_RSTRING_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RSTRING_H +/** + * @file + * @author Ruby developers + * @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 */ diff --git a/include/ruby/internal/core/rstruct.h b/include/ruby/internal/core/rstruct.h new file mode 100644 index 0000000000..9f873adad2 --- /dev/null +++ b/include/ruby/internal/core/rstruct.h @@ -0,0 +1,73 @@ +#ifndef RBIMPL_RSTRUCT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RSTRUCT_H +/** + * @file + * @author Ruby developers + * @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 */ diff --git a/include/ruby/internal/core/rtypeddata.h b/include/ruby/internal/core/rtypeddata.h new file mode 100644 index 0000000000..49e55dcf91 --- /dev/null +++ b/include/ruby/internal/core/rtypeddata.h @@ -0,0 +1,184 @@ +#ifndef RBIMPL_RTYPEDDATA_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RTYPEDDATA_H +/** + * @file + * @author Ruby developers + * @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 +#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 */ diff --git a/include/ruby/internal/ctype.h b/include/ruby/internal/ctype.h new file mode 100644 index 0000000000..7a8f032c58 --- /dev/null +++ b/include/ruby/internal/ctype.h @@ -0,0 +1,203 @@ +#ifndef RBIMPL_CTYPE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_CTYPE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Our own, locale independent, character handling routines. + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include +#endif + +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/dllexport.h" + +#ifndef ISPRINT +# define ISASCII rb_isascii +# define ISPRINT rb_isprint +# define ISGRAPH rb_isgraph +# define ISSPACE rb_isspace +# define ISUPPER rb_isupper +# define ISLOWER rb_islower +# define ISALNUM rb_isalnum +# define ISALPHA rb_isalpha +# define ISDIGIT rb_isdigit +# define ISXDIGIT rb_isxdigit +# define ISBLANK rb_isblank +# define ISCNTRL rb_iscntrl +# define ISPUNCT rb_ispunct +#endif + +#define TOUPPER rb_toupper +#define TOLOWER rb_tolower +#define STRCASECMP st_locale_insensitive_strcasecmp +#define STRNCASECMP st_locale_insensitive_strncasecmp +#define STRTOUL ruby_strtoul + +RBIMPL_SYMBOL_EXPORT_BEGIN() +/* locale insensitive functions */ +int st_locale_insensitive_strcasecmp(const char *s1, const char *s2); +int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n); +unsigned long ruby_strtoul(const char *str, char **endptr, int base); +RBIMPL_SYMBOL_EXPORT_END() + +/* + * We are making the functions below to return `int` instead of `bool`. They + * have been as such since their birth at 5f237d79033b2109afb768bc889611fa9630. + */ + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isascii(int c) +{ + return '\0' <= c && c <= '\x7f'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isupper(int c) +{ + return 'A' <= c && c <= 'Z'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_islower(int c) +{ + return 'a' <= c && c <= 'z'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isalpha(int c) +{ + return rb_isupper(c) || rb_islower(c); +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isdigit(int c) +{ + return '0' <= c && c <= '9'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isalnum(int c) +{ + return rb_isalpha(c) || rb_isdigit(c); +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isxdigit(int c) +{ + return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isblank(int c) +{ + return c == ' ' || c == '\t'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isspace(int c) +{ + return c == ' ' || ('\t' <= c && c <= '\r'); +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_iscntrl(int c) +{ + return ('\0' <= c && c < ' ') || c == '\x7f'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isprint(int c) +{ + return ' ' <= c && c <= '\x7e'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_ispunct(int c) +{ + return !rb_isalnum(c); +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_isgraph(int c) +{ + return '!' <= c && c <= '\x7e'; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_tolower(int c) +{ + return rb_isupper(c) ? (c|0x20) : c; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline int +rb_toupper(int c) +{ + return rb_islower(c) ? (c&0x5f) : c; +} + +#endif /* RBIMPL_CTYPE_H */ diff --git a/include/ruby/internal/dllexport.h b/include/ruby/internal/dllexport.h new file mode 100644 index 0000000000..ae1589d811 --- /dev/null +++ b/include/ruby/internal/dllexport.h @@ -0,0 +1,92 @@ +#ifndef RBIMPL_DLLEXPORT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_DLLEXPORT_H +/** + * @file + * @author Ruby developers + * @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 Tewaking visibility of C variables/functions. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/compiler_is.h" + +/* For MinGW, we need __declspec(dllimport) for RUBY_EXTERN on MJIT. + mswin's RUBY_EXTERN already has that. See also: win32/Makefile.sub */ +#undef RUBY_EXTERN +#if defined(MJIT_HEADER) && defined(_WIN32) +# define RUBY_EXTERN extern __declspec(dllimport) +#elif defined(RUBY_EXPORT) +# define RUBY_EXTERN extern +#elif defined(_WIN32) +# define RUBY_EXTERN extern __declspec(dllimport) +#else +# define RUBY_EXTERN extern +#endif + +#ifndef RUBY_SYMBOL_EXPORT_BEGIN +# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */ +#endif + +#ifndef RUBY_SYMBOL_EXPORT_END +# define RUBY_SYMBOL_EXPORT_END /* end */ +#endif + +#ifndef RUBY_FUNC_EXPORTED +# define RUBY_FUNC_EXPORTED /* void */ +#endif + +/* These macros are used for functions which are exported only for MJIT + and NOT ensured to be exported in future versions. */ + +#if ! defined(MJIT_HEADER) +# define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED +#elif ! RBIMPL_COMPILER_IS(MSVC) +# define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED +#else +# define MJIT_FUNC_EXPORTED static +#endif + +#define MJIT_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN +#define MJIT_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END + +/* On mswin, MJIT header transformation can't be used since cl.exe can't output + preprocessed output preserving macros. So this `MJIT_STATIC` is needed + to force non-static function to static on MJIT header to avoid symbol conflict. */ +#ifdef MJIT_HEADER +# define MJIT_STATIC static +#else +# define MJIT_STATIC +#endif + +/** Shortcut macro equivalent to `RUBY_SYMBOL_EXPORT_BEGIN extern "C" {`. + * \@shyouhei finds it handy. */ +#if defined(__DOXYGEN__) +# define RBIMPL_SYMBOL_EXPORT_BEGIN() /* void */ +#elif defined(__cplusplus) +# define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN extern "C" { +#else +# define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN +#endif + +/** Counterpart of #RBIMPL_SYMBOL_EXPORT_BEGIN */ +#if defined(__DOXYGEN__) +# define RBIMPL_SYMBOL_EXPORT_END() /* void */ +#elif defined(__cplusplus) +# define RBIMPL_SYMBOL_EXPORT_END() } RUBY_SYMBOL_EXPORT_END +#else +# define RBIMPL_SYMBOL_EXPORT_END() RUBY_SYMBOL_EXPORT_END +#endif +#endif /* RBIMPL_DLLEXPORT_H */ diff --git a/include/ruby/internal/dosish.h b/include/ruby/internal/dosish.h new file mode 100644 index 0000000000..eb71e36505 --- /dev/null +++ b/include/ruby/internal/dosish.h @@ -0,0 +1,63 @@ +#ifndef RBIMPL_DOSISH_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_DOSISH_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Support for so-called dosish systems. + */ +#ifdef __CYGWIN__ +#undef _WIN32 +#endif + +#if defined(_WIN32) +/* + DOSISH mean MS-Windows style filesystem. + But you should use more precise macros like DOSISH_DRIVE_LETTER, PATH_SEP, + ENV_IGNORECASE or CASEFOLD_FILESYSTEM. + */ +#define DOSISH 1 +# define DOSISH_DRIVE_LETTER +#endif + +#ifdef _WIN32 +#include "ruby/win32.h" +#endif + +#if defined(DOSISH) +#define PATH_SEP ";" +#else +#define PATH_SEP ":" +#endif + +#define PATH_SEP_CHAR PATH_SEP[0] + +#define PATH_ENV "PATH" + +#if defined(DOSISH) +#define ENV_IGNORECASE +#endif + +#ifndef CASEFOLD_FILESYSTEM +# if defined DOSISH +# define CASEFOLD_FILESYSTEM 1 +# else +# define CASEFOLD_FILESYSTEM 0 +# endif +#endif + +#endif /* RBIMPL_DOSISH_H */ diff --git a/include/ruby/internal/error.h b/include/ruby/internal/error.h new file mode 100644 index 0000000000..a7458f8e1b --- /dev/null +++ b/include/ruby/internal/error.h @@ -0,0 +1,74 @@ +#ifndef RBIMPL_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ERROR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Declares ::rb_raise(). + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/attributes.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +VALUE rb_errinfo(void); +void rb_set_errinfo(VALUE); + +/* for rb_readwrite_sys_fail first argument */ +enum rb_io_wait_readwrite {RB_IO_WAIT_READABLE, RB_IO_WAIT_WRITABLE}; +#define RB_IO_WAIT_READABLE RB_IO_WAIT_READABLE +#define RB_IO_WAIT_WRITABLE RB_IO_WAIT_WRITABLE + +PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2); +COLDFUNC PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2); +NORETURN(void rb_bug_errno(const char*, int)); +NORETURN(void rb_sys_fail(const char*)); +NORETURN(void rb_sys_fail_str(VALUE)); +NORETURN(void rb_mod_sys_fail(VALUE, const char*)); +NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE)); +NORETURN(void rb_readwrite_sys_fail(enum rb_io_wait_readwrite, const char*)); +NORETURN(void rb_iter_break(void)); +NORETURN(void rb_iter_break_value(VALUE)); +NORETURN(void rb_exit(int)); +NORETURN(void rb_notimplement(void)); +VALUE rb_syserr_new(int, const char *); +VALUE rb_syserr_new_str(int n, VALUE arg); +NORETURN(void rb_syserr_fail(int, const char*)); +NORETURN(void rb_syserr_fail_str(int, VALUE)); +NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*)); +NORETURN(void rb_mod_syserr_fail_str(VALUE, int, VALUE)); +NORETURN(void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite, int, const char*)); +NORETURN(void rb_unexpected_type(VALUE,int)); + +VALUE *rb_ruby_verbose_ptr(void); +VALUE *rb_ruby_debug_ptr(void); +#define ruby_verbose (*rb_ruby_verbose_ptr()) +#define ruby_debug (*rb_ruby_debug_ptr()) + +/* reports if `-W' specified */ +PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4); +PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2); +/* reports always */ +COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_ERROR_H */ diff --git a/include/ruby/internal/eval.h b/include/ruby/internal/eval.h new file mode 100644 index 0000000000..ea59b4c6fd --- /dev/null +++ b/include/ruby/internal/eval.h @@ -0,0 +1,50 @@ +#ifndef RBIMPL_EVAL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_EVAL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Declares ::rb_eval_string(). + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +VALUE rb_eval_string(const char*); +VALUE rb_eval_string_protect(const char*, int*); +VALUE rb_eval_string_wrap(const char*, int*); +VALUE rb_funcall(VALUE, ID, int, ...); +VALUE rb_funcallv(VALUE, ID, int, const VALUE*); +VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE*, int); +VALUE rb_funcallv_public(VALUE, ID, int, const VALUE*); +VALUE rb_funcallv_public_kw(VALUE, ID, int, const VALUE*, int); +#define rb_funcall2 rb_funcallv +#define rb_funcall3 rb_funcallv_public +VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*); +VALUE rb_funcall_passing_block_kw(VALUE, ID, int, const VALUE*, int); +VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE*, VALUE); +VALUE rb_funcall_with_block_kw(VALUE, ID, int, const VALUE*, VALUE, int); +VALUE rb_call_super(int, const VALUE*); +VALUE rb_call_super_kw(int, const VALUE*, int); +VALUE rb_current_receiver(void); +int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *); +VALUE rb_extract_keywords(VALUE *orighash); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_EVAL_H */ diff --git a/include/ruby/internal/event.h b/include/ruby/internal/event.h new file mode 100644 index 0000000000..7af74261b0 --- /dev/null +++ b/include/ruby/internal/event.h @@ -0,0 +1,75 @@ +#ifndef RBIMPL_EVENT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_EVENT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Debugging and tracing APIs. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* traditional set_trace_func events */ +#define RUBY_EVENT_NONE 0x0000 +#define RUBY_EVENT_LINE 0x0001 +#define RUBY_EVENT_CLASS 0x0002 +#define RUBY_EVENT_END 0x0004 +#define RUBY_EVENT_CALL 0x0008 +#define RUBY_EVENT_RETURN 0x0010 +#define RUBY_EVENT_C_CALL 0x0020 +#define RUBY_EVENT_C_RETURN 0x0040 +#define RUBY_EVENT_RAISE 0x0080 +#define RUBY_EVENT_ALL 0x00ff + +/* for TracePoint extended events */ +#define RUBY_EVENT_B_CALL 0x0100 +#define RUBY_EVENT_B_RETURN 0x0200 +#define RUBY_EVENT_THREAD_BEGIN 0x0400 +#define RUBY_EVENT_THREAD_END 0x0800 +#define RUBY_EVENT_FIBER_SWITCH 0x1000 +#define RUBY_EVENT_SCRIPT_COMPILED 0x2000 +#define RUBY_EVENT_TRACEPOINT_ALL 0xffff + +/* special events */ +#define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 + +/* internal events */ +#define RUBY_INTERNAL_EVENT_SWITCH 0x040000 +#define RUBY_EVENT_SWITCH 0x040000 /* obsolete name. this macro is for compatibility */ + /* 0x080000 */ +#define RUBY_INTERNAL_EVENT_NEWOBJ 0x100000 +#define RUBY_INTERNAL_EVENT_FREEOBJ 0x200000 +#define RUBY_INTERNAL_EVENT_GC_START 0x400000 +#define RUBY_INTERNAL_EVENT_GC_END_MARK 0x800000 +#define RUBY_INTERNAL_EVENT_GC_END_SWEEP 0x1000000 +#define RUBY_INTERNAL_EVENT_GC_ENTER 0x2000000 +#define RUBY_INTERNAL_EVENT_GC_EXIT 0x4000000 +#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x7f00000 +#define RUBY_INTERNAL_EVENT_MASK 0xffff0000 + +typedef uint32_t rb_event_flag_t; +typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass); + +#define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1 +void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); +int rb_remove_event_hook(rb_event_hook_func_t func); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_EVENT_H */ diff --git a/include/ruby/internal/fl_type.h b/include/ruby/internal/fl_type.h new file mode 100644 index 0000000000..cca1bad391 --- /dev/null +++ b/include/ruby/internal/fl_type.h @@ -0,0 +1,469 @@ +#ifndef RBIMPL_FL_TYPE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_FL_TYPE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines enum ::ruby_fl_type. + */ +#include "ruby/impl/config.h" /* for ENUM_OVER_INT */ +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/flag_enum.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/core/rbasic.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" +#include "ruby/assert.h" +#include "ruby/defines.h" + +/** @cond INTERNAL_MACRO */ +#ifdef ENUM_OVER_INT +# define RBIMPL_WIDER_ENUM 1 +#elif SIZEOF_INT * CHAR_BIT > 12+19+1 +# define RBIMPL_WIDER_ENUM 1 +#else +# define RBIMPL_WIDER_ENUM 0 +#endif +/** @endcond */ + +#define FL_SINGLETON RBIMPL_CAST((VALUE)RUBY_FL_SINGLETON) +#define FL_WB_PROTECTED RBIMPL_CAST((VALUE)RUBY_FL_WB_PROTECTED) +#define FL_PROMOTED0 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED0) +#define FL_PROMOTED1 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED1) +#define FL_FINALIZE RBIMPL_CAST((VALUE)RUBY_FL_FINALIZE) +#define FL_TAINT RBIMPL_CAST((VALUE)RUBY_FL_TAINT) +#define FL_UNTRUSTED RBIMPL_CAST((VALUE)RUBY_FL_UNTRUSTED) +#define FL_SEEN_OBJ_ID RBIMPL_CAST((VALUE)RUBY_FL_SEEN_OBJ_ID) +#define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR) +#define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE) + +#define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT) + +#define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0) +#define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1) +#define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2) +#define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3) +#define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4) +#define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5) +#define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6) +#define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7) +#define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8) +#define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9) +#define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10) +#define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11) +#define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12) +#define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13) +#define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14) +#define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15) +#define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16) +#define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17) +#define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18) +#define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19) + +#define ELTS_SHARED RUBY_ELTS_SHARED +#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED +#define RB_OBJ_FREEZE rb_obj_freeze_inline + +/** @cond INTERNAL_MACRO */ +#define RB_FL_ABLE RB_FL_ABLE +#define RB_FL_ALL RB_FL_ALL +#define RB_FL_ALL_RAW RB_FL_ALL_RAW +#define RB_FL_ANY RB_FL_ANY +#define RB_FL_ANY_RAW RB_FL_ANY_RAW +#define RB_FL_REVERSE RB_FL_REVERSE +#define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW +#define RB_FL_SET RB_FL_SET +#define RB_FL_SET_RAW RB_FL_SET_RAW +#define RB_FL_TEST RB_FL_TEST +#define RB_FL_TEST_RAW RB_FL_TEST_RAW +#define RB_FL_UNSET RB_FL_UNSET +#define RB_FL_UNSET_RAW RB_FL_UNSET_RAW +#define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW +#define RB_OBJ_FROZEN RB_OBJ_FROZEN +#define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW +#define RB_OBJ_INFECT RB_OBJ_INFECT +#define RB_OBJ_INFECT_RAW RB_OBJ_INFECT_RAW +#define RB_OBJ_TAINT RB_OBJ_TAINT +#define RB_OBJ_TAINTABLE RB_OBJ_TAINTABLE +#define RB_OBJ_TAINTED RB_OBJ_TAINTED +#define RB_OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW +#define RB_OBJ_TAINT_RAW RB_OBJ_TAINT_RAW +#define RB_OBJ_UNTRUST RB_OBJ_UNTRUST +#define RB_OBJ_UNTRUSTED RB_OBJ_UNTRUSTED +/** @endcond */ + +/** + * @defgroup deprecated_macros deprecated macro APIs + * @{ + * These macros are deprecated. Prefer their `RB_`-prefixed versions. + */ +#define FL_ABLE RB_FL_ABLE +#define FL_ALL RB_FL_ALL +#define FL_ALL_RAW RB_FL_ALL_RAW +#define FL_ANY RB_FL_ANY +#define FL_ANY_RAW RB_FL_ANY_RAW +#define FL_REVERSE RB_FL_REVERSE +#define FL_REVERSE_RAW RB_FL_REVERSE_RAW +#define FL_SET RB_FL_SET +#define FL_SET_RAW RB_FL_SET_RAW +#define FL_TEST RB_FL_TEST +#define FL_TEST_RAW RB_FL_TEST_RAW +#define FL_UNSET RB_FL_UNSET +#define FL_UNSET_RAW RB_FL_UNSET_RAW +#define OBJ_FREEZE RB_OBJ_FREEZE +#define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW +#define OBJ_FROZEN RB_OBJ_FROZEN +#define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW +#define OBJ_INFECT RB_OBJ_INFECT +#define OBJ_INFECT_RAW RB_OBJ_INFECT_RAW +#define OBJ_TAINT RB_OBJ_TAINT +#define OBJ_TAINTABLE RB_OBJ_TAINTABLE +#define OBJ_TAINTED RB_OBJ_TAINTED +#define OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW +#define OBJ_TAINT_RAW RB_OBJ_TAINT_RAW +#define OBJ_UNTRUST RB_OBJ_UNTRUST +#define OBJ_UNTRUSTED RB_OBJ_UNTRUSTED +/** @} */ + +/* This is an enum because GDB wants it (rather than a macro) */ +enum ruby_fl_ushift { RUBY_FL_USHIFT = 12 }; + +/* > The expression that defines the value of an enumeration constant shall be + * > an integer constant expression that has a value representable as an `int`. + * + * -- ISO/IEC 9899:2018 section 6.7.2.2 + * + * So ENUM_OVER_INT situation is an extension to the standard. Note however + * that we do not support 16 bit `int` environment. */ +RB_GNUC_EXTENSION +enum +RBIMPL_ATTR_FLAG_ENUM() +ruby_fl_type { + RUBY_FL_WB_PROTECTED = (1<<5), + RUBY_FL_PROMOTED0 = (1<<5), + RUBY_FL_PROMOTED1 = (1<<6), + RUBY_FL_PROMOTED = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1, + RUBY_FL_FINALIZE = (1<<7), + RUBY_FL_TAINT = (1<<8), + RUBY_FL_UNTRUSTED = RUBY_FL_TAINT, + RUBY_FL_SEEN_OBJ_ID = (1<<9), + RUBY_FL_EXIVAR = (1<<10), + RUBY_FL_FREEZE = (1<<11), + +#define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n)) + RBIMPL_FL_USER_N(0), + RBIMPL_FL_USER_N(1), + RBIMPL_FL_USER_N(2), + RBIMPL_FL_USER_N(3), + RBIMPL_FL_USER_N(4), + RBIMPL_FL_USER_N(5), + RBIMPL_FL_USER_N(6), + RBIMPL_FL_USER_N(7), + RBIMPL_FL_USER_N(8), + RBIMPL_FL_USER_N(9), + RBIMPL_FL_USER_N(10), + RBIMPL_FL_USER_N(11), + RBIMPL_FL_USER_N(12), + RBIMPL_FL_USER_N(13), + RBIMPL_FL_USER_N(14), + RBIMPL_FL_USER_N(15), + RBIMPL_FL_USER_N(16), + RBIMPL_FL_USER_N(17), + RBIMPL_FL_USER_N(18), +#if ENUM_OVER_INT + RBIMPL_FL_USER_N(19), +#else +# define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19)) +#endif +#undef RBIMPL_FL_USER_N +#undef RBIMPL_WIDER_ENUM + + RUBY_ELTS_SHARED = RUBY_FL_USER2, + RUBY_FL_SINGLETON = RUBY_FL_USER0, +}; + +enum { RUBY_FL_DUPPED = RUBY_T_MASK | RUBY_FL_EXIVAR | RUBY_FL_TAINT }; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +void rb_obj_infect(VALUE victim, VALUE carrier); +void rb_freeze_singleton_class(VALUE klass); +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +RBIMPL_ATTR_FORCEINLINE() +static bool +RB_FL_ABLE(VALUE obj) +{ + if (RB_SPECIAL_CONST_P(obj)) { + return false; + } + else if (RB_TYPE_P(obj, RUBY_T_NODE)) { + return false; + } + else { + return true; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RB_FL_TEST_RAW(VALUE obj, VALUE flags) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); + return RBASIC(obj)->flags & flags; +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RB_FL_TEST(VALUE obj, VALUE flags) +{ + if (RB_FL_ABLE(obj)) { + return RB_FL_TEST_RAW(obj, flags); + } + else { + return RBIMPL_VALUE_NULL; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FL_ANY_RAW(VALUE obj, VALUE flags) +{ + return RB_FL_TEST_RAW(obj, flags); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FL_ANY(VALUE obj, VALUE flags) +{ + return RB_FL_TEST(obj, flags); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FL_ALL_RAW(VALUE obj, VALUE flags) +{ + return RB_FL_TEST_RAW(obj, flags) == flags; +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FL_ALL(VALUE obj, VALUE flags) +{ + return RB_FL_TEST(obj, flags) == flags; +} + +RBIMPL_ATTR_NOALIAS() +RBIMPL_ATTR_ARTIFICIAL() +static inline void +rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags) +{ + obj->flags |= flags; +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_FL_SET_RAW(VALUE obj, VALUE flags) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); + rbimpl_fl_set_raw_raw(RBASIC(obj), flags); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_FL_SET(VALUE obj, VALUE flags) +{ + if (RB_FL_ABLE(obj)) { + RB_FL_SET_RAW(obj, flags); + } +} + +RBIMPL_ATTR_NOALIAS() +RBIMPL_ATTR_ARTIFICIAL() +static inline void +rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags) +{ + obj->flags &= ~flags; +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_FL_UNSET_RAW(VALUE obj, VALUE flags) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); + rbimpl_fl_unset_raw_raw(RBASIC(obj), flags); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_FL_UNSET(VALUE obj, VALUE flags) +{ + if (RB_FL_ABLE(obj)) { + RB_FL_UNSET_RAW(obj, flags); + } +} + +RBIMPL_ATTR_NOALIAS() +RBIMPL_ATTR_ARTIFICIAL() +static inline void +rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags) +{ + obj->flags ^= flags; +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_FL_REVERSE_RAW(VALUE obj, VALUE flags) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); + rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_FL_REVERSE(VALUE obj, VALUE flags) +{ + if (RB_FL_ABLE(obj)) { + RB_FL_REVERSE_RAW(obj, flags); + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_OBJ_TAINTABLE(VALUE obj) +{ + if (! RB_FL_ABLE(obj)) { + return false; + } + else if (RB_TYPE_P(obj, RUBY_T_BIGNUM)) { + return false; + } + else if (RB_TYPE_P(obj, RUBY_T_FLOAT)) { + return false; + } + else { + return true; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline VALUE +RB_OBJ_TAINTED_RAW(VALUE obj) +{ + return RB_FL_TEST_RAW(obj, RUBY_FL_TAINT); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_OBJ_TAINTED(VALUE obj) +{ + return RB_FL_ANY(obj, RUBY_FL_TAINT); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_OBJ_TAINT_RAW(VALUE obj) +{ + RB_FL_SET_RAW(obj, RUBY_FL_TAINT); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_OBJ_TAINT(VALUE obj) +{ + if (RB_OBJ_TAINTABLE(obj)) { + RB_OBJ_TAINT_RAW(obj); + } +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_OBJ_INFECT_RAW(VALUE dst, VALUE src) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_OBJ_TAINTABLE(dst)); + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(src)); + RB_FL_SET_RAW(dst, RB_OBJ_TAINTED_RAW(src)); +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_OBJ_INFECT(VALUE dst, VALUE src) +{ + if (RB_OBJ_TAINTABLE(dst) && RB_FL_ABLE(src)) { + RB_OBJ_INFECT_RAW(dst, src); + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +/* It is intentional not to return bool here. There is a place in ruby core + * (namely class.c:singleton_class_of()) where return value of this function is + * verbatimly passed to RB_FL_SET_RAW. */ +static inline VALUE +RB_OBJ_FROZEN_RAW(VALUE obj) +{ + return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_OBJ_FROZEN(VALUE obj) +{ + if (! RB_FL_ABLE(obj)) { + return true; + } + else { + return RB_OBJ_FROZEN_RAW(obj); + } +} + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +RB_OBJ_FREEZE_RAW(VALUE obj) +{ + RB_FL_SET_RAW(obj, RUBY_FL_FREEZE); +} + +static inline void +rb_obj_freeze_inline(VALUE x) +{ + if (RB_FL_ABLE(x)) { + RB_OBJ_FREEZE_RAW(x); + if (RBASIC_CLASS(x) && !(RBASIC(x)->flags & RUBY_FL_SINGLETON)) { + rb_freeze_singleton_class(x); + } + } +} + +#endif /* RBIMPL_FL_TYPE_H */ diff --git a/include/ruby/internal/gc.h b/include/ruby/internal/gc.h new file mode 100644 index 0000000000..029bbe4fc2 --- /dev/null +++ b/include/ruby/internal/gc.h @@ -0,0 +1,35 @@ +#ifndef RBIMPL_GC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_GC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Registering values to the GC. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +void rb_global_variable(VALUE*); +void rb_gc_register_mark_object(VALUE); +void rb_gc_register_address(VALUE*); +void rb_gc_unregister_address(VALUE*); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_GC_H */ diff --git a/include/ruby/internal/glob.h b/include/ruby/internal/glob.h new file mode 100644 index 0000000000..2764b94d02 --- /dev/null +++ b/include/ruby/internal/glob.h @@ -0,0 +1,35 @@ +#ifndef RBIMPL_GLOB_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_GLOB_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Declares ::rb_glob(). + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +typedef int ruby_glob_func(const char*,VALUE, void*); +void rb_glob(const char*,void(*)(const char*,VALUE,void*),VALUE); +int ruby_glob(const char*,int,ruby_glob_func*,VALUE); +int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_GLOB_H */ diff --git a/include/ruby/internal/globals.h b/include/ruby/internal/globals.h new file mode 100644 index 0000000000..cfffd0504d --- /dev/null +++ b/include/ruby/internal/globals.h @@ -0,0 +1,159 @@ +#ifndef RBIMPL_GLOBALS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_GLOBALS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Ruby-level global variables / constants, visible from C. + */ +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/fl_type.h" +#include "ruby/impl/special_consts.h" +#include "ruby/impl/value.h" +#include "ruby/impl/value_type.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +#define RUBY_INTEGER_UNIFICATION 1 + +RUBY_EXTERN VALUE rb_mKernel; +RUBY_EXTERN VALUE rb_mComparable; +RUBY_EXTERN VALUE rb_mEnumerable; +RUBY_EXTERN VALUE rb_mErrno; +RUBY_EXTERN VALUE rb_mFileTest; +RUBY_EXTERN VALUE rb_mGC; +RUBY_EXTERN VALUE rb_mMath; +RUBY_EXTERN VALUE rb_mProcess; +RUBY_EXTERN VALUE rb_mWaitReadable; +RUBY_EXTERN VALUE rb_mWaitWritable; + +RUBY_EXTERN VALUE rb_cBasicObject; +RUBY_EXTERN VALUE rb_cObject; +RUBY_EXTERN VALUE rb_cArray; +RUBY_EXTERN VALUE rb_cBinding; +RUBY_EXTERN VALUE rb_cClass; +RUBY_EXTERN VALUE rb_cCont; +RUBY_EXTERN VALUE rb_cData; +RUBY_EXTERN VALUE rb_cDir; +RUBY_EXTERN VALUE rb_cEncoding; +RUBY_EXTERN VALUE rb_cEnumerator; +RUBY_EXTERN VALUE rb_cFalseClass; +RUBY_EXTERN VALUE rb_cFile; +RUBY_EXTERN VALUE rb_cComplex; +RUBY_EXTERN VALUE rb_cFloat; +RUBY_EXTERN VALUE rb_cHash; +RUBY_EXTERN VALUE rb_cIO; +RUBY_EXTERN VALUE rb_cInteger; +RUBY_EXTERN VALUE rb_cMatch; +RUBY_EXTERN VALUE rb_cMethod; +RUBY_EXTERN VALUE rb_cModule; +RUBY_EXTERN VALUE rb_cNameErrorMesg; +RUBY_EXTERN VALUE rb_cNilClass; +RUBY_EXTERN VALUE rb_cNumeric; +RUBY_EXTERN VALUE rb_cProc; +RUBY_EXTERN VALUE rb_cRandom; +RUBY_EXTERN VALUE rb_cRange; +RUBY_EXTERN VALUE rb_cRational; +RUBY_EXTERN VALUE rb_cRegexp; +RUBY_EXTERN VALUE rb_cStat; +RUBY_EXTERN VALUE rb_cString; +RUBY_EXTERN VALUE rb_cStruct; +RUBY_EXTERN VALUE rb_cSymbol; +RUBY_EXTERN VALUE rb_cThread; +RUBY_EXTERN VALUE rb_cTime; +RUBY_EXTERN VALUE rb_cTrueClass; +RUBY_EXTERN VALUE rb_cUnboundMethod; + +RUBY_EXTERN VALUE rb_eException; +RUBY_EXTERN VALUE rb_eStandardError; +RUBY_EXTERN VALUE rb_eSystemExit; +RUBY_EXTERN VALUE rb_eInterrupt; +RUBY_EXTERN VALUE rb_eSignal; +RUBY_EXTERN VALUE rb_eFatal; +RUBY_EXTERN VALUE rb_eArgError; +RUBY_EXTERN VALUE rb_eEOFError; +RUBY_EXTERN VALUE rb_eIndexError; +RUBY_EXTERN VALUE rb_eStopIteration; +RUBY_EXTERN VALUE rb_eKeyError; +RUBY_EXTERN VALUE rb_eRangeError; +RUBY_EXTERN VALUE rb_eIOError; +RUBY_EXTERN VALUE rb_eRuntimeError; +RUBY_EXTERN VALUE rb_eFrozenError; +RUBY_EXTERN VALUE rb_eSecurityError; +RUBY_EXTERN VALUE rb_eSystemCallError; +RUBY_EXTERN VALUE rb_eThreadError; +RUBY_EXTERN VALUE rb_eTypeError; +RUBY_EXTERN VALUE rb_eZeroDivError; +RUBY_EXTERN VALUE rb_eNotImpError; +RUBY_EXTERN VALUE rb_eNoMemError; +RUBY_EXTERN VALUE rb_eNoMethodError; +RUBY_EXTERN VALUE rb_eFloatDomainError; +RUBY_EXTERN VALUE rb_eLocalJumpError; +RUBY_EXTERN VALUE rb_eSysStackError; +RUBY_EXTERN VALUE rb_eRegexpError; +RUBY_EXTERN VALUE rb_eEncodingError; +RUBY_EXTERN VALUE rb_eEncCompatError; +RUBY_EXTERN VALUE rb_eNoMatchingPatternError; + +RUBY_EXTERN VALUE rb_eScriptError; +RUBY_EXTERN VALUE rb_eNameError; +RUBY_EXTERN VALUE rb_eSyntaxError; +RUBY_EXTERN VALUE rb_eLoadError; + +RUBY_EXTERN VALUE rb_eMathDomainError; + +RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr; + +RBIMPL_ATTR_PURE() +static inline VALUE +rb_class_of(VALUE obj) +{ + if (! RB_SPECIAL_CONST_P(obj)) { + return RBASIC_CLASS(obj); + } + else if (obj == RUBY_Qfalse) { + return rb_cFalseClass; + } + else if (obj == RUBY_Qnil) { + return rb_cNilClass; + } + else if (obj == RUBY_Qtrue) { + return rb_cTrueClass; + } + else if (RB_FIXNUM_P(obj)) { + return rb_cInteger; + } + else if (RB_STATIC_SYM_P(obj)) { + return rb_cSymbol; + } + else if (RB_FLONUM_P(obj)) { + return rb_cFloat; + } + +#if RUBY_NDEBUG + RBIMPL_UNREACHABLE_RETURN(Qfalse); +#else + RUBY_ASSERT_FAIL(rb_class_of); +#endif +} + +#define CLASS_OF rb_class_of + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_GLOBALS_H */ diff --git a/include/ruby/internal/has/attribute.h b/include/ruby/internal/has/attribute.h new file mode 100644 index 0000000000..af51b93298 --- /dev/null +++ b/include/ruby/internal/has/attribute.h @@ -0,0 +1,164 @@ +#ifndef RBIMPL_HAS_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_ATTRIBUTE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_ATTRIBUTE. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/token_paste.h" + +#if defined(__has_attribute) +# if __has_attribute(pure) || RBIMPL_COMPILER_IS(GCC) +# /* FreeBSD's defines its own *broken* version of +# * __has_attribute. Cygwin copied that content to be a victim of the +# * broken-ness. We don't take them into account. */ +# define RBIMPL_HAVE___HAS_ATTRIBUTE 1 +# endif +#endif + +/** Wraps (or simulates) `__has_attribute`. */ +#if defined(RBIMPL_HAVE___HAS_ATTRIBUTE) +# define RBIMPL_HAS_ATTRIBUTE(_) __has_attribute(_) + +#elif RBIMPL_COMPILER_IS(GCC) +# /* GCC <= 4 lack __has_attribute predefined macro, while have attributes +# * themselves. We can simulate the macro like the following: */ +# define RBIMPL_HAS_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _) +# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_alloc_size RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_artificial RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0) +# define RBIMPL_HAS_ATTRIBUTE_cdecl RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_cold RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(GCC, 2, 6, 0) +# define RBIMPL_HAS_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0) +# define RBIMPL_HAS_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_error RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_format RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_hot RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_leaf RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) +# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) +# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) +# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_undefined RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(GCC, 3, 1, 0) +# define RBIMPL_HAS_ATTRIBUTE_nonnull RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(GCC, 2, 5, 0) +# define RBIMPL_HAS_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(GCC, 2,96, 0) +# define RBIMPL_HAS_ATTRIBUTE_returns_nonnull RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(GCC, 4, 1, 0) +# define RBIMPL_HAS_ATTRIBUTE_stdcall RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_unused RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(GCC, 3, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result RBIMPL_COMPILER_SINCE(GCC, 3, 4, 0) +# define RBIMPL_HAS_ATTRIBUTE_warning RBIMPL_COMPILER_SINCE(GCC, 4, 3, 0) +# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# /* Note that "0, 0, 0" might be inaccurate. */ + +#elif RBIMPL_COMPILER_IS(SunPro) +# /* Oracle Solaris Studio 12.4 (cc version 5.11) introduced __has_attribute. +# * Before that, following attributes were available. */ +# /* See https://docs.oracle.com/cd/F24633_01/index.html */ +# define RBIMPL_HAS_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _) +# define RBIMPL_HAS_ATTRIBUTE_alias RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_aligned RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_always_inline RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_HAS_ATTRIBUTE_const RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_constructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_destructor RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_malloc RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_packed RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_pure RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_returns_twice RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_HAS_ATTRIBUTE_vector_size RBIMPL_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RBIMPL_HAS_ATTRIBUTE_visibility RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# define RBIMPL_HAS_ATTRIBUTE_weak RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) + +#elif defined (_MSC_VER) +# define RBIMPL_HAS_ATTRIBUTE(_) 0 +# /* Fallback below doesn't work: see win32/Makefile.sub */ + +#else +# /* Take config.h definition when available. */ +# define RBIMPL_HAS_ATTRIBUTE(_) (RBIMPL_TOKEN_PASTE(RBIMPL_HAS_ATTRIBUTE_, _)+0) +# ifdef ALWAYS_INLINE +# define RBIMPL_HAS_ATTRIBUTE_always_inline 1 +# endif +# ifdef FUNC_CDECL +# define RBIMPL_HAS_ATTRIBUTE_cdecl 1 +# endif +# ifdef CONSTFUNC +# define RBIMPL_HAS_ATTRIBUTE_const 1 +# endif +# ifdef DEPRECATED +# define RBIMPL_HAS_ATTRIBUTE_deprecated 1 +# endif +# ifdef ERRORFUNC +# define RBIMPL_HAS_ATTRIBUTE_error 1 +# endif +# ifdef FUNC_FASTCALL +# define RBIMPL_HAS_ATTRIBUTE_fastcall 1 +# endif +# ifdef PUREFUNC +# define RBIMPL_HAS_ATTRIBUTE_pure 1 +# endif +# ifdef NO_ADDRESS_SAFETY_ANALYSIS +# define RBIMPL_HAS_ATTRIBUTE_no_address_safety_analysis 1 +# endif +# ifdef NO_SANITIZE +# define RBIMPL_HAS_ATTRIBUTE_no_sanitize 1 +# endif +# ifdef NO_SANITIZE_ADDRESS +# define RBIMPL_HAS_ATTRIBUTE_no_sanitize_address 1 +# endif +# ifdef NOINLINE +# define RBIMPL_HAS_ATTRIBUTE_noinline 1 +# endif +# ifdef RBIMPL_FUNC_NONNULL +# define RBIMPL_HAS_ATTRIBUTE_nonnull 1 +# endif +# ifdef NORETURN +# define RBIMPL_HAS_ATTRIBUTE_noreturn 1 +# endif +# ifdef FUNC_OPTIMIZED +# define RBIMPL_HAS_ATTRIBUTE_optimize 1 +# endif +# ifdef FUNC_STDCALL +# define RBIMPL_HAS_ATTRIBUTE_stdcall 1 +# endif +# ifdef MAYBE_UNUSED +# define RBIMPL_HAS_ATTRIBUTE_unused 1 +# endif +# ifdef WARN_UNUSED_RESULT +# define RBIMPL_HAS_ATTRIBUTE_warn_unused_result 1 +# endif +# ifdef WARNINGFUNC +# define RBIMPL_HAS_ATTRIBUTE_warning 1 +# endif +# ifdef WEAK +# define RBIMPL_HAS_ATTRIBUTE_weak 1 +# endif +#endif + +#endif /* RBIMPL_HAS_ATTRIBUTE_H */ diff --git a/include/ruby/internal/has/builtin.h b/include/ruby/internal/has/builtin.h new file mode 100644 index 0000000000..46f587c2cf --- /dev/null +++ b/include/ruby/internal/has/builtin.h @@ -0,0 +1,105 @@ +#ifndef RBIMPL_HAS_BUILTIN_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_BUILTIN_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_BUILTIN. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/token_paste.h" + +#if defined(__has_builtin) +# if RBIMPL_COMPILER_IS(Intel) +# /* :TODO: Intel C Compiler has __has_builtin (since 19.1 maybe?), and is +# * reportedly broken. We have to skip them. However the situation can +# * change. They might improve someday. We need to revisit here later. */ +# elif RBIMPL_COMPILER_IS(GCC) && ! __has_builtin(__builtin_alloca) +# /* FreeBSD's defines its own *broken* version of +# * __has_builtin. Cygwin copied that content to be a victim of the +# * broken-ness. We don't take them into account. */ +# else +# define RBIMPL_HAVE___HAS_BUILTIN 1 +# endif +#endif + +/** Wraps (or simulates) `__has_builtin`. */ +#if defined(RBIMPL_HAVE___HAS_BUILTIN) +# define RBIMPL_HAS_BUILTIN(_) __has_builtin(_) + +#elif RBIMPL_COMPILER_IS(GCC) +# /* :FIXME: Historically GCC has had tons of builtins, but it implemented +# * __has_builtin only since GCC 10. This section can be made more +# * granular. */ +# /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970 */ +# define RBIMPL_HAS_BUILTIN(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_BUILTIN_, _) +# define RBIMPL_HAS_BUILTIN___builtin_add_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) +# define RBIMPL_HAS_BUILTIN___builtin_alloca RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) +# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align RBIMPL_COMPILER_SINCE(GCC, 6, 1, 0) +# /* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 for bswap16. */ +# define RBIMPL_HAS_BUILTIN___builtin_bswap16 RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) +# define RBIMPL_HAS_BUILTIN___builtin_bswap32 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_bswap64 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_clz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_clzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_clzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_constant_p RBIMPL_COMPILER_SINCE(GCC, 2,95, 3) +# define RBIMPL_HAS_BUILTIN___builtin_ctz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_ctzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_ctzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_expect RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0) +# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) +# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0) +# define RBIMPL_HAS_BUILTIN___builtin_popcount RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_popcountl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_popcountll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) +# define RBIMPL_HAS_BUILTIN___builtin_unreachable RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0) +# /* Note that "0, 0, 0" might be inaccurate. */ + +#elif RBIMPL_COMPILER_IS(MSVC) +# /* MSVC has UNREACHABLE, but that is not __builtin_unreachable. */ +# define RBIMPL_HAS_BUILTIN(_) 0 + +#else +# /* Take config.h definition when available */ +# define RBIMPL_HAS_BUILTIN(_) (RBIMPL_TOKEN_PASTE(RBIMPL_HAS_BUILTIN_, _)+0) +# define RBIMPL_HAS_BUILTIN___builtin_add_overflow HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW +# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN +# define RBIMPL_HAS_BUILTIN___builtin_assume_aligned HAVE_BUILTIN___BUILTIN_ASSUME_ALIGNED +# define RBIMPL_HAS_BUILTIN___builtin_bswap16 HAVE_BUILTIN___BUILTIN_BSWAP16 +# define RBIMPL_HAS_BUILTIN___builtin_bswap32 HAVE_BUILTIN___BUILTIN_BSWAP32 +# define RBIMPL_HAS_BUILTIN___builtin_bswap64 HAVE_BUILTIN___BUILTIN_BSWAP64 +# define RBIMPL_HAS_BUILTIN___builtin_clz HAVE_BUILTIN___BUILTIN_CLZ +# define RBIMPL_HAS_BUILTIN___builtin_clzl HAVE_BUILTIN___BUILTIN_CLZL +# define RBIMPL_HAS_BUILTIN___builtin_clzll HAVE_BUILTIN___BUILTIN_CLZLL +# define RBIMPL_HAS_BUILTIN___builtin_constant_p HAVE_BUILTIN___BUILTIN_CONSTANT_P +# define RBIMPL_HAS_BUILTIN___builtin_ctz HAVE_BUILTIN___BUILTIN_CTZ +# define RBIMPL_HAS_BUILTIN___builtin_ctzll HAVE_BUILTIN___BUILTIN_CTZLL +# define RBIMPL_HAS_BUILTIN___builtin_expect HAVE_BUILTIN___BUILTIN_EXPECT +# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW +# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P +# define RBIMPL_HAS_BUILTIN___builtin_popcount HAVE_BUILTIN___BUILTIN_POPCOUNT +# define RBIMPL_HAS_BUILTIN___builtin_popcountll HAVE_BUILTIN___BUILTIN_POPCOUNTLL +# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW +# if defined(UNREACHABLE) +# define RBIMPL_HAS_BUILTIN___builtin_unreachable 1 +# endif +#endif + +#endif /* RBIMPL_HAS_BUILTIN_H */ diff --git a/include/ruby/internal/has/c_attribute.h b/include/ruby/internal/has/c_attribute.h new file mode 100644 index 0000000000..b7eb94d22a --- /dev/null +++ b/include/ruby/internal/has/c_attribute.h @@ -0,0 +1,38 @@ +#ifndef RBIMPL_HAS_C_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_C_ATTRIBUTE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_C_ATTRIBUTE. + */ + +/** Wraps (or simulates) `__has_c_attribute`. */ +#if defined(__cplusplus) +# /* Makes no sense. */ +# define RBIMPL_HAS_C_ATTRIBUTE(_) 0 + +#elif defined(__has_c_attribute) +# define RBIMPL_HAS_C_ATTRIBUTE(_) __has_c_attribute(_) + +#else +# /* As of writing everything that lacks __has_c_attribute also completely +# * lacks C2x attributes as well. Might change in future? */ +# define RBIMPL_HAS_C_ATTRIBUTE(_) 0 +#endif + +#endif /* RBIMPL_HAS_C_ATTRIBUTE_H */ diff --git a/include/ruby/internal/has/cpp_attribute.h b/include/ruby/internal/has/cpp_attribute.h new file mode 100644 index 0000000000..12847a11d6 --- /dev/null +++ b/include/ruby/internal/has/cpp_attribute.h @@ -0,0 +1,79 @@ +#ifndef RBIMPL_HAS_CPP_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_CPP_ATTRIBUTE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_CPP_ATTRIBUTE. + */ +#include "ruby/impl/compiler_is.h" +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/token_paste.h" + +/** @cond INTERNAL_MACRO */ +#if defined(__has_cpp_attribute) +# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) __has_cpp_attribute(_) + +#elif RBIMPL_COMPILER_IS(MSVC) +# /* MSVC has never updated its __cplusplus since forever (unless specified +# * explicitly by a compiler flag). They also lack __has_cpp_attribute until +# * 2019. However, they do have attributes since 2015 or so. */ +# /* https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance */ +# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_CPP_ATTRIBUTE_, _) +# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_carries_dependency 200809 * RBIMPL_COMPILER_SINCE(MSVC, 19, 00, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_fallthrough 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 10, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_maybe_unused 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_nodiscard 201603 * RBIMPL_COMPILER_SINCE(MSVC, 19, 11, 0) + +#elif RBIMPL_COMPILER_BEFORE(Clang, 3, 6, 0) +# /* Clang 3.6.0 introduced __has_cpp_attribute. Prior to that following +# * attributes were already there. */ +# /* https://clang.llvm.org/cxx_status.html */ +# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_CPP_ATTRIBUTE_, _) +# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(Clang, 3, 3, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(Clang, 3, 4, 0) + +#elif RBIMPL_COMPILER_BEFORE(GCC, 5, 0, 0) +# /* GCC 5+ have __has_cpp_attribute, while 4.x had following attributes. */ +# /* https://gcc.gnu.org/projects/cxx-status.html */ +# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_CPP_ATTRIBUTE_, _) +# define RBIMPL_HAS_CPP_ATTRIBUTE_noreturn 200809 * RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) +# define RBIMPL_HAS_CPP_ATTRIBUTE_deprecated 201309 * RBIMPL_COMPILER_SINCE(GCC, 4, 9, 0) + +#else +# /* :FIXME: +# * Candidate compilers to list here: +# * - icpc: They have __INTEL_CXX11_MODE__. +# * - SunPro: Seems they support C++11. +# */ +# define RBIMPL_HAS_CPP_ATTRIBUTE0(_) 0 +#endif +/** @endcond */ + +/** Wraps (or simulates) `__has_cpp_attribute`. */ +#if ! defined(__cplusplus) +# /* Makes no sense. */ +# define RBIMPL_HAS_CPP_ATTRIBUTE(_) 0 +#else +# /* GCC needs workarounds. See https://gcc.godbolt.org/z/jdz3pa */ +# define RBIMPL_HAS_CPP_ATTRIBUTE(_) \ + ((RBIMPL_HAS_CPP_ATTRIBUTE0(_) <= __cplusplus) ? RBIMPL_HAS_CPP_ATTRIBUTE0(_) : 0) +#endif + +#endif /* RBIMPL_HAS_CPP_ATTRIBUTE_H */ diff --git a/include/ruby/internal/has/declspec_attribute.h b/include/ruby/internal/has/declspec_attribute.h new file mode 100644 index 0000000000..ba6ad98fce --- /dev/null +++ b/include/ruby/internal/has/declspec_attribute.h @@ -0,0 +1,48 @@ +#ifndef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_DECLSPEC_ATTRIBUTE. + */ +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/token_paste.h" + +/** Wraps (or simulates) `__has_declspec_attribute`. */ +#if defined(__has_declspec_attribute) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) __has_declspec_attribute(_) +#else +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE(_) RBIMPL_TOKEN_PASTE(RBIMPL_HAS_DECLSPEC_ATTRIBUTE_, _) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_align RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_deprecated RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllexport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_dllimport RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_empty_bases RBIMPL_COMPILER_SINCE(MSVC,19, 0, 23918) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noalias RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noinline RBIMPL_COMPILER_SINCE(MSVC,13, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_noreturn RBIMPL_COMPILER_SINCE(MSVC,11, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow RBIMPL_COMPILER_SINCE(MSVC, 8, 0, 0) +# define RBIMPL_HAS_DECLSPEC_ATTRIBUTE_restrict RBIMPL_COMPILER_SINCE(MSVC,14, 0, 0) +# /* Note that "8, 0, 0" might be inaccurate. */ +# if ! defined(__cplusplus) +# /* Clang has this in both C/C++, but MSVC has this in C++ only.*/ +# undef RBIMPL_HAS_DECLSPEC_ATTRIBUTE_nothrow +# endif +#endif + +#endif /* RBIMPL_HAS_DECLSPEC_ATTRIBUTE_H */ diff --git a/include/ruby/internal/has/extension.h b/include/ruby/internal/has/extension.h new file mode 100644 index 0000000000..02a48bc74c --- /dev/null +++ b/include/ruby/internal/has/extension.h @@ -0,0 +1,33 @@ +#ifndef RBIMPL_HAS_EXTENSION_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_EXTENSION_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_EXTENSION. + */ +#include "ruby/impl/has/feature.h" + +/** Wraps (or simulates) `__has_extension`. */ +#if defined(__has_extension) +# define RBIMPL_HAS_EXTENSION(_) __has_extension(_) +#else +# /* Pre-3.0 clang had __has_feature but not __has_extension. */ +# define RBIMPL_HAS_EXTENSION(_) RBIMPL_HAS_FEATURE(_) +#endif + +#endif /* RBIMPL_HAS_EXTENSION_H */ diff --git a/include/ruby/internal/has/feature.h b/include/ruby/internal/has/feature.h new file mode 100644 index 0000000000..b827590c00 --- /dev/null +++ b/include/ruby/internal/has/feature.h @@ -0,0 +1,31 @@ +#ifndef RBIMPL_HAS_FEATURE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_FEATURE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_FEATURE. + */ + +/** Wraps (or simulates) `__has_feature`. */ +#if defined(__has_feature) +# define RBIMPL_HAS_FEATURE(_) __has_feature(_) +#else +# define RBIMPL_HAS_FEATURE(_) 0 +#endif + +#endif /* RBIMPL_HAS_FEATURE_H */ diff --git a/include/ruby/internal/has/warning.h b/include/ruby/internal/has/warning.h new file mode 100644 index 0000000000..03975ecc2f --- /dev/null +++ b/include/ruby/internal/has/warning.h @@ -0,0 +1,31 @@ +#ifndef RBIMPL_HAS_WARNING_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_HAS_WARNING_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_HAS_WARNING. + */ + +/** Wraps (or simulates) `__has_warning`. */ +#if defined(__has_warning) +# define RBIMPL_HAS_WARNING(_) __has_warning(_) +#else +# define RBIMPL_HAS_WARNING(_) 0 +#endif + +#endif /* RBIMPL_HAS_WARNING_H */ diff --git a/include/ruby/internal/intern/array.h b/include/ruby/internal/intern/array.h new file mode 100644 index 0000000000..bfa12191c4 --- /dev/null +++ b/include/ruby/internal/intern/array.h @@ -0,0 +1,78 @@ +#ifndef RBIMPL_INTERN_ARRAY_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_ARRAY_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cArray. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* array.c */ +void rb_mem_clear(VALUE*, long); +VALUE rb_assoc_new(VALUE, VALUE); +VALUE rb_check_array_type(VALUE); +VALUE rb_ary_new(void); +VALUE rb_ary_new_capa(long capa); +VALUE rb_ary_new_from_args(long n, ...); +VALUE rb_ary_new_from_values(long n, const VALUE *elts); +VALUE rb_ary_tmp_new(long); +void rb_ary_free(VALUE); +void rb_ary_modify(VALUE); +VALUE rb_ary_freeze(VALUE); +VALUE rb_ary_shared_with_p(VALUE, VALUE); +VALUE rb_ary_aref(int, const VALUE*, VALUE); +VALUE rb_ary_subseq(VALUE, long, long); +void rb_ary_store(VALUE, long, VALUE); +VALUE rb_ary_dup(VALUE); +VALUE rb_ary_resurrect(VALUE ary); +VALUE rb_ary_to_ary(VALUE); +VALUE rb_ary_to_s(VALUE); +VALUE rb_ary_cat(VALUE, const VALUE *, long); +VALUE rb_ary_push(VALUE, VALUE); +VALUE rb_ary_pop(VALUE); +VALUE rb_ary_shift(VALUE); +VALUE rb_ary_unshift(VALUE, VALUE); +VALUE rb_ary_entry(VALUE, long); +VALUE rb_ary_each(VALUE); +VALUE rb_ary_join(VALUE, VALUE); +VALUE rb_ary_reverse(VALUE); +VALUE rb_ary_rotate(VALUE, long); +VALUE rb_ary_sort(VALUE); +VALUE rb_ary_sort_bang(VALUE); +VALUE rb_ary_delete(VALUE, VALUE); +VALUE rb_ary_delete_at(VALUE, long); +VALUE rb_ary_clear(VALUE); +VALUE rb_ary_plus(VALUE, VALUE); +VALUE rb_ary_concat(VALUE, VALUE); +VALUE rb_ary_assoc(VALUE, VALUE); +VALUE rb_ary_rassoc(VALUE, VALUE); +VALUE rb_ary_includes(VALUE, VALUE); +VALUE rb_ary_cmp(VALUE, VALUE); +VALUE rb_ary_replace(VALUE copy, VALUE orig); +VALUE rb_get_values_at(VALUE, long, int, const VALUE*, VALUE(*)(VALUE,long)); +VALUE rb_ary_resize(VALUE ary, long len); +#define rb_ary_new2 rb_ary_new_capa +#define rb_ary_new3 rb_ary_new_from_args +#define rb_ary_new4 rb_ary_new_from_values + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_ARRAY_H */ diff --git a/include/ruby/internal/intern/bignum.h b/include/ruby/internal/intern/bignum.h new file mode 100644 index 0000000000..5af4c0ae42 --- /dev/null +++ b/include/ruby/internal/intern/bignum.h @@ -0,0 +1,105 @@ +#ifndef RBIMPL_INTERN_BIGNUM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_BIGNUM_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to so-called rb_cBignum. + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include +#endif + +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/long_long.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* bignum.c */ +VALUE rb_big_new(size_t, int); +int rb_bigzero_p(VALUE x); +VALUE rb_big_clone(VALUE); +void rb_big_2comp(VALUE); +VALUE rb_big_norm(VALUE); +void rb_big_resize(VALUE big, size_t len); +VALUE rb_cstr_to_inum(const char*, int, int); +VALUE rb_str_to_inum(VALUE, int, int); +VALUE rb_cstr2inum(const char*, int); +VALUE rb_str2inum(VALUE, int); +VALUE rb_big2str(VALUE, int); +long rb_big2long(VALUE); +#define rb_big2int(x) rb_big2long(x) +unsigned long rb_big2ulong(VALUE); +#define rb_big2uint(x) rb_big2ulong(x) +#if HAVE_LONG_LONG +LONG_LONG rb_big2ll(VALUE); +unsigned LONG_LONG rb_big2ull(VALUE); +#endif /* HAVE_LONG_LONG */ +void rb_big_pack(VALUE val, unsigned long *buf, long num_longs); +VALUE rb_big_unpack(unsigned long *buf, long num_longs); +int rb_uv_to_utf8(char[6],unsigned long); +VALUE rb_dbl2big(double); +double rb_big2dbl(VALUE); +VALUE rb_big_cmp(VALUE, VALUE); +VALUE rb_big_eq(VALUE, VALUE); +VALUE rb_big_eql(VALUE, VALUE); +VALUE rb_big_plus(VALUE, VALUE); +VALUE rb_big_minus(VALUE, VALUE); +VALUE rb_big_mul(VALUE, VALUE); +VALUE rb_big_div(VALUE, VALUE); +VALUE rb_big_idiv(VALUE, VALUE); +VALUE rb_big_modulo(VALUE, VALUE); +VALUE rb_big_divmod(VALUE, VALUE); +VALUE rb_big_pow(VALUE, VALUE); +VALUE rb_big_and(VALUE, VALUE); +VALUE rb_big_or(VALUE, VALUE); +VALUE rb_big_xor(VALUE, VALUE); +VALUE rb_big_lshift(VALUE, VALUE); +VALUE rb_big_rshift(VALUE, VALUE); + +/* For rb_integer_pack and rb_integer_unpack: */ +/* "MS" in MSWORD and MSBYTE means "most significant" */ +/* "LS" in LSWORD and LSBYTE means "least significant" */ +#define INTEGER_PACK_MSWORD_FIRST 0x01 +#define INTEGER_PACK_LSWORD_FIRST 0x02 +#define INTEGER_PACK_MSBYTE_FIRST 0x10 +#define INTEGER_PACK_LSBYTE_FIRST 0x20 +#define INTEGER_PACK_NATIVE_BYTE_ORDER 0x40 +#define INTEGER_PACK_2COMP 0x80 +#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION 0x400 +/* For rb_integer_unpack: */ +#define INTEGER_PACK_FORCE_BIGNUM 0x100 +#define INTEGER_PACK_NEGATIVE 0x200 +/* Combinations: */ +#define INTEGER_PACK_LITTLE_ENDIAN \ + (INTEGER_PACK_LSWORD_FIRST | \ + INTEGER_PACK_LSBYTE_FIRST) +#define INTEGER_PACK_BIG_ENDIAN \ + (INTEGER_PACK_MSWORD_FIRST | \ + INTEGER_PACK_MSBYTE_FIRST) +int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags); +VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags); +size_t rb_absint_size(VALUE val, int *nlz_bits_ret); +size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret); +int rb_absint_singlebit_p(VALUE val); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_BIGNUM_H */ diff --git a/include/ruby/internal/intern/class.h b/include/ruby/internal/intern/class.h new file mode 100644 index 0000000000..7a1cadd5b4 --- /dev/null +++ b/include/ruby/internal/intern/class.h @@ -0,0 +1,57 @@ +#ifndef RBIMPL_INTERN_CLASS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_CLASS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cClass/::rb_cModule. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/stdarg.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* class.c */ +VALUE rb_class_new(VALUE); +VALUE rb_mod_init_copy(VALUE, VALUE); +VALUE rb_singleton_class_clone(VALUE); +void rb_singleton_class_attached(VALUE,VALUE); +void rb_check_inheritable(VALUE); +VALUE rb_define_class_id(ID, VALUE); +VALUE rb_define_class_id_under(VALUE, ID, VALUE); +VALUE rb_module_new(void); +VALUE rb_define_module_id(ID); +VALUE rb_define_module_id_under(VALUE, ID); +VALUE rb_mod_included_modules(VALUE); +VALUE rb_mod_include_p(VALUE, VALUE); +VALUE rb_mod_ancestors(VALUE); +VALUE rb_class_instance_methods(int, const VALUE*, VALUE); +VALUE rb_class_public_instance_methods(int, const VALUE*, VALUE); +VALUE rb_class_protected_instance_methods(int, const VALUE*, VALUE); +VALUE rb_class_private_instance_methods(int, const VALUE*, VALUE); +VALUE rb_obj_singleton_methods(int, const VALUE*, VALUE); +void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int); +void rb_undef(VALUE, ID); +void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int); +void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int); +void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int); +VALUE rb_singleton_class(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_CLASS_H */ diff --git a/include/ruby/internal/intern/compar.h b/include/ruby/internal/intern/compar.h new file mode 100644 index 0000000000..c762dc1e24 --- /dev/null +++ b/include/ruby/internal/intern/compar.h @@ -0,0 +1,34 @@ +#ifndef RBIMPL_INTERN_COMPAR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_COMPAR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_mComparable. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* compar.c */ +int rb_cmpint(VALUE, VALUE, VALUE); +NORETURN(void rb_cmperr(VALUE, VALUE)); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_COMPAR_H */ diff --git a/include/ruby/internal/intern/complex.h b/include/ruby/internal/intern/complex.h new file mode 100644 index 0000000000..c3841cfdb6 --- /dev/null +++ b/include/ruby/internal/intern/complex.h @@ -0,0 +1,60 @@ +#ifndef RBIMPL_INTERN_COMPLEX_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_COMPLEX_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cComplex. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/arithmetic/long.h" /* INT2FIX is here. */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* complex.c */ +VALUE rb_complex_raw(VALUE, VALUE); +#define rb_complex_raw1(x) rb_complex_raw((x), INT2FIX(0)) +#define rb_complex_raw2(x,y) rb_complex_raw((x), (y)) +VALUE rb_complex_new(VALUE, VALUE); +#define rb_complex_new1(x) rb_complex_new((x), INT2FIX(0)) +#define rb_complex_new2(x,y) rb_complex_new((x), (y)) +VALUE rb_complex_new_polar(VALUE abs, VALUE arg); +DEPRECATED_BY(rb_complex_new_polar, VALUE rb_complex_polar(VALUE abs, VALUE arg)); +VALUE rb_complex_real(VALUE z); +VALUE rb_complex_imag(VALUE z); +VALUE rb_complex_plus(VALUE x, VALUE y); +VALUE rb_complex_minus(VALUE x, VALUE y); +VALUE rb_complex_mul(VALUE x, VALUE y); +VALUE rb_complex_div(VALUE x, VALUE y); +VALUE rb_complex_uminus(VALUE z); +VALUE rb_complex_conjugate(VALUE z); +VALUE rb_complex_abs(VALUE z); +VALUE rb_complex_arg(VALUE z); +VALUE rb_complex_pow(VALUE base, VALUE exp); +VALUE rb_dbl_complex_new(double real, double imag); +#define rb_complex_add rb_complex_plus +#define rb_complex_sub rb_complex_minus +#define rb_complex_nagate rb_complex_uminus + +VALUE rb_Complex(VALUE, VALUE); +#define rb_Complex1(x) rb_Complex((x), INT2FIX(0)) +#define rb_Complex2(x,y) rb_Complex((x), (y)) + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_COMPLEX_H */ diff --git a/include/ruby/internal/intern/cont.h b/include/ruby/internal/intern/cont.h new file mode 100644 index 0000000000..16c3cf8be1 --- /dev/null +++ b/include/ruby/internal/intern/cont.h @@ -0,0 +1,40 @@ +#ifndef RBIMPL_INTERN_CONT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_CONT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to rb_cFiber. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/iterator.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* cont.c */ +VALUE rb_fiber_new(rb_block_call_func_t, VALUE); +VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv); +VALUE rb_fiber_resume_kw(VALUE fib, int argc, const VALUE *argv, int kw_splat); +VALUE rb_fiber_yield(int argc, const VALUE *argv); +VALUE rb_fiber_yield_kw(int argc, const VALUE *argv, int kw_splat); +VALUE rb_fiber_current(void); +VALUE rb_fiber_alive_p(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_CONT_H */ diff --git a/include/ruby/internal/intern/dir.h b/include/ruby/internal/intern/dir.h new file mode 100644 index 0000000000..6fcf274a28 --- /dev/null +++ b/include/ruby/internal/intern/dir.h @@ -0,0 +1,33 @@ +#ifndef RBIMPL_INTERN_DIR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_DIR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cDir. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* dir.c */ +VALUE rb_dir_getwd(void); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_DIR_H */ diff --git a/include/ruby/internal/intern/enum.h b/include/ruby/internal/intern/enum.h new file mode 100644 index 0000000000..ef6fffe444 --- /dev/null +++ b/include/ruby/internal/intern/enum.h @@ -0,0 +1,33 @@ +#ifndef RBIMPL_INTERN_ENUM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_ENUM_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_mEnumerable. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* enum.c */ +VALUE rb_enum_values_pack(int, const VALUE*); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_ENUM_H */ diff --git a/include/ruby/internal/intern/enumerator.h b/include/ruby/internal/intern/enumerator.h new file mode 100644 index 0000000000..8f64b58de2 --- /dev/null +++ b/include/ruby/internal/intern/enumerator.h @@ -0,0 +1,79 @@ +#ifndef RBIMPL_INTERN_ENUMERATOR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_ENUMERATOR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cEnumerator. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/intern/eval.h" /* rb_frame_this_func */ +#include "ruby/impl/iterator.h" /* rb_block_given_p */ +#include "ruby/impl/symbol.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +typedef VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE); + +typedef struct { + VALUE begin; + VALUE end; + VALUE step; + int exclude_end; +} rb_arithmetic_sequence_components_t; + +/* enumerator.c */ +VALUE rb_enumeratorize(VALUE, VALUE, int, const VALUE *); +VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *); +VALUE rb_enumeratorize_with_size_kw(VALUE, VALUE, int, const VALUE *, rb_enumerator_size_func *, int); +int rb_arithmetic_sequence_extract(VALUE, rb_arithmetic_sequence_components_t *); + +RBIMPL_SYMBOL_EXPORT_END() + +#ifndef RUBY_EXPORT +# define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \ + rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn)) +# define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat) \ + rb_enumeratorize_with_size_kw(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn), kw_splat) +#endif + +#define SIZED_ENUMERATOR(obj, argc, argv, size_fn) \ + rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()), \ + (argc), (argv), (size_fn)) + +#define SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) \ + rb_enumeratorize_with_size_kw((obj), ID2SYM(rb_frame_this_func()), \ + (argc), (argv), (size_fn), (kw_splat)) + +#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \ + if (!rb_block_given_p()) \ + return SIZED_ENUMERATOR(obj, argc, argv, size_fn); \ + } while (0) + +#define RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) do { \ + if (!rb_block_given_p()) \ + return SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat); \ + } while (0) + +#define RETURN_ENUMERATOR(obj, argc, argv) \ + RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0) + +#define RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) \ + RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat) + +#endif /* RBIMPL_INTERN_ENUMERATOR_H */ diff --git a/include/ruby/internal/intern/error.h b/include/ruby/internal/intern/error.h new file mode 100644 index 0000000000..0cc5e1c858 --- /dev/null +++ b/include/ruby/internal/intern/error.h @@ -0,0 +1,82 @@ +#ifndef RBIMPL_INTERN_ERROR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_ERROR_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_eException. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/fl_type.h" +#include "ruby/backward/2/assume.h" +#include "ruby/backward/2/attributes.h" + +#define UNLIMITED_ARGUMENTS (-1) +#define rb_exc_new2 rb_exc_new_cstr +#define rb_exc_new3 rb_exc_new_str +#define rb_check_trusted rb_check_trusted +#define rb_check_trusted_inline rb_check_trusted +#define rb_check_arity rb_check_arity + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* error.c */ +VALUE rb_exc_new(VALUE, const char*, long); +VALUE rb_exc_new_cstr(VALUE, const char*); +VALUE rb_exc_new_str(VALUE, VALUE); +PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2); +PRINTF_ARGS(NORETURN(void rb_loaderror_with_path(VALUE path, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_name_error_str(VALUE, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_frozen_error_raise(VALUE, const char*, ...)), 2, 3); +NORETURN(void rb_invalid_str(const char*, const char*)); +NORETURN(void rb_error_frozen(const char*)); +NORETURN(void rb_error_frozen_object(VALUE)); +void rb_error_untrusted(VALUE); +void rb_check_frozen(VALUE); +void rb_check_trusted(VALUE); +void rb_check_copyable(VALUE obj, VALUE orig); +NORETURN(MJIT_STATIC void rb_error_arity(int, int, int)); +RBIMPL_SYMBOL_EXPORT_END() + +/* Does anyone use this? Remain not deleted for compatibility. */ +#define rb_check_frozen_internal(obj) do { \ + VALUE frozen_obj = (obj); \ + if (RB_UNLIKELY(RB_OBJ_FROZEN(frozen_obj))) { \ + rb_error_frozen_object(frozen_obj); \ + } \ + } while (0) + +static inline void +rb_check_frozen_inline(VALUE obj) +{ + if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) { + rb_error_frozen_object(obj); + } +} +#define rb_check_frozen rb_check_frozen_inline + +static inline int +rb_check_arity(int argc, int min, int max) +{ + if ((argc < min) || (max != UNLIMITED_ARGUMENTS && argc > max)) + rb_error_arity(argc, min, max); + return argc; +} + +#endif /* RBIMPL_INTERN_ERROR_H */ diff --git a/include/ruby/internal/intern/eval.h b/include/ruby/internal/intern/eval.h new file mode 100644 index 0000000000..75374df6be --- /dev/null +++ b/include/ruby/internal/intern/eval.h @@ -0,0 +1,59 @@ +#ifndef RBIMPL_INTERN_EVAL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_EVAL_H +/** + * @file + * @author Ruby developers + * @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 Pre-1.9 era evaluator APIs (now considered miscellaneous). + */ +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* eval.c */ +RBIMPL_ATTR_NORETURN() +void rb_exc_raise(VALUE); + +RBIMPL_ATTR_NORETURN() +void rb_exc_fatal(VALUE); + +RBIMPL_ATTR_NORETURN() +VALUE rb_f_exit(int, const VALUE*); + +RBIMPL_ATTR_NORETURN() +VALUE rb_f_abort(int, const VALUE*); + +RBIMPL_ATTR_NORETURN() +void rb_interrupt(void); +ID rb_frame_this_func(void); + +RBIMPL_ATTR_NORETURN() +void rb_jump_tag(int); +void rb_obj_call_init(VALUE, int, const VALUE*); +void rb_obj_call_init_kw(VALUE, int, const VALUE*, int); +VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); +ID rb_frame_callee(void); +VALUE rb_make_exception(int, const VALUE*); + +/* eval_jump.c */ +void rb_set_end_proc(void (*)(VALUE), VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_EVAL_H */ diff --git a/include/ruby/internal/intern/file.h b/include/ruby/internal/intern/file.h new file mode 100644 index 0000000000..ed8e50cba6 --- /dev/null +++ b/include/ruby/internal/intern/file.h @@ -0,0 +1,44 @@ +#ifndef RBIMPL_INTERN_FILE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_FILE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cFile. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* file.c */ +VALUE rb_file_s_expand_path(int, const VALUE *); +VALUE rb_file_expand_path(VALUE, VALUE); +VALUE rb_file_s_absolute_path(int, const VALUE *); +VALUE rb_file_absolute_path(VALUE, VALUE); +VALUE rb_file_dirname(VALUE fname); +int rb_find_file_ext_safe(VALUE*, const char* const*, int); /* Remove in 3.0 */ +VALUE rb_find_file_safe(VALUE, int); /* Remove in 3.0 */ +int rb_find_file_ext(VALUE*, const char* const*); +VALUE rb_find_file(VALUE); +VALUE rb_file_directory_p(VALUE,VALUE); +VALUE rb_str_encode_ospath(VALUE); +int rb_is_absolute_path(const char *); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_FILE_H */ diff --git a/include/ruby/internal/intern/gc.h b/include/ruby/internal/intern/gc.h new file mode 100644 index 0000000000..a75785cc49 --- /dev/null +++ b/include/ruby/internal/intern/gc.h @@ -0,0 +1,57 @@ +#ifndef RBIMPL_INTERN_GC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_GC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_mGC. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/attributes.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* gc.c */ +COLDFUNC NORETURN(void rb_memerror(void)); +PUREFUNC(int rb_during_gc(void)); +void rb_gc_mark_locations(const VALUE*, const VALUE*); +void rb_mark_tbl(struct st_table*); +void rb_mark_tbl_no_pin(struct st_table*); +void rb_mark_set(struct st_table*); +void rb_mark_hash(struct st_table*); +void rb_gc_update_tbl_refs(st_table *ptr); +void rb_gc_mark_maybe(VALUE); +void rb_gc_mark(VALUE); +void rb_gc_mark_movable(VALUE); +VALUE rb_gc_location(VALUE); +void rb_gc_force_recycle(VALUE); +void rb_gc(void); +void rb_gc_copy_finalizer(VALUE,VALUE); +VALUE rb_gc_enable(void); +VALUE rb_gc_disable(void); +VALUE rb_gc_start(void); +VALUE rb_define_finalizer(VALUE, VALUE); +VALUE rb_undefine_finalizer(VALUE); +size_t rb_gc_count(void); +size_t rb_gc_stat(VALUE); +VALUE rb_gc_latest_gc_info(VALUE); +void rb_gc_adjust_memory_usage(ssize_t); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_GC_H */ diff --git a/include/ruby/internal/intern/hash.h b/include/ruby/internal/intern/hash.h new file mode 100644 index 0000000000..3f0a930131 --- /dev/null +++ b/include/ruby/internal/intern/hash.h @@ -0,0 +1,59 @@ +#ifndef RBIMPL_INTERN_HASH_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_HASH_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cHash. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/st.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* hash.c */ +void rb_st_foreach_safe(struct st_table *, int (*)(st_data_t, st_data_t, st_data_t), st_data_t); +#define st_foreach_safe rb_st_foreach_safe +VALUE rb_check_hash_type(VALUE); +void rb_hash_foreach(VALUE, int (*)(VALUE, VALUE, VALUE), VALUE); +VALUE rb_hash(VALUE); +VALUE rb_hash_new(void); +VALUE rb_hash_dup(VALUE); +VALUE rb_hash_freeze(VALUE); +VALUE rb_hash_aref(VALUE, VALUE); +VALUE rb_hash_lookup(VALUE, VALUE); +VALUE rb_hash_lookup2(VALUE, VALUE, VALUE); +VALUE rb_hash_fetch(VALUE, VALUE); +VALUE rb_hash_aset(VALUE, VALUE, VALUE); +VALUE rb_hash_clear(VALUE); +VALUE rb_hash_delete_if(VALUE); +VALUE rb_hash_delete(VALUE,VALUE); +VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone); +void rb_hash_bulk_insert(long, const VALUE *, VALUE); +typedef VALUE rb_hash_update_func(VALUE newkey, VALUE oldkey, VALUE value); +VALUE rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func); +struct st_table *rb_hash_tbl(VALUE, const char *file, int line); +int rb_path_check(const char*); +int rb_env_path_tainted(void); +VALUE rb_env_clear(void); +VALUE rb_hash_size(VALUE); +void rb_hash_free(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_HASH_H */ diff --git a/include/ruby/internal/intern/io.h b/include/ruby/internal/intern/io.h new file mode 100644 index 0000000000..6b0133dddf --- /dev/null +++ b/include/ruby/internal/intern/io.h @@ -0,0 +1,70 @@ +#ifndef RBIMPL_INTERN_IO_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_IO_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cIO. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* io.c */ +#define rb_defout rb_stdout +RUBY_EXTERN VALUE rb_fs; +RUBY_EXTERN VALUE rb_output_fs; +RUBY_EXTERN VALUE rb_rs; +RUBY_EXTERN VALUE rb_default_rs; +RUBY_EXTERN VALUE rb_output_rs; +VALUE rb_io_write(VALUE, VALUE); +VALUE rb_io_gets(VALUE); +VALUE rb_io_getbyte(VALUE); +VALUE rb_io_ungetc(VALUE, VALUE); +VALUE rb_io_ungetbyte(VALUE, VALUE); +VALUE rb_io_close(VALUE); +VALUE rb_io_flush(VALUE); +VALUE rb_io_eof(VALUE); +VALUE rb_io_binmode(VALUE); +VALUE rb_io_ascii8bit_binmode(VALUE); +VALUE rb_io_addstr(VALUE, VALUE); +VALUE rb_io_printf(int, const VALUE*, VALUE); +VALUE rb_io_print(int, const VALUE*, VALUE); +VALUE rb_io_puts(int, const VALUE*, VALUE); +VALUE rb_io_fdopen(int, int, const char*); +VALUE rb_io_get_io(VALUE); +VALUE rb_file_open(const char*, const char*); +VALUE rb_file_open_str(VALUE, const char*); +VALUE rb_gets(void); +void rb_write_error(const char*); +void rb_write_error2(const char*, long); +void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds); +int rb_pipe(int *pipes); +int rb_reserved_fd_p(int fd); +int rb_cloexec_open(const char *pathname, int flags, mode_t mode); +int rb_cloexec_dup(int oldfd); +int rb_cloexec_dup2(int oldfd, int newfd); +int rb_cloexec_pipe(int fildes[2]); +int rb_cloexec_fcntl_dupfd(int fd, int minfd); +#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd) +void rb_update_max_fd(int fd); +void rb_fd_fix_cloexec(int fd); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_IO_H */ diff --git a/include/ruby/internal/intern/load.h b/include/ruby/internal/intern/load.h new file mode 100644 index 0000000000..d165237bfc --- /dev/null +++ b/include/ruby/internal/intern/load.h @@ -0,0 +1,39 @@ +#ifndef RBIMPL_INTERN_LOAD_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_LOAD_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_f_require(). + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* load.c */ +void rb_load(VALUE, int); +void rb_load_protect(VALUE, int, int*); +int rb_provided(const char*); +int rb_feature_provided(const char *, const char **); +void rb_provide(const char*); +VALUE rb_f_require(VALUE, VALUE); +VALUE rb_require_string(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_LOAD_H */ diff --git a/include/ruby/internal/intern/marshal.h b/include/ruby/internal/intern/marshal.h new file mode 100644 index 0000000000..88473ba4e3 --- /dev/null +++ b/include/ruby/internal/intern/marshal.h @@ -0,0 +1,35 @@ +#ifndef RBIMPL_INTERN_MARSHAL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_MARSHAL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to rb_mMarshal. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* marshal.c */ +VALUE rb_marshal_dump(VALUE, VALUE); +VALUE rb_marshal_load(VALUE); +void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE)); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_MARSHAL_H */ diff --git a/include/ruby/internal/intern/numeric.h b/include/ruby/internal/intern/numeric.h new file mode 100644 index 0000000000..fa4b1daa74 --- /dev/null +++ b/include/ruby/internal/intern/numeric.h @@ -0,0 +1,42 @@ +#ifndef RBIMPL_INTERN_NUMERIC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_NUMERIC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cNumeric. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/attributes.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* numeric.c */ +NORETURN(void rb_num_zerodiv(void)); +#define RB_NUM_COERCE_FUNCS_NEED_OPID 1 +VALUE rb_num_coerce_bin(VALUE, VALUE, ID); +VALUE rb_num_coerce_cmp(VALUE, VALUE, ID); +VALUE rb_num_coerce_relop(VALUE, VALUE, ID); +VALUE rb_num_coerce_bit(VALUE, VALUE, ID); +VALUE rb_num2fix(VALUE); +VALUE rb_fix2str(VALUE, int); +CONSTFUNC(VALUE rb_dbl_cmp(double, double)); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_NUMERIC_H */ diff --git a/include/ruby/internal/intern/object.h b/include/ruby/internal/intern/object.h new file mode 100644 index 0000000000..808836fbda --- /dev/null +++ b/include/ruby/internal/intern/object.h @@ -0,0 +1,90 @@ +#ifndef RBIMPL_INTERN_OBJECT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_OBJECT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cObject. + */ +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +#define RB_OBJ_INIT_COPY(obj, orig) \ + ((obj) != (orig) && (rb_obj_init_copy((obj), (orig)), 1)) +#define OBJ_INIT_COPY(obj, orig) RB_OBJ_INIT_COPY(obj, orig) + +VALUE rb_class_new_instance_pass_kw(int, const VALUE *, VALUE); +VALUE rb_class_new_instance(int, const VALUE*, VALUE); +VALUE rb_class_new_instance_kw(int, const VALUE*, VALUE, int); + +/* object.c */ +int rb_eql(VALUE, VALUE); +VALUE rb_any_to_s(VALUE); +VALUE rb_inspect(VALUE); +VALUE rb_obj_is_instance_of(VALUE, VALUE); +VALUE rb_obj_is_kind_of(VALUE, VALUE); +VALUE rb_obj_alloc(VALUE); +VALUE rb_obj_clone(VALUE); +VALUE rb_obj_dup(VALUE); +VALUE rb_obj_init_copy(VALUE,VALUE); +VALUE rb_obj_taint(VALUE); + +RBIMPL_ATTR_PURE() +VALUE rb_obj_tainted(VALUE); +VALUE rb_obj_untaint(VALUE); +VALUE rb_obj_untrust(VALUE); + +RBIMPL_ATTR_PURE() +VALUE rb_obj_untrusted(VALUE); +VALUE rb_obj_trust(VALUE); +VALUE rb_obj_freeze(VALUE); + +RBIMPL_ATTR_PURE() +VALUE rb_obj_frozen_p(VALUE); + +VALUE rb_obj_id(VALUE); +VALUE rb_memory_id(VALUE); +VALUE rb_obj_class(VALUE); + +RBIMPL_ATTR_PURE() +VALUE rb_class_real(VALUE); + +RBIMPL_ATTR_PURE() +VALUE rb_class_inherited_p(VALUE, VALUE); +VALUE rb_class_superclass(VALUE); +VALUE rb_class_get_superclass(VALUE); +VALUE rb_convert_type(VALUE,int,const char*,const char*); +VALUE rb_check_convert_type(VALUE,int,const char*,const char*); +VALUE rb_check_to_integer(VALUE, const char *); +VALUE rb_check_to_float(VALUE); +VALUE rb_to_int(VALUE); +VALUE rb_check_to_int(VALUE); +VALUE rb_Integer(VALUE); +VALUE rb_to_float(VALUE); +VALUE rb_Float(VALUE); +VALUE rb_String(VALUE); +VALUE rb_Array(VALUE); +VALUE rb_Hash(VALUE); +double rb_cstr_to_dbl(const char*, int); +double rb_str_to_dbl(VALUE, int); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_OBJECT_H */ diff --git a/include/ruby/internal/intern/parse.h b/include/ruby/internal/intern/parse.h new file mode 100644 index 0000000000..cc6424f539 --- /dev/null +++ b/include/ruby/internal/intern/parse.h @@ -0,0 +1,64 @@ +#ifndef RBIMPL_INTERN_PARSE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_PARSE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cSymbol. + */ +#include "ruby/impl/attr/const.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* parse.y */ +ID rb_id_attrset(ID); + +RBIMPL_ATTR_CONST() +int rb_is_const_id(ID); + +RBIMPL_ATTR_CONST() +int rb_is_global_id(ID); + +RBIMPL_ATTR_CONST() +int rb_is_instance_id(ID); + +RBIMPL_ATTR_CONST() +int rb_is_attrset_id(ID); + +RBIMPL_ATTR_CONST() +int rb_is_class_id(ID); + +RBIMPL_ATTR_CONST() +int rb_is_local_id(ID); + +RBIMPL_ATTR_CONST() +int rb_is_junk_id(ID); +int rb_symname_p(const char*); +int rb_sym_interned_p(VALUE); +VALUE rb_backref_get(void); +void rb_backref_set(VALUE); +VALUE rb_lastline_get(void); +void rb_lastline_set(VALUE); + +/* symbol.c */ +VALUE rb_sym_all_symbols(void); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_PARSE_H */ diff --git a/include/ruby/internal/intern/proc.h b/include/ruby/internal/intern/proc.h new file mode 100644 index 0000000000..7ee864d9a3 --- /dev/null +++ b/include/ruby/internal/intern/proc.h @@ -0,0 +1,53 @@ +#ifndef RBIMPL_INTERN_PROC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_PROC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cProc. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/iterator.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* proc.c */ +VALUE rb_block_proc(void); +VALUE rb_block_lambda(void); +VALUE rb_proc_new(rb_block_call_func_t, VALUE); +VALUE rb_obj_is_proc(VALUE); +VALUE rb_proc_call(VALUE, VALUE); +VALUE rb_proc_call_kw(VALUE, VALUE, int); +VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE); +VALUE rb_proc_call_with_block_kw(VALUE, int argc, const VALUE *argv, VALUE, int); +int rb_proc_arity(VALUE); +VALUE rb_proc_lambda_p(VALUE); +VALUE rb_binding_new(void); +VALUE rb_obj_method(VALUE, VALUE); +VALUE rb_obj_is_method(VALUE); +VALUE rb_method_call(int, const VALUE*, VALUE); +VALUE rb_method_call_kw(int, const VALUE*, VALUE, int); +VALUE rb_method_call_with_block(int, const VALUE *, VALUE, VALUE); +VALUE rb_method_call_with_block_kw(int, const VALUE *, VALUE, VALUE, int); +int rb_mod_method_arity(VALUE, ID); +int rb_obj_method_arity(VALUE, ID); +VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_PROC_H */ diff --git a/include/ruby/internal/intern/process.h b/include/ruby/internal/intern/process.h new file mode 100644 index 0000000000..bbbea1f86a --- /dev/null +++ b/include/ruby/internal/intern/process.h @@ -0,0 +1,46 @@ +#ifndef RBIMPL_INTERN_PROCESS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_PROCESS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_mProcess. + */ +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/config.h" /* rb_pid_t is defined here. */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* process.c */ +void rb_last_status_set(int status, rb_pid_t pid); +VALUE rb_last_status_get(void); +int rb_proc_exec(const char*); + +RBIMPL_ATTR_NORETURN() +VALUE rb_f_exec(int, const VALUE*); +rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags); +void rb_syswait(rb_pid_t pid); +rb_pid_t rb_spawn(int, const VALUE*); +rb_pid_t rb_spawn_err(int, const VALUE*, char*, size_t); +VALUE rb_proc_times(VALUE); +VALUE rb_detach_process(rb_pid_t pid); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_PROCESS_H */ diff --git a/include/ruby/internal/intern/random.h b/include/ruby/internal/intern/random.h new file mode 100644 index 0000000000..2f054cd688 --- /dev/null +++ b/include/ruby/internal/intern/random.h @@ -0,0 +1,45 @@ +#ifndef RBIMPL_INTERN_RANDOM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_RANDOM_H +/** + * @file + * @author Ruby developers + * @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 MT19937 backended pseudo random number generator. + * @see Matsumoto, M., Nishimura, T., "Mersenne Twister: A 623- + * dimensionally equidistributed uniform pseudorandom number + * generator", ACM Trans. on Modeling and Computer Simulation, 8 + * (1): pp 3-30, 1998. https://doi.org/10.1145/272991.272995 + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* random.c */ +unsigned int rb_genrand_int32(void); +double rb_genrand_real(void); +void rb_reset_random_seed(void); +VALUE rb_random_bytes(VALUE rnd, long n); +VALUE rb_random_int(VALUE rnd, VALUE max); +unsigned int rb_random_int32(VALUE rnd); +double rb_random_real(VALUE rnd); +unsigned long rb_random_ulong_limited(VALUE rnd, unsigned long limit); +unsigned long rb_genrand_ulong_limited(unsigned long i); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_RANDOM_H */ diff --git a/include/ruby/internal/intern/range.h b/include/ruby/internal/intern/range.h new file mode 100644 index 0000000000..0841baa0d5 --- /dev/null +++ b/include/ruby/internal/intern/range.h @@ -0,0 +1,35 @@ +#ifndef RBIMPL_INTERN_RANGE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_RANGE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cRange. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* range.c */ +VALUE rb_range_new(VALUE, VALUE, int); +VALUE rb_range_beg_len(VALUE, long*, long*, long, int); +int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_RANGE_H */ diff --git a/include/ruby/internal/intern/rational.h b/include/ruby/internal/intern/rational.h new file mode 100644 index 0000000000..d56a6ec752 --- /dev/null +++ b/include/ruby/internal/intern/rational.h @@ -0,0 +1,46 @@ +#ifndef RBIMPL_INTERN_RATIONAL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_RATIONAL_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cRational. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/arithmetic/long.h" /* INT2FIX is here. */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* rational.c */ +VALUE rb_rational_raw(VALUE, VALUE); +#define rb_rational_raw1(x) rb_rational_raw((x), INT2FIX(1)) +#define rb_rational_raw2(x,y) rb_rational_raw((x), (y)) +VALUE rb_rational_new(VALUE, VALUE); +#define rb_rational_new1(x) rb_rational_new((x), INT2FIX(1)) +#define rb_rational_new2(x,y) rb_rational_new((x), (y)) +VALUE rb_Rational(VALUE, VALUE); +#define rb_Rational1(x) rb_Rational((x), INT2FIX(1)) +#define rb_Rational2(x,y) rb_Rational((x), (y)) +VALUE rb_rational_num(VALUE rat); +VALUE rb_rational_den(VALUE rat); +VALUE rb_flt_rationalize_with_prec(VALUE, VALUE); +VALUE rb_flt_rationalize(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_RATIONAL_H */ diff --git a/include/ruby/internal/intern/re.h b/include/ruby/internal/intern/re.h new file mode 100644 index 0000000000..4392cef1a2 --- /dev/null +++ b/include/ruby/internal/intern/re.h @@ -0,0 +1,50 @@ +#ifndef RBIMPL_INTERN_RE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_RE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cRegexp. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* re.c */ +#define rb_memcmp memcmp +int rb_memcicmp(const void*,const void*,long); +void rb_match_busy(VALUE); +VALUE rb_reg_nth_defined(int, VALUE); +VALUE rb_reg_nth_match(int, VALUE); +int rb_reg_backref_number(VALUE match, VALUE backref); +VALUE rb_reg_last_match(VALUE); +VALUE rb_reg_match_pre(VALUE); +VALUE rb_reg_match_post(VALUE); +VALUE rb_reg_match_last(VALUE); +#define HAVE_RB_REG_NEW_STR 1 +VALUE rb_reg_new_str(VALUE, int); +VALUE rb_reg_new(const char *, long, int); +VALUE rb_reg_alloc(void); +VALUE rb_reg_init_str(VALUE re, VALUE s, int options); +VALUE rb_reg_match(VALUE, VALUE); +VALUE rb_reg_match2(VALUE); +int rb_reg_options(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_RE_H */ diff --git a/include/ruby/internal/intern/ruby.h b/include/ruby/internal/intern/ruby.h new file mode 100644 index 0000000000..bbfda510d5 --- /dev/null +++ b/include/ruby/internal/intern/ruby.h @@ -0,0 +1,37 @@ +#ifndef RBIMPL_INTERN_RUBY_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_RUBY_H +/** + * @file + * @author Ruby developers + * @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 Process-global APIs. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* ruby.c */ +#define rb_argv rb_get_argv() +RUBY_EXTERN VALUE rb_argv0; +VALUE rb_get_argv(void); +void *rb_load_file(const char*); +void *rb_load_file_str(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_RUBY_H */ diff --git a/include/ruby/internal/intern/select.h b/include/ruby/internal/intern/select.h new file mode 100644 index 0000000000..09244dcce5 --- /dev/null +++ b/include/ruby/internal/intern/select.h @@ -0,0 +1,52 @@ +#ifndef RBIMPL_INTERN_SELECT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_SELECT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs to provide ::rb_fd_select(). + * @note Functions and structs defined in this header file are not + * necessarily ruby-specific. They don't need ::VALUE etc. + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_SYS_TYPES_H +# include /* for NFDBITS (BSD Net/2) */ +#endif + +#include "ruby/impl/dllexport.h" + +/* thread.c */ +#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT) +# include "ruby/impl/intern/select/largesize.h" +#elif defined(_WIN32) +# include "ruby/impl/intern/select/win32.h" +# define rb_fd_resize(n, f) ((void)(f)) +#else +# include "ruby/impl/intern/select/posix.h" +# define rb_fd_resize(n, f) ((void)(f)) +#endif + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +struct timeval; + +int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_SELECT_H */ diff --git a/include/ruby/internal/intern/select/largesize.h b/include/ruby/internal/intern/select/largesize.h new file mode 100644 index 0000000000..c5f321f1dc --- /dev/null +++ b/include/ruby/internal/intern/select/largesize.h @@ -0,0 +1,103 @@ +#ifndef RBIMPL_INTERN_SELECT_LARGESIZE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_SELECT_LARGESIZE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs to provide ::rb_fd_select(). + * + * Several Unix platforms support file descriptors bigger than FD_SETSIZE in + * `select(2)` system call. + * + * - Linux 2.2.12 (?) + * + * - NetBSD 1.2 (src/sys/kern/sys_generic.c:1.25) + * `select(2)` documents how to allocate fd_set dynamically. + * http://netbsd.gw.com/cgi-bin/man-cgi?select++NetBSD-4.0 + * + * - FreeBSD 2.2 (src/sys/kern/sys_generic.c:1.19) + * + * - OpenBSD 2.0 (src/sys/kern/sys_generic.c:1.4) + * `select(2)` documents how to allocate fd_set dynamically. + * http://www.openbsd.org/cgi-bin/man.cgi?query=select&manpath=OpenBSD+4.4 + * + * - HP-UX documents how to allocate fd_set dynamically. + * http://docs.hp.com/en/B2355-60105/select.2.html + * + * - Solaris 8 has `select_large_fdset` + * + * - Mac OS X 10.7 (Lion) + * `select(2)` returns `EINVAL` if `nfds` is greater than `FD_SET_SIZE` and + * `_DARWIN_UNLIMITED_SELECT` (or `_DARWIN_C_SOURCE`) isn't defined. + * http://developer.apple.com/library/mac/#releasenotes/Darwin/SymbolVariantsRelNotes/_index.html + * + * When `fd_set` is not big enough to hold big file descriptors, it should be + * allocated dynamically. Note that this assumes `fd_set` is structured as + * bitmap. + * + * `rb_fd_init` allocates the memory. + * `rb_fd_term` frees the memory. + * `rb_fd_set` may re-allocate bitmap. + * + * So `rb_fd_set` doesn't reject file descriptors bigger than `FD_SETSIZE`. + */ +#include "ruby/impl/attr/nonnull.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/dllexport.h" + +/**@cond INTERNAL_MACRO */ +#define rb_fd_ptr rb_fd_ptr +#define rb_fd_max rb_fd_max +/** @endcond */ + +struct timeval; + +typedef struct { + int maxfd; + fd_set *fdset; +} rb_fdset_t; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +void rb_fd_init(rb_fdset_t *); +void rb_fd_term(rb_fdset_t *); +void rb_fd_zero(rb_fdset_t *); +void rb_fd_set(int, rb_fdset_t *); +void rb_fd_clr(int, rb_fdset_t *); +int rb_fd_isset(int, const rb_fdset_t *); +void rb_fd_copy(rb_fdset_t *, const fd_set *, int); +void rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src); +int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_NONNULL(()) +RBIMPL_ATTR_PURE() +/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */ +static inline fd_set * +rb_fd_ptr(const rb_fdset_t *f) +{ + return f->fdset; +} + +RBIMPL_ATTR_NONNULL(()) +RBIMPL_ATTR_PURE() +static inline int +rb_fd_max(const rb_fdset_t *f) +{ + return f->maxfd; +} + +#endif /* RBIMPL_INTERN_SELECT_LARGESIZE_H */ diff --git a/include/ruby/internal/intern/select/posix.h b/include/ruby/internal/intern/select/posix.h new file mode 100644 index 0000000000..a2ac51df92 --- /dev/null +++ b/include/ruby/internal/intern/select/posix.h @@ -0,0 +1,82 @@ +#ifndef RBIMPL_INTERN_SELECT_POSIX_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_SELECT_POSIX_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs to provide ::rb_fd_select(). + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_SYS_SELECT_H +# include /* for select(2) (modern POSIX) */ +#endif + +#ifdef HAVE_UNISTD_H +# include /* for select(2) (archaic UNIX) */ +#endif + +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/attr/const.h" + +typedef fd_set rb_fdset_t; + +#define rb_fd_zero FD_ZERO +#define rb_fd_set FD_SET +#define rb_fd_clr FD_CLR +#define rb_fd_isset FD_ISSET +#define rb_fd_init FD_ZERO +#define rb_fd_select select +/**@cond INTERNAL_MACRO */ +#define rb_fd_copy rb_fd_copy +#define rb_fd_dup rb_fd_dup +#define rb_fd_ptr rb_fd_ptr +#define rb_fd_max rb_fd_max +/** @endcond */ + +static inline void +rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int n) +{ + *dst = *src; +} + +static inline void +rb_fd_dup(rb_fdset_t *dst, const fd_set *src, int n) +{ + *dst = *src; +} + +RBIMPL_ATTR_PURE() +/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */ +static inline fd_set * +rb_fd_ptr(rb_fdset_t *f) +{ + return f; +} + +RBIMPL_ATTR_CONST() +static inline int +rb_fd_max(const rb_fdset_t *f) +{ + return FD_SETSIZE; +} + +/* :FIXME: What are these? They don't exist for shibling implementations. */ +#define rb_fd_init_copy(d, s) (*(d) = *(s)) +#define rb_fd_term(f) ((void)(f)) + +#endif /* RBIMPL_INTERN_SELECT_POSIX_H */ diff --git a/include/ruby/internal/intern/select/win32.h b/include/ruby/internal/intern/select/win32.h new file mode 100644 index 0000000000..0a1da61e63 --- /dev/null +++ b/include/ruby/internal/intern/select/win32.h @@ -0,0 +1,124 @@ +#ifndef RBIMPL_INTERN_SELECT_WIN32_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_SELECT_WIN32_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs to provide ::rb_fd_select(). + */ +#include "ruby/impl/dosish.h" /* for rb_w32_select */ +#include "ruby/impl/attr/nonnull.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/attr/noalias.h" +#include "ruby/impl/dllexport.h" +#include "ruby/assert.h" + +/**@cond INTERNAL_MACRO */ +#define rb_fd_zero rb_fd_zero +#define rb_fd_clr rb_fd_clr +#define rb_fd_isset rb_fd_isset +#define rb_fd_copy rb_fd_copy +#define rb_fd_dup rb_fd_dup +#define rb_fd_ptr rb_fd_ptr +#define rb_fd_max rb_fd_max +/** @endcond */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +struct timeval; + +typedef struct { + int capa; + fd_set *fdset; +} rb_fdset_t; + +void rb_fd_init(rb_fdset_t *); +void rb_fd_term(rb_fdset_t *); +void rb_fd_set(int, rb_fdset_t *); +void rb_w32_fd_copy(rb_fdset_t *, const fd_set *, int); +void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src); + +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_NONNULL(()) +RBIMPL_ATTR_NOALIAS() +static inline void +rb_fd_zero(rb_fdset_t *f) +{ + f->fdset->fd_count = 0; +} + +RBIMPL_ATTR_NONNULL(()) +static inline void +rb_fd_clr(int n, rb_fdset_t *f) +{ + rb_w32_fdclr(n, f->fdset); +} + +RBIMPL_ATTR_NONNULL(()) +static inline int +rb_fd_isset(int n, rb_fdset_t *f) +{ + return rb_w32_fdisset(n, f->fdset); +} + +RBIMPL_ATTR_NONNULL(()) +static inline void +rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int n) +{ + rb_w32_fd_copy(dst, src, n); +} + +RBIMPL_ATTR_NONNULL(()) +static inline void +rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src) +{ + rb_w32_fd_dup(dst, src); +} + +static inline int +rb_fd_select(int n, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout) +{ + return rb_w32_select( + n, + rfds ? rfds->fdset : NULL, + wfds ? wfds->fdset : NULL, + efds ? efds->fdset : NULL, + timeout); +} + +RBIMPL_ATTR_NONNULL(()) +RBIMPL_ATTR_PURE() +/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */ +static inline fd_set * +rb_fd_ptr(const rb_fdset_t *f) +{ + return f->fdset; +} + +RBIMPL_ATTR_NONNULL(()) +RBIMPL_ATTR_PURE() +static inline int +rb_fd_max(const rb_fdset_t *f) +{ + const fd_set *p = f->fdset; + + RBIMPL_ASSERT_OR_ASSUME(p); + return p->fd_count; +} + +#endif /* RBIMPL_INTERN_SELECT_WIN32_H */ diff --git a/include/ruby/internal/intern/signal.h b/include/ruby/internal/intern/signal.h new file mode 100644 index 0000000000..43ce470c2e --- /dev/null +++ b/include/ruby/internal/intern/signal.h @@ -0,0 +1,40 @@ +#ifndef RBIMPL_INTERN_SIGNAL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_SIGNAL_H +/** + * @file + * @author Ruby developers + * @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 Signal handling APIs. + */ +#include "ruby/impl/config.h" /* POSIX_SIGNAL / RETSIGTYPE */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* signal.c */ +VALUE rb_f_kill(int, const VALUE*); +#ifdef POSIX_SIGNAL +#define posix_signal ruby_posix_signal +RETSIGTYPE (*posix_signal(int, RETSIGTYPE (*)(int)))(int); +#endif +const char *ruby_signal_name(int); +void ruby_default_signal(int); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_SIGNAL_H */ diff --git a/include/ruby/internal/intern/sprintf.h b/include/ruby/internal/intern/sprintf.h new file mode 100644 index 0000000000..c2b1818cdf --- /dev/null +++ b/include/ruby/internal/intern/sprintf.h @@ -0,0 +1,43 @@ +#ifndef RBIMPL_INTERN_SPRINTF_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_SPRINTF_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Our own private printf(3). + */ +#include "ruby/impl/attr/format.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* sprintf.c */ +VALUE rb_f_sprintf(int, const VALUE*); + +RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2) +VALUE rb_sprintf(const char*, ...); +VALUE rb_vsprintf(const char*, va_list); + +RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3) +VALUE rb_str_catf(VALUE, const char*, ...); +VALUE rb_str_vcatf(VALUE, const char*, va_list); +VALUE rb_str_format(int, const VALUE *, VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_SPRINTF_H */ diff --git a/include/ruby/internal/intern/string.h b/include/ruby/internal/intern/string.h new file mode 100644 index 0000000000..ba4107c79f --- /dev/null +++ b/include/ruby/internal/intern/string.h @@ -0,0 +1,326 @@ +#ifndef RBIMPL_INTERN_STRING_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_STRING_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cString. + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include +#endif + +#ifdef HAVE_STRING_H +# include +#endif + +#ifdef HAVE_STDINT_H +# include +#endif + +#include "ruby/impl/attr/nonnull.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/constant_p.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/variable.h" /* rb_gvar_setter_t */ +#include "ruby/st.h" /* st_index_t */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* string.c */ +VALUE rb_str_new(const char*, long); +VALUE rb_str_new_cstr(const char*); +VALUE rb_str_new_shared(VALUE); +VALUE rb_str_new_frozen(VALUE); +VALUE rb_str_new_with_class(VALUE, const char*, long); +VALUE rb_tainted_str_new_cstr(const char*); +VALUE rb_tainted_str_new(const char*, long); +VALUE rb_external_str_new(const char*, long); +VALUE rb_external_str_new_cstr(const char*); +VALUE rb_locale_str_new(const char*, long); +VALUE rb_locale_str_new_cstr(const char*); +VALUE rb_filesystem_str_new(const char*, long); +VALUE rb_filesystem_str_new_cstr(const char*); +VALUE rb_str_buf_new(long); +VALUE rb_str_buf_new_cstr(const char*); +VALUE rb_str_buf_new2(const char*); +VALUE rb_str_tmp_new(long); +VALUE rb_usascii_str_new(const char*, long); +VALUE rb_usascii_str_new_cstr(const char*); +VALUE rb_utf8_str_new(const char*, long); +VALUE rb_utf8_str_new_cstr(const char*); +VALUE rb_str_new_static(const char *, long); +VALUE rb_usascii_str_new_static(const char *, long); +VALUE rb_utf8_str_new_static(const char *, long); +void rb_str_free(VALUE); +void rb_str_shared_replace(VALUE, VALUE); +VALUE rb_str_buf_append(VALUE, VALUE); +VALUE rb_str_buf_cat(VALUE, const char*, long); +VALUE rb_str_buf_cat2(VALUE, const char*); +VALUE rb_str_buf_cat_ascii(VALUE, const char*); +VALUE rb_obj_as_string(VALUE); +VALUE rb_check_string_type(VALUE); +void rb_must_asciicompat(VALUE); +VALUE rb_str_dup(VALUE); +VALUE rb_str_resurrect(VALUE str); +VALUE rb_str_locktmp(VALUE); +VALUE rb_str_unlocktmp(VALUE); +VALUE rb_str_dup_frozen(VALUE); +#define rb_str_dup_frozen rb_str_new_frozen +VALUE rb_str_plus(VALUE, VALUE); +VALUE rb_str_times(VALUE, VALUE); +long rb_str_sublen(VALUE, long); +VALUE rb_str_substr(VALUE, long, long); +VALUE rb_str_subseq(VALUE, long, long); +char *rb_str_subpos(VALUE, long, long*); +void rb_str_modify(VALUE); +void rb_str_modify_expand(VALUE, long); +VALUE rb_str_freeze(VALUE); +void rb_str_set_len(VALUE, long); +VALUE rb_str_resize(VALUE, long); +VALUE rb_str_cat(VALUE, const char*, long); +VALUE rb_str_cat_cstr(VALUE, const char*); +VALUE rb_str_cat2(VALUE, const char*); +VALUE rb_str_append(VALUE, VALUE); +VALUE rb_str_concat(VALUE, VALUE); +st_index_t rb_memhash(const void *ptr, long len); +st_index_t rb_hash_start(st_index_t); +st_index_t rb_hash_uint32(st_index_t, uint32_t); +st_index_t rb_hash_uint(st_index_t, st_index_t); +st_index_t rb_hash_end(st_index_t); +#define rb_hash_uint32(h, i) st_hash_uint32((h), (i)) +#define rb_hash_uint(h, i) st_hash_uint((h), (i)) +#define rb_hash_end(h) st_hash_end(h) +st_index_t rb_str_hash(VALUE); +int rb_str_hash_cmp(VALUE,VALUE); +int rb_str_comparable(VALUE, VALUE); +int rb_str_cmp(VALUE, VALUE); +VALUE rb_str_equal(VALUE str1, VALUE str2); +VALUE rb_str_drop_bytes(VALUE, long); +void rb_str_update(VALUE, long, long, VALUE); +VALUE rb_str_replace(VALUE, VALUE); +VALUE rb_str_inspect(VALUE); +VALUE rb_str_dump(VALUE); +VALUE rb_str_split(VALUE, const char*); +rb_gvar_setter_t rb_str_setter; +VALUE rb_str_intern(VALUE); +VALUE rb_sym_to_s(VALUE); +long rb_str_strlen(VALUE); +VALUE rb_str_length(VALUE); +long rb_str_offset(VALUE, long); +RBIMPL_ATTR_PURE() +size_t rb_str_capacity(VALUE); +VALUE rb_str_ellipsize(VALUE, long); +VALUE rb_str_scrub(VALUE, VALUE); +VALUE rb_str_succ(VALUE); + +RBIMPL_ATTR_NONNULL(()) +static inline long +rbimpl_strlen(const char *str) +{ + return RBIMPL_CAST((long)strlen(str)); +} + +static inline VALUE +rbimpl_str_new(const char *str, long len) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_str_new(str, len); + } + else if /* constexpr */ (! RBIMPL_CONSTANT_P(len)) { + return rb_str_new(str, len); + } + else { + return rb_str_new_static(str, len); + } +} + +static inline VALUE +rbimpl_str_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_str_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + return rb_str_new_static(str, len); + } +} + +static inline VALUE +rbimpl_usascii_str_new(const char *str, long len) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_usascii_str_new(str, len); + } + else if /* constexpr */ (! RBIMPL_CONSTANT_P(len)) { + return rb_usascii_str_new(str, len); + } + else { + return rb_usascii_str_new_static(str, len); + } +} + +static inline VALUE +rbimpl_utf8_str_new(const char *str, long len) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_utf8_str_new(str, len); + } + else if /* constexpr */ (! RBIMPL_CONSTANT_P(len)) { + return rb_utf8_str_new(str, len); + } + else { + return rb_utf8_str_new_static(str, len); + } +} + +static inline VALUE +rbimpl_tainted_str_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_tainted_str_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + return rb_tainted_str_new(str, len); + } +} + +static inline VALUE +rbimpl_usascii_str_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_usascii_str_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + return rb_usascii_str_new_static(str, len); + } +} + +static inline VALUE +rbimpl_utf8_str_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_utf8_str_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + return rb_utf8_str_new_static(str, len); + } +} + +static inline VALUE +rbimpl_external_str_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_external_str_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + return rb_external_str_new(str, len); + } +} + +static inline VALUE +rbimpl_locale_str_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_locale_str_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + return rb_locale_str_new(str, len); + } +} + +static inline VALUE +rbimpl_str_buf_new_cstr(const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_str_buf_new_cstr(str); + } + else { + long len = rbimpl_strlen(str); + VALUE buf = rb_str_buf_new(len); + return rb_str_buf_cat(buf, str, len); + } +} + +static inline VALUE +rbimpl_str_cat_cstr(VALUE buf, const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_str_cat_cstr(buf, str); + } + else { + long len = rbimpl_strlen(str); + return rb_str_cat(buf, str, len); + } +} + +static inline VALUE +rbimpl_exc_new_cstr(VALUE exc, const char *str) +{ + if /* constexpr */ (! RBIMPL_CONSTANT_P(str)) { + return rb_exc_new_cstr(exc, str); + } + else { + long len = rbimpl_strlen(str); + return rb_exc_new(exc, str, len); + } +} + +#define rb_str_new rbimpl_str_new +#define rb_str_new_cstr rbimpl_str_new_cstr +#define rb_usascii_str_new rbimpl_usascii_str_new +#define rb_utf8_str_new rbimpl_utf8_str_new +#define rb_tainted_str_new_cstr rbimpl_tainted_str_new_cstr +#define rb_usascii_str_new_cstr rbimpl_usascii_str_new_cstr +#define rb_utf8_str_new_cstr rbimpl_utf8_str_new_cstr +#define rb_external_str_new_cstr rbimpl_external_str_new_cstr +#define rb_locale_str_new_cstr rbimpl_locale_str_new_cstr +#define rb_str_buf_new_cstr rbimpl_str_buf_new_cstr +#define rb_str_cat_cstr rbimpl_str_cat_cstr +#define rb_exc_new_cstr rbimpl_exc_new_cstr +#define rb_str_new2 rb_str_new_cstr +#define rb_str_new3 rb_str_new_shared +#define rb_str_new4 rb_str_new_frozen +#define rb_str_new5 rb_str_new_with_class +#define rb_tainted_str_new2 rb_tainted_str_new_cstr +#define rb_str_buf_new2 rb_str_buf_new_cstr +#define rb_usascii_str_new2 rb_usascii_str_new_cstr +#define rb_str_buf_cat rb_str_cat +#define rb_str_buf_cat2 rb_str_cat_cstr +#define rb_str_cat2 rb_str_cat_cstr +#define rb_strlen_lit(str) (sizeof(str "") - 1) +#define rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str)) +#define rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str)) +#define rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str)) +#define rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc)) +#define rb_str_new_literal(str) rb_str_new_lit(str) +#define rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str) +#define rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str) +#define rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc) + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_STRING_H */ diff --git a/include/ruby/internal/intern/struct.h b/include/ruby/internal/intern/struct.h new file mode 100644 index 0000000000..18d1058d9f --- /dev/null +++ b/include/ruby/internal/intern/struct.h @@ -0,0 +1,47 @@ +#ifndef RBIMPL_INTERN_STRUCT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_STRUCT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cStruct. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/intern/vm.h" /* rb_alloc_func_t */ +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* struct.c */ +VALUE rb_struct_new(VALUE, ...); +VALUE rb_struct_define(const char*, ...); +VALUE rb_struct_define_under(VALUE, const char*, ...); +VALUE rb_struct_alloc(VALUE, VALUE); +VALUE rb_struct_initialize(VALUE, VALUE); +VALUE rb_struct_aref(VALUE, VALUE); +VALUE rb_struct_aset(VALUE, VALUE, VALUE); +VALUE rb_struct_getmember(VALUE, ID); +VALUE rb_struct_s_members(VALUE); +VALUE rb_struct_members(VALUE); +VALUE rb_struct_size(VALUE s); +VALUE rb_struct_alloc_noinit(VALUE); +VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...); +VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, ...); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_STRUCT_H */ diff --git a/include/ruby/internal/intern/thread.h b/include/ruby/internal/intern/thread.h new file mode 100644 index 0000000000..38784fcca3 --- /dev/null +++ b/include/ruby/internal/intern/thread.h @@ -0,0 +1,76 @@ +#ifndef RBIMPL_INTERN_THREAD_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_THREAD_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cThread. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +struct timeval; + +/* thread.c */ +void rb_thread_schedule(void); +void rb_thread_wait_fd(int); +int rb_thread_fd_writable(int); +void rb_thread_fd_close(int); +int rb_thread_alone(void); +void rb_thread_sleep(int); +void rb_thread_sleep_forever(void); +void rb_thread_sleep_deadly(void); +VALUE rb_thread_stop(void); +VALUE rb_thread_wakeup(VALUE); +VALUE rb_thread_wakeup_alive(VALUE); +VALUE rb_thread_run(VALUE); +VALUE rb_thread_kill(VALUE); +VALUE rb_thread_create(VALUE (*)(void *), void*); +void rb_thread_wait_for(struct timeval); +VALUE rb_thread_current(void); +VALUE rb_thread_main(void); +VALUE rb_thread_local_aref(VALUE, ID); +VALUE rb_thread_local_aset(VALUE, ID, VALUE); +void rb_thread_atfork(void); +void rb_thread_atfork_before_exec(void); +VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); +VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE); +VALUE rb_exec_recursive_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); +VALUE rb_exec_recursive_paired_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE); + +typedef void rb_unblock_function_t(void *); +typedef VALUE rb_blocking_function_t(void *); +void rb_thread_check_ints(void); +int rb_thread_interrupted(VALUE thval); + +#define RUBY_UBF_IO RBIMPL_CAST((rb_unblock_function_t *)-1) +#define RUBY_UBF_PROCESS RBIMPL_CAST((rb_unblock_function_t *)-1) +VALUE rb_mutex_new(void); +VALUE rb_mutex_locked_p(VALUE mutex); +VALUE rb_mutex_trylock(VALUE mutex); +VALUE rb_mutex_lock(VALUE mutex); +VALUE rb_mutex_unlock(VALUE mutex); +VALUE rb_mutex_sleep(VALUE self, VALUE timeout); +VALUE rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_THREAD_H */ diff --git a/include/ruby/internal/intern/time.h b/include/ruby/internal/intern/time.h new file mode 100644 index 0000000000..b49802ccf4 --- /dev/null +++ b/include/ruby/internal/intern/time.h @@ -0,0 +1,52 @@ +#ifndef RBIMPL_INTERN_TIME_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_TIME_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cTime. + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_TIME_H +# include /* for time_t */ +#endif + +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +struct timespec; +struct timeval; + +/* time.c */ +void rb_timespec_now(struct timespec *); +VALUE rb_time_new(time_t, long); +VALUE rb_time_nano_new(time_t, long); +VALUE rb_time_timespec_new(const struct timespec *, int); +VALUE rb_time_num_new(VALUE, VALUE); +struct timeval rb_time_interval(VALUE num); +struct timeval rb_time_timeval(VALUE time); +struct timespec rb_time_timespec(VALUE time); +struct timespec rb_time_timespec_interval(VALUE num); +VALUE rb_time_utc_offset(VALUE time); +VALUE rb_time_succ(VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_TIME_H */ diff --git a/include/ruby/internal/intern/variable.h b/include/ruby/internal/intern/variable.h new file mode 100644 index 0000000000..d8de93a8d6 --- /dev/null +++ b/include/ruby/internal/intern/variable.h @@ -0,0 +1,83 @@ +#ifndef RBIMPL_INTERN_VARIABLE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_VARIABLE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to names inside of a Ruby program. + */ +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/st.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* variable.c */ +VALUE rb_mod_name(VALUE); +VALUE rb_class_path(VALUE); +VALUE rb_class_path_cached(VALUE); +void rb_set_class_path(VALUE, VALUE, const char*); +void rb_set_class_path_string(VALUE, VALUE, VALUE); +VALUE rb_path_to_class(VALUE); +VALUE rb_path2class(const char*); +VALUE rb_class_name(VALUE); +VALUE rb_autoload_load(VALUE, ID); +VALUE rb_autoload_p(VALUE, ID); +VALUE rb_f_trace_var(int, const VALUE*); +VALUE rb_f_untrace_var(int, const VALUE*); +VALUE rb_f_global_variables(void); +void rb_alias_variable(ID, ID); +void rb_copy_generic_ivar(VALUE,VALUE); +void rb_free_generic_ivar(VALUE); +VALUE rb_ivar_get(VALUE, ID); +VALUE rb_ivar_set(VALUE, ID, VALUE); +VALUE rb_ivar_defined(VALUE, ID); +void rb_ivar_foreach(VALUE, int (*)(ID, VALUE, st_data_t), st_data_t); +st_index_t rb_ivar_count(VALUE); +VALUE rb_attr_get(VALUE, ID); +VALUE rb_obj_instance_variables(VALUE); +VALUE rb_obj_remove_instance_variable(VALUE, VALUE); +void *rb_mod_const_at(VALUE, void*); +void *rb_mod_const_of(VALUE, void*); +VALUE rb_const_list(void*); +VALUE rb_mod_constants(int, const VALUE *, VALUE); +VALUE rb_mod_remove_const(VALUE, VALUE); +int rb_const_defined(VALUE, ID); +int rb_const_defined_at(VALUE, ID); +int rb_const_defined_from(VALUE, ID); +VALUE rb_const_get(VALUE, ID); +VALUE rb_const_get_at(VALUE, ID); +VALUE rb_const_get_from(VALUE, ID); +void rb_const_set(VALUE, ID, VALUE); +VALUE rb_const_remove(VALUE, ID); +#if 0 /* EXPERIMENTAL: remove if no problem */ +RBIMPL_ATTR_NORETURN() +VALUE rb_mod_const_missing(VALUE,VALUE); +#endif +VALUE rb_cvar_defined(VALUE, ID); +void rb_cvar_set(VALUE, ID, VALUE); +VALUE rb_cvar_get(VALUE, ID); +void rb_cv_set(VALUE, const char*, VALUE); +VALUE rb_cv_get(VALUE, const char*); +void rb_define_class_variable(VALUE, const char*, VALUE); +VALUE rb_mod_class_variables(int, const VALUE*, VALUE); +VALUE rb_mod_remove_cvar(VALUE, VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_VARIABLE_H */ diff --git a/include/ruby/internal/intern/vm.h b/include/ruby/internal/intern/vm.h new file mode 100644 index 0000000000..1fc8423dde --- /dev/null +++ b/include/ruby/internal/intern/vm.h @@ -0,0 +1,77 @@ +#ifndef RBIMPL_INTERN_VM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERN_VM_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Public APIs related to ::rb_cRubyVM. + */ +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/* vm.c */ +int rb_sourceline(void); +const char *rb_sourcefile(void); +int rb_frame_method_id_and_class(ID *idp, VALUE *klassp); + +/* vm_eval.c */ +VALUE rb_check_funcall(VALUE, ID, int, const VALUE*); +VALUE rb_check_funcall_kw(VALUE, ID, int, const VALUE*, int); +void rb_remove_method(VALUE, const char*); +void rb_remove_method_id(VALUE, ID); + +VALUE rb_eval_cmd_kw(VALUE, VALUE, int); +VALUE rb_apply(VALUE, ID, VALUE); + +VALUE rb_obj_instance_eval(int, const VALUE*, VALUE); +VALUE rb_obj_instance_exec(int, const VALUE*, VALUE); +VALUE rb_mod_module_eval(int, const VALUE*, VALUE); +VALUE rb_mod_module_exec(int, const VALUE*, VALUE); + +/* vm_method.c */ +#define HAVE_RB_DEFINE_ALLOC_FUNC 1 +typedef VALUE (*rb_alloc_func_t)(VALUE); +void rb_define_alloc_func(VALUE, rb_alloc_func_t); +void rb_undef_alloc_func(VALUE); +rb_alloc_func_t rb_get_alloc_func(VALUE); +void rb_clear_constant_cache(void); +void rb_clear_method_cache_by_class(VALUE); +void rb_alias(VALUE, ID, ID); +void rb_attr(VALUE,ID,int,int,int); +int rb_method_boundp(VALUE, ID, int); +int rb_method_basic_definition_p(VALUE, ID); + +int rb_obj_respond_to(VALUE, ID, int); +int rb_respond_to(VALUE, ID); + +RBIMPL_ATTR_NORETURN() +VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker); +#if !defined(RUBY_EXPORT) && defined(_WIN32) +RUBY_EXTERN VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE, VALUE marker); +#define rb_f_notimplement (*rb_f_notimplement_) +#endif + +/* vm_backtrace.c */ +void rb_backtrace(void); +VALUE rb_make_backtrace(void); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERN_VM_H */ diff --git a/include/ruby/internal/interpreter.h b/include/ruby/internal/interpreter.h new file mode 100644 index 0000000000..23b70b2926 --- /dev/null +++ b/include/ruby/internal/interpreter.h @@ -0,0 +1,94 @@ +#ifndef RBIMPL_INTERPRETER_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_INTERPRETER_H +/** + * @file + * @author Ruby developers + * @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 Interpreter embedding APIs. + */ +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +/** + * @defgroup embed CRuby Embedding APIs + * CRuby interpreter APIs. These are APIs to embed MRI interpreter into your + * program. + * These functions are not a part of Ruby extension library API. + * Extension libraries of Ruby should not depend on these functions. + * @{ + */ + +/** @defgroup ruby1 ruby(1) implementation + * A part of the implementation of ruby(1) command. + * Other programs that embed Ruby interpreter do not always need to use these + * functions. + * @{ + */ + +void ruby_sysinit(int *argc, char ***argv); +void ruby_init(void); +void* ruby_options(int argc, char** argv); +int ruby_executable_node(void *n, int *status); +int ruby_run_node(void *n); + +/* version.c */ +void ruby_show_version(void); +#ifndef ruby_show_copyright +void ruby_show_copyright(void); +#endif + +/*! A convenience macro to call ruby_init_stack(). Must be placed just after + * variable declarations */ +#define RUBY_INIT_STACK \ + VALUE variable_in_this_stack_frame; \ + ruby_init_stack(&variable_in_this_stack_frame); +/*! @} */ + +void ruby_init_stack(volatile VALUE*); + +int ruby_setup(void); +int ruby_cleanup(volatile int); + +void ruby_finalize(void); + +RBIMPL_ATTR_NORETURN() +void ruby_stop(int); + +void ruby_set_stack_size(size_t); +int ruby_stack_check(void); +size_t ruby_stack_length(VALUE**); + +int ruby_exec_node(void *n); + +void ruby_script(const char* name); +void ruby_set_script_name(VALUE name); + +void ruby_prog_init(void); +void ruby_set_argv(int, char**); +void *ruby_process_options(int, char**); +void ruby_init_loadpath(void); +void ruby_incpush(const char*); +void ruby_sig_finalize(void); + +/*! @} */ + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_INTERPRETER_H */ diff --git a/include/ruby/internal/iterator.h b/include/ruby/internal/iterator.h new file mode 100644 index 0000000000..980c6ebf7f --- /dev/null +++ b/include/ruby/internal/iterator.h @@ -0,0 +1,65 @@ +#ifndef RBIMPL_ITERATOR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_ITERATOR_H +/** + * @file + * @author Ruby developers + * @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 Block related APIs. + */ +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +#define RB_BLOCK_CALL_FUNC_STRICT 1 +#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1 +#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) \ + VALUE yielded_arg, VALUE callback_arg, int argc, const VALUE *argv, VALUE blockarg +typedef VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); +typedef rb_block_call_func *rb_block_call_func_t; + +VALUE rb_each(VALUE); +VALUE rb_yield(VALUE); +VALUE rb_yield_values(int n, ...); +VALUE rb_yield_values2(int n, const VALUE *argv); +VALUE rb_yield_values_kw(int n, const VALUE *argv, int kw_splat); +VALUE rb_yield_splat(VALUE); +VALUE rb_yield_splat_kw(VALUE, int); +VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); /* rb_block_call_func */ +int rb_keyword_given_p(void); +int rb_block_given_p(void); +void rb_need_block(void); +VALUE rb_iterate(VALUE(*)(VALUE),VALUE,rb_block_call_func_t,VALUE); +VALUE rb_block_call(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE); +VALUE rb_block_call_kw(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE,int); +VALUE rb_rescue(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE); +VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...); +VALUE rb_vrescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,va_list); +VALUE rb_ensure(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE),VALUE); +VALUE rb_catch(const char*,rb_block_call_func_t,VALUE); +VALUE rb_catch_obj(VALUE,rb_block_call_func_t,VALUE); + +RBIMPL_ATTR_NORETURN() +void rb_throw(const char*,VALUE); + +RBIMPL_ATTR_NORETURN() +void rb_throw_obj(VALUE,VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_ITERATOR_H */ diff --git a/include/ruby/internal/memory.h b/include/ruby/internal/memory.h new file mode 100644 index 0000000000..8525cff96c --- /dev/null +++ b/include/ruby/internal/memory.h @@ -0,0 +1,286 @@ +#ifndef RBIMPL_MEMORY_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_MEMORY_H +/** + * @file + * @author Ruby developers + * @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 Memory management stuff. + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include +#endif + +#ifdef HAVE_STRING_H +# include +#endif + +#ifdef HAVE_STDINT_H +# include +#endif + +#ifdef HAVE_ALLOCA_H +# include +#endif + +#if defined(_MSC_VER) && defined(_WIN64) +# include +# pragma intrinsic(_umul128) +#endif + +#include "ruby/impl/attr/alloc_size.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/attr/noalias.h" +#include "ruby/impl/attr/nonnull.h" +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/attr/restrict.h" +#include "ruby/impl/attr/returns_nonnull.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/has/builtin.h" +#include "ruby/impl/stdalign.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/xmalloc.h" +#include "ruby/backward/2/limits.h" +#include "ruby/backward/2/long_long.h" +#include "ruby/backward/2/assume.h" +#include "ruby/defines.h" + +/* Make alloca work the best possible way. */ +#if defined(alloca) +# /* Take that. */ +#elif RBIMPL_HAS_BUILTIN(__builtin_alloca) +# define alloca __builtin_alloca +#elif defined(_AIX) +# pragma alloca +#elif defined(__cplusplus) +extern "C" void *alloca(size_t); +#else +extern void *alloca(); +#endif + +#if defined(HAVE_INT128_T) && SIZEOF_SIZE_T <= 8 +# define DSIZE_T uint128_t +#elif SIZEOF_SIZE_T * 2 <= SIZEOF_LONG_LONG +# define DSIZE_T unsigned LONG_LONG +#endif + +#ifdef C_ALLOCA +# define RUBY_ALLOCV_LIMIT 0 +#else +# define RUBY_ALLOCV_LIMIT 1024 +#endif + +#ifdef __GNUC__ +#define RB_GC_GUARD(v) \ + (*__extension__ ({ \ + volatile VALUE *rb_gc_guarded_ptr = &(v); \ + __asm__("" : : "m"(rb_gc_guarded_ptr)); \ + rb_gc_guarded_ptr; \ + })) +#elif defined _MSC_VER +#define RB_GC_GUARD(v) (*rb_gc_guarded_ptr(&(v))) +#else +#define HAVE_RB_GC_GUARDED_PTR_VAL 1 +#define RB_GC_GUARD(v) (*rb_gc_guarded_ptr_val(&(v),(v))) +#endif + +/* Casts needed because void* is NOT compaible with others in C++. */ +#define RB_ALLOC_N(type,n) RBIMPL_CAST((type *)ruby_xmalloc2((n), sizeof(type))) +#define RB_ALLOC(type) RBIMPL_CAST((type *)ruby_xmalloc(sizeof(type))) +#define RB_ZALLOC_N(type,n) RBIMPL_CAST((type *)ruby_xcalloc((n), sizeof(type))) +#define RB_ZALLOC(type) (RB_ZALLOC_N(type, 1)) +#define RB_REALLOC_N(var,type,n) \ + ((var) = RBIMPL_CAST((type *)ruby_xrealloc2((void *)(var), (n), sizeof(type)))) + +/* I don't know why but __builtin_alloca_with_align's second argument + takes bits rather than bytes. */ +#if RBIMPL_HAS_BUILTIN(__builtin_alloca_with_align) +# define ALLOCA_N(type, n) \ + RBIMPL_CAST((type *) \ + __builtin_alloca_with_align( \ + rbimpl_size_mul_or_raise(sizeof(type), (n)), \ + RUBY_ALIGNOF(type) * CHAR_BIT)) +#else +# define ALLOCA_N(type,n) \ + RBIMPL_CAST((type *)alloca(rbimpl_size_mul_or_raise(sizeof(type), (n)))) +#endif + +/* allocates _n_ bytes temporary buffer and stores VALUE including it + * in _v_. _n_ may be evaluated twice. */ +#define RB_ALLOCV(v, n) \ + ((n) < RUBY_ALLOCV_LIMIT ? \ + ((v) = 0, alloca(n)) : \ + rb_alloc_tmp_buffer(&(v), (n))) +#define RB_ALLOCV_N(type, v, n) \ + RBIMPL_CAST((type *) \ + (((size_t)(n) < RUBY_ALLOCV_LIMIT / sizeof(type)) ? \ + ((v) = 0, alloca((n) * sizeof(type))) : \ + rb_alloc_tmp_buffer2(&(v), (n), sizeof(type)))) +#define RB_ALLOCV_END(v) rb_free_tmp_buffer(&(v)) + +#define MEMZERO(p,type,n) memset((p), 0, rbimpl_size_mul_or_raise(sizeof(type), (n))) +#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) +#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) +#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) + +#define ALLOC_N RB_ALLOC_N +#define ALLOC RB_ALLOC +#define ZALLOC_N RB_ZALLOC_N +#define ZALLOC RB_ZALLOC +#define REALLOC_N RB_REALLOC_N +#define ALLOCV RB_ALLOCV +#define ALLOCV_N RB_ALLOCV_N +#define ALLOCV_END RB_ALLOCV_END + +/* Expecting this struct to be eliminated by function inlinings */ +struct rbimpl_size_mul_overflow_tag { + bool left; + size_t right; +}; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((2)) +void *rb_alloc_tmp_buffer(volatile VALUE *store, long len); + +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((2,3)) +void *rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t len,size_t count); + +void rb_free_tmp_buffer(volatile VALUE *store); + +RBIMPL_ATTR_NORETURN() +void ruby_malloc_size_overflow(size_t, size_t); + +#ifdef HAVE_RB_GC_GUARDED_PTR_VAL +volatile VALUE *rb_gc_guarded_ptr_val(volatile VALUE *ptr, VALUE val); +#endif +RBIMPL_SYMBOL_EXPORT_END() + +#ifdef _MSC_VER +# pragma optimize("", off) + +static inline volatile VALUE * +rb_gc_guarded_ptr(volatile VALUE *ptr) +{ + return ptr; +} + +# pragma optimize("", on) +#endif + +/* Does anyone use it? Just here for backwards compatibility. */ +static inline int +rb_mul_size_overflow(size_t a, size_t b, size_t max, size_t *c) +{ +#ifdef DSIZE_T + RB_GNUC_EXTENSION DSIZE_T da, db, c2; + da = a; + db = b; + c2 = da * db; + if (c2 > max) return 1; + *c = RBIMPL_CAST((size_t)c2); +#else + if (b != 0 && a > max / b) return 1; + *c = a * b; +#endif + return 0; +} + +#if RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0) +RBIMPL_ATTR_CONSTEXPR(CXX14) /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70507 */ +#elif RBIMPL_COMPILER_SINCE(Clang, 7, 0, 0) +RBIMPL_ATTR_CONSTEXPR(CXX14) /* https://bugs.llvm.org/show_bug.cgi?id=37633 */ +#endif +RBIMPL_ATTR_CONST() +static inline struct rbimpl_size_mul_overflow_tag +rbimpl_size_mul_overflow(size_t x, size_t y) +{ + struct rbimpl_size_mul_overflow_tag ret = { false, 0, }; + +#if RBIMPL_HAS_BUILTIN(__builtin_mul_overflow) + ret.left = __builtin_mul_overflow(x, y, &ret.right); + +#elif defined(DSIZE_T) + RB_GNUC_EXTENSION DSIZE_T dx = x; + RB_GNUC_EXTENSION DSIZE_T dy = y; + RB_GNUC_EXTENSION DSIZE_T dz = dx * dy; + ret.left = dz > SIZE_MAX; + ret.right = RBIMPL_CAST((size_t)dz); + +#elif defined(_MSC_VER) && defined(_WIN64) + unsigned __int64 dp = 0; + unsigned __int64 dz = _umul128(x, y, &dp); + ret.left = RBIMPL_CAST((bool)dp); + ret.right = RBIMPL_CAST((size_t)dz); + +#else + /* https://wiki.sei.cmu.edu/confluence/display/c/INT30-C.+Ensure+that+unsigned+integer+operations+do+not+wrap */ + ret.left = (y != 0) && (x > SIZE_MAX / y); + ret.right = x * y; +#endif + + return ret; +} + +static inline size_t +rbimpl_size_mul_or_raise(size_t x, size_t y) +{ + struct rbimpl_size_mul_overflow_tag size = + rbimpl_size_mul_overflow(x, y); + + if (RB_LIKELY(! size.left)) { + return size.right; + } + else { + ruby_malloc_size_overflow(x, y); + RBIMPL_UNREACHABLE_RETURN(0); + } +} + +static inline void * +rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize) +{ + return rb_alloc_tmp_buffer_with_count( + store, rbimpl_size_mul_or_raise(count, elsize), count); +} + +RBIMPL_ATTR_NOALIAS() +RBIMPL_ATTR_NONNULL((1)) +RBIMPL_ATTR_RETURNS_NONNULL() +/* At least since 2004, glibc's annotates memcpy to be + * __attribute__((__nonnull__(1, 2))). However it is safe to pass NULL to the + * source pointer, if n is 0. Let's wrap memcpy. */ +static inline void * +ruby_nonempty_memcpy(void *dest, const void *src, size_t n) +{ + if (n) { + return memcpy(dest, src, n); + } + else { + return dest; + } +} +#undef memcpy +#define memcpy ruby_nonempty_memcpy + +#endif /* RBIMPL_MEMORY_H */ diff --git a/include/ruby/internal/method.h b/include/ruby/internal/method.h new file mode 100644 index 0000000000..fd2d9af070 --- /dev/null +++ b/include/ruby/internal/method.h @@ -0,0 +1,39 @@ +#ifndef RBIMPL_METHOD_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_METHOD_H +/** + * @file + * @author Ruby developers + * @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 Creation and modification of Ruby methods. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/backward/2/stdarg.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int); +void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int); +void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int); + +void rb_undef_method(VALUE,const char*); +void rb_define_alias(VALUE,const char*,const char*); +void rb_define_attr(VALUE,const char*,int,int); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_METHOD_H */ diff --git a/include/ruby/internal/module.h b/include/ruby/internal/module.h new file mode 100644 index 0000000000..8dc1988b5b --- /dev/null +++ b/include/ruby/internal/module.h @@ -0,0 +1,39 @@ +#ifndef RBIMPL_MODULE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_MODULE_H +/** + * @file + * @author Ruby developers + * @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 Creation and modification of Ruby modules. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +VALUE rb_define_class(const char*,VALUE); +VALUE rb_define_module(const char*); +VALUE rb_define_class_under(VALUE, const char*, VALUE); +VALUE rb_define_module_under(VALUE, const char*); + +void rb_include_module(VALUE,VALUE); +void rb_extend_object(VALUE,VALUE); +void rb_prepend_module(VALUE,VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_MODULE_H */ diff --git a/include/ruby/internal/newobj.h b/include/ruby/internal/newobj.h new file mode 100644 index 0000000000..0f7e9ba06c --- /dev/null +++ b/include/ruby/internal/newobj.h @@ -0,0 +1,73 @@ +#ifndef RBIMPL_NEWOBJ_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_NEWOBJ_H +/** + * @file + * @author Ruby developers + * @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 #NEWOBJ. + */ +#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/special_consts.h" +#include "ruby/impl/value.h" +#include "ruby/assert.h" + +#define RB_NEWOBJ(obj,type) type *(obj) = RBIMPL_CAST((type *)rb_newobj()) +#define RB_NEWOBJ_OF(obj,type,klass,flags) type *(obj) = RBIMPL_CAST((type *)rb_newobj_of(klass, flags)) + +#define NEWOBJ RB_NEWOBJ +#define NEWOBJ_OF RB_NEWOBJ_OF /* core has special NEWOBJ_OF() in internal.h */ +#define OBJSETUP rb_obj_setup /* use NEWOBJ_OF instead of NEWOBJ()+OBJSETUP() */ +#define CLONESETUP rb_clone_setup +#define DUPSETUP rb_dup_setup + +RBIMPL_SYMBOL_EXPORT_BEGIN() +VALUE rb_newobj(void); +VALUE rb_newobj_of(VALUE, VALUE); +VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type); +VALUE rb_obj_class(VALUE); +VALUE rb_singleton_class_clone(VALUE); +void rb_singleton_class_attached(VALUE,VALUE); +void rb_copy_generic_ivar(VALUE,VALUE); +RBIMPL_SYMBOL_EXPORT_END() + +static inline void +rb_clone_setup(VALUE clone, VALUE obj) +{ + RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); + RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(clone)); + + const VALUE flags = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1 | RUBY_FL_FINALIZE; + rb_obj_setup(clone, rb_singleton_class_clone(obj), + RB_FL_TEST_RAW(obj, ~flags)); + rb_singleton_class_attached(RBASIC_CLASS(clone), clone); + if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(clone, obj); +} + +static inline void +rb_dup_setup(VALUE dup, VALUE obj) +{ + RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); + RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(dup)); + + rb_obj_setup(dup, rb_obj_class(obj), RB_FL_TEST_RAW(obj, RUBY_FL_DUPPED)); + if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(dup, obj); +} + +#endif /* RBIMPL_NEWOBJ_H */ diff --git a/include/ruby/internal/rgengc.h b/include/ruby/internal/rgengc.h new file mode 100644 index 0000000000..34096455fb --- /dev/null +++ b/include/ruby/internal/rgengc.h @@ -0,0 +1,199 @@ +#ifndef RBIMPL_RGENGC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_RGENGC_H +/** + * @file + * @author Ruby developers + * @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 RGENGC write-barrier APIs. + * @see Sasada, K., "Gradual write-barrier insertion into a Ruby + * interpreter", in proceedings of the 2019 ACM SIGPLAN + * International Symposium on Memory Management (ISMM 2019), pp + * 115-121, 2019. https://doi.org/10.1145/3315573.3329986 + */ +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/special_consts.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/value.h" +#include "ruby/assert.h" +#include "ruby/backward/2/attributes.h" + +#undef USE_RGENGC +#define USE_RGENGC 1 + +#ifndef USE_RINCGC +# define USE_RINCGC 1 +#endif + +#ifndef USE_RGENGC_LOGGING_WB_UNPROTECT +# define USE_RGENGC_LOGGING_WB_UNPROTECT 0 +#endif + +#ifndef RGENGC_WB_PROTECTED_ARRAY +# define RGENGC_WB_PROTECTED_ARRAY 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_HASH +# define RGENGC_WB_PROTECTED_HASH 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_STRUCT +# define RGENGC_WB_PROTECTED_STRUCT 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_STRING +# define RGENGC_WB_PROTECTED_STRING 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_OBJECT +# define RGENGC_WB_PROTECTED_OBJECT 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_REGEXP +# define RGENGC_WB_PROTECTED_REGEXP 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_CLASS +# define RGENGC_WB_PROTECTED_CLASS 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_FLOAT +# define RGENGC_WB_PROTECTED_FLOAT 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_COMPLEX +# define RGENGC_WB_PROTECTED_COMPLEX 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_RATIONAL +# define RGENGC_WB_PROTECTED_RATIONAL 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_BIGNUM +# define RGENGC_WB_PROTECTED_BIGNUM 1 +#endif + +#ifndef RGENGC_WB_PROTECTED_NODE_CREF +# define RGENGC_WB_PROTECTED_NODE_CREF 1 +#endif + +/** + * @name Write barrier (WB) interfaces: + * @{ + * + * @note The following core interfaces can be changed in the future. Please + * catch up if you want to insert WB into C-extensions correctly. + */ + +/** + * WB for new reference from `a' to `b'. Write `b' into `*slot'. `slot' is a + * pointer in `a'. + */ +#define RB_OBJ_WRITE(a, slot, b) \ + RBIMPL_CAST(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)) +/** + * WB for new reference from `a' to `b'. This doesn't write any values, but + * only a WB declaration. `oldv' is replaced value with `b' (not used in + * current Ruby). + */ +#define RB_OBJ_WRITTEN(a, oldv, b) \ + RBIMPL_CAST(rb_obj_written((VALUE)(a), (VALUE)(oldv), (VALUE)(b), __FILE__, __LINE__)) +/** @} */ + +#define OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW +#define OBJ_PROMOTED RB_OBJ_PROMOTED +#define OBJ_WB_UNPROTECT RB_OBJ_WB_UNPROTECT + +#define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__) +#define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \ + (RGENGC_WB_PROTECTED_##type ? OBJ_WB_UNPROTECT(obj) : obj) +#define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging + +/** @cond INTERNAL_MACRO */ +#define RB_OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW +#define RB_OBJ_PROMOTED RB_OBJ_PROMOTED +/** @endcond */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() +void rb_gc_writebarrier(VALUE a, VALUE b); +void rb_gc_writebarrier_unprotect(VALUE obj); +#if USE_RGENGC_LOGGING_WB_UNPROTECT +void rb_gc_unprotect_logging(void *objptr, const char *filename, int line); +#endif +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_OBJ_PROMOTED_RAW(VALUE obj) +{ + RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj)); + return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_OBJ_PROMOTED(VALUE obj) +{ + if (! RB_FL_ABLE(obj)) { + return false; + } + else { + return RB_OBJ_PROMOTED_RAW(obj); + } +} + +static inline VALUE +rb_obj_wb_unprotect(VALUE x, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) +{ +#if USE_RGENGC_LOGGING_WB_UNPROTECT + RGENGC_LOGGING_WB_UNPROTECT(RBIMPL_CAST((void *)x), filename, line); +#endif + rb_gc_writebarrier_unprotect(x); + return x; +} + +static inline VALUE +rb_obj_written(VALUE a, RB_UNUSED_VAR(VALUE oldv), VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) +{ +#if USE_RGENGC_LOGGING_WB_UNPROTECT + RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line); +#endif + + if (!RB_SPECIAL_CONST_P(b)) { + rb_gc_writebarrier(a, b); + } + + return a; +} + +static inline VALUE +rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line)) +{ +#ifdef RGENGC_LOGGING_WRITE + RGENGC_LOGGING_WRITE(a, slot, b, filename, line); +#endif + + *slot = b; + + rb_obj_written(a, RUBY_Qundef /* ignore `oldv' now */, b, filename, line); + return a; +} + +#endif /* RBIMPL_RGENGC_H */ diff --git a/include/ruby/internal/scan_args.h b/include/ruby/internal/scan_args.h new file mode 100644 index 0000000000..ca31786175 --- /dev/null +++ b/include/ruby/internal/scan_args.h @@ -0,0 +1,394 @@ +#ifndef RBIMPL_SCAN_ARGS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_SCAN_ARGS_H +/** + * @file + * @author Ruby developers + * @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 Compile-time static implementation of ::rb_scan_args(). + * + * This is a beast. It statically analyses the argument spec string, and + * expands the assignment of variables into dedicated codes. + */ +#include "ruby/impl/attr/diagnose_if.h" +#include "ruby/impl/attr/error.h" +#include "ruby/impl/attr/forceinline.h" +#include "ruby/impl/attr/noreturn.h" +#include "ruby/impl/config.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/intern/array.h" /* rb_ary_new_from_values */ +#include "ruby/impl/intern/error.h" /* rb_error_arity */ +#include "ruby/impl/intern/hash.h" /* rb_hash_dup */ +#include "ruby/impl/intern/proc.h" /* rb_block_proc */ +#include "ruby/impl/iterator.h" /* rb_block_given_p / rb_keyword_given_p */ +#include "ruby/impl/static_assert.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/value.h" +#include "ruby/assert.h" + +#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS 0 +#define RB_SCAN_ARGS_KEYWORDS 1 +#define RB_SCAN_ARGS_LAST_HASH_KEYWORDS 3 +#define RB_NO_KEYWORDS 0 +#define RB_PASS_KEYWORDS 1 +#define RB_PASS_CALLED_KEYWORDS rb_keyword_given_p() +/* rb_scan_args() format allows ':' for optional hash */ +#define HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1 + +RBIMPL_SYMBOL_EXPORT_BEGIN() +int rb_scan_args(int, const VALUE*, const char*, ...); +int rb_scan_args_kw(int, int, const VALUE*, const char*, ...); + +RBIMPL_ATTR_ERROR(("bad scan arg format")) +void rb_scan_args_bad_format(const char*); + +RBIMPL_ATTR_ERROR(("variable argument length doesn't match")) +void rb_scan_args_length_mismatch(const char*,int); + +RBIMPL_SYMBOL_EXPORT_END() + +/* If we could use constexpr the following macros could be inline functions + * ... but sadly we cannot. */ + +#define rb_scan_args_isdigit(c) (RBIMPL_CAST((unsigned char)((c)-'0'))<10) + +#define rb_scan_args_count_end(fmt, ofs, vari) \ + ((fmt)[ofs] ? -1 : (vari)) + +#define rb_scan_args_count_block(fmt, ofs, vari) \ + ((fmt)[ofs]!='&' ? \ + rb_scan_args_count_end(fmt, ofs, vari) : \ + rb_scan_args_count_end(fmt, (ofs)+1, (vari)+1)) + +#define rb_scan_args_count_hash(fmt, ofs, vari) \ + ((fmt)[ofs]!=':' ? \ + rb_scan_args_count_block(fmt, ofs, vari) : \ + rb_scan_args_count_block(fmt, (ofs)+1, (vari)+1)) + +#define rb_scan_args_count_trail(fmt, ofs, vari) \ + (!rb_scan_args_isdigit((fmt)[ofs]) ? \ + rb_scan_args_count_hash(fmt, ofs, vari) : \ + rb_scan_args_count_hash(fmt, (ofs)+1, (vari)+((fmt)[ofs]-'0'))) + +#define rb_scan_args_count_var(fmt, ofs, vari) \ + ((fmt)[ofs]!='*' ? \ + rb_scan_args_count_trail(fmt, ofs, vari) : \ + rb_scan_args_count_trail(fmt, (ofs)+1, (vari)+1)) + +#define rb_scan_args_count_opt(fmt, ofs, vari) \ + (!rb_scan_args_isdigit((fmt)[ofs]) ? \ + rb_scan_args_count_var(fmt, ofs, vari) : \ + rb_scan_args_count_var(fmt, (ofs)+1, (vari)+(fmt)[ofs]-'0')) + +#define rb_scan_args_count_lead(fmt, ofs, vari) \ + (!rb_scan_args_isdigit((fmt)[ofs]) ? \ + rb_scan_args_count_var(fmt, ofs, vari) : \ + rb_scan_args_count_opt(fmt, (ofs)+1, (vari)+(fmt)[ofs]-'0')) + +#define rb_scan_args_count(fmt) rb_scan_args_count_lead(fmt, 0, 0) + +#if RBIMPL_HAS_ATTRIBUTE(diagnose_if) +# /* Assertions done in the attribute. */ +# define rb_scan_args_verify(fmt, varc) RBIMPL_ASSERT_NOTHING +#else +# /* At one sight it _seems_ the expressions below could be written using +# * static assrtions. The reality is no, they don't. Because fmt is a string +# * literal, any operations against fmt cannot produce the "integer constant +# * expression"s, as defined in ISO/IEC 9899:2018 section 6.6 paragraph #6. +# * Static assertions need such integer constant expressions as defined in +# * ISO/IEC 9899:2018 section 6.7.10 paragraph #3. +# * +# * GCC nonetheless constant-folds this into no-op, though. */ +# define rb_scan_args_verify(fmt, varc) \ + (sizeof(char[1-2*(rb_scan_args_count(fmt)<0)])!=1 ? \ + rb_scan_args_bad_format(fmt) : \ + sizeof(char[1-2*(rb_scan_args_count(fmt)!=(varc))])!=1 ? \ + rb_scan_args_length_mismatch(fmt, varc) : \ + RBIMPL_ASSERT_NOTHING) +#endif + +static inline bool +rb_scan_args_keyword_p(int kw_flag, VALUE last) +{ + switch (kw_flag) { + case RB_SCAN_ARGS_PASS_CALLED_KEYWORDS: + return !! rb_keyword_given_p(); + case RB_SCAN_ARGS_KEYWORDS: + return true; + case RB_SCAN_ARGS_LAST_HASH_KEYWORDS: + return RB_TYPE_P(last, T_HASH); + default: + return false; + } +} + +RBIMPL_ATTR_FORCEINLINE() +static bool +rb_scan_args_lead_p(const char *fmt) +{ + return rb_scan_args_isdigit(fmt[0]); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_n_lead(const char *fmt) +{ + return (rb_scan_args_lead_p(fmt) ? fmt[0]-'0' : 0); +} + +RBIMPL_ATTR_FORCEINLINE() +static bool +rb_scan_args_opt_p(const char *fmt) +{ + return (rb_scan_args_lead_p(fmt) && rb_scan_args_isdigit(fmt[1])); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_n_opt(const char *fmt) +{ + return (rb_scan_args_opt_p(fmt) ? fmt[1]-'0' : 0); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_var_idx(const char *fmt) +{ + return (!rb_scan_args_lead_p(fmt) ? 0 : !rb_scan_args_isdigit(fmt[1]) ? 1 : 2); +} + +RBIMPL_ATTR_FORCEINLINE() +static bool +rb_scan_args_f_var(const char *fmt) +{ + return (fmt[rb_scan_args_var_idx(fmt)]=='*'); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_trail_idx(const char *fmt) +{ + const int idx = rb_scan_args_var_idx(fmt); + return idx+(fmt[idx]=='*'); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_n_trail(const char *fmt) +{ + const int idx = rb_scan_args_trail_idx(fmt); + return (rb_scan_args_isdigit(fmt[idx]) ? fmt[idx]-'0' : 0); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_hash_idx(const char *fmt) +{ + const int idx = rb_scan_args_trail_idx(fmt); + return idx+rb_scan_args_isdigit(fmt[idx]); +} + +RBIMPL_ATTR_FORCEINLINE() +static bool +rb_scan_args_f_hash(const char *fmt) +{ + return (fmt[rb_scan_args_hash_idx(fmt)]==':'); +} + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_block_idx(const char *fmt) +{ + const int idx = rb_scan_args_hash_idx(fmt); + return idx+(fmt[idx]==':'); +} + +RBIMPL_ATTR_FORCEINLINE() +static bool +rb_scan_args_f_block(const char *fmt) +{ + return (fmt[rb_scan_args_block_idx(fmt)]=='&'); +} + +# if 0 +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_end_idx(const char *fmt) +{ + const int idx = rb_scan_args_block_idx(fmt); + return idx+(fmt[idx]=='&'); +} +# endif + +/* NOTE: Use `char *fmt` instead of `const char *fmt` because of clang's bug*/ +/* https://bugs.llvm.org/show_bug.cgi?id=38095 */ +# define rb_scan_args0(argc, argv, fmt, varc, vars) \ + rb_scan_args_set(RB_SCAN_ARGS_PASS_CALLED_KEYWORDS, argc, argv, \ + rb_scan_args_n_lead(fmt), \ + rb_scan_args_n_opt(fmt), \ + rb_scan_args_n_trail(fmt), \ + rb_scan_args_f_var(fmt), \ + rb_scan_args_f_hash(fmt), \ + rb_scan_args_f_block(fmt), \ + (rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc) +# define rb_scan_args_kw0(kw_flag, argc, argv, fmt, varc, vars) \ + rb_scan_args_set(kw_flag, argc, argv, \ + rb_scan_args_n_lead(fmt), \ + rb_scan_args_n_opt(fmt), \ + rb_scan_args_n_trail(fmt), \ + rb_scan_args_f_var(fmt), \ + rb_scan_args_f_hash(fmt), \ + rb_scan_args_f_block(fmt), \ + (rb_scan_args_verify(fmt, varc), vars), (char *)fmt, varc) + +RBIMPL_ATTR_FORCEINLINE() +static int +rb_scan_args_set(int kw_flag, int argc, const VALUE *argv, + int n_lead, int n_opt, int n_trail, + bool f_var, bool f_hash, bool f_block, + VALUE *vars[], RB_UNUSED_VAR(const char *fmt), RB_UNUSED_VAR(int varc)) + RBIMPL_ATTR_DIAGNOSE_IF(rb_scan_args_count(fmt) < 0, "bad scan arg format", "error") + RBIMPL_ATTR_DIAGNOSE_IF(rb_scan_args_count(fmt) != varc, "variable argument length doesn't match", "error") +{ + int i, argi = 0, vari = 0; + VALUE *var, hash = Qnil; +#define rb_scan_args_next_param() vars[vari++] + const int n_mand = n_lead + n_trail; + + if (f_hash && argc > 0) { + VALUE last = argv[argc - 1]; + if (rb_scan_args_keyword_p(kw_flag, last)) { + hash = rb_hash_dup(last); + argc--; + } + } + + if (argc < n_mand) { + goto argc_error; + } + + /* capture leading mandatory arguments */ + for (i = n_lead; i-- > 0; ) { + var = rb_scan_args_next_param(); + if (var) *var = argv[argi]; + argi++; + } + /* capture optional arguments */ + for (i = n_opt; i-- > 0; ) { + var = rb_scan_args_next_param(); + if (argi < argc - n_trail) { + if (var) *var = argv[argi]; + argi++; + } + else { + if (var) *var = Qnil; + } + } + /* capture variable length arguments */ + if (f_var) { + int n_var = argc - argi - n_trail; + + var = rb_scan_args_next_param(); + if (0 < n_var) { + if (var) *var = rb_ary_new_from_values(n_var, &argv[argi]); + argi += n_var; + } + else { + if (var) *var = rb_ary_new(); + } + } + /* capture trailing mandatory arguments */ + for (i = n_trail; i-- > 0; ) { + var = rb_scan_args_next_param(); + if (var) *var = argv[argi]; + argi++; + } + /* capture an option hash - phase 2: assignment */ + if (f_hash) { + var = rb_scan_args_next_param(); + if (var) *var = hash; + } + /* capture iterator block */ + if (f_block) { + var = rb_scan_args_next_param(); + if (rb_block_given_p()) { + *var = rb_block_proc(); + } + else { + *var = Qnil; + } + } + + if (argi < argc) { + argc_error: + rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt); + } + + return argc; +#undef rb_scan_args_next_param +} + +#if ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) +# /* skip */ + +#elif ! defined(HAVE_VA_ARGS_MACRO) +# /* skip */ + +#elif ! defined(__OPTIMIZE__) +# /* skip */ + +#elif defined(HAVE___VA_OPT__) +# define rb_scan_args(argc, argvp, fmt, ...) \ + __builtin_choose_expr( \ + __builtin_constant_p(fmt), \ + rb_scan_args0( \ + argc, argvp, fmt, \ + (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ + ((VALUE*[]){__VA_ARGS__})), \ + (rb_scan_args)(argc, argvp, fmt __VA_OPT__(, __VA_ARGS__))) +# define rb_scan_args_kw(kw_flag, argc, argvp, fmt, ...) \ + __builtin_choose_expr( \ + __builtin_constant_p(fmt), \ + rb_scan_args_kw0( \ + kw_flag, argc, argvp, fmt, \ + (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ + ((VALUE*[]){__VA_ARGS__})), \ + (rb_scan_args_kw)(kw_flag, argc, argvp, fmt __VA_OPT__(, __VA_ARGS__))) + +#elif defined(__STRICT_ANSI__) +# /* skip */ + +#elif defined(__GNUC__) +# define rb_scan_args(argc, argvp, fmt, ...) \ + __builtin_choose_expr( \ + __builtin_constant_p(fmt), \ + rb_scan_args0( \ + argc, argvp, fmt, \ + (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ + ((VALUE*[]){__VA_ARGS__})), \ + (rb_scan_args)(argc, argvp, fmt, __VA_ARGS__)) +# define rb_scan_args_kw(kw_flag, argc, argvp, fmt, ...) \ + __builtin_choose_expr( \ + __builtin_constant_p(fmt), \ + rb_scan_args_kw0( \ + kw_flag, argc, argvp, fmt, \ + (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ + ((VALUE*[]){__VA_ARGS__})), \ + (rb_scan_args_kw)(kw_flag, argc, argvp, fmt, __VA_ARGS__ /**/)) +#endif + +#endif /* RBIMPL_SCAN_ARGS_H */ diff --git a/include/ruby/internal/special_consts.h b/include/ruby/internal/special_consts.h new file mode 100644 index 0000000000..5fb3b8eb94 --- /dev/null +++ b/include/ruby/internal/special_consts.h @@ -0,0 +1,204 @@ +#ifndef RBIMPL_SPECIAL_CONSTS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_SPECIAL_CONSTS_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines enum ::ruby_special_consts. + * @see Sasada, K., "A Lighweight Representation of Floting-Point + * Numbers on Ruby Interpreter", in proceedings of 10th JSSST + * SIGPPL Workshop on Programming and Programming Languages + * (PPL2008), pp. 9-16, 2008. + */ +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/const.h" +#include "ruby/impl/attr/constexpr.h" +#include "ruby/impl/attr/enum_extensibility.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/value.h" + +#if defined(USE_FLONUM) +# /* Take that. */ +#elif SIZEOF_VALUE >= SIZEOF_DOUBLE +# define USE_FLONUM 1 +#else +# define USE_FLONUM 0 +#endif + +#define RTEST RB_TEST + +#define FIXNUM_P RB_FIXNUM_P +#define IMMEDIATE_P RB_IMMEDIATE_P +#define NIL_P RB_NIL_P +#define SPECIAL_CONST_P RB_SPECIAL_CONST_P +#define STATIC_SYM_P RB_STATIC_SYM_P + +#define Qfalse RUBY_Qfalse +#define Qnil RUBY_Qnil +#define Qtrue RUBY_Qtrue +#define Qundef RUBY_Qundef + +/** @cond INTERNAL_MACRO */ +#define FIXNUM_FLAG RUBY_FIXNUM_FLAG +#define FLONUM_FLAG RUBY_FLONUM_FLAG +#define FLONUM_MASK RUBY_FLONUM_MASK +#define FLONUM_P RB_FLONUM_P +#define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK +#define SYMBOL_FLAG RUBY_SYMBOL_FLAG + +#define RB_FIXNUM_P RB_FIXNUM_P +#define RB_FLONUM_P RB_FLONUM_P +#define RB_IMMEDIATE_P RB_IMMEDIATE_P +#define RB_NIL_P RB_NIL_P +#define RB_SPECIAL_CONST_P RB_SPECIAL_CONST_P +#define RB_STATIC_SYM_P RB_STATIC_SYM_P +#define RB_TEST RB_TEST +/** @endcond */ + +/** special constants - i.e. non-zero and non-fixnum constants */ +enum +RBIMPL_ATTR_ENUM_EXTENSIBILITY(closed) +ruby_special_consts { +#if USE_FLONUM + RUBY_Qfalse = 0x00, /* ...0000 0000 */ + RUBY_Qtrue = 0x14, /* ...0001 0100 */ + RUBY_Qnil = 0x08, /* ...0000 1000 */ + RUBY_Qundef = 0x34, /* ...0011 0100 */ + RUBY_IMMEDIATE_MASK = 0x07, /* ...0000 0111 */ + RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ + RUBY_FLONUM_MASK = 0x03, /* ...0000 0011 */ + RUBY_FLONUM_FLAG = 0x02, /* ...xxxx xx10 */ + RUBY_SYMBOL_FLAG = 0x0c, /* ...xxxx 1100 */ +#else + RUBY_Qfalse = 0x00, /* ...0000 0000 */ + RUBY_Qtrue = 0x02, /* ...0000 0010 */ + RUBY_Qnil = 0x04, /* ...0000 0100 */ + RUBY_Qundef = 0x06, /* ...0000 0110 */ + RUBY_IMMEDIATE_MASK = 0x03, /* ...0000 0011 */ + RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ + RUBY_FLONUM_MASK = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */ + RUBY_FLONUM_FLAG = 0x02, /* ...0000 0010 */ + RUBY_SYMBOL_FLAG = 0x0e, /* ...0000 1110 */ +#endif + + RUBY_SPECIAL_SHIFT = 8 /** Least significant 8 bits are reserved. */ +}; + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +/* + * :NOTE: rbimpl_test HAS to be `__attribute__((const))` in order for clang to + * properly deduce `__builtin_assume()`. + */ +static inline bool +RB_TEST(VALUE obj) +{ + /* + * Qfalse: ....0000 0000 + * Qnil: ....0000 1000 + * ~Qnil: ....1111 0111 + * v ....xxxx xxxx + * ---------------------------- + * RTEST(v) ....xxxx 0xxx + * + * RTEST(v) can be 0 if and only if (v == Qfalse || v == Qnil). + */ + return obj & ~RUBY_Qnil; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_NIL_P(VALUE obj) +{ + return obj == RUBY_Qnil; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FIXNUM_P(VALUE obj) +{ + return obj & RUBY_FIXNUM_FLAG; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX14) +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_STATIC_SYM_P(VALUE obj) +{ + RBIMPL_ATTR_CONSTEXPR(CXX14) + const VALUE mask = ~(RBIMPL_VALUE_FULL << RUBY_SPECIAL_SHIFT); + return (obj & mask) == RUBY_SYMBOL_FLAG; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FLONUM_P(VALUE obj) +{ +#if USE_FLONUM + return (obj & RUBY_FLONUM_MASK) == RUBY_FLONUM_FLAG; +#else + return false; +#endif +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_IMMEDIATE_P(VALUE obj) +{ + return obj & RUBY_IMMEDIATE_MASK; +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_SPECIAL_CONST_P(VALUE obj) +{ + return RB_IMMEDIATE_P(obj) || ! RB_TEST(obj); +} + +RBIMPL_ATTR_CONST() +RBIMPL_ATTR_CONSTEXPR(CXX11) +/* This function is to mimic old rb_special_const_p macro but have anyone + * actually used its return value? Wasn't it just something no one needed? */ +static inline VALUE +rb_special_const_p(VALUE obj) +{ + return RB_SPECIAL_CONST_P(obj) * RUBY_Qtrue; +} + +/** + * @cond INTERNAL_MACRO + * See [ruby-dev:27513] for the following macros. + */ +#define RUBY_Qfalse RBIMPL_CAST((VALUE)RUBY_Qfalse) +#define RUBY_Qtrue RBIMPL_CAST((VALUE)RUBY_Qtrue) +#define RUBY_Qnil RBIMPL_CAST((VALUE)RUBY_Qnil) +#define RUBY_Qundef RBIMPL_CAST((VALUE)RUBY_Qundef) +/** @endcond */ + +#endif /* RBIMPL_SPECIAL_CONSTS_H */ diff --git a/include/ruby/internal/static_assert.h b/include/ruby/internal/static_assert.h new file mode 100644 index 0000000000..e7788ab31a --- /dev/null +++ b/include/ruby/internal/static_assert.h @@ -0,0 +1,77 @@ +#ifndef RBIMPL_STATIC_ASSERT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_STATIC_ASSERT_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_STATIC_ASSERT. + */ +#include +#include "ruby/impl/has/extension.h" +#include "ruby/impl/compiler_since.h" + +/** @cond INTERNAL_MACRO */ +#if defined(__cplusplus) && defined(__cpp_static_assert) +# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ +# define RBIMPL_STATIC_ASSERT0 static_assert + +#elif defined(__cplusplus) && RBIMPL_COMPILER_SINCE(MSVC, 16, 0, 0) +# define RBIMPL_STATIC_ASSERT0 static_assert + +#elif defined(__INTEL_CXX11_MODE__) +# define RBIMPL_STATIC_ASSERT0 static_assert + +#elif defined(__cplusplus) && __cplusplus >= 201103L +# define RBIMPL_STATIC_ASSERT0 static_assert + +#elif defined(__cplusplus) && RBIMPL_HAS_EXTENSION(cxx_static_assert) +# define RBIMPL_STATIC_ASSERT0 __extension__ static_assert + +#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ +# define RBIMPL_STATIC_ASSERT0 __extension__ static_assert + +#elif defined(__STDC_VERSION__) && RBIMPL_HAS_EXTENSION(c_static_assert) +# define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert + +#elif defined(__STDC_VERSION__) && RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) +# define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert + +#elif defined(static_assert) +# /* Take definition */ +# define RBIMPL_STATIC_ASSERT0 static_assert +#endif +/** @endcond */ + +/** + * @brief Wraps (or simulates) `static_assert` + * @param name Valid C/C++ identifier, describing the assertion. + * @param expr Expression to assert. + * @note `name` shall not be a string literal. + */ +#if defined(__DOXYGEN__) +# define RBIMPL_STATIC_ASSERT static_assert + +#elif defined(RBIMPL_STATIC_ASSERT0) +# define RBIMPL_STATIC_ASSERT(name, expr) \ + RBIMPL_STATIC_ASSERT0(expr, # name ": " # expr) + +#else +# define RBIMPL_STATIC_ASSERT(name, expr) \ + typedef int static_assert_ ## name ## _check[1 - 2 * !(expr)] +#endif + +#endif /* RBIMPL_STATIC_ASSERT_H */ diff --git a/include/ruby/internal/stdalign.h b/include/ruby/internal/stdalign.h new file mode 100644 index 0000000000..a3dcfb90ef --- /dev/null +++ b/include/ruby/internal/stdalign.h @@ -0,0 +1,124 @@ +#ifndef RBIMPL_STDALIGN_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_STDALIGN_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_ALIGNAS / #RBIMPL_ALIGNOF + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_STDALIGN_H +# include +#endif + +#include "ruby/impl/compiler_is.h" +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/feature.h" +#include "ruby/impl/has/extension.h" +#include "ruby/impl/has/attribute.h" +#include "ruby/impl/has/declspec_attribute.h" + +/** + * Wraps (or simulates) `alignas`. This is C++11's `alignas` and is _different_ + * from C11 `_Alignas`. For instance, + * + * ```CXX + * typedef struct alignas(128) foo { int foo } foo; + * ``` + * + * is a valid C++ while + * + * ```C + * typedef struct _Alignas(128) foo { int foo } foo; + * ``` + * + * is an invalid C because: + * + * - You cannot `struct _Alignas`. + * - A `typedef` cannot have alignments. + */ +#if defined(__cplusplus) && RBIMPL_HAS_FEATURE(cxx_alignas) +# define RBIMPL_ALIGNAS alignas + +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +# define RBIMPL_ALIGNAS alignas + +#elif defined(__INTEL_CXX11_MODE__) +# define RBIMPL_ALIGNAS alignas + +#elif defined(__GXX_EXPERIMENTAL_CXX0X__) +# define RBIMPL_ALIGNAS alignas + +#elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(align) +# define RBIMPL_ALIGNAS(_) __declspec(align(_)) + +#elif RBIMPL_HAS_ATTRIBUTE(aliged) +# define RBIMPL_ALIGNAS(_) __attribute__((__aligned__(_))) + +#else +# define RBIMPL_ALIGNAS(_) /* void */ +#endif + +/** + * Wraps (or simulates) `alignof`. Unlike #RBIMPL_ALIGNAS, we can safely say + * both C/C++ definitions are effective. + */ +#if defined(__cplusplus) && RBIMPL_HAS_EXTENSION(cxx_alignof) +# define RBIMPL_ALIGNOF __extension__ alignof + +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +# define RBIMPL_ALIGNOF alignof + +#elif defined(__INTEL_CXX11_MODE__) +# define RBIMPL_ALIGNOF alignof + +#elif defined(__GXX_EXPERIMENTAL_CXX0X__) +# define RBIMPL_ALIGNOF alignof + +#elif defined(__STDC_VERSION__) && RBIMPL_HAS_EXTENSION(c_alignof) +# define RBIMPL_ALIGNOF __extension__ _Alignof + +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define RBIMPL_ALIGNOF _Alignof + +#elif RBIMPL_COMPILER_IS(MSVC) +# define RBIMPL_ALIGNOF __alignof + +#elif defined(__GNUC__) +# /* At least GCC 2.95 had this. */ +# define RBIMPL_ALIGNOF __extension__ __alignof__ + +#elif defined(__alignof_is_defined) || defined(__DOXYGEN__) +# /* OK, we can safely take definition. */ +# define RBIMPL_ALIGNOF alignof + +#elif RBIMPL_COMPILER_SINCE(SunPro, 5, 9, 0) +# /* According to their manual, Sun Studio 12 introduced __alignof__ for both +# * C/C++. */ +# define RBIMPL_ALIGNOF __alignof__ + +#elif 0 +# /* THIS IS NG, you cannot define a new type inside of offsetof. */ +# /* see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm */ +# define RBIMPL_ALIGNOF(T) offsetof(struct { char _; T t; }, t) + +#else +# error :FIXME: add your compiler here to obtain an alignment. +#endif + +#endif /* RBIMPL_STDALIGN_H */ diff --git a/include/ruby/internal/stdbool.h b/include/ruby/internal/stdbool.h new file mode 100644 index 0000000000..36ccaa0c6f --- /dev/null +++ b/include/ruby/internal/stdbool.h @@ -0,0 +1,51 @@ +#ifndef RBIMPL_STDBOOL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_STDBOOL_H +/** + * @file + * @author Ruby developers + * @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 C99 shim for + */ +#include "ruby/impl/config.h" + +#if defined(__bool_true_false_are_defined) +# /* Take that. */ + +#elif defined(__cplusplus) +# /* bool is a keyword in C++. */ +# if defined(HAVE_STDBOOL_H) && (__cplusplus >= 201103L) +# include +# endif +# +# ifndef __bool_true_false_are_defined +# define __bool_true_false_are_defined +# endif + +#elif defined(HAVE_STDBOOL_H) +# /* Take stdbool.h definition. */ +# include + +#else +typedef unsigned char _Bool; +# /* See also http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2229.htm */ +# define bool _Bool +# define true ((_Bool)+1) +# define false ((_Bool)+0) +# define __bool_true_false_are_defined +#endif + +#endif /* RBIMPL_STDBOOL_H */ diff --git a/include/ruby/internal/symbol.h b/include/ruby/internal/symbol.h new file mode 100644 index 0000000000..a7b2358894 --- /dev/null +++ b/include/ruby/internal/symbol.h @@ -0,0 +1,114 @@ +#ifndef RBIMPL_SYMBOL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_SYMBOL_H +/** + * @file + * @author Ruby developers + * @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 #rb_intern + */ +#include "ruby/impl/config.h" + +#ifdef HAVE_STDDEF_H +# include +#endif + +#ifdef HAVE_STRING_H +# include +#endif + +#include "ruby/impl/attr/nonnull.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/attr/noalias.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/constant_p.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/has/builtin.h" +#include "ruby/impl/value.h" + +#define RB_ID2SYM rb_id2sym +#define RB_SYM2ID rb_sym2id +#define ID2SYM RB_ID2SYM +#define SYM2ID RB_SYM2ID +#define CONST_ID_CACHE RUBY_CONST_ID_CACHE +#define CONST_ID RUBY_CONST_ID + +/** @cond INTERNAL_MACRO */ +#define rb_intern_const rb_intern_const +/** @endcond */ + +RBIMPL_SYMBOL_EXPORT_BEGIN() +ID rb_sym2id(VALUE); +VALUE rb_id2sym(ID); +ID rb_intern(const char*); +ID rb_intern2(const char*, long); +ID rb_intern_str(VALUE str); +const char *rb_id2name(ID); +ID rb_check_id(volatile VALUE *); +ID rb_to_id(VALUE); +VALUE rb_id2str(ID); +VALUE rb_sym2str(VALUE); +VALUE rb_to_symbol(VALUE name); +VALUE rb_check_symbol(volatile VALUE *namep); +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_PURE() +RBIMPL_ATTR_NONNULL(()) +static inline ID +rb_intern_const(const char *str) +{ + size_t len = strlen(str); + return rb_intern2(str, RBIMPL_CAST((long)len)); +} + +RBIMPL_ATTR_NOALIAS() +RBIMPL_ATTR_NONNULL(()) +static inline ID +rbimpl_intern_const(ID *ptr, const char *str) +{ + while (! *ptr) { + *ptr = rb_intern_const(str); + } + + return *ptr; +} + +/* Does anyone use it? Preserved for backward compat. */ +#define RUBY_CONST_ID_CACHE(result, str) \ + { \ + static ID rb_intern_id_cache; \ + rbimpl_intern_const(&rb_intern_id_cache, (str)); \ + result rb_intern_id_cache; \ + } +#define RUBY_CONST_ID(var, str) \ + do { \ + static ID rbimpl_id; \ + (var) = rbimpl_intern_const(&rbimpl_id, (str)); \ + } while (0) + +#if defined(HAVE_STMT_AND_DECL_IN_EXPR) +/* __builtin_constant_p and statement expression is available + * since gcc-2.7.2.3 at least. */ +#define rb_intern(str) \ + (RBIMPL_CONSTANT_P(str) ? \ + __extension__ ({ \ + static ID rbimpl_id; \ + rbimpl_intern_const(&rbimpl_id, (str)); \ + }) : \ + (rb_intern)(str)) +#endif + +#endif /* RBIMPL_SYMBOL_H */ diff --git a/include/ruby/internal/token_paste.h b/include/ruby/internal/token_paste.h new file mode 100644 index 0000000000..473fd597f8 --- /dev/null +++ b/include/ruby/internal/token_paste.h @@ -0,0 +1,75 @@ +#ifndef RBIMPL_TOKEN_PASTE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_TOKEN_PASTE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RBIMPL_TOKEN_PASTE. + */ +#include "ruby/impl/config.h" +#include "ruby/impl/compiler_since.h" +#include "ruby/impl/has/warning.h" +#include "ruby/impl/warning_push.h" + +/* :TODO: add your compiler here. There are many compilers that can suppress + * warnings via pragmas, but not all of them accept such things inside of `#if` + * and variants' conditions. And such nitpicking behavours tend not be + * documented. Please improve this file when you are really sure about your + * compiler's behaviour. */ + +#if RBIMPL_COMPILER_SINCE(GCC, 4, 2, 0) +# /* GCC is one of such compiler who cannot write `_Pragma` inside of a `#if`. +# * Cannot but globally kill everything. This is of course a very bad thing. +# * If you know how to reroute this please tell us. */ +# /* https://gcc.godbolt.org/z/K2xr7X */ +# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) +# pragma GCC diagnostic ignored "-Wundef" +# /* > warning: "symbol" is not defined, evaluates to 0 [-Wundef] */ + +#elif RBIMPL_COMPILER_IS(Intel) +# /* Ditto for icc. */ +# /* https://gcc.godbolt.org/z/pTwDxE */ +# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) +# pragma warning(disable: 193) +# /* > warning #193: zero used for undefined preprocessing identifier */ + +#elif RBIMPL_COMPILER_BEFORE(MSVC, 19, 14, 26428) +# /* :FIXME: is 19.14 the exact version they supported this? */ +# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) +# pragma warning(disable: 4668) +# /* > warning C4668: 'symbol' is not defined as a preprocessor macro */ + +#elif RBIMPL_COMPILER_IS(MSVC) +# define RBIMPL_TOKEN_PASTE(x, y) \ + RBIMPL_WARNING_PUSH() \ + RBIMPL_WARNING_IGNORED(4668) \ + TOKEN_PASTE(x, y) \ + RBIMPL_WARNING_POP() + +#elif RBIMPL_HAS_WARNING("-Wundef") +# define RBIMPL_TOKEN_PASTE(x, y) \ + RBIMPL_WARNING_PUSH() \ + RBIMPL_WARNING_IGNORED(-Wundef) \ + TOKEN_PASTE(x, y) \ + RBIMPL_WARNING_POP() + +#else +# /* No way. */ +# define RBIMPL_TOKEN_PASTE(x, y) TOKEN_PASTE(x, y) +#endif + +#endif /* RBIMPL_TOKEN_PASTE_H */ diff --git a/include/ruby/internal/value.h b/include/ruby/internal/value.h new file mode 100644 index 0000000000..905cc04187 --- /dev/null +++ b/include/ruby/internal/value.h @@ -0,0 +1,66 @@ +#ifndef RBIMPL_VALUE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_VALUE_H +/** + * @file + * @author Ruby developers + * @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 ::VALUE and ::ID. + */ +#include "ruby/impl/static_assert.h" +#include "ruby/backward/2/long_long.h" +#include "ruby/backward/2/limits.h" + +#if defined HAVE_UINTPTR_T && 0 +typedef uintptr_t VALUE; +typedef uintptr_t ID; +# define SIGNED_VALUE intptr_t +# define SIZEOF_VALUE SIZEOF_UINTPTR_T +# undef PRI_VALUE_PREFIX +# define RBIMPL_VALUE_NULL UINTPTR_C(0) +# define RBIMPL_VALUE_ONE UINTPTR_C(1) +# define RBIMPL_VALUE_FULL UINTPTR_MAX + +#elif SIZEOF_LONG == SIZEOF_VOIDP +typedef unsigned long VALUE; +typedef unsigned long ID; +# define SIGNED_VALUE long +# define SIZEOF_VALUE SIZEOF_LONG +# define PRI_VALUE_PREFIX "l" +# define RBIMPL_VALUE_NULL 0UL +# define RBIMPL_VALUE_ONE 1UL +# define RBIMPL_VALUE_FULL ULONG_MAX + +#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP +typedef unsigned LONG_LONG VALUE; +typedef unsigned LONG_LONG ID; +# define SIGNED_VALUE LONG_LONG +# define LONG_LONG_VALUE 1 +# define SIZEOF_VALUE SIZEOF_LONG_LONG +# define PRI_VALUE_PREFIX PRI_LL_PREFIX +# define RBIMPL_VALUE_NULL 0ULL +# define RBIMPL_VALUE_ONE 1ULL +# define RBIMPL_VALUE_FULL ULLONG_MAX + +#else +# error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<---- +#endif + +RBIMPL_STATIC_ASSERT(sizeof_int, SIZEOF_INT == sizeof(int)); +RBIMPL_STATIC_ASSERT(sizeof_long, SIZEOF_LONG == sizeof(long)); +RBIMPL_STATIC_ASSERT(sizeof_long_long, SIZEOF_LONG_LONG == sizeof(LONG_LONG)); +RBIMPL_STATIC_ASSERT(sizeof_voidp, SIZEOF_VOIDP == sizeof(void *)); +#endif /* RBIMPL_VALUE_H */ diff --git a/include/ruby/internal/value_type.h b/include/ruby/internal/value_type.h new file mode 100644 index 0000000000..be1b3559b6 --- /dev/null +++ b/include/ruby/internal/value_type.h @@ -0,0 +1,354 @@ +#ifndef RBIMPL_VALUE_TYPE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_VALUE_TYPE_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines enum ::ruby_value_type. + */ +#include "ruby/impl/assume.h" +#include "ruby/impl/attr/artificial.h" +#include "ruby/impl/attr/cold.h" +#include "ruby/impl/attr/enum_extensibility.h" +#include "ruby/impl/attr/forceinline.h" +#include "ruby/impl/attr/pure.h" +#include "ruby/impl/cast.h" +#include "ruby/impl/constant_p.h" +#include "ruby/impl/core/rbasic.h" +#include "ruby/impl/dllexport.h" +#include "ruby/impl/has/builtin.h" +#include "ruby/impl/special_consts.h" +#include "ruby/impl/stdbool.h" +#include "ruby/impl/value.h" +#include "ruby/assert.h" + +#if defined(T_DATA) +/* + * :!BEWARE!: (Recent?) Solaris' have conflicting definition of + * T_DATA. Let us stop here. Please have a workaround like this: + * + * ```C + * #include // <- Include this one first. + * #undef T_DATA // <- ... and stick to RUBY_T_DATA forever. + * #include // <- OS-provided T_DATA introduced. + * ``` + * + * See also [ruby-core:4261] + */ +# error Bail out due to conflicting definition of T_DATA. +#endif + +#define T_ARRAY RUBY_T_ARRAY +#define T_BIGNUM RUBY_T_BIGNUM +#define T_CLASS RUBY_T_CLASS +#define T_COMPLEX RUBY_T_COMPLEX +#define T_DATA RUBY_T_DATA +#define T_FALSE RUBY_T_FALSE +#define T_FILE RUBY_T_FILE +#define T_FIXNUM RUBY_T_FIXNUM +#define T_FLOAT RUBY_T_FLOAT +#define T_HASH RUBY_T_HASH +#define T_ICLASS RUBY_T_ICLASS +#define T_IMEMO RUBY_T_IMEMO +#define T_MASK RUBY_T_MASK +#define T_MATCH RUBY_T_MATCH +#define T_MODULE RUBY_T_MODULE +#define T_MOVED RUBY_T_MOVED +#define T_NIL RUBY_T_NIL +#define T_NODE RUBY_T_NODE +#define T_NONE RUBY_T_NONE +#define T_OBJECT RUBY_T_OBJECT +#define T_RATIONAL RUBY_T_RATIONAL +#define T_REGEXP RUBY_T_REGEXP +#define T_STRING RUBY_T_STRING +#define T_STRUCT RUBY_T_STRUCT +#define T_SYMBOL RUBY_T_SYMBOL +#define T_TRUE RUBY_T_TRUE +#define T_UNDEF RUBY_T_UNDEF +#define T_ZOMBIE RUBY_T_ZOMBIE + +#define BUILTIN_TYPE RB_BUILTIN_TYPE +#define DYNAMIC_SYM_P RB_DYNAMIC_SYM_P +#define RB_INTEGER_TYPE_P rb_integer_type_p +#define SYMBOL_P RB_SYMBOL_P +#define rb_type_p RB_TYPE_P + +/** @cond INTERNAL_MACRO */ +#define RB_BUILTIN_TYPE RB_BUILTIN_TYPE +#define RB_DYNAMIC_SYM_P RB_DYNAMIC_SYM_P +#define RB_FLOAT_TYPE_P RB_FLOAT_TYPE_P +#define RB_SYMBOL_P RB_SYMBOL_P +#define RB_TYPE_P RB_TYPE_P +#define Check_Type Check_Type + +#if RUBY_NDEBUG +# define RBIMPL_ASSERT_TYPE(v, t) RBIMPL_ASSERT_OR_ASSUME(RB_TYPE_P((v), (t))) +#else +# define RBIMPL_ASSERT_TYPE Check_Type +#endif +/** @endcond */ + +#define TYPE(_) RBIMPL_CAST((int)rb_type(_)) + +/** C-level type of an object. */ +enum +RBIMPL_ATTR_ENUM_EXTENSIBILITY(closed) +ruby_value_type { + RUBY_T_NONE = 0x00, /**< Non-object (sweeped etc.) */ + + RUBY_T_OBJECT = 0x01, /**< @see struct ::RObject */ + RUBY_T_CLASS = 0x02, /**< @see struct ::RClass and ::rb_cClass */ + RUBY_T_MODULE = 0x03, /**< @see struct ::RClass and ::rb_cModule */ + RUBY_T_FLOAT = 0x04, /**< @see struct ::RFloat */ + RUBY_T_STRING = 0x05, /**< @see struct ::RString */ + RUBY_T_REGEXP = 0x06, /**< @see struct ::RRegexp */ + RUBY_T_ARRAY = 0x07, /**< @see struct ::RArray */ + RUBY_T_HASH = 0x08, /**< @see struct ::RHash */ + RUBY_T_STRUCT = 0x09, /**< @see struct ::RStruct */ + RUBY_T_BIGNUM = 0x0a, /**< @see struct ::RBignum */ + RUBY_T_FILE = 0x0b, /**< @see struct ::RFile */ + RUBY_T_DATA = 0x0c, /**< @see struct ::RTypedData */ + RUBY_T_MATCH = 0x0d, /**< @see struct ::RMatch */ + RUBY_T_COMPLEX = 0x0e, /**< @see struct ::RComplex */ + RUBY_T_RATIONAL = 0x0f, /**< @see struct ::RRational */ + + RUBY_T_NIL = 0x11, /**< @see ::RUBY_Qnil */ + RUBY_T_TRUE = 0x12, /**< @see ::RUBY_Qfalse */ + RUBY_T_FALSE = 0x13, /**< @see ::RUBY_Qtrue */ + RUBY_T_SYMBOL = 0x14, /**< @see struct ::RSymbol */ + RUBY_T_FIXNUM = 0x15, /**< Integers formerly known as Fixnums. */ + RUBY_T_UNDEF = 0x16, /**< @see ::RUBY_Qundef */ + + RUBY_T_IMEMO = 0x1a, /**< @see struct ::RIMemo */ + RUBY_T_NODE = 0x1b, /**< @see struct ::RNode */ + RUBY_T_ICLASS = 0x1c, /**< Hidden classes known as IClasses. */ + RUBY_T_ZOMBIE = 0x1d, /**< @see struct ::RZombie */ + RUBY_T_MOVED = 0x1e, /**< @see struct ::RMoved */ + + RUBY_T_MASK = 0x1f +}; + +RBIMPL_SYMBOL_EXPORT_BEGIN() +RBIMPL_ATTR_COLD() +void rb_check_type(VALUE obj, int t); +RBIMPL_SYMBOL_EXPORT_END() + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline enum ruby_value_type +RB_BUILTIN_TYPE(VALUE obj) +{ + RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj)); + + VALUE ret = RBASIC(obj)->flags & RUBY_T_MASK; + return RBIMPL_CAST((enum ruby_value_type)ret); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +static inline bool +rb_integer_type_p(VALUE obj) +{ + if (RB_FIXNUM_P(obj)) { + return true; + } + else if (RB_SPECIAL_CONST_P(obj)) { + return false; + } + else { + return RB_BUILTIN_TYPE(obj) == RUBY_T_BIGNUM; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +static inline enum ruby_value_type +rb_type(VALUE obj) +{ + if (! RB_SPECIAL_CONST_P(obj)) { + return RB_BUILTIN_TYPE(obj); + } + else if (obj == RUBY_Qfalse) { + return RUBY_T_FALSE; + } + else if (obj == RUBY_Qnil) { + return RUBY_T_NIL; + } + else if (obj == RUBY_Qtrue) { + return RUBY_T_TRUE; + } + else if (obj == RUBY_Qundef) { + return RUBY_T_UNDEF; + } + else if (RB_FIXNUM_P(obj)) { + return RUBY_T_FIXNUM; + } + else if (RB_STATIC_SYM_P(obj)) { + return RUBY_T_SYMBOL; + } + else { + RBIMPL_ASSUME(RB_FLONUM_P(obj)); + return RUBY_T_FLOAT; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_FLOAT_TYPE_P(VALUE obj) +{ + if (RB_FLONUM_P(obj)) { + return true; + } + else if (RB_SPECIAL_CONST_P(obj)) { + return false; + } + else { + return RB_BUILTIN_TYPE(obj) == RUBY_T_FLOAT; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_DYNAMIC_SYM_P(VALUE obj) +{ + if (RB_SPECIAL_CONST_P(obj)) { + return false; + } + else { + return RB_BUILTIN_TYPE(obj) == RUBY_T_SYMBOL; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_SYMBOL_P(VALUE obj) +{ + return RB_STATIC_SYM_P(obj) || RB_DYNAMIC_SYM_P(obj); +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +RBIMPL_ATTR_FORCEINLINE() +static bool +rbimpl_RB_TYPE_P_fastpath(VALUE obj, enum ruby_value_type t) +{ + if (t == RUBY_T_TRUE) { + return obj == RUBY_Qtrue; + } + else if (t == RUBY_T_FALSE) { + return obj == RUBY_Qfalse; + } + else if (t == RUBY_T_NIL) { + return obj == RUBY_Qnil; + } + else if (t == RUBY_T_UNDEF) { + return obj == RUBY_Qundef; + } + else if (t == RUBY_T_FIXNUM) { + return RB_FIXNUM_P(obj); + } + else if (t == RUBY_T_SYMBOL) { + return RB_SYMBOL_P(obj); + } + else if (t == RUBY_T_FLOAT) { + return RB_FLOAT_TYPE_P(obj); + } + else if (RB_SPECIAL_CONST_P(obj)) { + return false; + } + else if (t == RB_BUILTIN_TYPE(obj)) { + return true; + } + else { + return false; + } +} + +RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_ARTIFICIAL() +static inline bool +RB_TYPE_P(VALUE obj, enum ruby_value_type t) +{ + if (RBIMPL_CONSTANT_P(t)) { + return rbimpl_RB_TYPE_P_fastpath(obj, t); + } + else { + return t == rb_type(obj); + } +} + +/** @cond INTERNAL_MACRO */ +/* Clang, unlike GCC, cannot propagate __builtin_constant_p beyond function + * boundary. */ +#if defined(__clang__) +# undef RB_TYPE_P +# define RB_TYPE_P(obj, t) \ + (RBIMPL_CONSTANT_P(t) ? \ + rbimpl_RB_TYPE_P_fastpath((obj), (t)) : \ + (RB_TYPE_P)((obj), (t))) +#endif + +/* clang 3.x (4.2 compatible) can't eliminate CSE of RB_BUILTIN_TYPE + * in inline function and caller function + * See also 8998c06461ea0bef11b3aeb30b6d2ab71c8762ba + */ +#if RBIMPL_COMPILER_BEFORE(Clang, 4, 0, 0) +# undef rb_integer_type_p +# define rb_integer_type_p(obj) \ + __extension__ ({ \ + const VALUE integer_type_obj = (obj); \ + (RB_FIXNUM_P(integer_type_obj) || \ + (!RB_SPECIAL_CONST_P(integer_type_obj) && \ + RB_BUILTIN_TYPE(integer_type_obj) == RUBY_T_BIGNUM)); \ + }) +#endif +/** @endcond */ + +RBIMPL_ATTR_PURE() +RBIMPL_ATTR_ARTIFICIAL() +/* Defined in ruby/impl/core/rtypeddata.h */ +static inline bool rbimpl_rtypeddata_p(VALUE obj); + +RBIMPL_ATTR_ARTIFICIAL() +static inline void +Check_Type(VALUE v, enum ruby_value_type t) +{ + if (RB_UNLIKELY(! RB_TYPE_P(v, t))) { + goto slowpath; + } + else if (t != RUBY_T_DATA) { + goto fastpath; + } + else if (rbimpl_rtypeddata_p(v)) { + /* The intention itself is not necessarily clear to me, but at least it + * is intentional to rule out typed data here. See commit + * a7c32bf81d3391cfb78cfda278f469717d0fb794. */ + goto slowpath; + } + else { + goto fastpath; + } + + fastpath: + return; + + slowpath: /* <- :TODO: mark this label as cold. */ + rb_check_type(v, t); +} + +#endif /* RBIMPL_VALUE_TYPE_H */ diff --git a/include/ruby/internal/variable.h b/include/ruby/internal/variable.h new file mode 100644 index 0000000000..70aa43ea44 --- /dev/null +++ b/include/ruby/internal/variable.h @@ -0,0 +1,62 @@ +#ifndef RBIMPL_VARIABLE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_VARIABLE_H +/** + * @file + * @author Ruby developers + * @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 C-function backended Ruby-global variables. + */ +#include "ruby/impl/dllexport.h" +#include "ruby/impl/value.h" +#include "ruby/impl/attr/noreturn.h" + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +typedef VALUE rb_gvar_getter_t(ID id, VALUE *data); +typedef void rb_gvar_setter_t(VALUE val, ID id, VALUE *data); +typedef void rb_gvar_marker_t(VALUE *var); + +rb_gvar_getter_t rb_gvar_undef_getter; +rb_gvar_setter_t rb_gvar_undef_setter; +rb_gvar_marker_t rb_gvar_undef_marker; + +rb_gvar_getter_t rb_gvar_val_getter; +rb_gvar_setter_t rb_gvar_val_setter; +rb_gvar_marker_t rb_gvar_val_marker; + +rb_gvar_getter_t rb_gvar_var_getter; +rb_gvar_setter_t rb_gvar_var_setter; +rb_gvar_marker_t rb_gvar_var_marker; + +RBIMPL_ATTR_NORETURN() +rb_gvar_setter_t rb_gvar_readonly_setter; + +void rb_define_variable(const char*,VALUE*); +void rb_define_virtual_variable(const char*,rb_gvar_getter_t*,rb_gvar_setter_t*); +void rb_define_hooked_variable(const char*,VALUE*,rb_gvar_getter_t*,rb_gvar_setter_t*); +void rb_define_readonly_variable(const char*,const VALUE*); +void rb_define_const(VALUE,const char*,VALUE); +void rb_define_global_const(const char*,VALUE); + +VALUE rb_gv_set(const char*, VALUE); +VALUE rb_gv_get(const char*); +VALUE rb_iv_get(VALUE, const char*); +VALUE rb_iv_set(VALUE, const char*, VALUE); + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_VARIABLE_H */ diff --git a/include/ruby/internal/warning_push.h b/include/ruby/internal/warning_push.h new file mode 100644 index 0000000000..e13e749b82 --- /dev/null +++ b/include/ruby/internal/warning_push.h @@ -0,0 +1,91 @@ +#ifndef RBIMPL_WARNING_PUSH_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_WARNING_PUSH_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines RBIMPL_WARNING_PUSH. + * @cond INTERNAL_MACRO + * + * ### Q&A ### + * + * Q: Why all the macros defined in this file are function-like macros? + * + * A: Sigh. This is because of Doxgen. Its `SKIP_FUNCTION_MACROS = YES` + * configuration setting requests us that if we want it to ignore these + * macros, then we have to do two things: (1) let them be defined as + * function-like macros, and (2) place them separately in their own line, + * like below: + * + * ```CXX + * // NG -- foo's type considered something like `unsigned int`. + * RBIMPL_WARNING_PUSH + * int foo(void); + * RBIMPL_WARNING_POP + * + * // OK -- the macros are ignored by Doxygen. + * RBIMPL_WARNING_PUSH() + * int foo(void); + * RBIMPL_WARNING_POP() + * ``` + */ +#include "ruby/impl/compiler_is.h" +#include "ruby/impl/compiler_since.h" + +#if RBIMPL_COMPILER_SINCE(MSVC, 12, 0, 0) +# /* Not sure exactly when but it seems VC++ 6.0 is a version with it.*/ +# define RBIMPL_WARNING_PUSH() __pragma(warning(push)) +# define RBIMPL_WARNING_POP() __pragma(warning(pop)) +# define RBIMPL_WARNING_ERROR(flag) __pragma(warning(error: flag)) +# define RBIMPL_WARNING_IGNORED(flag) __pragma(warning(disable: flag)) + +#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0) +# define RBIMPL_WARNING_PUSH() __pragma(warning(push)) +# define RBIMPL_WARNING_POP() __pragma(warning(pop)) +# define RBIMPL_WARNING_ERROR(flag) __pragma(warning(error: flag)) +# define RBIMPL_WARNING_IGNORED(flag) __pragma(warning(disable: flag)) + +#elif RBIMPL_COMPILER_IS(Clang) || RBIMPL_COMPILER_IS(Apple) +# /* Not sure exactly when but it seems LLVM 2.6.0 is a version with it. */ +# define RBIMPL_WARNING_PRAGMA0(x) _Pragma(# x) +# define RBIMPL_WARNING_PRAGMA1(x) RBIMPL_WARNING_PRAGMA0(clang diagnostic x) +# define RBIMPL_WARNING_PRAGMA2(x, y) RBIMPL_WARNING_PRAGMA1(x # y) +# define RBIMPL_WARNING_PUSH() RBIMPL_WARNING_PRAGMA1(push) +# define RBIMPL_WARNING_POP() RBIMPL_WARNING_PRAGMA1(pop) +# define RBIMPL_WARNING_ERROR(flag) RBIMPL_WARNING_PRAGMA2(error, flag) +# define RBIMPL_WARNING_IGNORED(flag) RBIMPL_WARNING_PRAGMA2(ignored, flag) + +#elif RBIMPL_COMPILER_SINCE(GCC, 4, 6, 0) +# /* https://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Diagnostic-Pragmas.html */ +# define RBIMPL_WARNING_PRAGMA0(x) _Pragma(# x) +# define RBIMPL_WARNING_PRAGMA1(x) RBIMPL_WARNING_PRAGMA0(GCC diagnostic x) +# define RBIMPL_WARNING_PRAGMA2(x, y) RBIMPL_WARNING_PRAGMA1(x # y) +# define RBIMPL_WARNING_PUSH() RBIMPL_WARNING_PRAGMA1(push) +# define RBIMPL_WARNING_POP() RBIMPL_WARNING_PRAGMA1(pop) +# define RBIMPL_WARNING_ERROR(flag) RBIMPL_WARNING_PRAGMA2(error, flag) +# define RBIMPL_WARNING_IGNORED(flag) RBIMPL_WARNING_PRAGMA2(ignored, flag) + +#else +# /* :FIXME: improve here */ +# define RBIMPL_WARNING_PUSH() /* void */ +# define RBIMPL_WARNING_POP() /* void */ +# define RBIMPL_WARNING_ERROR(flag) /* void */ +# define RBIMPL_WARNING_IGNORED(flag) /* void */ +#endif /* _MSC_VER */ +/** @endcond */ + +#endif /* RBIMPL_WARNING_PUSH_H */ diff --git a/include/ruby/internal/xmalloc.h b/include/ruby/internal/xmalloc.h new file mode 100644 index 0000000000..145a3e236f --- /dev/null +++ b/include/ruby/internal/xmalloc.h @@ -0,0 +1,201 @@ +#ifndef RBIMPL_XMALLOC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RBIMPL_XMALLOC_H +/** + * @file + * @author Ruby developers + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Declares ::ruby_xmalloc(). + */ +#include "ruby/impl/config.h" + +#ifdef STDC_HEADERS +# include +#endif + +#ifdef HAVE_STDLIB_H +# include +#endif + +#include "ruby/impl/attr/alloc_size.h" +#include "ruby/impl/attr/nodiscard.h" +#include "ruby/impl/attr/noexcept.h" +#include "ruby/impl/attr/restrict.h" +#include "ruby/impl/attr/returns_nonnull.h" +#include "ruby/impl/dllexport.h" + +#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS +# define USE_GC_MALLOC_OBJ_INFO_DETAILS 0 +#endif + +#define xmalloc ruby_xmalloc +#define xmalloc2 ruby_xmalloc2 +#define xcalloc ruby_xcalloc +#define xrealloc ruby_xrealloc +#define xrealloc2 ruby_xrealloc2 +#define xfree ruby_xfree + +RBIMPL_SYMBOL_EXPORT_BEGIN() + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((1)) +void *ruby_xmalloc(size_t size) +RBIMPL_ATTR_NOEXCEPT(malloc(size)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((1,2)) +void *ruby_xmalloc2(size_t nelems, size_t elemsiz) +RBIMPL_ATTR_NOEXCEPT(malloc(nelems * elemsiz)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((1,2)) +void *ruby_xcalloc(size_t nelems, size_t elemsiz) +RBIMPL_ATTR_NOEXCEPT(calloc(nelems, elemsiz)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((2)) +void *ruby_xrealloc(void *ptr, size_t newsiz) +RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newsiz)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((2,3)) +void *ruby_xrealloc2(void *ptr, size_t newelems, size_t newsiz) +RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz)) +; + +void ruby_xfree(void *ptr) +RBIMPL_ATTR_NOEXCEPT(free(ptr)) +; + +#if USE_GC_MALLOC_OBJ_INFO_DETAILS || defined(__DOXYGEN) +# define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__) +# define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__) +# define ruby_xcalloc(s1, s2) ruby_xcalloc_with_location(s1, s2, __FILE__, __LINE__) +# define ruby_xrealloc(ptr, s1) ruby_xrealloc_with_location(ptr, s1, __FILE__, __LINE__) +# define ruby_xrealloc2(ptr, s1, s2) ruby_xrealloc2_with_location(ptr, s1, s2, __FILE__, __LINE__) + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((1)) +void *ruby_xmalloc_body(size_t size) +RBIMPL_ATTR_NOEXCEPT(malloc(size)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((1,2)) +void *ruby_xmalloc2_body(size_t nelems, size_t elemsiz) +RBIMPL_ATTR_NOEXCEPT(malloc(nelems * elemsiz)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RESTRICT() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((1,2)) +void *ruby_xcalloc_body(size_t nelems, size_t elemsiz) +RBIMPL_ATTR_NOEXCEPT(calloc(nelems, elemsiz)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((2)) +void *ruby_xrealloc_body(void *ptr, size_t newsiz) +RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newsiz)) +; + +RBIMPL_ATTR_NODISCARD() +RBIMPL_ATTR_RETURNS_NONNULL() +RBIMPL_ATTR_ALLOC_SIZE((2,3)) +void *ruby_xrealloc2_body(void *ptr, size_t newelems, size_t newsiz) +RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz)) +; + +RUBY_EXTERN const char *ruby_malloc_info_file; +RUBY_EXTERN int ruby_malloc_info_line; + +static inline void * +ruby_xmalloc_with_location(size_t s, const char *file, int line) +{ + void *ptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + ptr = ruby_xmalloc_body(s); + ruby_malloc_info_file = NULL; + return ptr; +} + +static inline void * +ruby_xmalloc2_with_location(size_t s1, size_t s2, const char *file, int line) +{ + void *ptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + ptr = ruby_xmalloc2_body(s1, s2); + ruby_malloc_info_file = NULL; + return ptr; +} + +static inline void * +ruby_xcalloc_with_location(size_t s1, size_t s2, const char *file, int line) +{ + void *ptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + ptr = ruby_xcalloc_body(s1, s2); + ruby_malloc_info_file = NULL; + return ptr; +} + +static inline void * +ruby_xrealloc_with_location(void *ptr, size_t s, const char *file, int line) +{ + void *rptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + rptr = ruby_xrealloc_body(ptr, s); + ruby_malloc_info_file = NULL; + return rptr; +} + +static inline void * +ruby_xrealloc2_with_location(void *ptr, size_t s1, size_t s2, const char *file, int line) +{ + void *rptr; + ruby_malloc_info_file = file; + ruby_malloc_info_line = line; + rptr = ruby_xrealloc2_body(ptr, s1, s2); + ruby_malloc_info_file = NULL; + return rptr; +} +#endif + +RBIMPL_SYMBOL_EXPORT_END() + +#endif /* RBIMPL_XMALLOC_H */ -- cgit v1.2.3