diff options
Diffstat (limited to 'ext')
189 files changed, 2403 insertions, 13960 deletions
diff --git a/ext/-test-/RUBY_ALIGNOF/depend b/ext/-test-/RUBY_ALIGNOF/depend index f12fdf59cc..21ef8c6dd0 100644 --- a/ext/-test-/RUBY_ALIGNOF/depend +++ b/ext/-test-/RUBY_ALIGNOF/depend @@ -14,6 +14,7 @@ c.o: $(hdrdir)/ruby/backward/2/stdalign.h c.o: $(hdrdir)/ruby/backward/2/stdarg.h c.o: $(hdrdir)/ruby/defines.h c.o: $(hdrdir)/ruby/intern.h +c.o: $(hdrdir)/ruby/internal/abi.h c.o: $(hdrdir)/ruby/internal/anyargs.h c.o: $(hdrdir)/ruby/internal/arithmetic.h c.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/abi/abi.c b/ext/-test-/abi/abi.c new file mode 100644 index 0000000000..923e0f67b8 --- /dev/null +++ b/ext/-test-/abi/abi.c @@ -0,0 +1,11 @@ +#include <limits.h> + +unsigned long long +ruby_abi_version(void) +{ + return ULONG_MAX; +} + +void +Init_abi(void) +{} diff --git a/ext/-test-/abi/extconf.rb b/ext/-test-/abi/extconf.rb new file mode 100644 index 0000000000..d786b15db9 --- /dev/null +++ b/ext/-test-/abi/extconf.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: false +require_relative "../auto_ext.rb" +auto_ext(inc: true) diff --git a/ext/-test-/arith_seq/extract/depend b/ext/-test-/arith_seq/extract/depend index ac77825275..57cbaa9a0c 100644 --- a/ext/-test-/arith_seq/extract/depend +++ b/ext/-test-/arith_seq/extract/depend @@ -13,6 +13,7 @@ extract.o: $(hdrdir)/ruby/backward/2/stdalign.h extract.o: $(hdrdir)/ruby/backward/2/stdarg.h extract.o: $(hdrdir)/ruby/defines.h extract.o: $(hdrdir)/ruby/intern.h +extract.o: $(hdrdir)/ruby/internal/abi.h extract.o: $(hdrdir)/ruby/internal/anyargs.h extract.o: $(hdrdir)/ruby/internal/arithmetic.h extract.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/array/concat/depend b/ext/-test-/array/concat/depend index e1d49bc648..79c833738e 100644 --- a/ext/-test-/array/concat/depend +++ b/ext/-test-/array/concat/depend @@ -14,6 +14,7 @@ to_ary_concat.o: $(hdrdir)/ruby/backward/2/stdalign.h to_ary_concat.o: $(hdrdir)/ruby/backward/2/stdarg.h to_ary_concat.o: $(hdrdir)/ruby/defines.h to_ary_concat.o: $(hdrdir)/ruby/intern.h +to_ary_concat.o: $(hdrdir)/ruby/internal/abi.h to_ary_concat.o: $(hdrdir)/ruby/internal/anyargs.h to_ary_concat.o: $(hdrdir)/ruby/internal/arithmetic.h to_ary_concat.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/array/resize/depend b/ext/-test-/array/resize/depend index bd0b1bf280..49e0f346d3 100644 --- a/ext/-test-/array/resize/depend +++ b/ext/-test-/array/resize/depend @@ -13,6 +13,7 @@ resize.o: $(hdrdir)/ruby/backward/2/stdalign.h resize.o: $(hdrdir)/ruby/backward/2/stdarg.h resize.o: $(hdrdir)/ruby/defines.h resize.o: $(hdrdir)/ruby/intern.h +resize.o: $(hdrdir)/ruby/internal/abi.h resize.o: $(hdrdir)/ruby/internal/anyargs.h resize.o: $(hdrdir)/ruby/internal/arithmetic.h resize.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/bignum/depend b/ext/-test-/bignum/depend index 28edc15f2b..d4072fb35c 100644 --- a/ext/-test-/bignum/depend +++ b/ext/-test-/bignum/depend @@ -13,6 +13,7 @@ big2str.o: $(hdrdir)/ruby/backward/2/stdalign.h big2str.o: $(hdrdir)/ruby/backward/2/stdarg.h big2str.o: $(hdrdir)/ruby/defines.h big2str.o: $(hdrdir)/ruby/intern.h +big2str.o: $(hdrdir)/ruby/internal/abi.h big2str.o: $(hdrdir)/ruby/internal/anyargs.h big2str.o: $(hdrdir)/ruby/internal/arithmetic.h big2str.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -172,6 +173,7 @@ bigzero.o: $(hdrdir)/ruby/backward/2/stdalign.h bigzero.o: $(hdrdir)/ruby/backward/2/stdarg.h bigzero.o: $(hdrdir)/ruby/defines.h bigzero.o: $(hdrdir)/ruby/intern.h +bigzero.o: $(hdrdir)/ruby/internal/abi.h bigzero.o: $(hdrdir)/ruby/internal/anyargs.h bigzero.o: $(hdrdir)/ruby/internal/arithmetic.h bigzero.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -331,6 +333,7 @@ div.o: $(hdrdir)/ruby/backward/2/stdalign.h div.o: $(hdrdir)/ruby/backward/2/stdarg.h div.o: $(hdrdir)/ruby/defines.h div.o: $(hdrdir)/ruby/intern.h +div.o: $(hdrdir)/ruby/internal/abi.h div.o: $(hdrdir)/ruby/internal/anyargs.h div.o: $(hdrdir)/ruby/internal/arithmetic.h div.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -491,6 +494,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -649,6 +653,7 @@ intpack.o: $(hdrdir)/ruby/backward/2/stdalign.h intpack.o: $(hdrdir)/ruby/backward/2/stdarg.h intpack.o: $(hdrdir)/ruby/defines.h intpack.o: $(hdrdir)/ruby/intern.h +intpack.o: $(hdrdir)/ruby/internal/abi.h intpack.o: $(hdrdir)/ruby/internal/anyargs.h intpack.o: $(hdrdir)/ruby/internal/arithmetic.h intpack.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -808,6 +813,7 @@ mul.o: $(hdrdir)/ruby/backward/2/stdalign.h mul.o: $(hdrdir)/ruby/backward/2/stdarg.h mul.o: $(hdrdir)/ruby/defines.h mul.o: $(hdrdir)/ruby/intern.h +mul.o: $(hdrdir)/ruby/internal/abi.h mul.o: $(hdrdir)/ruby/internal/anyargs.h mul.o: $(hdrdir)/ruby/internal/arithmetic.h mul.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -967,6 +973,7 @@ str2big.o: $(hdrdir)/ruby/backward/2/stdalign.h str2big.o: $(hdrdir)/ruby/backward/2/stdarg.h str2big.o: $(hdrdir)/ruby/defines.h str2big.o: $(hdrdir)/ruby/intern.h +str2big.o: $(hdrdir)/ruby/internal/abi.h str2big.o: $(hdrdir)/ruby/internal/anyargs.h str2big.o: $(hdrdir)/ruby/internal/arithmetic.h str2big.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/bug-14834/depend b/ext/-test-/bug-14834/depend index 0867139906..7bac8409e8 100644 --- a/ext/-test-/bug-14834/depend +++ b/ext/-test-/bug-14834/depend @@ -14,6 +14,7 @@ bug-14384.o: $(hdrdir)/ruby/backward/2/stdarg.h bug-14384.o: $(hdrdir)/ruby/debug.h bug-14384.o: $(hdrdir)/ruby/defines.h bug-14384.o: $(hdrdir)/ruby/intern.h +bug-14384.o: $(hdrdir)/ruby/internal/abi.h bug-14384.o: $(hdrdir)/ruby/internal/anyargs.h bug-14384.o: $(hdrdir)/ruby/internal/arithmetic.h bug-14384.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/bug-3571/depend b/ext/-test-/bug-3571/depend index 73d1fec435..2303f47594 100644 --- a/ext/-test-/bug-3571/depend +++ b/ext/-test-/bug-3571/depend @@ -14,6 +14,7 @@ bug.o: $(hdrdir)/ruby/backward/2/stdalign.h bug.o: $(hdrdir)/ruby/backward/2/stdarg.h bug.o: $(hdrdir)/ruby/defines.h bug.o: $(hdrdir)/ruby/intern.h +bug.o: $(hdrdir)/ruby/internal/abi.h bug.o: $(hdrdir)/ruby/internal/anyargs.h bug.o: $(hdrdir)/ruby/internal/arithmetic.h bug.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/bug-5832/depend b/ext/-test-/bug-5832/depend index 73d1fec435..2303f47594 100644 --- a/ext/-test-/bug-5832/depend +++ b/ext/-test-/bug-5832/depend @@ -14,6 +14,7 @@ bug.o: $(hdrdir)/ruby/backward/2/stdalign.h bug.o: $(hdrdir)/ruby/backward/2/stdarg.h bug.o: $(hdrdir)/ruby/defines.h bug.o: $(hdrdir)/ruby/intern.h +bug.o: $(hdrdir)/ruby/internal/abi.h bug.o: $(hdrdir)/ruby/internal/anyargs.h bug.o: $(hdrdir)/ruby/internal/arithmetic.h bug.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/bug_reporter/depend b/ext/-test-/bug_reporter/depend index d36d0fb6c2..603dd53ebf 100644 --- a/ext/-test-/bug_reporter/depend +++ b/ext/-test-/bug_reporter/depend @@ -14,6 +14,7 @@ bug_reporter.o: $(hdrdir)/ruby/backward/2/stdalign.h bug_reporter.o: $(hdrdir)/ruby/backward/2/stdarg.h bug_reporter.o: $(hdrdir)/ruby/defines.h bug_reporter.o: $(hdrdir)/ruby/intern.h +bug_reporter.o: $(hdrdir)/ruby/internal/abi.h bug_reporter.o: $(hdrdir)/ruby/internal/anyargs.h bug_reporter.o: $(hdrdir)/ruby/internal/arithmetic.h bug_reporter.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/class/depend b/ext/-test-/class/depend index bb74e1f24d..a615eacd74 100644 --- a/ext/-test-/class/depend +++ b/ext/-test-/class/depend @@ -13,6 +13,7 @@ class2name.o: $(hdrdir)/ruby/backward/2/stdalign.h class2name.o: $(hdrdir)/ruby/backward/2/stdarg.h class2name.o: $(hdrdir)/ruby/defines.h class2name.o: $(hdrdir)/ruby/intern.h +class2name.o: $(hdrdir)/ruby/internal/abi.h class2name.o: $(hdrdir)/ruby/internal/anyargs.h class2name.o: $(hdrdir)/ruby/internal/arithmetic.h class2name.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -172,6 +173,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/debug/depend b/ext/-test-/debug/depend index 20f7be675b..c3a0c278aa 100644 --- a/ext/-test-/debug/depend +++ b/ext/-test-/debug/depend @@ -14,6 +14,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ inspector.o: $(hdrdir)/ruby/backward/2/stdarg.h inspector.o: $(hdrdir)/ruby/debug.h inspector.o: $(hdrdir)/ruby/defines.h inspector.o: $(hdrdir)/ruby/intern.h +inspector.o: $(hdrdir)/ruby/internal/abi.h inspector.o: $(hdrdir)/ruby/internal/anyargs.h inspector.o: $(hdrdir)/ruby/internal/arithmetic.h inspector.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -332,6 +334,7 @@ profile_frames.o: $(hdrdir)/ruby/backward/2/stdarg.h profile_frames.o: $(hdrdir)/ruby/debug.h profile_frames.o: $(hdrdir)/ruby/defines.h profile_frames.o: $(hdrdir)/ruby/intern.h +profile_frames.o: $(hdrdir)/ruby/internal/abi.h profile_frames.o: $(hdrdir)/ruby/internal/anyargs.h profile_frames.o: $(hdrdir)/ruby/internal/arithmetic.h profile_frames.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/dln/empty/depend b/ext/-test-/dln/empty/depend index 99151fa055..e16082a7dc 100644 --- a/ext/-test-/dln/empty/depend +++ b/ext/-test-/dln/empty/depend @@ -1,3 +1,162 @@ # AUTOGENERATED DEPENDENCIES START +empty.o: $(RUBY_EXTCONF_H) +empty.o: $(arch_hdrdir)/ruby/config.h +empty.o: $(hdrdir)/ruby.h +empty.o: $(hdrdir)/ruby/assert.h +empty.o: $(hdrdir)/ruby/backward.h +empty.o: $(hdrdir)/ruby/backward/2/assume.h +empty.o: $(hdrdir)/ruby/backward/2/attributes.h +empty.o: $(hdrdir)/ruby/backward/2/bool.h +empty.o: $(hdrdir)/ruby/backward/2/inttypes.h +empty.o: $(hdrdir)/ruby/backward/2/limits.h +empty.o: $(hdrdir)/ruby/backward/2/long_long.h +empty.o: $(hdrdir)/ruby/backward/2/stdalign.h +empty.o: $(hdrdir)/ruby/backward/2/stdarg.h +empty.o: $(hdrdir)/ruby/defines.h +empty.o: $(hdrdir)/ruby/intern.h +empty.o: $(hdrdir)/ruby/internal/abi.h +empty.o: $(hdrdir)/ruby/internal/anyargs.h +empty.o: $(hdrdir)/ruby/internal/arithmetic.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/char.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/double.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/fixnum.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/gid_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/int.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/intptr_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/long.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/long_long.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/mode_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/off_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/pid_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/short.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/size_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/st_data_t.h +empty.o: $(hdrdir)/ruby/internal/arithmetic/uid_t.h +empty.o: $(hdrdir)/ruby/internal/assume.h +empty.o: $(hdrdir)/ruby/internal/attr/alloc_size.h +empty.o: $(hdrdir)/ruby/internal/attr/artificial.h +empty.o: $(hdrdir)/ruby/internal/attr/cold.h +empty.o: $(hdrdir)/ruby/internal/attr/const.h +empty.o: $(hdrdir)/ruby/internal/attr/constexpr.h +empty.o: $(hdrdir)/ruby/internal/attr/deprecated.h +empty.o: $(hdrdir)/ruby/internal/attr/diagnose_if.h +empty.o: $(hdrdir)/ruby/internal/attr/enum_extensibility.h +empty.o: $(hdrdir)/ruby/internal/attr/error.h +empty.o: $(hdrdir)/ruby/internal/attr/flag_enum.h +empty.o: $(hdrdir)/ruby/internal/attr/forceinline.h +empty.o: $(hdrdir)/ruby/internal/attr/format.h +empty.o: $(hdrdir)/ruby/internal/attr/maybe_unused.h +empty.o: $(hdrdir)/ruby/internal/attr/noalias.h +empty.o: $(hdrdir)/ruby/internal/attr/nodiscard.h +empty.o: $(hdrdir)/ruby/internal/attr/noexcept.h +empty.o: $(hdrdir)/ruby/internal/attr/noinline.h +empty.o: $(hdrdir)/ruby/internal/attr/nonnull.h +empty.o: $(hdrdir)/ruby/internal/attr/noreturn.h +empty.o: $(hdrdir)/ruby/internal/attr/pure.h +empty.o: $(hdrdir)/ruby/internal/attr/restrict.h +empty.o: $(hdrdir)/ruby/internal/attr/returns_nonnull.h +empty.o: $(hdrdir)/ruby/internal/attr/warning.h +empty.o: $(hdrdir)/ruby/internal/attr/weakref.h +empty.o: $(hdrdir)/ruby/internal/cast.h +empty.o: $(hdrdir)/ruby/internal/compiler_is.h +empty.o: $(hdrdir)/ruby/internal/compiler_is/apple.h +empty.o: $(hdrdir)/ruby/internal/compiler_is/clang.h +empty.o: $(hdrdir)/ruby/internal/compiler_is/gcc.h +empty.o: $(hdrdir)/ruby/internal/compiler_is/intel.h +empty.o: $(hdrdir)/ruby/internal/compiler_is/msvc.h +empty.o: $(hdrdir)/ruby/internal/compiler_is/sunpro.h +empty.o: $(hdrdir)/ruby/internal/compiler_since.h +empty.o: $(hdrdir)/ruby/internal/config.h +empty.o: $(hdrdir)/ruby/internal/constant_p.h +empty.o: $(hdrdir)/ruby/internal/core.h +empty.o: $(hdrdir)/ruby/internal/core/rarray.h +empty.o: $(hdrdir)/ruby/internal/core/rbasic.h +empty.o: $(hdrdir)/ruby/internal/core/rbignum.h +empty.o: $(hdrdir)/ruby/internal/core/rclass.h +empty.o: $(hdrdir)/ruby/internal/core/rdata.h +empty.o: $(hdrdir)/ruby/internal/core/rfile.h +empty.o: $(hdrdir)/ruby/internal/core/rhash.h +empty.o: $(hdrdir)/ruby/internal/core/robject.h +empty.o: $(hdrdir)/ruby/internal/core/rregexp.h +empty.o: $(hdrdir)/ruby/internal/core/rstring.h +empty.o: $(hdrdir)/ruby/internal/core/rstruct.h +empty.o: $(hdrdir)/ruby/internal/core/rtypeddata.h +empty.o: $(hdrdir)/ruby/internal/ctype.h +empty.o: $(hdrdir)/ruby/internal/dllexport.h +empty.o: $(hdrdir)/ruby/internal/dosish.h +empty.o: $(hdrdir)/ruby/internal/error.h +empty.o: $(hdrdir)/ruby/internal/eval.h +empty.o: $(hdrdir)/ruby/internal/event.h +empty.o: $(hdrdir)/ruby/internal/fl_type.h +empty.o: $(hdrdir)/ruby/internal/gc.h +empty.o: $(hdrdir)/ruby/internal/glob.h +empty.o: $(hdrdir)/ruby/internal/globals.h +empty.o: $(hdrdir)/ruby/internal/has/attribute.h +empty.o: $(hdrdir)/ruby/internal/has/builtin.h +empty.o: $(hdrdir)/ruby/internal/has/c_attribute.h +empty.o: $(hdrdir)/ruby/internal/has/cpp_attribute.h +empty.o: $(hdrdir)/ruby/internal/has/declspec_attribute.h +empty.o: $(hdrdir)/ruby/internal/has/extension.h +empty.o: $(hdrdir)/ruby/internal/has/feature.h +empty.o: $(hdrdir)/ruby/internal/has/warning.h +empty.o: $(hdrdir)/ruby/internal/intern/array.h +empty.o: $(hdrdir)/ruby/internal/intern/bignum.h +empty.o: $(hdrdir)/ruby/internal/intern/class.h +empty.o: $(hdrdir)/ruby/internal/intern/compar.h +empty.o: $(hdrdir)/ruby/internal/intern/complex.h +empty.o: $(hdrdir)/ruby/internal/intern/cont.h +empty.o: $(hdrdir)/ruby/internal/intern/dir.h +empty.o: $(hdrdir)/ruby/internal/intern/enum.h +empty.o: $(hdrdir)/ruby/internal/intern/enumerator.h +empty.o: $(hdrdir)/ruby/internal/intern/error.h +empty.o: $(hdrdir)/ruby/internal/intern/eval.h +empty.o: $(hdrdir)/ruby/internal/intern/file.h +empty.o: $(hdrdir)/ruby/internal/intern/gc.h +empty.o: $(hdrdir)/ruby/internal/intern/hash.h +empty.o: $(hdrdir)/ruby/internal/intern/io.h +empty.o: $(hdrdir)/ruby/internal/intern/load.h +empty.o: $(hdrdir)/ruby/internal/intern/marshal.h +empty.o: $(hdrdir)/ruby/internal/intern/numeric.h +empty.o: $(hdrdir)/ruby/internal/intern/object.h +empty.o: $(hdrdir)/ruby/internal/intern/parse.h +empty.o: $(hdrdir)/ruby/internal/intern/proc.h +empty.o: $(hdrdir)/ruby/internal/intern/process.h +empty.o: $(hdrdir)/ruby/internal/intern/random.h +empty.o: $(hdrdir)/ruby/internal/intern/range.h +empty.o: $(hdrdir)/ruby/internal/intern/rational.h +empty.o: $(hdrdir)/ruby/internal/intern/re.h +empty.o: $(hdrdir)/ruby/internal/intern/ruby.h +empty.o: $(hdrdir)/ruby/internal/intern/select.h +empty.o: $(hdrdir)/ruby/internal/intern/select/largesize.h +empty.o: $(hdrdir)/ruby/internal/intern/signal.h +empty.o: $(hdrdir)/ruby/internal/intern/sprintf.h +empty.o: $(hdrdir)/ruby/internal/intern/string.h +empty.o: $(hdrdir)/ruby/internal/intern/struct.h +empty.o: $(hdrdir)/ruby/internal/intern/thread.h +empty.o: $(hdrdir)/ruby/internal/intern/time.h +empty.o: $(hdrdir)/ruby/internal/intern/variable.h +empty.o: $(hdrdir)/ruby/internal/intern/vm.h +empty.o: $(hdrdir)/ruby/internal/interpreter.h +empty.o: $(hdrdir)/ruby/internal/iterator.h +empty.o: $(hdrdir)/ruby/internal/memory.h +empty.o: $(hdrdir)/ruby/internal/method.h +empty.o: $(hdrdir)/ruby/internal/module.h +empty.o: $(hdrdir)/ruby/internal/newobj.h +empty.o: $(hdrdir)/ruby/internal/rgengc.h +empty.o: $(hdrdir)/ruby/internal/scan_args.h +empty.o: $(hdrdir)/ruby/internal/special_consts.h +empty.o: $(hdrdir)/ruby/internal/static_assert.h +empty.o: $(hdrdir)/ruby/internal/stdalign.h +empty.o: $(hdrdir)/ruby/internal/stdbool.h +empty.o: $(hdrdir)/ruby/internal/symbol.h +empty.o: $(hdrdir)/ruby/internal/value.h +empty.o: $(hdrdir)/ruby/internal/value_type.h +empty.o: $(hdrdir)/ruby/internal/variable.h +empty.o: $(hdrdir)/ruby/internal/warning_push.h +empty.o: $(hdrdir)/ruby/internal/xmalloc.h +empty.o: $(hdrdir)/ruby/missing.h +empty.o: $(hdrdir)/ruby/ruby.h +empty.o: $(hdrdir)/ruby/st.h +empty.o: $(hdrdir)/ruby/subst.h empty.o: empty.c # AUTOGENERATED DEPENDENCIES END diff --git a/ext/-test-/dln/empty/empty.c b/ext/-test-/dln/empty/empty.c index c4f94f1644..2b4fd42cd2 100644 --- a/ext/-test-/dln/empty/empty.c +++ b/ext/-test-/dln/empty/empty.c @@ -1,3 +1,5 @@ +#include "ruby.h" + void Init_empty(void) { diff --git a/ext/-test-/enumerator_kw/depend b/ext/-test-/enumerator_kw/depend index 4347538d37..14a9557e41 100644 --- a/ext/-test-/enumerator_kw/depend +++ b/ext/-test-/enumerator_kw/depend @@ -14,6 +14,7 @@ enumerator_kw.o: $(hdrdir)/ruby/backward/2/stdalign.h enumerator_kw.o: $(hdrdir)/ruby/backward/2/stdarg.h enumerator_kw.o: $(hdrdir)/ruby/defines.h enumerator_kw.o: $(hdrdir)/ruby/intern.h +enumerator_kw.o: $(hdrdir)/ruby/internal/abi.h enumerator_kw.o: $(hdrdir)/ruby/internal/anyargs.h enumerator_kw.o: $(hdrdir)/ruby/internal/arithmetic.h enumerator_kw.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/exception/depend b/ext/-test-/exception/depend index 05f6ff6552..e00f0b279d 100644 --- a/ext/-test-/exception/depend +++ b/ext/-test-/exception/depend @@ -13,6 +13,7 @@ dataerror.o: $(hdrdir)/ruby/backward/2/stdalign.h dataerror.o: $(hdrdir)/ruby/backward/2/stdarg.h dataerror.o: $(hdrdir)/ruby/defines.h dataerror.o: $(hdrdir)/ruby/intern.h +dataerror.o: $(hdrdir)/ruby/internal/abi.h dataerror.o: $(hdrdir)/ruby/internal/anyargs.h dataerror.o: $(hdrdir)/ruby/internal/arithmetic.h dataerror.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ enc_raise.o: $(hdrdir)/ruby/backward/2/stdarg.h enc_raise.o: $(hdrdir)/ruby/defines.h enc_raise.o: $(hdrdir)/ruby/encoding.h enc_raise.o: $(hdrdir)/ruby/intern.h +enc_raise.o: $(hdrdir)/ruby/internal/abi.h enc_raise.o: $(hdrdir)/ruby/internal/anyargs.h enc_raise.o: $(hdrdir)/ruby/internal/arithmetic.h enc_raise.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -343,6 +345,7 @@ ensured.o: $(hdrdir)/ruby/backward/2/stdalign.h ensured.o: $(hdrdir)/ruby/backward/2/stdarg.h ensured.o: $(hdrdir)/ruby/defines.h ensured.o: $(hdrdir)/ruby/intern.h +ensured.o: $(hdrdir)/ruby/internal/abi.h ensured.o: $(hdrdir)/ruby/internal/anyargs.h ensured.o: $(hdrdir)/ruby/internal/arithmetic.h ensured.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -502,6 +505,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/fatal/depend b/ext/-test-/fatal/depend index ccb274e8f8..5b1adb6607 100644 --- a/ext/-test-/fatal/depend +++ b/ext/-test-/fatal/depend @@ -14,6 +14,7 @@ rb_fatal.o: $(hdrdir)/ruby/backward/2/stdalign.h rb_fatal.o: $(hdrdir)/ruby/backward/2/stdarg.h rb_fatal.o: $(hdrdir)/ruby/defines.h rb_fatal.o: $(hdrdir)/ruby/intern.h +rb_fatal.o: $(hdrdir)/ruby/internal/abi.h rb_fatal.o: $(hdrdir)/ruby/internal/anyargs.h rb_fatal.o: $(hdrdir)/ruby/internal/arithmetic.h rb_fatal.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/file/depend b/ext/-test-/file/depend index a6ac8bb55c..f0fffc2485 100644 --- a/ext/-test-/file/depend +++ b/ext/-test-/file/depend @@ -14,6 +14,7 @@ fs.o: $(hdrdir)/ruby/backward/2/stdarg.h fs.o: $(hdrdir)/ruby/defines.h fs.o: $(hdrdir)/ruby/encoding.h fs.o: $(hdrdir)/ruby/intern.h +fs.o: $(hdrdir)/ruby/internal/abi.h fs.o: $(hdrdir)/ruby/internal/anyargs.h fs.o: $(hdrdir)/ruby/internal/arithmetic.h fs.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -185,6 +186,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -344,6 +346,7 @@ stat.o: $(hdrdir)/ruby/backward/2/stdarg.h stat.o: $(hdrdir)/ruby/defines.h stat.o: $(hdrdir)/ruby/encoding.h stat.o: $(hdrdir)/ruby/intern.h +stat.o: $(hdrdir)/ruby/internal/abi.h stat.o: $(hdrdir)/ruby/internal/anyargs.h stat.o: $(hdrdir)/ruby/internal/arithmetic.h stat.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/file/fs.c b/ext/-test-/file/fs.c index 63d2356d76..1a6c3d06dc 100644 --- a/ext/-test-/file/fs.c +++ b/ext/-test-/file/fs.c @@ -28,7 +28,7 @@ typedef struct statvfs statfs_t; # if defined HAVE_STRUCT_STATVFS_F_TYPE # define HAVE_STRUCT_STATFS_T_F_TYPE 1 # endif -#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE) /* AIX, HP-UX, Solaris */ +#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE) /* AIX, Solaris */ typedef struct statvfs statfs_t; # define STATFS(f, s) statvfs((f), (s)) # define HAVE_STRUCT_STATFS_T_F_FSTYPENAME 1 diff --git a/ext/-test-/float/depend b/ext/-test-/float/depend index 661f4876d8..9391a445a3 100644 --- a/ext/-test-/float/depend +++ b/ext/-test-/float/depend @@ -17,6 +17,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -176,6 +177,7 @@ nextafter.o: $(hdrdir)/ruby/backward/2/stdalign.h nextafter.o: $(hdrdir)/ruby/backward/2/stdarg.h nextafter.o: $(hdrdir)/ruby/defines.h nextafter.o: $(hdrdir)/ruby/intern.h +nextafter.o: $(hdrdir)/ruby/internal/abi.h nextafter.o: $(hdrdir)/ruby/internal/anyargs.h nextafter.o: $(hdrdir)/ruby/internal/arithmetic.h nextafter.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/funcall/depend b/ext/-test-/funcall/depend index adec76f144..24e8c54bd9 100644 --- a/ext/-test-/funcall/depend +++ b/ext/-test-/funcall/depend @@ -14,6 +14,7 @@ funcall.o: $(hdrdir)/ruby/backward/2/stdalign.h funcall.o: $(hdrdir)/ruby/backward/2/stdarg.h funcall.o: $(hdrdir)/ruby/defines.h funcall.o: $(hdrdir)/ruby/intern.h +funcall.o: $(hdrdir)/ruby/internal/abi.h funcall.o: $(hdrdir)/ruby/internal/anyargs.h funcall.o: $(hdrdir)/ruby/internal/arithmetic.h funcall.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/gvl/call_without_gvl/depend b/ext/-test-/gvl/call_without_gvl/depend index d74a525224..cd184aa01c 100644 --- a/ext/-test-/gvl/call_without_gvl/depend +++ b/ext/-test-/gvl/call_without_gvl/depend @@ -13,6 +13,7 @@ call_without_gvl.o: $(hdrdir)/ruby/backward/2/stdalign.h call_without_gvl.o: $(hdrdir)/ruby/backward/2/stdarg.h call_without_gvl.o: $(hdrdir)/ruby/defines.h call_without_gvl.o: $(hdrdir)/ruby/intern.h +call_without_gvl.o: $(hdrdir)/ruby/internal/abi.h call_without_gvl.o: $(hdrdir)/ruby/internal/anyargs.h call_without_gvl.o: $(hdrdir)/ruby/internal/arithmetic.h call_without_gvl.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/hash/depend b/ext/-test-/hash/depend index b8460734ce..a8bc47e640 100644 --- a/ext/-test-/hash/depend +++ b/ext/-test-/hash/depend @@ -14,6 +14,7 @@ delete.o: $(hdrdir)/ruby/backward/2/stdalign.h delete.o: $(hdrdir)/ruby/backward/2/stdarg.h delete.o: $(hdrdir)/ruby/defines.h delete.o: $(hdrdir)/ruby/intern.h +delete.o: $(hdrdir)/ruby/internal/abi.h delete.o: $(hdrdir)/ruby/internal/anyargs.h delete.o: $(hdrdir)/ruby/internal/arithmetic.h delete.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/integer/depend b/ext/-test-/integer/depend index 522f6283ac..b12159f308 100644 --- a/ext/-test-/integer/depend +++ b/ext/-test-/integer/depend @@ -14,6 +14,7 @@ core_ext.o: $(hdrdir)/ruby/backward/2/stdalign.h core_ext.o: $(hdrdir)/ruby/backward/2/stdarg.h core_ext.o: $(hdrdir)/ruby/defines.h core_ext.o: $(hdrdir)/ruby/intern.h +core_ext.o: $(hdrdir)/ruby/internal/abi.h core_ext.o: $(hdrdir)/ruby/internal/anyargs.h core_ext.o: $(hdrdir)/ruby/internal/arithmetic.h core_ext.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -181,6 +182,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -340,6 +342,7 @@ my_integer.o: $(hdrdir)/ruby/backward/2/stdalign.h my_integer.o: $(hdrdir)/ruby/backward/2/stdarg.h my_integer.o: $(hdrdir)/ruby/defines.h my_integer.o: $(hdrdir)/ruby/intern.h +my_integer.o: $(hdrdir)/ruby/internal/abi.h my_integer.o: $(hdrdir)/ruby/internal/anyargs.h my_integer.o: $(hdrdir)/ruby/internal/arithmetic.h my_integer.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/iseq_load/depend b/ext/-test-/iseq_load/depend index cffd631383..308956550c 100644 --- a/ext/-test-/iseq_load/depend +++ b/ext/-test-/iseq_load/depend @@ -14,6 +14,7 @@ iseq_load.o: $(hdrdir)/ruby/backward/2/stdalign.h iseq_load.o: $(hdrdir)/ruby/backward/2/stdarg.h iseq_load.o: $(hdrdir)/ruby/defines.h iseq_load.o: $(hdrdir)/ruby/intern.h +iseq_load.o: $(hdrdir)/ruby/internal/abi.h iseq_load.o: $(hdrdir)/ruby/internal/anyargs.h iseq_load.o: $(hdrdir)/ruby/internal/arithmetic.h iseq_load.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/iter/depend b/ext/-test-/iter/depend index 5bda724d22..d14c164cd4 100644 --- a/ext/-test-/iter/depend +++ b/ext/-test-/iter/depend @@ -14,6 +14,7 @@ break.o: $(hdrdir)/ruby/backward/2/stdalign.h break.o: $(hdrdir)/ruby/backward/2/stdarg.h break.o: $(hdrdir)/ruby/defines.h break.o: $(hdrdir)/ruby/intern.h +break.o: $(hdrdir)/ruby/internal/abi.h break.o: $(hdrdir)/ruby/internal/anyargs.h break.o: $(hdrdir)/ruby/internal/arithmetic.h break.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -332,6 +334,7 @@ yield.o: $(hdrdir)/ruby/backward/2/stdalign.h yield.o: $(hdrdir)/ruby/backward/2/stdarg.h yield.o: $(hdrdir)/ruby/defines.h yield.o: $(hdrdir)/ruby/intern.h +yield.o: $(hdrdir)/ruby/internal/abi.h yield.o: $(hdrdir)/ruby/internal/anyargs.h yield.o: $(hdrdir)/ruby/internal/arithmetic.h yield.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/load/dot.dot/depend b/ext/-test-/load/dot.dot/depend index a0445e288b..d8b8937c3c 100644 --- a/ext/-test-/load/dot.dot/depend +++ b/ext/-test-/load/dot.dot/depend @@ -1,3 +1,162 @@ # AUTOGENERATED DEPENDENCIES START +dot.dot.o: $(RUBY_EXTCONF_H) +dot.dot.o: $(arch_hdrdir)/ruby/config.h +dot.dot.o: $(hdrdir)/ruby.h +dot.dot.o: $(hdrdir)/ruby/assert.h +dot.dot.o: $(hdrdir)/ruby/backward.h +dot.dot.o: $(hdrdir)/ruby/backward/2/assume.h +dot.dot.o: $(hdrdir)/ruby/backward/2/attributes.h +dot.dot.o: $(hdrdir)/ruby/backward/2/bool.h +dot.dot.o: $(hdrdir)/ruby/backward/2/inttypes.h +dot.dot.o: $(hdrdir)/ruby/backward/2/limits.h +dot.dot.o: $(hdrdir)/ruby/backward/2/long_long.h +dot.dot.o: $(hdrdir)/ruby/backward/2/stdalign.h +dot.dot.o: $(hdrdir)/ruby/backward/2/stdarg.h +dot.dot.o: $(hdrdir)/ruby/defines.h +dot.dot.o: $(hdrdir)/ruby/intern.h +dot.dot.o: $(hdrdir)/ruby/internal/abi.h +dot.dot.o: $(hdrdir)/ruby/internal/anyargs.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/char.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/double.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/fixnum.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/gid_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/int.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/intptr_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/long.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/long_long.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/mode_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/off_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/pid_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/short.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/size_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/st_data_t.h +dot.dot.o: $(hdrdir)/ruby/internal/arithmetic/uid_t.h +dot.dot.o: $(hdrdir)/ruby/internal/assume.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/alloc_size.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/artificial.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/cold.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/const.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/constexpr.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/deprecated.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/diagnose_if.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/enum_extensibility.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/error.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/flag_enum.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/forceinline.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/format.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/maybe_unused.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/noalias.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/nodiscard.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/noexcept.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/noinline.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/nonnull.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/noreturn.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/pure.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/restrict.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/returns_nonnull.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/warning.h +dot.dot.o: $(hdrdir)/ruby/internal/attr/weakref.h +dot.dot.o: $(hdrdir)/ruby/internal/cast.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is/apple.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is/clang.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is/gcc.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is/intel.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is/msvc.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_is/sunpro.h +dot.dot.o: $(hdrdir)/ruby/internal/compiler_since.h +dot.dot.o: $(hdrdir)/ruby/internal/config.h +dot.dot.o: $(hdrdir)/ruby/internal/constant_p.h +dot.dot.o: $(hdrdir)/ruby/internal/core.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rarray.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rbasic.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rbignum.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rclass.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rdata.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rfile.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rhash.h +dot.dot.o: $(hdrdir)/ruby/internal/core/robject.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rregexp.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rstring.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rstruct.h +dot.dot.o: $(hdrdir)/ruby/internal/core/rtypeddata.h +dot.dot.o: $(hdrdir)/ruby/internal/ctype.h +dot.dot.o: $(hdrdir)/ruby/internal/dllexport.h +dot.dot.o: $(hdrdir)/ruby/internal/dosish.h +dot.dot.o: $(hdrdir)/ruby/internal/error.h +dot.dot.o: $(hdrdir)/ruby/internal/eval.h +dot.dot.o: $(hdrdir)/ruby/internal/event.h +dot.dot.o: $(hdrdir)/ruby/internal/fl_type.h +dot.dot.o: $(hdrdir)/ruby/internal/gc.h +dot.dot.o: $(hdrdir)/ruby/internal/glob.h +dot.dot.o: $(hdrdir)/ruby/internal/globals.h +dot.dot.o: $(hdrdir)/ruby/internal/has/attribute.h +dot.dot.o: $(hdrdir)/ruby/internal/has/builtin.h +dot.dot.o: $(hdrdir)/ruby/internal/has/c_attribute.h +dot.dot.o: $(hdrdir)/ruby/internal/has/cpp_attribute.h +dot.dot.o: $(hdrdir)/ruby/internal/has/declspec_attribute.h +dot.dot.o: $(hdrdir)/ruby/internal/has/extension.h +dot.dot.o: $(hdrdir)/ruby/internal/has/feature.h +dot.dot.o: $(hdrdir)/ruby/internal/has/warning.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/array.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/bignum.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/class.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/compar.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/complex.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/cont.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/dir.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/enum.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/enumerator.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/error.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/eval.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/file.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/gc.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/hash.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/io.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/load.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/marshal.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/numeric.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/object.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/parse.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/proc.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/process.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/random.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/range.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/rational.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/re.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/ruby.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/select.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/select/largesize.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/signal.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/sprintf.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/string.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/struct.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/thread.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/time.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/variable.h +dot.dot.o: $(hdrdir)/ruby/internal/intern/vm.h +dot.dot.o: $(hdrdir)/ruby/internal/interpreter.h +dot.dot.o: $(hdrdir)/ruby/internal/iterator.h +dot.dot.o: $(hdrdir)/ruby/internal/memory.h +dot.dot.o: $(hdrdir)/ruby/internal/method.h +dot.dot.o: $(hdrdir)/ruby/internal/module.h +dot.dot.o: $(hdrdir)/ruby/internal/newobj.h +dot.dot.o: $(hdrdir)/ruby/internal/rgengc.h +dot.dot.o: $(hdrdir)/ruby/internal/scan_args.h +dot.dot.o: $(hdrdir)/ruby/internal/special_consts.h +dot.dot.o: $(hdrdir)/ruby/internal/static_assert.h +dot.dot.o: $(hdrdir)/ruby/internal/stdalign.h +dot.dot.o: $(hdrdir)/ruby/internal/stdbool.h +dot.dot.o: $(hdrdir)/ruby/internal/symbol.h +dot.dot.o: $(hdrdir)/ruby/internal/value.h +dot.dot.o: $(hdrdir)/ruby/internal/value_type.h +dot.dot.o: $(hdrdir)/ruby/internal/variable.h +dot.dot.o: $(hdrdir)/ruby/internal/warning_push.h +dot.dot.o: $(hdrdir)/ruby/internal/xmalloc.h +dot.dot.o: $(hdrdir)/ruby/missing.h +dot.dot.o: $(hdrdir)/ruby/ruby.h +dot.dot.o: $(hdrdir)/ruby/st.h +dot.dot.o: $(hdrdir)/ruby/subst.h dot.dot.o: dot.dot.c # AUTOGENERATED DEPENDENCIES END diff --git a/ext/-test-/load/dot.dot/dot.dot.c b/ext/-test-/load/dot.dot/dot.dot.c index 936d28931a..ce7563bf8d 100644 --- a/ext/-test-/load/dot.dot/dot.dot.c +++ b/ext/-test-/load/dot.dot/dot.dot.c @@ -1 +1,3 @@ +#include "ruby.h" + void Init_dot(void) {} diff --git a/ext/-test-/load/protect/depend b/ext/-test-/load/protect/depend index 43413b4e95..dd4ee71b62 100644 --- a/ext/-test-/load/protect/depend +++ b/ext/-test-/load/protect/depend @@ -14,6 +14,7 @@ protect.o: $(hdrdir)/ruby/backward/2/stdalign.h protect.o: $(hdrdir)/ruby/backward/2/stdarg.h protect.o: $(hdrdir)/ruby/defines.h protect.o: $(hdrdir)/ruby/intern.h +protect.o: $(hdrdir)/ruby/internal/abi.h protect.o: $(hdrdir)/ruby/internal/anyargs.h protect.o: $(hdrdir)/ruby/internal/arithmetic.h protect.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/marshal/compat/depend b/ext/-test-/marshal/compat/depend index 366fb88966..2c3ecf1ab9 100644 --- a/ext/-test-/marshal/compat/depend +++ b/ext/-test-/marshal/compat/depend @@ -14,6 +14,7 @@ usrcompat.o: $(hdrdir)/ruby/backward/2/stdalign.h usrcompat.o: $(hdrdir)/ruby/backward/2/stdarg.h usrcompat.o: $(hdrdir)/ruby/defines.h usrcompat.o: $(hdrdir)/ruby/intern.h +usrcompat.o: $(hdrdir)/ruby/internal/abi.h usrcompat.o: $(hdrdir)/ruby/internal/anyargs.h usrcompat.o: $(hdrdir)/ruby/internal/arithmetic.h usrcompat.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/marshal/internal_ivar/depend b/ext/-test-/marshal/internal_ivar/depend index b90f9b2570..cacb54a1a7 100644 --- a/ext/-test-/marshal/internal_ivar/depend +++ b/ext/-test-/marshal/internal_ivar/depend @@ -14,6 +14,7 @@ internal_ivar.o: $(hdrdir)/ruby/backward/2/stdalign.h internal_ivar.o: $(hdrdir)/ruby/backward/2/stdarg.h internal_ivar.o: $(hdrdir)/ruby/defines.h internal_ivar.o: $(hdrdir)/ruby/intern.h +internal_ivar.o: $(hdrdir)/ruby/internal/abi.h internal_ivar.o: $(hdrdir)/ruby/internal/anyargs.h internal_ivar.o: $(hdrdir)/ruby/internal/arithmetic.h internal_ivar.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/marshal/usr/depend b/ext/-test-/marshal/usr/depend index 4a01f2d5e6..717101cbcf 100644 --- a/ext/-test-/marshal/usr/depend +++ b/ext/-test-/marshal/usr/depend @@ -14,6 +14,7 @@ usrmarshal.o: $(hdrdir)/ruby/backward/2/stdalign.h usrmarshal.o: $(hdrdir)/ruby/backward/2/stdarg.h usrmarshal.o: $(hdrdir)/ruby/defines.h usrmarshal.o: $(hdrdir)/ruby/intern.h +usrmarshal.o: $(hdrdir)/ruby/internal/abi.h usrmarshal.o: $(hdrdir)/ruby/internal/anyargs.h usrmarshal.o: $(hdrdir)/ruby/internal/arithmetic.h usrmarshal.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/memory_status/depend b/ext/-test-/memory_status/depend index c9cc903ff6..a65fe66ae3 100644 --- a/ext/-test-/memory_status/depend +++ b/ext/-test-/memory_status/depend @@ -14,6 +14,7 @@ memory_status.o: $(hdrdir)/ruby/backward/2/stdalign.h memory_status.o: $(hdrdir)/ruby/backward/2/stdarg.h memory_status.o: $(hdrdir)/ruby/defines.h memory_status.o: $(hdrdir)/ruby/intern.h +memory_status.o: $(hdrdir)/ruby/internal/abi.h memory_status.o: $(hdrdir)/ruby/internal/anyargs.h memory_status.o: $(hdrdir)/ruby/internal/arithmetic.h memory_status.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/memory_view/depend b/ext/-test-/memory_view/depend index c42e9f54a3..7ce2d0374c 100644 --- a/ext/-test-/memory_view/depend +++ b/ext/-test-/memory_view/depend @@ -14,6 +14,7 @@ memory_view.o: $(hdrdir)/ruby/backward/2/stdalign.h memory_view.o: $(hdrdir)/ruby/backward/2/stdarg.h memory_view.o: $(hdrdir)/ruby/defines.h memory_view.o: $(hdrdir)/ruby/intern.h +memory_view.o: $(hdrdir)/ruby/internal/abi.h memory_view.o: $(hdrdir)/ruby/internal/anyargs.h memory_view.o: $(hdrdir)/ruby/internal/arithmetic.h memory_view.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/method/depend b/ext/-test-/method/depend index f091d37189..85cf4d174a 100644 --- a/ext/-test-/method/depend +++ b/ext/-test-/method/depend @@ -14,6 +14,7 @@ arity.o: $(hdrdir)/ruby/backward/2/stdalign.h arity.o: $(hdrdir)/ruby/backward/2/stdarg.h arity.o: $(hdrdir)/ruby/defines.h arity.o: $(hdrdir)/ruby/intern.h +arity.o: $(hdrdir)/ruby/internal/abi.h arity.o: $(hdrdir)/ruby/internal/anyargs.h arity.o: $(hdrdir)/ruby/internal/arithmetic.h arity.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/notimplement/depend b/ext/-test-/notimplement/depend index 73d1fec435..2303f47594 100644 --- a/ext/-test-/notimplement/depend +++ b/ext/-test-/notimplement/depend @@ -14,6 +14,7 @@ bug.o: $(hdrdir)/ruby/backward/2/stdalign.h bug.o: $(hdrdir)/ruby/backward/2/stdarg.h bug.o: $(hdrdir)/ruby/defines.h bug.o: $(hdrdir)/ruby/intern.h +bug.o: $(hdrdir)/ruby/internal/abi.h bug.o: $(hdrdir)/ruby/internal/anyargs.h bug.o: $(hdrdir)/ruby/internal/arithmetic.h bug.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/num2int/depend b/ext/-test-/num2int/depend index 77db0bfb83..a3283838dd 100644 --- a/ext/-test-/num2int/depend +++ b/ext/-test-/num2int/depend @@ -14,6 +14,7 @@ num2int.o: $(hdrdir)/ruby/backward/2/stdalign.h num2int.o: $(hdrdir)/ruby/backward/2/stdarg.h num2int.o: $(hdrdir)/ruby/defines.h num2int.o: $(hdrdir)/ruby/intern.h +num2int.o: $(hdrdir)/ruby/internal/abi.h num2int.o: $(hdrdir)/ruby/internal/anyargs.h num2int.o: $(hdrdir)/ruby/internal/arithmetic.h num2int.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/path_to_class/depend b/ext/-test-/path_to_class/depend index 4911b80adc..17f8e957c3 100644 --- a/ext/-test-/path_to_class/depend +++ b/ext/-test-/path_to_class/depend @@ -14,6 +14,7 @@ path_to_class.o: $(hdrdir)/ruby/backward/2/stdalign.h path_to_class.o: $(hdrdir)/ruby/backward/2/stdarg.h path_to_class.o: $(hdrdir)/ruby/defines.h path_to_class.o: $(hdrdir)/ruby/intern.h +path_to_class.o: $(hdrdir)/ruby/internal/abi.h path_to_class.o: $(hdrdir)/ruby/internal/anyargs.h path_to_class.o: $(hdrdir)/ruby/internal/arithmetic.h path_to_class.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/popen_deadlock/depend b/ext/-test-/popen_deadlock/depend index e36a6c9568..22da87f2fe 100644 --- a/ext/-test-/popen_deadlock/depend +++ b/ext/-test-/popen_deadlock/depend @@ -1,6 +1,20 @@ # AUTOGENERATED DEPENDENCIES START infinite_loop_dlsym.o: $(RUBY_EXTCONF_H) infinite_loop_dlsym.o: $(arch_hdrdir)/ruby/config.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/assert.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/assume.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/attributes.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/bool.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/gcc_version_since.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/inttypes.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/limits.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/long_long.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/stdalign.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/stdarg.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/defines.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/intern.h +infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/abi.h infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/anyargs.h infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/arithmetic.h infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -140,19 +154,6 @@ infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/value_type.h infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/variable.h infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/warning_push.h infinite_loop_dlsym.o: $(hdrdir)/ruby/internal/xmalloc.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/assert.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/assume.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/attributes.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/bool.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/gcc_version_since.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/inttypes.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/limits.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/long_long.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/stdalign.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/backward/2/stdarg.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/defines.h -infinite_loop_dlsym.o: $(hdrdir)/ruby/intern.h infinite_loop_dlsym.o: $(hdrdir)/ruby/missing.h infinite_loop_dlsym.o: $(hdrdir)/ruby/ruby.h infinite_loop_dlsym.o: $(hdrdir)/ruby/st.h diff --git a/ext/-test-/postponed_job/depend b/ext/-test-/postponed_job/depend index 36f08b6ebd..35aca7f2b0 100644 --- a/ext/-test-/postponed_job/depend +++ b/ext/-test-/postponed_job/depend @@ -15,6 +15,7 @@ postponed_job.o: $(hdrdir)/ruby/backward/2/stdarg.h postponed_job.o: $(hdrdir)/ruby/debug.h postponed_job.o: $(hdrdir)/ruby/defines.h postponed_job.o: $(hdrdir)/ruby/intern.h +postponed_job.o: $(hdrdir)/ruby/internal/abi.h postponed_job.o: $(hdrdir)/ruby/internal/anyargs.h postponed_job.o: $(hdrdir)/ruby/internal/arithmetic.h postponed_job.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/printf/depend b/ext/-test-/printf/depend index 143317c778..6dfe1fe03d 100644 --- a/ext/-test-/printf/depend +++ b/ext/-test-/printf/depend @@ -15,6 +15,7 @@ printf.o: $(hdrdir)/ruby/backward/2/stdarg.h printf.o: $(hdrdir)/ruby/defines.h printf.o: $(hdrdir)/ruby/encoding.h printf.o: $(hdrdir)/ruby/intern.h +printf.o: $(hdrdir)/ruby/internal/abi.h printf.o: $(hdrdir)/ruby/internal/anyargs.h printf.o: $(hdrdir)/ruby/internal/arithmetic.h printf.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/proc/depend b/ext/-test-/proc/depend index a1ce4cdf42..e3f1cf6ce9 100644 --- a/ext/-test-/proc/depend +++ b/ext/-test-/proc/depend @@ -14,6 +14,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ receiver.o: $(hdrdir)/ruby/backward/2/stdalign.h receiver.o: $(hdrdir)/ruby/backward/2/stdarg.h receiver.o: $(hdrdir)/ruby/defines.h receiver.o: $(hdrdir)/ruby/intern.h +receiver.o: $(hdrdir)/ruby/internal/abi.h receiver.o: $(hdrdir)/ruby/internal/anyargs.h receiver.o: $(hdrdir)/ruby/internal/arithmetic.h receiver.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -332,6 +334,7 @@ super.o: $(hdrdir)/ruby/backward/2/stdalign.h super.o: $(hdrdir)/ruby/backward/2/stdarg.h super.o: $(hdrdir)/ruby/defines.h super.o: $(hdrdir)/ruby/intern.h +super.o: $(hdrdir)/ruby/internal/abi.h super.o: $(hdrdir)/ruby/internal/anyargs.h super.o: $(hdrdir)/ruby/internal/arithmetic.h super.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/random/depend b/ext/-test-/random/depend index 7cef34f115..602526cf7b 100644 --- a/ext/-test-/random/depend +++ b/ext/-test-/random/depend @@ -14,6 +14,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -172,6 +173,7 @@ loop.o: $(hdrdir)/ruby/backward/2/stdalign.h loop.o: $(hdrdir)/ruby/backward/2/stdarg.h loop.o: $(hdrdir)/ruby/defines.h loop.o: $(hdrdir)/ruby/intern.h +loop.o: $(hdrdir)/ruby/internal/abi.h loop.o: $(hdrdir)/ruby/internal/anyargs.h loop.o: $(hdrdir)/ruby/internal/arithmetic.h loop.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/rational/depend b/ext/-test-/rational/depend index 3fbe6e0a07..8729695886 100644 --- a/ext/-test-/rational/depend +++ b/ext/-test-/rational/depend @@ -18,6 +18,7 @@ rat.o: $(hdrdir)/ruby/backward/2/stdalign.h rat.o: $(hdrdir)/ruby/backward/2/stdarg.h rat.o: $(hdrdir)/ruby/defines.h rat.o: $(hdrdir)/ruby/intern.h +rat.o: $(hdrdir)/ruby/internal/abi.h rat.o: $(hdrdir)/ruby/internal/anyargs.h rat.o: $(hdrdir)/ruby/internal/arithmetic.h rat.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/rb_call_super_kw/depend b/ext/-test-/rb_call_super_kw/depend index a8126a9efe..3512a081c9 100644 --- a/ext/-test-/rb_call_super_kw/depend +++ b/ext/-test-/rb_call_super_kw/depend @@ -14,6 +14,7 @@ rb_call_super_kw.o: $(hdrdir)/ruby/backward/2/stdalign.h rb_call_super_kw.o: $(hdrdir)/ruby/backward/2/stdarg.h rb_call_super_kw.o: $(hdrdir)/ruby/defines.h rb_call_super_kw.o: $(hdrdir)/ruby/intern.h +rb_call_super_kw.o: $(hdrdir)/ruby/internal/abi.h rb_call_super_kw.o: $(hdrdir)/ruby/internal/anyargs.h rb_call_super_kw.o: $(hdrdir)/ruby/internal/arithmetic.h rb_call_super_kw.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/recursion/depend b/ext/-test-/recursion/depend index 12d7ae6026..e499f95e73 100644 --- a/ext/-test-/recursion/depend +++ b/ext/-test-/recursion/depend @@ -14,6 +14,7 @@ recursion.o: $(hdrdir)/ruby/backward/2/stdalign.h recursion.o: $(hdrdir)/ruby/backward/2/stdarg.h recursion.o: $(hdrdir)/ruby/defines.h recursion.o: $(hdrdir)/ruby/intern.h +recursion.o: $(hdrdir)/ruby/internal/abi.h recursion.o: $(hdrdir)/ruby/internal/anyargs.h recursion.o: $(hdrdir)/ruby/internal/arithmetic.h recursion.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/regexp/depend b/ext/-test-/regexp/depend index c46d876241..fa431e013a 100644 --- a/ext/-test-/regexp/depend +++ b/ext/-test-/regexp/depend @@ -14,6 +14,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ parse_depth_limit.o: $(hdrdir)/ruby/backward/2/stdalign.h parse_depth_limit.o: $(hdrdir)/ruby/backward/2/stdarg.h parse_depth_limit.o: $(hdrdir)/ruby/defines.h parse_depth_limit.o: $(hdrdir)/ruby/intern.h +parse_depth_limit.o: $(hdrdir)/ruby/internal/abi.h parse_depth_limit.o: $(hdrdir)/ruby/internal/anyargs.h parse_depth_limit.o: $(hdrdir)/ruby/internal/arithmetic.h parse_depth_limit.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/scan_args/depend b/ext/-test-/scan_args/depend index 99fd82ce34..2194936b04 100644 --- a/ext/-test-/scan_args/depend +++ b/ext/-test-/scan_args/depend @@ -14,6 +14,7 @@ scan_args.o: $(hdrdir)/ruby/backward/2/stdalign.h scan_args.o: $(hdrdir)/ruby/backward/2/stdarg.h scan_args.o: $(hdrdir)/ruby/defines.h scan_args.o: $(hdrdir)/ruby/intern.h +scan_args.o: $(hdrdir)/ruby/internal/abi.h scan_args.o: $(hdrdir)/ruby/internal/anyargs.h scan_args.o: $(hdrdir)/ruby/internal/arithmetic.h scan_args.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/st/foreach/depend b/ext/-test-/st/foreach/depend index 6128230798..0464ee3c53 100644 --- a/ext/-test-/st/foreach/depend +++ b/ext/-test-/st/foreach/depend @@ -14,6 +14,7 @@ foreach.o: $(hdrdir)/ruby/backward/2/stdalign.h foreach.o: $(hdrdir)/ruby/backward/2/stdarg.h foreach.o: $(hdrdir)/ruby/defines.h foreach.o: $(hdrdir)/ruby/intern.h +foreach.o: $(hdrdir)/ruby/internal/abi.h foreach.o: $(hdrdir)/ruby/internal/anyargs.h foreach.o: $(hdrdir)/ruby/internal/arithmetic.h foreach.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/st/numhash/depend b/ext/-test-/st/numhash/depend index b3475f5fc5..9665ed6e39 100644 --- a/ext/-test-/st/numhash/depend +++ b/ext/-test-/st/numhash/depend @@ -14,6 +14,7 @@ numhash.o: $(hdrdir)/ruby/backward/2/stdalign.h numhash.o: $(hdrdir)/ruby/backward/2/stdarg.h numhash.o: $(hdrdir)/ruby/defines.h numhash.o: $(hdrdir)/ruby/intern.h +numhash.o: $(hdrdir)/ruby/internal/abi.h numhash.o: $(hdrdir)/ruby/internal/anyargs.h numhash.o: $(hdrdir)/ruby/internal/arithmetic.h numhash.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/st/update/depend b/ext/-test-/st/update/depend index bbf97cbbfb..01960df965 100644 --- a/ext/-test-/st/update/depend +++ b/ext/-test-/st/update/depend @@ -14,6 +14,7 @@ update.o: $(hdrdir)/ruby/backward/2/stdalign.h update.o: $(hdrdir)/ruby/backward/2/stdarg.h update.o: $(hdrdir)/ruby/defines.h update.o: $(hdrdir)/ruby/intern.h +update.o: $(hdrdir)/ruby/internal/abi.h update.o: $(hdrdir)/ruby/internal/anyargs.h update.o: $(hdrdir)/ruby/internal/arithmetic.h update.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/string/depend b/ext/-test-/string/depend index 1e2e123130..773231047e 100644 --- a/ext/-test-/string/depend +++ b/ext/-test-/string/depend @@ -16,6 +16,7 @@ capacity.o: $(hdrdir)/ruby/backward/2/stdarg.h capacity.o: $(hdrdir)/ruby/defines.h capacity.o: $(hdrdir)/ruby/encoding.h capacity.o: $(hdrdir)/ruby/intern.h +capacity.o: $(hdrdir)/ruby/internal/abi.h capacity.o: $(hdrdir)/ruby/internal/anyargs.h capacity.o: $(hdrdir)/ruby/internal/arithmetic.h capacity.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -188,6 +189,7 @@ coderange.o: $(hdrdir)/ruby/backward/2/stdarg.h coderange.o: $(hdrdir)/ruby/defines.h coderange.o: $(hdrdir)/ruby/encoding.h coderange.o: $(hdrdir)/ruby/intern.h +coderange.o: $(hdrdir)/ruby/internal/abi.h coderange.o: $(hdrdir)/ruby/internal/anyargs.h coderange.o: $(hdrdir)/ruby/internal/arithmetic.h coderange.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -359,6 +361,7 @@ cstr.o: $(hdrdir)/ruby/backward/2/stdarg.h cstr.o: $(hdrdir)/ruby/defines.h cstr.o: $(hdrdir)/ruby/encoding.h cstr.o: $(hdrdir)/ruby/intern.h +cstr.o: $(hdrdir)/ruby/internal/abi.h cstr.o: $(hdrdir)/ruby/internal/anyargs.h cstr.o: $(hdrdir)/ruby/internal/arithmetic.h cstr.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -532,6 +535,7 @@ ellipsize.o: $(hdrdir)/ruby/backward/2/stdalign.h ellipsize.o: $(hdrdir)/ruby/backward/2/stdarg.h ellipsize.o: $(hdrdir)/ruby/defines.h ellipsize.o: $(hdrdir)/ruby/intern.h +ellipsize.o: $(hdrdir)/ruby/internal/abi.h ellipsize.o: $(hdrdir)/ruby/internal/anyargs.h ellipsize.o: $(hdrdir)/ruby/internal/arithmetic.h ellipsize.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -692,6 +696,7 @@ enc_associate.o: $(hdrdir)/ruby/backward/2/stdarg.h enc_associate.o: $(hdrdir)/ruby/defines.h enc_associate.o: $(hdrdir)/ruby/encoding.h enc_associate.o: $(hdrdir)/ruby/intern.h +enc_associate.o: $(hdrdir)/ruby/internal/abi.h enc_associate.o: $(hdrdir)/ruby/internal/anyargs.h enc_associate.o: $(hdrdir)/ruby/internal/arithmetic.h enc_associate.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -862,6 +867,7 @@ enc_str_buf_cat.o: $(hdrdir)/ruby/backward/2/stdarg.h enc_str_buf_cat.o: $(hdrdir)/ruby/defines.h enc_str_buf_cat.o: $(hdrdir)/ruby/encoding.h enc_str_buf_cat.o: $(hdrdir)/ruby/intern.h +enc_str_buf_cat.o: $(hdrdir)/ruby/internal/abi.h enc_str_buf_cat.o: $(hdrdir)/ruby/internal/anyargs.h enc_str_buf_cat.o: $(hdrdir)/ruby/internal/arithmetic.h enc_str_buf_cat.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1033,6 +1039,7 @@ fstring.o: $(hdrdir)/ruby/backward/2/stdarg.h fstring.o: $(hdrdir)/ruby/defines.h fstring.o: $(hdrdir)/ruby/encoding.h fstring.o: $(hdrdir)/ruby/intern.h +fstring.o: $(hdrdir)/ruby/internal/abi.h fstring.o: $(hdrdir)/ruby/internal/anyargs.h fstring.o: $(hdrdir)/ruby/internal/arithmetic.h fstring.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1203,6 +1210,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1362,6 +1370,7 @@ modify.o: $(hdrdir)/ruby/backward/2/stdalign.h modify.o: $(hdrdir)/ruby/backward/2/stdarg.h modify.o: $(hdrdir)/ruby/defines.h modify.o: $(hdrdir)/ruby/intern.h +modify.o: $(hdrdir)/ruby/internal/abi.h modify.o: $(hdrdir)/ruby/internal/anyargs.h modify.o: $(hdrdir)/ruby/internal/arithmetic.h modify.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1522,6 +1531,7 @@ new.o: $(hdrdir)/ruby/backward/2/stdarg.h new.o: $(hdrdir)/ruby/defines.h new.o: $(hdrdir)/ruby/encoding.h new.o: $(hdrdir)/ruby/intern.h +new.o: $(hdrdir)/ruby/internal/abi.h new.o: $(hdrdir)/ruby/internal/anyargs.h new.o: $(hdrdir)/ruby/internal/arithmetic.h new.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1692,6 +1702,7 @@ nofree.o: $(hdrdir)/ruby/backward/2/stdalign.h nofree.o: $(hdrdir)/ruby/backward/2/stdarg.h nofree.o: $(hdrdir)/ruby/defines.h nofree.o: $(hdrdir)/ruby/intern.h +nofree.o: $(hdrdir)/ruby/internal/abi.h nofree.o: $(hdrdir)/ruby/internal/anyargs.h nofree.o: $(hdrdir)/ruby/internal/arithmetic.h nofree.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1851,6 +1862,7 @@ normalize.o: $(hdrdir)/ruby/backward/2/stdarg.h normalize.o: $(hdrdir)/ruby/defines.h normalize.o: $(hdrdir)/ruby/encoding.h normalize.o: $(hdrdir)/ruby/intern.h +normalize.o: $(hdrdir)/ruby/internal/abi.h normalize.o: $(hdrdir)/ruby/internal/anyargs.h normalize.o: $(hdrdir)/ruby/internal/arithmetic.h normalize.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2023,6 +2035,7 @@ qsort.o: $(hdrdir)/ruby/backward/2/stdarg.h qsort.o: $(hdrdir)/ruby/defines.h qsort.o: $(hdrdir)/ruby/encoding.h qsort.o: $(hdrdir)/ruby/intern.h +qsort.o: $(hdrdir)/ruby/internal/abi.h qsort.o: $(hdrdir)/ruby/internal/anyargs.h qsort.o: $(hdrdir)/ruby/internal/arithmetic.h qsort.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2194,6 +2207,7 @@ rb_interned_str.o: $(hdrdir)/ruby/backward/2/stdalign.h rb_interned_str.o: $(hdrdir)/ruby/backward/2/stdarg.h rb_interned_str.o: $(hdrdir)/ruby/defines.h rb_interned_str.o: $(hdrdir)/ruby/intern.h +rb_interned_str.o: $(hdrdir)/ruby/internal/abi.h rb_interned_str.o: $(hdrdir)/ruby/internal/anyargs.h rb_interned_str.o: $(hdrdir)/ruby/internal/arithmetic.h rb_interned_str.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2353,6 +2367,7 @@ rb_str_dup.o: $(hdrdir)/ruby/backward/2/stdalign.h rb_str_dup.o: $(hdrdir)/ruby/backward/2/stdarg.h rb_str_dup.o: $(hdrdir)/ruby/defines.h rb_str_dup.o: $(hdrdir)/ruby/intern.h +rb_str_dup.o: $(hdrdir)/ruby/internal/abi.h rb_str_dup.o: $(hdrdir)/ruby/internal/anyargs.h rb_str_dup.o: $(hdrdir)/ruby/internal/arithmetic.h rb_str_dup.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2512,6 +2527,7 @@ set_len.o: $(hdrdir)/ruby/backward/2/stdalign.h set_len.o: $(hdrdir)/ruby/backward/2/stdarg.h set_len.o: $(hdrdir)/ruby/defines.h set_len.o: $(hdrdir)/ruby/intern.h +set_len.o: $(hdrdir)/ruby/internal/abi.h set_len.o: $(hdrdir)/ruby/internal/anyargs.h set_len.o: $(hdrdir)/ruby/internal/arithmetic.h set_len.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/struct/depend b/ext/-test-/struct/depend index c9dcffd3c4..920a065216 100644 --- a/ext/-test-/struct/depend +++ b/ext/-test-/struct/depend @@ -14,6 +14,7 @@ duplicate.o: $(hdrdir)/ruby/backward/2/stdalign.h duplicate.o: $(hdrdir)/ruby/backward/2/stdarg.h duplicate.o: $(hdrdir)/ruby/defines.h duplicate.o: $(hdrdir)/ruby/intern.h +duplicate.o: $(hdrdir)/ruby/internal/abi.h duplicate.o: $(hdrdir)/ruby/internal/anyargs.h duplicate.o: $(hdrdir)/ruby/internal/arithmetic.h duplicate.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -332,6 +334,7 @@ len.o: $(hdrdir)/ruby/backward/2/stdalign.h len.o: $(hdrdir)/ruby/backward/2/stdarg.h len.o: $(hdrdir)/ruby/defines.h len.o: $(hdrdir)/ruby/intern.h +len.o: $(hdrdir)/ruby/internal/abi.h len.o: $(hdrdir)/ruby/internal/anyargs.h len.o: $(hdrdir)/ruby/internal/arithmetic.h len.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -491,6 +494,7 @@ member.o: $(hdrdir)/ruby/backward/2/stdalign.h member.o: $(hdrdir)/ruby/backward/2/stdarg.h member.o: $(hdrdir)/ruby/defines.h member.o: $(hdrdir)/ruby/intern.h +member.o: $(hdrdir)/ruby/internal/abi.h member.o: $(hdrdir)/ruby/internal/anyargs.h member.o: $(hdrdir)/ruby/internal/arithmetic.h member.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/symbol/depend b/ext/-test-/symbol/depend index f462855b40..b94e4ce821 100644 --- a/ext/-test-/symbol/depend +++ b/ext/-test-/symbol/depend @@ -14,6 +14,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ type.o: $(hdrdir)/ruby/backward/2/stdalign.h type.o: $(hdrdir)/ruby/backward/2/stdarg.h type.o: $(hdrdir)/ruby/defines.h type.o: $(hdrdir)/ruby/intern.h +type.o: $(hdrdir)/ruby/internal/abi.h type.o: $(hdrdir)/ruby/internal/anyargs.h type.o: $(hdrdir)/ruby/internal/arithmetic.h type.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/thread_fd/depend b/ext/-test-/thread_fd/depend index 0c8c31eac7..ecf738108a 100644 --- a/ext/-test-/thread_fd/depend +++ b/ext/-test-/thread_fd/depend @@ -13,6 +13,7 @@ thread_fd.o: $(hdrdir)/ruby/backward/2/stdalign.h thread_fd.o: $(hdrdir)/ruby/backward/2/stdarg.h thread_fd.o: $(hdrdir)/ruby/defines.h thread_fd.o: $(hdrdir)/ruby/intern.h +thread_fd.o: $(hdrdir)/ruby/internal/abi.h thread_fd.o: $(hdrdir)/ruby/internal/anyargs.h thread_fd.o: $(hdrdir)/ruby/internal/arithmetic.h thread_fd.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/time/depend b/ext/-test-/time/depend index 557f65af6b..b7d1a2b114 100644 --- a/ext/-test-/time/depend +++ b/ext/-test-/time/depend @@ -14,6 +14,7 @@ init.o: $(hdrdir)/ruby/backward/2/stdalign.h init.o: $(hdrdir)/ruby/backward/2/stdarg.h init.o: $(hdrdir)/ruby/defines.h init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/internal/abi.h init.o: $(hdrdir)/ruby/internal/anyargs.h init.o: $(hdrdir)/ruby/internal/arithmetic.h init.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -174,6 +175,7 @@ leap_second.o: $(hdrdir)/ruby/backward/2/stdalign.h leap_second.o: $(hdrdir)/ruby/backward/2/stdarg.h leap_second.o: $(hdrdir)/ruby/defines.h leap_second.o: $(hdrdir)/ruby/intern.h +leap_second.o: $(hdrdir)/ruby/internal/abi.h leap_second.o: $(hdrdir)/ruby/internal/anyargs.h leap_second.o: $(hdrdir)/ruby/internal/arithmetic.h leap_second.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -337,6 +339,7 @@ new.o: $(hdrdir)/ruby/backward/2/stdalign.h new.o: $(hdrdir)/ruby/backward/2/stdarg.h new.o: $(hdrdir)/ruby/defines.h new.o: $(hdrdir)/ruby/intern.h +new.o: $(hdrdir)/ruby/internal/abi.h new.o: $(hdrdir)/ruby/internal/anyargs.h new.o: $(hdrdir)/ruby/internal/arithmetic.h new.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/tracepoint/depend b/ext/-test-/tracepoint/depend index f05f13d08d..8e2aa7eab6 100644 --- a/ext/-test-/tracepoint/depend +++ b/ext/-test-/tracepoint/depend @@ -14,6 +14,7 @@ gc_hook.o: $(hdrdir)/ruby/backward/2/stdarg.h gc_hook.o: $(hdrdir)/ruby/debug.h gc_hook.o: $(hdrdir)/ruby/defines.h gc_hook.o: $(hdrdir)/ruby/intern.h +gc_hook.o: $(hdrdir)/ruby/internal/abi.h gc_hook.o: $(hdrdir)/ruby/internal/anyargs.h gc_hook.o: $(hdrdir)/ruby/internal/arithmetic.h gc_hook.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -173,6 +174,7 @@ tracepoint.o: $(hdrdir)/ruby/backward/2/stdarg.h tracepoint.o: $(hdrdir)/ruby/debug.h tracepoint.o: $(hdrdir)/ruby/defines.h tracepoint.o: $(hdrdir)/ruby/intern.h +tracepoint.o: $(hdrdir)/ruby/internal/abi.h tracepoint.o: $(hdrdir)/ruby/internal/anyargs.h tracepoint.o: $(hdrdir)/ruby/internal/arithmetic.h tracepoint.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/typeddata/depend b/ext/-test-/typeddata/depend index 9eb0666c70..02f6de6e20 100644 --- a/ext/-test-/typeddata/depend +++ b/ext/-test-/typeddata/depend @@ -14,6 +14,7 @@ typeddata.o: $(hdrdir)/ruby/backward/2/stdalign.h typeddata.o: $(hdrdir)/ruby/backward/2/stdarg.h typeddata.o: $(hdrdir)/ruby/defines.h typeddata.o: $(hdrdir)/ruby/intern.h +typeddata.o: $(hdrdir)/ruby/internal/abi.h typeddata.o: $(hdrdir)/ruby/internal/anyargs.h typeddata.o: $(hdrdir)/ruby/internal/arithmetic.h typeddata.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/vm/depend b/ext/-test-/vm/depend index a01669802d..7f110d48eb 100644 --- a/ext/-test-/vm/depend +++ b/ext/-test-/vm/depend @@ -13,6 +13,7 @@ at_exit.o: $(hdrdir)/ruby/backward/2/stdalign.h at_exit.o: $(hdrdir)/ruby/backward/2/stdarg.h at_exit.o: $(hdrdir)/ruby/defines.h at_exit.o: $(hdrdir)/ruby/intern.h +at_exit.o: $(hdrdir)/ruby/internal/abi.h at_exit.o: $(hdrdir)/ruby/internal/anyargs.h at_exit.o: $(hdrdir)/ruby/internal/arithmetic.h at_exit.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/-test-/wait/depend b/ext/-test-/wait/depend index b5cdd12836..e71bda9968 100644 --- a/ext/-test-/wait/depend +++ b/ext/-test-/wait/depend @@ -14,6 +14,7 @@ wait.o: $(hdrdir)/ruby/backward/2/stdarg.h wait.o: $(hdrdir)/ruby/defines.h wait.o: $(hdrdir)/ruby/encoding.h wait.o: $(hdrdir)/ruby/intern.h +wait.o: $(hdrdir)/ruby/internal/abi.h wait.o: $(hdrdir)/ruby/internal/anyargs.h wait.o: $(hdrdir)/ruby/internal/arithmetic.h wait.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 65e7c864e2..97510fad86 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -115,6 +115,8 @@ static ID id_half; */ static unsigned short VpGetException(void); static void VpSetException(unsigned short f); +static void VpCheckException(Real *p, bool always); +static VALUE VpCheckGetValue(Real *p); static void VpInternalRound(Real *c, size_t ixDigit, DECDIG vPrev, DECDIG v); static int VpLimitRound(Real *c, size_t ixDigit); static Real *VpCopy(Real *pv, Real const* const x); @@ -165,27 +167,6 @@ is_kind_of_BigDecimal(VALUE const v) return rb_typeddata_is_kind_of(v, &BigDecimal_data_type); } -static void -VpCheckException(Real *p, bool always) -{ - if (VpIsNaN(p)) { - VpException(VP_EXCEPTION_NaN, "Computation results to 'NaN'(Not a Number)", always); - } - else if (VpIsPosInf(p)) { - VpException(VP_EXCEPTION_INFINITY, "Computation results to 'Infinity'", always); - } - else if (VpIsNegInf(p)) { - VpException(VP_EXCEPTION_INFINITY, "Computation results to '-Infinity'", always); - } -} - -static VALUE -VpCheckGetValue(Real *p) -{ - VpCheckException(p, false); - return p->obj; -} - NORETURN(static void cannot_be_coerced_into_BigDecimal(VALUE, VALUE)); static void @@ -275,11 +256,13 @@ GetVpValue(VALUE v, int must) } /* call-seq: - * BigDecimal.double_fig + * BigDecimal.double_fig -> integer + * + * Returns the number of digits a Float object is allowed to have; + * the result is system-dependent: + * + * BigDecimal.double_fig # => 16 * - * The BigDecimal.double_fig class method returns the number of digits a - * Float number is allowed to have. The result depends upon the CPU and OS - * in use. */ static VALUE BigDecimal_double_fig(VALUE self) @@ -288,7 +271,7 @@ BigDecimal_double_fig(VALUE self) } /* call-seq: - * big_decimal.precs -> array + * precs -> array * * Returns an Array of two Integer values that represent platform-dependent * internal storage properties. @@ -298,7 +281,6 @@ BigDecimal_double_fig(VALUE self) * significant digits in scientific notation, and BigDecimal#precision for * obtaining the number of digits in decimal notation. * - * BigDecimal('5').precs #=> [9, 18] */ static VALUE @@ -318,73 +300,202 @@ BigDecimal_prec(VALUE self) return obj; } -/* - * call-seq: - * big_decimal.precision -> intreger - * - * Returns the number of decimal digits in this number. - * - * Example: - * - * BigDecimal("0").precision # => 0 - * BigDecimal("1").precision # => 1 - * BigDecimal("-1e20").precision # => 21 - * BigDecimal("1e-20").precision # => 20 - * BigDecimal("Infinity").precision # => 0 - * BigDecimal("-Infinity").precision # => 0 - * BigDecimal("NaN").precision # => 0 - */ -static VALUE -BigDecimal_precision(VALUE self) +static void +BigDecimal_count_precision_and_scale(VALUE self, ssize_t *out_precision, ssize_t *out_scale) { ENTER(1); + if (out_precision == NULL && out_scale == NULL) + return; + Real *p; GUARD_OBJ(p, GetVpValue(self, 1)); + if (VpIsZero(p) || !VpIsDef(p)) { + zero: + if (out_precision) *out_precision = 0; + if (out_scale) *out_scale = 0; + return; + } + + DECDIG x; + + ssize_t n = p->Prec; /* The length of frac without zeros. */ + while (n > 0 && p->frac[n-1] == 0) --n; + if (n == 0) goto zero; + + int nlz = BASE_FIG; + for (x = p->frac[0]; x > 0; x /= 10) --nlz; + + int ntz = 0; + for (x = p->frac[n-1]; x > 0 && x % 10 == 0; x /= 10) ++ntz; /* - * The most significant digit is frac[0], and the least significant digit is frac[Prec-1]. - * When the exponent is zero, the decimal point is located just before frac[0]. + * Calculate the precision and the scale + * ------------------------------------- + * + * The most significant digit is frac[0], and the least significant digit + * is frac[Prec-1]. When the exponent is zero, the decimal point is + * located just before frac[0]. + * * When the exponent is negative, the decimal point moves to leftward. - * Conversely, when the exponent is positive, the decimal point moves to rightward. + * In this case, the precision can be calculated by + * + * precision = BASE_FIG * (-exponent + n) - ntz, + * + * and the scale is the same as precision. + * + * 0 . 0000 0000 | frac[0] ... frac[n-1] | + * |<----------| exponent == -2 | + * |---------------------------------->| precision + * |---------------------------------->| scale + * + * + * Conversely, when the exponent is positive, the decimal point moves to + * rightward. In this case, the scale equals to + * + * BASE_FIG * (n - exponent) - ntz. * - * | frac[0] frac[1] frac[2] . frac[3] frac[4] ... frac[Prec-1] - * |------------------------> exponent == 3 + * the precision equals to + * + * scale + BASE_FIG * exponent - nlz. + * + * | frac[0] frac[1] . frac[2] ... frac[n-1] | + * |---------------->| exponent == 2 | + * | |---------------------->| scale + * |---------------------------------------->| precision */ ssize_t ex = p->exponent; - ssize_t precision = 0; + + /* Count the number of decimal digits before frac[1]. */ + ssize_t n_digits_head = BASE_FIG; if (ex < 0) { - precision = (-ex + 1) * BASE_FIG; /* 1 is for p->frac[0] */ - ex = 0; + n_digits_head += (-ex) * BASE_FIG; /* The number of leading zeros before frac[0]. */ + ex = 0; } - else if (p->Prec > 0) { - DECDIG x = p->frac[0]; - for (precision = 0; x > 0; x /= 10) { - ++precision; - } + else if (ex > 0) { + /* Count the number of decimal digits without the leading zeros in + * the most significant digit in the integral part. + */ + n_digits_head -= nlz; /* Make the number of digits */ } - if (ex > (ssize_t)p->Prec) { - precision += (ex - 1) * BASE_FIG; + if (out_precision) { + ssize_t precision = n_digits_head; + + /* Count the number of decimal digits after frac[0]. */ + if (ex > (ssize_t)n) { + /* In this case the number is an integer with some trailing zeros. */ + precision += (ex - 1) * BASE_FIG; + } + else if (n > 0) { + precision += (n - 1) * BASE_FIG; + + if (ex < (ssize_t)n) { + precision -= ntz; + } + } + + *out_precision = precision; } - else if (p->Prec > 0) { - ssize_t n = (ssize_t)p->Prec - 1; - while (n > 0 && p->frac[n] == 0) --n; - precision += n * BASE_FIG; + if (out_scale) { + ssize_t scale = 0; - if (ex < (ssize_t)p->Prec) { - DECDIG x = p->frac[n]; - for (; x > 0 && x % 10 == 0; x /= 10) { - --precision; - } + if (p->exponent < 0) { + scale = n_digits_head + (n - 1) * BASE_FIG - ntz; } + else if (n > p->exponent) { + scale = (n - p->exponent) * BASE_FIG - ntz; + } + + *out_scale = scale; } +} +/* + * call-seq: + * precision -> integer + * + * Returns the number of decimal digits in +self+: + * + * BigDecimal("0").precision # => 0 + * BigDecimal("1").precision # => 1 + * BigDecimal("1.1").precision # => 2 + * BigDecimal("3.1415").precision # => 5 + * BigDecimal("-1e20").precision # => 21 + * BigDecimal("1e-20").precision # => 20 + * BigDecimal("Infinity").precision # => 0 + * BigDecimal("-Infinity").precision # => 0 + * BigDecimal("NaN").precision # => 0 + * + */ +static VALUE +BigDecimal_precision(VALUE self) +{ + ssize_t precision; + BigDecimal_count_precision_and_scale(self, &precision, NULL); return SSIZET2NUM(precision); } +/* + * call-seq: + * scale -> integer + * + * Returns the number of decimal digits following the decimal digits in +self+. + * + * BigDecimal("0").scale # => 0 + * BigDecimal("1").scale # => 1 + * BigDecimal("1.1").scale # => 1 + * BigDecimal("3.1415").scale # => 4 + * BigDecimal("-1e20").precision # => 0 + * BigDecimal("1e-20").precision # => 20 + * BigDecimal("Infinity").scale # => 0 + * BigDecimal("-Infinity").scale # => 0 + * BigDecimal("NaN").scale # => 0 + */ +static VALUE +BigDecimal_scale(VALUE self) +{ + ssize_t scale; + BigDecimal_count_precision_and_scale(self, NULL, &scale); + return SSIZET2NUM(scale); +} + +/* + * call-seq: + * precision_scale -> [integer, integer] + * + * Returns a 2-length array; the first item is the result of + * BigDecimal#precision and the second one is of BigDecimal#scale. + * + * See BigDecimal#precision. + * See BigDecimal#scale. + */ +static VALUE +BigDecimal_precision_scale(VALUE self) +{ + ssize_t precision, scale; + BigDecimal_count_precision_and_scale(self, &precision, &scale); + return rb_assoc_new(SSIZET2NUM(precision), SSIZET2NUM(scale)); +} + +/* + * call-seq: + * n_significant_digits -> integer + * + * Returns the number of decimal significant digits in +self+. + * + * BigDecimal("0").scale # => 0 + * BigDecimal("1").scale # => 1 + * BigDecimal("1.1").scale # => 2 + * BigDecimal("3.1415").scale # => 5 + * BigDecimal("-1e20").precision # => 1 + * BigDecimal("1e-20").precision # => 1 + * BigDecimal("Infinity").scale # => 0 + * BigDecimal("-Infinity").scale # => 0 + * BigDecimal("NaN").scale # => 0 + */ static VALUE BigDecimal_n_significant_digits(VALUE self) { @@ -392,32 +503,38 @@ BigDecimal_n_significant_digits(VALUE self) Real *p; GUARD_OBJ(p, GetVpValue(self, 1)); - - ssize_t n = p->Prec; - while (n > 0 && p->frac[n-1] == 0) --n; - if (n <= 0) { + if (VpIsZero(p) || !VpIsDef(p)) { return INT2FIX(0); } - int nlz, ntz; + ssize_t n = p->Prec; /* The length of frac without trailing zeros. */ + for (n = p->Prec; n > 0 && p->frac[n-1] == 0; --n); + if (n == 0) return INT2FIX(0); - DECDIG x = p->frac[0]; - for (nlz = BASE_FIG; x > 0; x /= 10) --nlz; + DECDIG x; + int nlz = BASE_FIG; + for (x = p->frac[0]; x > 0; x /= 10) --nlz; - x = p->frac[n-1]; - for (ntz = 0; x > 0 && x % 10 == 0; x /= 10) ++ntz; + int ntz = 0; + for (x = p->frac[n-1]; x > 0 && x % 10 == 0; x /= 10) ++ntz; - ssize_t n_digits = BASE_FIG * n - nlz - ntz; - return SSIZET2NUM(n_digits); + ssize_t n_significant_digits = BASE_FIG*n - nlz - ntz; + return SSIZET2NUM(n_significant_digits); } /* - * call-seq: hash + * call-seq: + * hash -> integer + * + * Returns the integer hash value for +self+. + * + * Two instances of \BigDecimal have the same hash value if and only if + * they have equal: * - * Creates a hash for this BigDecimal. + * - Sign. + * - Fractional part. + * - Exponent. * - * Two BigDecimals with equal sign, - * fractional part and exponent have the same hash. */ static VALUE BigDecimal_hash(VALUE self) @@ -437,16 +554,16 @@ BigDecimal_hash(VALUE self) } /* - * call-seq: _dump + * call-seq: + * _dump -> string * - * Method used to provide marshalling support. + * Returns a string representing the marshalling of +self+. + * See module Marshal. * - * inf = BigDecimal('Infinity') - * #=> Infinity - * BigDecimal._load(inf._dump) - * #=> Infinity + * inf = BigDecimal('Infinity') # => Infinity + * dumped = inf._dump # => "9:Infinity" + * BigDecimal._load(dumped) # => Infinity * - * See the Marshal module. */ static VALUE BigDecimal_dump(int argc, VALUE *argv, VALUE self) @@ -580,42 +697,166 @@ check_rounding_mode(VALUE const v) return sw; } -/* call-seq: - * BigDecimal.mode(mode, value) - * - * Controls handling of arithmetic exceptions and rounding. If no value - * is supplied, the current value is returned. - * - * Six values of the mode parameter control the handling of arithmetic - * exceptions: - * - * BigDecimal::EXCEPTION_NaN - * BigDecimal::EXCEPTION_INFINITY - * BigDecimal::EXCEPTION_UNDERFLOW - * BigDecimal::EXCEPTION_OVERFLOW - * BigDecimal::EXCEPTION_ZERODIVIDE - * BigDecimal::EXCEPTION_ALL - * - * For each mode parameter above, if the value set is false, computation - * continues after an arithmetic exception of the appropriate type. - * When computation continues, results are as follows: - * - * EXCEPTION_NaN:: NaN - * EXCEPTION_INFINITY:: +Infinity or -Infinity - * EXCEPTION_UNDERFLOW:: 0 - * EXCEPTION_OVERFLOW:: +Infinity or -Infinity - * EXCEPTION_ZERODIVIDE:: +Infinity or -Infinity - * - * One value of the mode parameter controls the rounding of numeric values: - * BigDecimal::ROUND_MODE. The values it can take are: - * - * ROUND_UP, :up:: round away from zero - * ROUND_DOWN, :down, :truncate:: round towards zero (truncate) - * ROUND_HALF_UP, :half_up, :default:: round towards the nearest neighbor, unless both neighbors are equidistant, in which case round away from zero. (default) - * ROUND_HALF_DOWN, :half_down:: round towards the nearest neighbor, unless both neighbors are equidistant, in which case round towards zero. - * ROUND_HALF_EVEN, :half_even, :banker:: round towards the nearest neighbor, unless both neighbors are equidistant, in which case round towards the even neighbor (Banker's rounding) - * ROUND_CEILING, :ceiling, :ceil:: round towards positive infinity (ceil) - * ROUND_FLOOR, :floor:: round towards negative infinity (floor) +/* call-seq: + * BigDecimal.mode(mode, setting = nil) -> integer + * + * Returns an integer representing the mode settings + * for exception handling and rounding. + * + * These modes control exception handling: + * + * - \BigDecimal::EXCEPTION_NaN. + * - \BigDecimal::EXCEPTION_INFINITY. + * - \BigDecimal::EXCEPTION_UNDERFLOW. + * - \BigDecimal::EXCEPTION_OVERFLOW. + * - \BigDecimal::EXCEPTION_ZERODIVIDE. + * - \BigDecimal::EXCEPTION_ALL. + * + * Values for +setting+ for exception handling: + * + * - +true+: sets the given +mode+ to +true+. + * - +false+: sets the given +mode+ to +false+. + * - +nil+: does not modify the mode settings. + * + * You can use method BigDecimal.save_exception_mode + * to temporarily change, and then automatically restore, exception modes. + * + * For clarity, some examples below begin by setting all + * exception modes to +false+. + * + * This mode controls the way rounding is to be performed: + * + * - \BigDecimal::ROUND_MODE + * + * You can use method BigDecimal.save_rounding_mode + * to temporarily change, and then automatically restore, the rounding mode. + * + * <b>NaNs</b> + * + * Mode \BigDecimal::EXCEPTION_NaN controls behavior + * when a \BigDecimal NaN is created. + * + * Settings: + * + * - +false+ (default): Returns <tt>BigDecimal('NaN')</tt>. + * - +true+: Raises FloatDomainError. + * + * Examples: + * + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0 + * BigDecimal('NaN') # => NaN + * BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true) # => 2 + * BigDecimal('NaN') # Raises FloatDomainError + * + * <b>Infinities</b> + * + * Mode \BigDecimal::EXCEPTION_INFINITY controls behavior + * when a \BigDecimal Infinity or -Infinity is created. + * Settings: + * + * - +false+ (default): Returns <tt>BigDecimal('Infinity')</tt> + * or <tt>BigDecimal('-Infinity')</tt>. + * - +true+: Raises FloatDomainError. + * + * Examples: + * + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0 + * BigDecimal('Infinity') # => Infinity + * BigDecimal('-Infinity') # => -Infinity + * BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true) # => 1 + * BigDecimal('Infinity') # Raises FloatDomainError + * BigDecimal('-Infinity') # Raises FloatDomainError + * + * <b>Underflow</b> + * + * Mode \BigDecimal::EXCEPTION_UNDERFLOW controls behavior + * when a \BigDecimal underflow occurs. + * Settings: + * + * - +false+ (default): Returns <tt>BigDecimal('0')</tt> + * or <tt>BigDecimal('-Infinity')</tt>. + * - +true+: Raises FloatDomainError. + * + * Examples: + * + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0 + * def flow_under + * x = BigDecimal('0.1') + * 100.times { x *= x } + * end + * flow_under # => 100 + * BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, true) # => 4 + * flow_under # Raises FloatDomainError + * + * <b>Overflow</b> + * + * Mode \BigDecimal::EXCEPTION_OVERFLOW controls behavior + * when a \BigDecimal overflow occurs. + * Settings: + * + * - +false+ (default): Returns <tt>BigDecimal('Infinity')</tt> + * or <tt>BigDecimal('-Infinity')</tt>. + * - +true+: Raises FloatDomainError. + * + * Examples: + * + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0 + * def flow_over + * x = BigDecimal('10') + * 100.times { x *= x } + * end + * flow_over # => 100 + * BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) # => 1 + * flow_over # Raises FloatDomainError + * + * <b>Zero Division</b> + * + * Mode \BigDecimal::EXCEPTION_ZERODIVIDE controls behavior + * when a zero-division occurs. + * Settings: + * + * - +false+ (default): Returns <tt>BigDecimal('Infinity')</tt> + * or <tt>BigDecimal('-Infinity')</tt>. + * - +true+: Raises FloatDomainError. + * + * Examples: + * + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0 + * one = BigDecimal('1') + * zero = BigDecimal('0') + * one / zero # => Infinity + * BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true) # => 16 + * one / zero # Raises FloatDomainError + * + * <b>All Exceptions</b> + * + * Mode \BigDecimal::EXCEPTION_ALL controls all of the above: + * + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0 + * BigDecimal.mode(BigDecimal::EXCEPTION_ALL, true) # => 23 + * + * <b>Rounding</b> + * + * Mode \BigDecimal::ROUND_MODE controls the way rounding is to be performed; + * its +setting+ values are: + * + * - +ROUND_UP+: Round away from zero. + * Aliased as +:up+. + * - +ROUND_DOWN+: Round toward zero. + * Aliased as +:down+ and +:truncate+. + * - +ROUND_HALF_UP+: Round toward the nearest neighbor; + * if the neighbors are equidistant, round away from zero. + * Aliased as +:half_up+ and +:default+. + * - +ROUND_HALF_DOWN+: Round toward the nearest neighbor; + * if the neighbors are equidistant, round toward zero. + * Aliased as +:half_down+. + * - +ROUND_HALF_EVEN+ (Banker's rounding): Round toward the nearest neighbor; + * if the neighbors are equidistant, round toward the even neighbor. + * Aliased as +:half_even+ and +:banker+. + * - +ROUND_CEILING+: Round toward positive infinity. + * Aliased as +:ceiling+ and +:ceil+. + * - +ROUND_FLOOR+: Round toward negative infinity. + * Aliased as +:floor:+. * */ static VALUE @@ -739,7 +980,18 @@ VpCreateRbObject(size_t mx, const char *str, bool raise_exception) } #define VpAllocReal(prec) (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(DECDIG)) -#define VpReallocReal(ptr, prec) (Real *)VpMemRealloc((ptr), offsetof(Real, frac) + (prec) * sizeof(DECDIG)) + +static Real * +VpReallocReal(Real *pv, size_t prec) +{ + VALUE obj = pv ? pv->obj : 0; + Real *new_pv = (Real *)VpMemRealloc(pv, offsetof(Real, frac) + prec * sizeof(DECDIG)); + if (obj) { + new_pv->obj = 0; + BigDecimal_wrap_struct(obj, new_pv); + } + return new_pv; +} static Real * VpCopy(Real *pv, Real const* const x) @@ -966,12 +1218,14 @@ BigDecimal_coerce(VALUE self, VALUE other) } /* - * call-seq: - * +big_decimal -> big_decimal + * call-seq: + * +big_decimal -> self * - * Return self. + * Returns +self+: + * + * +BigDecimal(5) # => 0.5e1 + * +BigDecimal(-5) # => -0.5e1 * - * +BigDecimal('5') #=> 0.5e1 */ static VALUE @@ -981,22 +1235,21 @@ BigDecimal_uplus(VALUE self) } /* - * Document-method: BigDecimal#add - * Document-method: BigDecimal#+ + * call-seq: + * self + value -> bigdecimal * - * call-seq: - * add(value, digits) + * Returns the \BigDecimal sum of +self+ and +value+: * - * Add the specified value. + * b = BigDecimal('111111.111') # => 0.111111111e6 + * b + 2 # => 0.111113111e6 + * b + 2.0 # => 0.111113111e6 + * b + Rational(2, 1) # => 0.111113111e6 + * b + Complex(2, 0) # => (0.111113111e6+0i) * - * e.g. - * c = a.add(b,n) - * c = a + b + * See the {Note About Precision}[BigDecimal.html#class-BigDecimal-label-A+Note+About+Precision]. * - * digits:: If specified and less than the number of significant digits of the - * result, the result is rounded to that number of digits, according - * to BigDecimal.mode. */ + static VALUE BigDecimal_add(VALUE self, VALUE r) { @@ -1038,21 +1291,18 @@ BigDecimal_add(VALUE self, VALUE r) return VpCheckGetValue(c); } - /* call-seq: - * a - b -> bigdecimal - * - * Subtract the specified value. - * - * e.g. - * c = a - b + /* call-seq: + * self - value -> bigdecimal * - * The precision of the result value depends on the type of +b+. + * Returns the \BigDecimal difference of +self+ and +value+: * - * If +b+ is a Float, the precision of the result is Float::DIG+1. + * b = BigDecimal('333333.333') # => 0.333333333e6 + * b - 2 # => 0.333331333e6 + * b - 2.0 # => 0.333331333e6 + * b - Rational(2, 1) # => 0.333331333e6 + * b - Complex(2, 0) # => (0.333331333e6+0i) * - * If +b+ is a BigDecimal, the precision of the result is +b+'s precision of - * internal representation from platform. So, it's return value is platform - * dependent. + * See the {Note About Precision}[BigDecimal.html#class-BigDecimal-label-A+Note+About+Precision]. * */ static VALUE @@ -1231,12 +1481,19 @@ BigDecimal_eq(VALUE self, VALUE r) return BigDecimalCmp(self, r, '='); } -/* call-seq: - * a < b +/* call-seq: + * self < other -> true or false + * + * Returns +true+ if +self+ is less than +other+, +false+ otherwise: + * + * b = BigDecimal('1.5') # => 0.15e1 + * b < 2 # => true + * b < 2.0 # => true + * b < Rational(2, 1) # => true + * b < 1.5 # => false * - * Returns true if a is less than b. + * Raises an exception if the comparison cannot be made. * - * Values may be coerced to perform the comparison (see ==, BigDecimal#coerce). */ static VALUE BigDecimal_lt(VALUE self, VALUE r) @@ -1244,12 +1501,20 @@ BigDecimal_lt(VALUE self, VALUE r) return BigDecimalCmp(self, r, '<'); } -/* call-seq: - * a <= b +/* call-seq: + * self <= other -> true or false + * + * Returns +true+ if +self+ is less or equal to than +other+, +false+ otherwise: * - * Returns true if a is less than or equal to b. + * b = BigDecimal('1.5') # => 0.15e1 + * b <= 2 # => true + * b <= 2.0 # => true + * b <= Rational(2, 1) # => true + * b <= 1.5 # => true + * b < 1 # => false + * + * Raises an exception if the comparison cannot be made. * - * Values may be coerced to perform the comparison (see ==, BigDecimal#coerce). */ static VALUE BigDecimal_le(VALUE self, VALUE r) @@ -1257,12 +1522,19 @@ BigDecimal_le(VALUE self, VALUE r) return BigDecimalCmp(self, r, 'L'); } -/* call-seq: - * a > b +/* call-seq: + * self > other -> true or false + * + * Returns +true+ if +self+ is greater than +other+, +false+ otherwise: * - * Returns true if a is greater than b. + * b = BigDecimal('1.5') + * b > 1 # => true + * b > 1.0 # => true + * b > Rational(1, 1) # => true + * b > 2 # => false + * + * Raises an exception if the comparison cannot be made. * - * Values may be coerced to perform the comparison (see ==, BigDecimal#coerce). */ static VALUE BigDecimal_gt(VALUE self, VALUE r) @@ -1270,12 +1542,20 @@ BigDecimal_gt(VALUE self, VALUE r) return BigDecimalCmp(self, r, '>'); } -/* call-seq: - * a >= b +/* call-seq: + * self >= other -> true or false + * + * Returns +true+ if +self+ is greater than or equal to +other+, +false+ otherwise: * - * Returns true if a is greater than or equal to b. + * b = BigDecimal('1.5') + * b >= 1 # => true + * b >= 1.0 # => true + * b >= Rational(1, 1) # => true + * b >= 1.5 # => true + * b > 2 # => false + * + * Raises an exception if the comparison cannot be made. * - * Values may be coerced to perform the comparison (see ==, BigDecimal#coerce) */ static VALUE BigDecimal_ge(VALUE self, VALUE r) @@ -1285,11 +1565,14 @@ BigDecimal_ge(VALUE self, VALUE r) /* * call-seq: - * -big_decimal -> big_decimal + * -self -> bigdecimal + * + * Returns the \BigDecimal negation of self: * - * Return the negation of self. + * b0 = BigDecimal('1.5') + * b1 = -b0 # => -0.15e1 + * b2 = -b1 # => 0.15e1 * - * -BigDecimal('5') #=> -0.5e1 */ static VALUE @@ -1303,21 +1586,6 @@ BigDecimal_neg(VALUE self) return VpCheckGetValue(c); } - /* - * Document-method: BigDecimal#mult - * - * call-seq: mult(value, digits) - * - * Multiply by the specified value. - * - * e.g. - * c = a.mult(b,n) - * c = a * b - * - * digits:: If specified and less than the number of significant digits of the - * result, the result is rounded to that number of digits, according - * to BigDecimal.mode. - */ static VALUE BigDecimal_mult(VALUE self, VALUE r) { @@ -1351,6 +1619,7 @@ BigDecimal_divide(VALUE self, VALUE r, Real **c, Real **res, Real **div) { ENTER(5); Real *a, *b; + ssize_t a_prec, b_prec; size_t mx; TypedData_Get_Struct(self, Real, &BigDecimal_data_type, a); @@ -1376,26 +1645,35 @@ BigDecimal_divide(VALUE self, VALUE r, Real **c, Real **res, Real **div) TypedData_Get_Struct(rr, Real, &BigDecimal_data_type, b); SAVE(b); - *div = b; - mx = a->Prec + vabs(a->exponent); - if (mx < b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent); - mx++; /* NOTE: An additional digit is needed for the compatibility to - the version 1.2.1 and the former. */ - mx = (mx + 1) * VpBaseFig(); - GUARD_OBJ((*c), VpCreateRbObject(mx, "#0", true)); - GUARD_OBJ((*res), VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0", true)); + + BigDecimal_count_precision_and_scale(self, &a_prec, NULL); + BigDecimal_count_precision_and_scale(rr, &b_prec, NULL); + mx = (a_prec > b_prec) ? a_prec : b_prec; + mx *= 2; + + if (2*BIGDECIMAL_DOUBLE_FIGURES > mx) + mx = 2*BIGDECIMAL_DOUBLE_FIGURES; + + GUARD_OBJ((*c), VpCreateRbObject(mx + 2*BASE_FIG, "#0", true)); + GUARD_OBJ((*res), VpCreateRbObject((mx + 1)*2 + 2*BASE_FIG, "#0", true)); VpDivd(*c, *res, a, b); + return Qnil; } +static VALUE BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod); + /* call-seq: - * a / b -> bigdecimal - * quo(value) -> bigdecimal + * a / b -> bigdecimal * * Divide by the specified value. * + * The result precision will be the precision of the larger operand, + * but its minimum is 2*Float::DIG. + * * See BigDecimal#div. + * See BigDecimal#quo. */ static VALUE BigDecimal_div(VALUE self, VALUE r) @@ -1417,6 +1695,45 @@ BigDecimal_div(VALUE self, VALUE r) return VpCheckGetValue(c); } +static VALUE BigDecimal_round(int argc, VALUE *argv, VALUE self); + +/* call-seq: + * quo(value) -> bigdecimal + * quo(value, digits) -> bigdecimal + * + * Divide by the specified value. + * + * digits:: If specified and less than the number of significant digits of + * the result, the result is rounded to the given number of digits, + * according to the rounding mode indicated by BigDecimal.mode. + * + * If digits is 0 or omitted, the result is the same as for the + * / operator. + * + * See BigDecimal#/. + * See BigDecimal#div. + */ +static VALUE +BigDecimal_quo(int argc, VALUE *argv, VALUE self) +{ + VALUE value, digits, result; + SIGNED_VALUE n = -1; + + argc = rb_scan_args(argc, argv, "11", &value, &digits); + if (argc > 1) { + n = GetPrecisionInt(digits); + } + + if (n > 0) { + result = BigDecimal_div2(self, value, digits); + } + else { + result = BigDecimal_div(self, value); + } + + return result; +} + /* * %: mod = a%b = a - (a.to_f/b).floor * b * div = (a.to_f/b).floor @@ -1427,6 +1744,7 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod) ENTER(8); Real *c=NULL, *d=NULL, *res=NULL; Real *a, *b; + ssize_t a_prec, b_prec; size_t mx; TypedData_Get_Struct(self, Real, &BigDecimal_data_type, a); @@ -1484,26 +1802,39 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod) return Qtrue; } - mx = a->Prec + vabs(a->exponent); - if (mx<b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent); - mx = (mx + 1) * VpBaseFig(); - GUARD_OBJ(c, VpCreateRbObject(mx, "0", true)); - GUARD_OBJ(res, VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0", true)); + BigDecimal_count_precision_and_scale(self, &a_prec, NULL); + BigDecimal_count_precision_and_scale(rr, &b_prec, NULL); + + mx = (a_prec > b_prec) ? a_prec : b_prec; + mx *= 2; + + if (2*BIGDECIMAL_DOUBLE_FIGURES > mx) + mx = 2*BIGDECIMAL_DOUBLE_FIGURES; + + GUARD_OBJ(c, VpCreateRbObject(mx + 2*BASE_FIG, "0", true)); + GUARD_OBJ(res, VpCreateRbObject(mx*2 + 2*BASE_FIG, "#0", true)); VpDivd(c, res, a, b); - mx = c->Prec * (VpBaseFig() + 1); + + mx = c->Prec * BASE_FIG; GUARD_OBJ(d, VpCreateRbObject(mx, "0", true)); VpActiveRound(d, c, VP_ROUND_DOWN, 0); + VpMult(res, d, b); VpAddSub(c, a, res, -1); + if (!VpIsZero(c) && (VpGetSign(a) * VpGetSign(b) < 0)) { - VpAddSub(res, d, VpOne(), -1); - GUARD_OBJ(d, VpCreateRbObject(GetAddSubPrec(c, b)*(VpBaseFig() + 1), "0", true)); - VpAddSub(d, c, b, 1); - *div = res; - *mod = d; - } else { - *div = d; - *mod = c; + /* result adjustment for negative case */ + res = VpReallocReal(res, d->MaxPrec); + res->MaxPrec = d->MaxPrec; + VpAddSub(res, d, VpOne(), -1); + GUARD_OBJ(d, VpCreateRbObject(GetAddSubPrec(c, b) * 2*BASE_FIG, "0", true)); + VpAddSub(d, c, b, 1); + *div = res; + *mod = d; + } + else { + *div = d; + *mod = c; } return Qtrue; @@ -1663,11 +1994,18 @@ BigDecimal_div2(VALUE self, VALUE b, VALUE n) Real *res = NULL; Real *av = NULL, *bv = NULL, *cv = NULL; size_t mx = ix + VpBaseFig()*2; + size_t b_prec = ix; size_t pl = VpSetPrecLimit(0); GUARD_OBJ(cv, VpCreateRbObject(mx + VpBaseFig(), "0", true)); GUARD_OBJ(av, GetVpValue(self, 1)); - GUARD_OBJ(bv, GetVpValue(b, 1)); + /* TODO: I want to refactor this precision control for a float value later + * by introducing an implicit conversion function instead of + * GetVpValueWithPrec. */ + if (RB_FLOAT_TYPE_P(b) && b_prec > BIGDECIMAL_DOUBLE_FIGURES) { + b_prec = BIGDECIMAL_DOUBLE_FIGURES; + } + GUARD_OBJ(bv, GetVpValueWithPrec(b, b_prec, 1)); mx = av->Prec + bv->Prec + 2; if (mx <= cv->MaxPrec) mx = cv->MaxPrec + 1; GUARD_OBJ(res, VpCreateRbObject((mx * 2 + 2)*VpBaseFig(), "#0", true)); @@ -1682,6 +2020,7 @@ BigDecimal_div2(VALUE self, VALUE b, VALUE n) * Document-method: BigDecimal#div * * call-seq: + * div(value) -> integer * div(value, digits) -> bigdecimal or integer * * Divide by the specified value. @@ -1696,6 +2035,9 @@ BigDecimal_div2(VALUE self, VALUE b, VALUE n) * If digits is not specified, the result is an integer, * by analogy with Float#div; see also BigDecimal#divmod. * + * See BigDecimal#/. + * See BigDecimal#quo. + * * Examples: * * a = BigDecimal("4") @@ -1719,6 +2061,31 @@ BigDecimal_div3(int argc, VALUE *argv, VALUE self) return BigDecimal_div2(self, b, n); } + /* + * call-seq: + * add(value, ndigits) -> new_bigdecimal + * + * Returns the \BigDecimal sum of +self+ and +value+ + * with a precision of +ndigits+ decimal digits. + * + * When +ndigits+ is less than the number of significant digits + * in the sum, the sum is rounded to that number of digits, + * according to the current rounding mode; see BigDecimal.mode. + * + * Examples: + * + * # Set the rounding mode. + * BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up) + * b = BigDecimal('111111.111') + * b.add(1, 0) # => 0.111112111e6 + * b.add(1, 3) # => 0.111e6 + * b.add(1, 6) # => 0.111112e6 + * b.add(1, 15) # => 0.111112111e6 + * b.add(1.0, 15) # => 0.111112111e6 + * b.add(Rational(1, 1), 15) # => 0.111112111e6 + * + */ + static VALUE BigDecimal_add2(VALUE self, VALUE b, VALUE n) { @@ -1766,6 +2133,31 @@ BigDecimal_sub2(VALUE self, VALUE b, VALUE n) } } + /* + * call-seq: + * mult(other, ndigits) -> bigdecimal + * + * Returns the \BigDecimal product of +self+ and +value+ + * with a precision of +ndigits+ decimal digits. + * + * When +ndigits+ is less than the number of significant digits + * in the sum, the sum is rounded to that number of digits, + * according to the current rounding mode; see BigDecimal.mode. + * + * Examples: + * + * # Set the rounding mode. + * BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up) + * b = BigDecimal('555555.555') + * b.mult(3, 0) # => 0.1666666665e7 + * b.mult(3, 3) # => 0.167e7 + * b.mult(3, 6) # => 0.166667e7 + * b.mult(3, 15) # => 0.1666666665e7 + * b.mult(3.0, 0) # => 0.1666666665e7 + * b.mult(Rational(3, 1), 0) # => 0.1666666665e7 + * b.mult(Complex(3, 0), 0) # => (0.1666666665e7+0.0i) + * + */ static VALUE BigDecimal_mult2(VALUE self, VALUE b, VALUE n) @@ -1786,12 +2178,13 @@ BigDecimal_mult2(VALUE self, VALUE b, VALUE n) /* * call-seq: - * big_decimal.abs -> big_decimal + * abs -> bigdecimal * - * Returns the absolute value, as a BigDecimal. + * Returns the \BigDecimal absolute value of +self+: + * + * BigDecimal('5').abs # => 0.5e1 + * BigDecimal('-3').abs # => 0.3e1 * - * BigDecimal('5').abs #=> 0.5e1 - * BigDecimal('-3').abs #=> 0.3e1 */ static VALUE @@ -2637,12 +3030,18 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self) return VpCheckGetValue(y); } -/* call-seq: - * a ** n -> bigdecimal +/* call-seq: + * self ** other -> bigdecimal * - * Returns the value raised to the power of n. + * Returns the \BigDecimal value of +self+ raised to power +other+: + * + * b = BigDecimal('3.14') + * b ** 2 # => 0.98596e1 + * b ** 2.0 # => 0.98596e1 + * b ** Rational(2, 1) # => 0.98596e1 + * + * Related: BigDecimal#power. * - * See BigDecimal#power. */ static VALUE BigDecimal_power_op(VALUE self, VALUE exp) @@ -2732,21 +3131,29 @@ rb_uint64_convert_to_BigDecimal(uint64_t uval, RB_UNUSED_VAR(size_t digs), int r } else { DECDIG buf[BIGDECIMAL_INT64_MAX_LENGTH] = {0,}; - size_t exp = 0, ntz = 0; - for (; uval > 0; ++exp) { - DECDIG r = uval % BASE; - if (r == 0) ++ntz; - buf[BIGDECIMAL_INT64_MAX_LENGTH - exp - 1] = r; + DECDIG r = uval % BASE; + size_t len = 0, ntz = 0; + if (r == 0) { + // Count and skip trailing zeros + for (; r == 0 && uval > 0; ++ntz) { + uval /= BASE; + r = uval % BASE; + } + } + for (; uval > 0; ++len) { + // Store digits + buf[BIGDECIMAL_INT64_MAX_LENGTH - len - 1] = r; uval /= BASE; + r = uval % BASE; } - const size_t len = exp - ntz; + const size_t exp = len + ntz; vp = VpAllocReal(len); vp->MaxPrec = len; vp->Prec = len; vp->exponent = exp; VpSetSign(vp, 1); - MEMCPY(vp->frac, buf + BIGDECIMAL_INT64_MAX_LENGTH - exp, DECDIG, len); + MEMCPY(vp->frac, buf + BIGDECIMAL_INT64_MAX_LENGTH - len, DECDIG, len); } return BigDecimal_wrap_struct(obj, vp); @@ -2770,8 +3177,12 @@ rb_big_convert_to_BigDecimal(VALUE val, RB_UNUSED_VAR(size_t digs), int raise_ex { assert(RB_TYPE_P(val, T_BIGNUM)); - size_t size = rb_absint_size(val, NULL); + int leading_zeros; + size_t size = rb_absint_size(val, &leading_zeros); int sign = FIX2INT(rb_big_cmp(val, INT2FIX(0))); + if (sign < 0 && leading_zeros == 0) { + size += 1; + } if (size <= sizeof(long)) { if (sign < 0) { return rb_int64_convert_to_BigDecimal(NUM2LONG(val), digs, raise_exception); @@ -2870,7 +3281,7 @@ rb_float_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception) VALUE inum; size_t RB_UNUSED_VAR(prec) = 0; - size_t exp = 0; + SIGNED_VALUE exp = 0; if (decpt > 0) { if (decpt < len10) { /* @@ -3078,50 +3489,49 @@ rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception) return rb_str_convert_to_BigDecimal(str, digs, raise_exception); } -/* call-seq: - * BigDecimal(arg, exception: true) - * BigDecimal(arg, digits, exception: true) - * - * Returns <i>arg</i> converted to a BigDecimal. Numeric types are converted - * directly. Other types except for String are first converted to String - * by <code>to_str</code>. Strings can be converted when it has appropriate - * forms of decimal numbers. Exceptions can be suppressed by passing - * <code>exception: false</code>. +/* call-seq: + * BigDecimal(value, exception: true) -> bigdecimal + * BigDecimal(value, ndigits, exception: true) -> bigdecimal * - * When <i>arg</i> is a Float and <i>digits</i> is <code>0</code>, the number - * of digits is determined by the algorithm of <code>dtoa</code> function - * written by David M. Gay. That algorithm is based on "How to Print Floating- - * Point Numbers Accurately" by Guy L. Steele, Jr. and Jon L. White [Proc. ACM - * SIGPLAN '90, pp. 112-126]. + * Returns the \BigDecimal converted from +value+ + * with a precision of +ndigits+ decimal digits. * - * arg:: The value converted to a BigDecimal. + * When +ndigits+ is less than the number of significant digits + * in the value, the result is rounded to that number of digits, + * according to the current rounding mode; see BigDecimal.mode. * - * If it is a String, spaces are ignored and unrecognized characters - * terminate the value. + * Returns +value+ converted to a \BigDecimal, depending on the type of +value+: * - * digits:: The number of significant digits, as an Integer. If omitted, - * the number of significant digits is determined from <i>arg</i>. + * - Integer, Float, Rational, Complex, or BigDecimal: converted directly: * - * The actual number of significant digits used in computation is - * usually larger than the specified number. + * # Integer, Complex, or BigDecimal value does not require ndigits; ignored if given. + * BigDecimal(2) # => 0.2e1 + * BigDecimal(Complex(2, 0)) # => 0.2e1 + * BigDecimal(BigDecimal(2)) # => 0.2e1 + * # Float or Rational value requires ndigits. + * BigDecimal(2.0, 0) # => 0.2e1 + * BigDecimal(Rational(2, 1), 0) # => 0.2e1 * - * exception:: Whether an exception should be raised on invalid arguments. - * +true+ by default, if passed +false+, just returns +nil+ - * for invalid. + * - String: converted by parsing if it contains an integer or floating-point literal; + * leading and trailing whitespace is ignored: * + * # String does not require ndigits; ignored if given. + * BigDecimal('2') # => 0.2e1 + * BigDecimal('2.0') # => 0.2e1 + * BigDecimal('0.2e1') # => 0.2e1 + * BigDecimal(' 2.0 ') # => 0.2e1 * - * ==== Exceptions + * - Other type that responds to method <tt>:to_str</tt>: + * first converted to a string, then converted to a \BigDecimal, as above. * - * TypeError:: If the +initial+ type is neither Integer, Float, - * Rational, nor BigDecimal, this exception is raised. + * - Other type: * - * TypeError:: If the +digits+ is not an Integer, this exception is raised. + * - Raises an exception if keyword argument +exception+ is +true+. + * - Returns +nil+ if keyword argument +exception+ is +true+. * - * ArgumentError:: If +initial+ is a Float, and the +digits+ is larger than - * Float::DIG + 1, this exception is raised. + * Raises an exception if +value+ evaluates to a Float + * and +digits+ is larger than Float::DIG + 1. * - * ArgumentError:: If the +initial+ is a Float or Rational, and the +digits+ - * value is omitted, this exception is raised. */ static VALUE f_BigDecimal(int argc, VALUE *argv, VALUE self) @@ -3671,6 +4081,18 @@ BigDecimal_negative_zero(void) * * (1.2 - 1.0) == 0.2 #=> false * + * == A Note About Precision + * + * For a calculation using a \BigDecimal and another +value+, + * the precision of the result depends on the type of +value+: + * + * - If +value+ is a \Float, + * the precision is Float::DIG + 1. + * - If +value+ is a \Rational, the precision is larger than Float::DIG + 1. + * - If +value+ is a \BigDecimal, the precision is +value+'s precision in the + * internal representation, which is platform-dependent. + * - If +value+ is other object, the precision is determined by the result of +BigDecimal(value)+. + * * == Special features of accurate decimal arithmetic * * Because BigDecimal is more accurate than normal binary floating point @@ -3931,6 +4353,8 @@ Init_bigdecimal(void) /* instance methods */ rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0); rb_define_method(rb_cBigDecimal, "precision", BigDecimal_precision, 0); + rb_define_method(rb_cBigDecimal, "scale", BigDecimal_scale, 0); + rb_define_method(rb_cBigDecimal, "precision_scale", BigDecimal_precision_scale, 0); rb_define_method(rb_cBigDecimal, "n_significant_digits", BigDecimal_n_significant_digits, 0); rb_define_method(rb_cBigDecimal, "add", BigDecimal_add2, 2); @@ -3949,7 +4373,7 @@ Init_bigdecimal(void) rb_define_method(rb_cBigDecimal, "-@", BigDecimal_neg, 0); rb_define_method(rb_cBigDecimal, "*", BigDecimal_mult, 1); rb_define_method(rb_cBigDecimal, "/", BigDecimal_div, 1); - rb_define_method(rb_cBigDecimal, "quo", BigDecimal_div, 1); + rb_define_method(rb_cBigDecimal, "quo", BigDecimal_quo, -1); rb_define_method(rb_cBigDecimal, "%", BigDecimal_mod, 1); rb_define_method(rb_cBigDecimal, "modulo", BigDecimal_mod, 1); rb_define_method(rb_cBigDecimal, "remainder", BigDecimal_remainder, 1); @@ -4123,6 +4547,27 @@ VpSetException(unsigned short f) bigdecimal_set_thread_local_exception_mode(f); } +static void +VpCheckException(Real *p, bool always) +{ + if (VpIsNaN(p)) { + VpException(VP_EXCEPTION_NaN, "Computation results in 'NaN' (Not a Number)", always); + } + else if (VpIsPosInf(p)) { + VpException(VP_EXCEPTION_INFINITY, "Computation results in 'Infinity'", always); + } + else if (VpIsNegInf(p)) { + VpException(VP_EXCEPTION_INFINITY, "Computation results in '-Infinity'", always); + } +} + +static VALUE +VpCheckGetValue(Real *p) +{ + VpCheckException(p, false); + return p->obj; +} + /* * Precision limit. */ @@ -5486,18 +5931,17 @@ VpDivd(Real *c, Real *r, Real *a, Real *b) word_c = c->MaxPrec; word_r = r->MaxPrec; - ind_c = 0; - ind_r = 1; - if (word_a >= word_r) goto space_error; + ind_r = 1; r->frac[0] = 0; while (ind_r <= word_a) { r->frac[ind_r] = a->frac[ind_r - 1]; ++ind_r; } - while (ind_r < word_r) r->frac[ind_r++] = 0; + + ind_c = 0; while (ind_c < word_c) c->frac[ind_c++] = 0; /* initial procedure */ diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec index bb4610cbbd..2ed7d09373 100644 --- a/ext/bigdecimal/bigdecimal.gemspec +++ b/ext/bigdecimal/bigdecimal.gemspec @@ -1,10 +1,8 @@ # coding: utf-8 -bigdecimal_version = '3.1.0.dev' - Gem::Specification.new do |s| s.name = "bigdecimal" - s.version = bigdecimal_version + s.version = "3.1.2" s.authors = ["Kenta Murata", "Zachary Scott", "Shigeo Kobayashi"] s.email = ["mrkn@mrkn.jp"] diff --git a/ext/bigdecimal/depend b/ext/bigdecimal/depend index d6f40714b3..ee892162f2 100644 --- a/ext/bigdecimal/depend +++ b/ext/bigdecimal/depend @@ -15,6 +15,7 @@ bigdecimal.o: $(hdrdir)/ruby/backward/2/stdalign.h bigdecimal.o: $(hdrdir)/ruby/backward/2/stdarg.h bigdecimal.o: $(hdrdir)/ruby/defines.h bigdecimal.o: $(hdrdir)/ruby/intern.h +bigdecimal.o: $(hdrdir)/ruby/internal/abi.h bigdecimal.o: $(hdrdir)/ruby/internal/anyargs.h bigdecimal.o: $(hdrdir)/ruby/internal/arithmetic.h bigdecimal.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -180,6 +181,7 @@ missing.o: $(hdrdir)/ruby/backward/2/stdalign.h missing.o: $(hdrdir)/ruby/backward/2/stdarg.h missing.o: $(hdrdir)/ruby/defines.h missing.o: $(hdrdir)/ruby/intern.h +missing.o: $(hdrdir)/ruby/internal/abi.h missing.o: $(hdrdir)/ruby/internal/anyargs.h missing.o: $(hdrdir)/ruby/internal/arithmetic.h missing.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb index c92aacb3f2..9b0c55b21c 100644 --- a/ext/bigdecimal/extconf.rb +++ b/ext/bigdecimal/extconf.rb @@ -3,10 +3,7 @@ require 'mkmf' def check_bigdecimal_version(gemspec_path) message "checking RUBY_BIGDECIMAL_VERSION... " - - bigdecimal_version = - IO.readlines(gemspec_path) - .grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([^\']+)\'/, 1] + bigdecimal_version = File.read(gemspec_path).match(/^\s*s\.version\s+=\s+['"]([^'"]+)['"]\s*$/)[1] version_components = bigdecimal_version.split('.') bigdecimal_version = version_components[0, 3].join('.') diff --git a/ext/bigdecimal/lib/bigdecimal/jacobian.rb b/ext/bigdecimal/lib/bigdecimal/jacobian.rb index 5e29304299..4448024c74 100644 --- a/ext/bigdecimal/lib/bigdecimal/jacobian.rb +++ b/ext/bigdecimal/lib/bigdecimal/jacobian.rb @@ -42,8 +42,8 @@ module Jacobian end - # Computes the derivative of f[i] at x[i]. - # fx is the value of f at x. + # Computes the derivative of +f[i]+ at +x[i]+. + # +fx+ is the value of +f+ at +x+. def dfdxi(f,fx,x,i) nRetry = 0 n = x.size @@ -75,7 +75,7 @@ module Jacobian deriv end - # Computes the Jacobian of f at x. fx is the value of f at x. + # Computes the Jacobian of +f+ at +x+. +fx+ is the value of +f+ at +x+. def jacobian(f,fx,x) n = x.size dfdx = Array.new(n*n) diff --git a/ext/cgi/escape/depend b/ext/cgi/escape/depend index e726e579d8..e3904d0695 100644 --- a/ext/cgi/escape/depend +++ b/ext/cgi/escape/depend @@ -15,6 +15,7 @@ escape.o: $(hdrdir)/ruby/backward/2/stdarg.h escape.o: $(hdrdir)/ruby/defines.h escape.o: $(hdrdir)/ruby/encoding.h escape.o: $(hdrdir)/ruby/intern.h +escape.o: $(hdrdir)/ruby/internal/abi.h escape.o: $(hdrdir)/ruby/internal/anyargs.h escape.o: $(hdrdir)/ruby/internal/arithmetic.h escape.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c index 809f95ef4c..f88b61478b 100644 --- a/ext/cgi/escape/escape.c +++ b/ext/cgi/escape/escape.c @@ -32,12 +32,21 @@ preserve_original_state(VALUE orig, VALUE dest) rb_enc_associate(dest, rb_enc_get(orig)); } +static inline long +escaped_length(VALUE str) +{ + const long len = RSTRING_LEN(str); + if (len >= LONG_MAX / HTML_ESCAPE_MAX_LEN) { + ruby_malloc_size_overflow(len, HTML_ESCAPE_MAX_LEN); + } + return len * HTML_ESCAPE_MAX_LEN; +} + static VALUE optimized_escape_html(VALUE str) { VALUE vbuf; - typedef char escape_buf[HTML_ESCAPE_MAX_LEN]; - char *buf = *ALLOCV_N(escape_buf, vbuf, RSTRING_LEN(str)); + char *buf = ALLOCV_N(char, vbuf, escaped_length(str)); const char *cstr = RSTRING_PTR(str); const char *end = cstr + RSTRING_LEN(str); diff --git a/ext/continuation/depend b/ext/continuation/depend index 14ecac1443..81218f9965 100644 --- a/ext/continuation/depend +++ b/ext/continuation/depend @@ -13,6 +13,7 @@ continuation.o: $(hdrdir)/ruby/backward/2/stdalign.h continuation.o: $(hdrdir)/ruby/backward/2/stdarg.h continuation.o: $(hdrdir)/ruby/defines.h continuation.o: $(hdrdir)/ruby/intern.h +continuation.o: $(hdrdir)/ruby/internal/abi.h continuation.o: $(hdrdir)/ruby/internal/anyargs.h continuation.o: $(hdrdir)/ruby/internal/arithmetic.h continuation.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/coverage/depend b/ext/coverage/depend index 228ee7381a..57d368d3f5 100644 --- a/ext/coverage/depend +++ b/ext/coverage/depend @@ -16,6 +16,7 @@ coverage.o: $(hdrdir)/ruby/backward/2/stdalign.h coverage.o: $(hdrdir)/ruby/backward/2/stdarg.h coverage.o: $(hdrdir)/ruby/defines.h coverage.o: $(hdrdir)/ruby/intern.h +coverage.o: $(hdrdir)/ruby/internal/abi.h coverage.o: $(hdrdir)/ruby/internal/anyargs.h coverage.o: $(hdrdir)/ruby/internal/arithmetic.h coverage.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -164,7 +165,6 @@ coverage.o: $(top_srcdir)/ccan/check_type/check_type.h coverage.o: $(top_srcdir)/ccan/container_of/container_of.h coverage.o: $(top_srcdir)/ccan/list/list.h coverage.o: $(top_srcdir)/ccan/str/str.h -coverage.o: $(top_srcdir)/darray.h coverage.o: $(top_srcdir)/gc.h coverage.o: $(top_srcdir)/internal.h coverage.o: $(top_srcdir)/internal/array.h diff --git a/ext/date/date_core.c b/ext/date/date_core.c index f6579b81e4..c7b4459c89 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -4339,15 +4339,24 @@ get_limit(VALUE opt) return 128; } +#ifndef HAVE_RB_CATEGORY_WARN +#define rb_category_warn(category, fmt) rb_warn(fmt) +#endif + static void check_limit(VALUE str, VALUE opt) { + size_t slen, limit; if (NIL_P(str)) return; - if (SYMBOL_P(str)) str = rb_sym2str(str); + if (SYMBOL_P(str)) { + rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, + "The ability to parse Symbol is an unintentional bug and is deprecated"); + str = rb_sym2str(str); + } StringValue(str); - size_t slen = RSTRING_LEN(str); - size_t limit = get_limit(opt); + slen = RSTRING_LEN(str); + limit = get_limit(opt); if (slen > limit) { rb_raise(rb_eArgError, "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit); @@ -4445,11 +4454,11 @@ date_s_parse(int argc, VALUE *argv, VALUE klass) { int argc2 = 2; - VALUE argv2[3]; + VALUE argv2[3], hash; argv2[0] = str; argv2[1] = comp; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__parse(argc2, argv2, klass); + hash = date_s__parse(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -4514,10 +4523,10 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__iso8601(argc2, argv2, klass); + hash = date_s__iso8601(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -4573,10 +4582,10 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__rfc3339(argc2, argv2, klass); + hash = date_s__rfc3339(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -4632,10 +4641,10 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__xmlschema(argc2, argv2, klass); + hash = date_s__xmlschema(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -4693,10 +4702,10 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__rfc2822(argc2, argv2, klass); + hash = date_s__rfc2822(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -4752,10 +4761,10 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__httpdate(argc2, argv2, klass); + hash = date_s__httpdate(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -4815,10 +4824,10 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; if (!NIL_P(opt)) argv2[argc2++] = opt; - VALUE hash = date_s__jisx0301(argc2, argv2, klass); + hash = date_s__jisx0301(argc2, argv2, klass); return d_new_by_frags(klass, hash, sg); } } @@ -8200,12 +8209,12 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass) { int argc2 = 2; - VALUE argv2[3]; + VALUE argv2[3], hash; argv2[0] = str; argv2[1] = comp; argv2[2] = opt; if (!NIL_P(opt)) argc2++; - VALUE hash = date_s__parse(argc2, argv2, klass); + hash = date_s__parse(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } @@ -8245,11 +8254,11 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; argv2[1] = opt; if (!NIL_P(opt)) argc2--; - VALUE hash = date_s__iso8601(argc2, argv2, klass); + hash = date_s__iso8601(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } @@ -8285,11 +8294,11 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; argv2[1] = opt; if (!NIL_P(opt)) argc2++; - VALUE hash = date_s__rfc3339(argc2, argv2, klass); + hash = date_s__rfc3339(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } @@ -8325,11 +8334,11 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; argv2[1] = opt; if (!NIL_P(opt)) argc2++; - VALUE hash = date_s__xmlschema(argc2, argv2, klass); + hash = date_s__xmlschema(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } @@ -8366,11 +8375,11 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; argv2[1] = opt; if (!NIL_P(opt)) argc2++; - VALUE hash = date_s__rfc2822(argc2, argv2, klass); + hash = date_s__rfc2822(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } @@ -8406,11 +8415,11 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; argv2[1] = opt; if (!NIL_P(opt)) argc2++; - VALUE hash = date_s__httpdate(argc2, argv2, klass); + hash = date_s__httpdate(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } @@ -8451,11 +8460,11 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass) { int argc2 = 1; - VALUE argv2[2]; + VALUE argv2[2], hash; argv2[0] = str; argv2[1] = opt; if (!NIL_P(opt)) argc2++; - VALUE hash = date_s__jisx0301(argc2, argv2, klass); + hash = date_s__jisx0301(argc2, argv2, klass); return dt_new_by_frags(klass, hash, sg); } } diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index 5fa036ed72..95274d5baa 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -253,6 +253,8 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc) #define ABBR_DAYS "sun|mon|tue|wed|thu|fri|sat" #define ABBR_MONTHS "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec" +#define NUMBER "(?<!\\d)\\d" + #ifdef TIGHT_PARSER #define VALID_DAYS "(?:" DAYS ")" "|(?:tues|wednes|thurs|thur|" ABBR_DAYS ")\\.?" #define VALID_MONTHS "(?:" MONTHS ")" "|(?:sept|" ABBR_MONTHS ")\\.?" @@ -652,24 +654,27 @@ parse_time(VALUE str, VALUE hash) { static const char pat_source[] = "(" + "" NUMBER "+\\s*" "(?:" - "\\d+\\s*:\\s*\\d+" "(?:" + ":\\s*\\d+" + "(?:" #ifndef TIGHT_PARSER - "\\s*:\\s*\\d+(?:[,.]\\d*)?" + "\\s*:\\s*\\d+(?:[,.]\\d*)?" #else - "\\s*:\\s*\\d+(?:[,.]\\d+)?" + "\\s*:\\s*\\d+(?:[,.]\\d+)?" #endif + ")?" + "|" + "h(?:\\s*\\d+m?(?:\\s*\\d+s?)?)?" + ")" + "(?:" + "\\s*" + "[ap](?:m\\b|\\.m\\.)" ")?" "|" - "\\d+\\s*h(?:\\s*\\d+m?(?:\\s*\\d+s?)?)?" - ")" - "(?:" - "\\s*" "[ap](?:m\\b|\\.m\\.)" - ")?" - "|" - "\\d+\\s*[ap](?:m\\b|\\.m\\.)" + ")" ")" "(?:" "\\s*" @@ -691,6 +696,9 @@ parse_time(VALUE str, VALUE hash) #endif } +#define BEGIN_ERA "\\b" +#define END_ERA "(?!(?<!\\.)[a-z])" + #ifdef TIGHT_PARSER static int parse_era1_cb(VALUE m, VALUE hash) @@ -702,7 +710,7 @@ static int parse_era1(VALUE str, VALUE hash) { static const char pat_source[] = - "(a(?:d|\\.d\\.))"; + BEGIN_ERA "(a(?:d\\b|\\.d\\.))" END_ERA; static VALUE pat = Qnil; REGCOMP_I(pat); @@ -724,8 +732,9 @@ parse_era2_cb(VALUE m, VALUE hash) static int parse_era2(VALUE str, VALUE hash) { - static const char pat_source[] = - "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|b(?:c|\\.c\\.))"; + static const char pat_source[] = BEGIN_ERA + "(c(?:e\\b|\\.e\\.)|b(?:ce\\b|\\.c\\.e\\.)|b(?:c\\b|\\.c\\.))" + END_ERA; static VALUE pat = Qnil; REGCOMP_I(pat); @@ -829,7 +838,7 @@ parse_eu(VALUE str, VALUE hash) FPW_COM FPT_COM #endif #ifndef TIGHT_PARSER - "('?\\d+)[^-\\d\\s]*" + "('?" NUMBER "+)[^-\\d\\s]*" #else "(\\d+)(?:(?:st|nd|rd|th)\\b)?" #endif @@ -842,7 +851,11 @@ parse_eu(VALUE str, VALUE hash) "(?:" "\\s*" #ifndef TIGHT_PARSER - "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))?" + "(?:" + BEGIN_ERA + "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))" + END_ERA + ")?" "\\s*" "('?-?\\d+(?:(?:st|nd|rd|th)\\b)?)" #else @@ -919,8 +932,8 @@ parse_us(VALUE str, VALUE hash) COM_FPT #endif "(?:" - "\\s*,?" - "\\s*" + "\\s*+,?" + "\\s*+" #ifndef TIGHT_PARSER "(c(?:e|\\.e\\.)|b(?:ce|\\.c\\.e\\.)|a(?:d|\\.d\\.)|b(?:c|\\.c\\.))?" "\\s*" @@ -967,7 +980,7 @@ parse_iso(VALUE str, VALUE hash) { static const char pat_source[] = #ifndef TIGHT_PARSER - "('?[-+]?\\d+)-(\\d+)-('?-?\\d+)" + "('?[-+]?" NUMBER "+)-(\\d+)-('?-?\\d+)" #else BOS FPW_COM FPT_COM @@ -1321,7 +1334,7 @@ parse_vms11(VALUE str, VALUE hash) { static const char pat_source[] = #ifndef TIGHT_PARSER - "('?-?\\d+)-(" ABBR_MONTHS ")[^-/.]*" + "('?-?" NUMBER "+)-(" ABBR_MONTHS ")[^-/.]*" "-('?-?\\d+)" #else BOS @@ -1416,7 +1429,7 @@ parse_sla(VALUE str, VALUE hash) { static const char pat_source[] = #ifndef TIGHT_PARSER - "('?-?\\d+)/\\s*('?\\d+)(?:\\D\\s*('?-?\\d+))?" + "('?-?" NUMBER "+)/\\s*('?\\d+)(?:\\D\\s*('?-?\\d+))?" #else BOS FPW_COM FPT_COM @@ -1524,7 +1537,7 @@ parse_dot(VALUE str, VALUE hash) { static const char pat_source[] = #ifndef TIGHT_PARSER - "('?-?\\d+)\\.\\s*('?\\d+)\\.\\s*('?-?\\d+)" + "('?-?" NUMBER "+)\\.\\s*('?\\d+)\\.\\s*('?-?\\d+)" #else BOS FPW_COM FPT_COM @@ -1684,7 +1697,7 @@ parse_mday(VALUE str, VALUE hash) { static const char pat_source[] = #ifndef TIGHT_PARSER - "(\\d+)(st|nd|rd|th)\\b" + "(" NUMBER "+)(st|nd|rd|th)\\b" #else BOS FPW_COM FPT_COM @@ -1922,7 +1935,7 @@ parse_ddd(VALUE str, VALUE hash) #ifdef TIGHT_PARSER BOS #endif - "([-+]?)(\\d{2,14})" + "([-+]?)(" NUMBER "{2,14})" "(?:" "\\s*" "t?" diff --git a/ext/date/depend b/ext/date/depend index 6841df724d..3f550cd0a7 100644 --- a/ext/date/depend +++ b/ext/date/depend @@ -15,6 +15,7 @@ date_core.o: $(hdrdir)/ruby/backward/2/stdarg.h date_core.o: $(hdrdir)/ruby/defines.h date_core.o: $(hdrdir)/ruby/encoding.h date_core.o: $(hdrdir)/ruby/intern.h +date_core.o: $(hdrdir)/ruby/internal/abi.h date_core.o: $(hdrdir)/ruby/internal/anyargs.h date_core.o: $(hdrdir)/ruby/internal/arithmetic.h date_core.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -188,6 +189,7 @@ date_parse.o: $(hdrdir)/ruby/backward/2/stdarg.h date_parse.o: $(hdrdir)/ruby/defines.h date_parse.o: $(hdrdir)/ruby/encoding.h date_parse.o: $(hdrdir)/ruby/intern.h +date_parse.o: $(hdrdir)/ruby/internal/abi.h date_parse.o: $(hdrdir)/ruby/internal/anyargs.h date_parse.o: $(hdrdir)/ruby/internal/arithmetic.h date_parse.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -362,6 +364,7 @@ date_strftime.o: $(hdrdir)/ruby/backward/2/stdalign.h date_strftime.o: $(hdrdir)/ruby/backward/2/stdarg.h date_strftime.o: $(hdrdir)/ruby/defines.h date_strftime.o: $(hdrdir)/ruby/intern.h +date_strftime.o: $(hdrdir)/ruby/internal/abi.h date_strftime.o: $(hdrdir)/ruby/internal/anyargs.h date_strftime.o: $(hdrdir)/ruby/internal/arithmetic.h date_strftime.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -523,6 +526,7 @@ date_strptime.o: $(hdrdir)/ruby/backward/2/stdarg.h date_strptime.o: $(hdrdir)/ruby/defines.h date_strptime.o: $(hdrdir)/ruby/encoding.h date_strptime.o: $(hdrdir)/ruby/intern.h +date_strptime.o: $(hdrdir)/ruby/internal/abi.h date_strptime.o: $(hdrdir)/ruby/internal/anyargs.h date_strptime.o: $(hdrdir)/ruby/internal/arithmetic.h date_strptime.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/date/extconf.rb b/ext/date/extconf.rb index f891de403d..358f64173a 100644 --- a/ext/date/extconf.rb +++ b/ext/date/extconf.rb @@ -3,6 +3,7 @@ require 'mkmf' config_string("strict_warnflags") {|w| $warnflags += " #{w}"} +have_func("rb_category_warn") with_werror("", {:werror => true}) do |opt, | have_var("timezone", "time.h", opt) have_var("altzone", "time.h", opt) diff --git a/ext/date/zonetab.h b/ext/date/zonetab.h index d82b011dc1..39a435db16 100644 --- a/ext/date/zonetab.h +++ b/ext/date/zonetab.h @@ -49,7 +49,7 @@ struct zone; #ifndef GPERF_DOWNCASE #define GPERF_DOWNCASE 1 -static unsigned char gperf_downcase[256] = +static const unsigned char gperf_downcase[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, diff --git a/ext/digest/bubblebabble/depend b/ext/digest/bubblebabble/depend index 28d4f472a9..38f5ddb1e2 100644 --- a/ext/digest/bubblebabble/depend +++ b/ext/digest/bubblebabble/depend @@ -14,6 +14,7 @@ bubblebabble.o: $(hdrdir)/ruby/backward/2/stdalign.h bubblebabble.o: $(hdrdir)/ruby/backward/2/stdarg.h bubblebabble.o: $(hdrdir)/ruby/defines.h bubblebabble.o: $(hdrdir)/ruby/intern.h +bubblebabble.o: $(hdrdir)/ruby/internal/abi.h bubblebabble.o: $(hdrdir)/ruby/internal/anyargs.h bubblebabble.o: $(hdrdir)/ruby/internal/arithmetic.h bubblebabble.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/digest/depend b/ext/digest/depend index 041ba8be51..5a84fd53ec 100644 --- a/ext/digest/depend +++ b/ext/digest/depend @@ -14,6 +14,7 @@ digest.o: $(hdrdir)/ruby/backward/2/stdalign.h digest.o: $(hdrdir)/ruby/backward/2/stdarg.h digest.o: $(hdrdir)/ruby/defines.h digest.o: $(hdrdir)/ruby/intern.h +digest.o: $(hdrdir)/ruby/internal/abi.h digest.o: $(hdrdir)/ruby/internal/anyargs.h digest.o: $(hdrdir)/ruby/internal/arithmetic.h digest.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/digest/digest.gemspec b/ext/digest/digest.gemspec index f8dff1797a..4a01c5fde1 100644 --- a/ext/digest/digest.gemspec +++ b/ext/digest/digest.gemspec @@ -1,12 +1,12 @@ # coding: utf-8 # frozen_string_literal: true -version_module = Module.new do - version_rb = File.join(__dir__, "lib/digest/version.rb") - module_eval(File.read(version_rb), version_rb) -end - Gem::Specification.new do |spec| + version_module = Module.new do + version_rb = File.join(__dir__, "lib/digest/version.rb") + module_eval(File.read(version_rb), version_rb) + end + spec.name = "digest" spec.version = version_module::Digest::VERSION spec.authors = ["Akinori MUSHA"] diff --git a/ext/digest/extconf.rb b/ext/digest/extconf.rb index ba2c7b671f..0e5f08d794 100644 --- a/ext/digest/extconf.rb +++ b/ext/digest/extconf.rb @@ -4,4 +4,8 @@ require "mkmf" +$INSTALLFILES = { + "digest.h" => "$(HDRDIR)" +} if $extmk + create_makefile("digest") diff --git a/ext/digest/install_headers.rb b/ext/digest/install_headers.rb deleted file mode 100644 index 0dd8022107..0000000000 --- a/ext/digest/install_headers.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "fileutils" - -*files, dest = ARGV - -if File.exist?(File.join(dest, "ruby.h")) - warn "installing header files" - - files.each { |file| - FileUtils.install file, dest, mode: 0644, verbose: true - } -else - warn "not installing header files when installed as an external library" -end diff --git a/ext/digest/lib/digest/version.rb b/ext/digest/lib/digest/version.rb index ed5a5bf1aa..79e6aeee99 100644 --- a/ext/digest/lib/digest/version.rb +++ b/ext/digest/lib/digest/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Digest - VERSION = "3.1.0.pre3" + VERSION = "3.1.0" end diff --git a/ext/digest/md5/depend b/ext/digest/md5/depend index 2e07652cc5..0353e7a40d 100644 --- a/ext/digest/md5/depend +++ b/ext/digest/md5/depend @@ -17,6 +17,7 @@ md5.o: $(hdrdir)/ruby/backward/2/stdalign.h md5.o: $(hdrdir)/ruby/backward/2/stdarg.h md5.o: $(hdrdir)/ruby/defines.h md5.o: $(hdrdir)/ruby/intern.h +md5.o: $(hdrdir)/ruby/internal/abi.h md5.o: $(hdrdir)/ruby/internal/anyargs.h md5.o: $(hdrdir)/ruby/internal/arithmetic.h md5.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -178,6 +179,7 @@ md5init.o: $(hdrdir)/ruby/backward/2/stdalign.h md5init.o: $(hdrdir)/ruby/backward/2/stdarg.h md5init.o: $(hdrdir)/ruby/defines.h md5init.o: $(hdrdir)/ruby/intern.h +md5init.o: $(hdrdir)/ruby/internal/abi.h md5init.o: $(hdrdir)/ruby/internal/anyargs.h md5init.o: $(hdrdir)/ruby/internal/arithmetic.h md5init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/digest/rmd160/depend b/ext/digest/rmd160/depend index fe3652a2f6..3a0ed72732 100644 --- a/ext/digest/rmd160/depend +++ b/ext/digest/rmd160/depend @@ -17,6 +17,7 @@ rmd160.o: $(hdrdir)/ruby/backward/2/stdalign.h rmd160.o: $(hdrdir)/ruby/backward/2/stdarg.h rmd160.o: $(hdrdir)/ruby/defines.h rmd160.o: $(hdrdir)/ruby/intern.h +rmd160.o: $(hdrdir)/ruby/internal/abi.h rmd160.o: $(hdrdir)/ruby/internal/anyargs.h rmd160.o: $(hdrdir)/ruby/internal/arithmetic.h rmd160.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -178,6 +179,7 @@ rmd160init.o: $(hdrdir)/ruby/backward/2/stdalign.h rmd160init.o: $(hdrdir)/ruby/backward/2/stdarg.h rmd160init.o: $(hdrdir)/ruby/defines.h rmd160init.o: $(hdrdir)/ruby/intern.h +rmd160init.o: $(hdrdir)/ruby/internal/abi.h rmd160init.o: $(hdrdir)/ruby/internal/anyargs.h rmd160init.o: $(hdrdir)/ruby/internal/arithmetic.h rmd160init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/digest/sha1/depend b/ext/digest/sha1/depend index 2b73455c03..a4e454d214 100644 --- a/ext/digest/sha1/depend +++ b/ext/digest/sha1/depend @@ -17,6 +17,7 @@ sha1.o: $(hdrdir)/ruby/backward/2/stdalign.h sha1.o: $(hdrdir)/ruby/backward/2/stdarg.h sha1.o: $(hdrdir)/ruby/defines.h sha1.o: $(hdrdir)/ruby/intern.h +sha1.o: $(hdrdir)/ruby/internal/abi.h sha1.o: $(hdrdir)/ruby/internal/anyargs.h sha1.o: $(hdrdir)/ruby/internal/arithmetic.h sha1.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -178,6 +179,7 @@ sha1init.o: $(hdrdir)/ruby/backward/2/stdalign.h sha1init.o: $(hdrdir)/ruby/backward/2/stdarg.h sha1init.o: $(hdrdir)/ruby/defines.h sha1init.o: $(hdrdir)/ruby/intern.h +sha1init.o: $(hdrdir)/ruby/internal/abi.h sha1init.o: $(hdrdir)/ruby/internal/anyargs.h sha1init.o: $(hdrdir)/ruby/internal/arithmetic.h sha1init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/digest/sha2/depend b/ext/digest/sha2/depend index b3e52c644e..2fb598aa48 100644 --- a/ext/digest/sha2/depend +++ b/ext/digest/sha2/depend @@ -17,6 +17,7 @@ sha2.o: $(hdrdir)/ruby/backward/2/stdalign.h sha2.o: $(hdrdir)/ruby/backward/2/stdarg.h sha2.o: $(hdrdir)/ruby/defines.h sha2.o: $(hdrdir)/ruby/intern.h +sha2.o: $(hdrdir)/ruby/internal/abi.h sha2.o: $(hdrdir)/ruby/internal/anyargs.h sha2.o: $(hdrdir)/ruby/internal/arithmetic.h sha2.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -178,6 +179,7 @@ sha2init.o: $(hdrdir)/ruby/backward/2/stdalign.h sha2init.o: $(hdrdir)/ruby/backward/2/stdarg.h sha2init.o: $(hdrdir)/ruby/defines.h sha2init.o: $(hdrdir)/ruby/intern.h +sha2init.o: $(hdrdir)/ruby/internal/abi.h sha2init.o: $(hdrdir)/ruby/internal/anyargs.h sha2init.o: $(hdrdir)/ruby/internal/arithmetic.h sha2init.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c index e7d7b15c5b..21d5acbe96 100644 --- a/ext/digest/sha2/sha2.c +++ b/ext/digest/sha2/sha2.c @@ -128,7 +128,7 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */ #define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16) -#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__GNUC__) || defined(_HPUX_SOURCE) || defined(__IBMC__) +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__GNUC__) || defined(__IBMC__) #define ULL(number) number##ULL #else #define ULL(number) (uint64_t)(number) diff --git a/ext/etc/depend b/ext/etc/depend index 9c2de2ba96..a541db6db6 100644 --- a/ext/etc/depend +++ b/ext/etc/depend @@ -20,6 +20,7 @@ etc.o: $(hdrdir)/ruby/backward/2/stdarg.h etc.o: $(hdrdir)/ruby/defines.h etc.o: $(hdrdir)/ruby/encoding.h etc.o: $(hdrdir)/ruby/intern.h +etc.o: $(hdrdir)/ruby/internal/abi.h etc.o: $(hdrdir)/ruby/internal/anyargs.h etc.o: $(hdrdir)/ruby/internal/arithmetic.h etc.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 737d295abc..9a691d6e34 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -52,7 +52,7 @@ char *getenv(); #endif char *getlogin(); -#define RUBY_ETC_VERSION "1.3.0" +#define RUBY_ETC_VERSION "1.4.0" #ifdef HAVE_RB_DEPRECATE_CONSTANT void rb_deprecate_constant(VALUE mod, const char *name); @@ -1158,8 +1158,7 @@ Init_etc(void) #endif NULL); #if 0 - /* Define-const: Passwd - * + /* * Passwd is a Struct that contains the following members: * * name:: @@ -1197,12 +1196,11 @@ Init_etc(void) * expire:: * account expiration time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_EXPIRE+ */ - rb_define_const(mEtc, "Passwd", sPasswd); + sPasswd = rb_define_class_under(mEtc, "Passwd", rb_cStruct); #endif - rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */ - rb_deprecate_constant(rb_cStruct, "Passwd"); rb_extend_object(sPasswd, rb_mEnumerable); rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0); + #ifdef HAVE_GETGRENT sGroup = rb_struct_define_under(mEtc, "Group", "name", #ifdef HAVE_STRUCT_GROUP_GR_PASSWD @@ -1211,8 +1209,7 @@ Init_etc(void) "gid", "mem", NULL); #if 0 - /* Define-const: Group - * + /* * Group is a Struct that is only available when compiled with +HAVE_GETGRENT+. * * The struct contains the following members: @@ -1220,11 +1217,10 @@ Init_etc(void) * name:: * contains the name of the group as a String. * passwd:: - * contains the encrypted password as a String. An 'x' is + * contains the encrypted password as a String. An <code>'x'</code> is * returned if password access to the group is not available; an empty * string is returned if no password is needed to obtain membership of * the group. - * * Must be compiled with +HAVE_STRUCT_GROUP_GR_PASSWD+. * gid:: * contains the group's numeric ID as an integer. @@ -1232,10 +1228,8 @@ Init_etc(void) * is an Array of Strings containing the short login names of the * members of the group. */ - rb_define_const(mEtc, "Group", sGroup); + sGroup = rb_define_class_under(mEtc, "Group", rb_cStruct); #endif - rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */ - rb_deprecate_constant(rb_cStruct, "Group"); rb_extend_object(sGroup, rb_mEnumerable); rb_define_singleton_method(sGroup, "each", etc_each_group, 0); #endif diff --git a/ext/etc/etc.gemspec b/ext/etc/etc.gemspec index 7d687e3b99..98c6d66faa 100644 --- a/ext/etc/etc.gemspec +++ b/ext/etc/etc.gemspec @@ -22,23 +22,22 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/ruby/etc" spec.licenses = ["Ruby", "BSD-2-Clause"] + changelogs = Dir.glob("logs/ChangeLog-[1-9]*[^~]", base: __dir__) spec.files = %w[ LICENSE.txt README.md + ChangeLog ext/etc/constdefs.h ext/etc/etc.c ext/etc/extconf.rb ext/etc/mkconstants.rb test/etc/test_etc.rb - ] + ] + changelogs + spec.rdoc_options = ["--main", "README.md"] + spec.extra_rdoc_files = spec.files.grep_v(/\.{rb,[ch]}\z/) spec.bindir = "exe" spec.require_paths = ["lib"] spec.extensions = %w{ext/etc/extconf.rb} - spec.required_ruby_version = ">= 2.3.0" - - spec.add_development_dependency "bundler" - spec.add_development_dependency "rake" - spec.add_development_dependency "rake-compiler" - spec.add_development_dependency "test-unit" + spec.required_ruby_version = ">= 2.6.0" end diff --git a/ext/etc/extconf.rb b/ext/etc/extconf.rb index 6e7810a5e8..159b1614b7 100644 --- a/ext/etc/extconf.rb +++ b/ext/etc/extconf.rb @@ -47,6 +47,7 @@ if !File.exist?("#{srcdir}/depend") %x[#{RbConfig.ruby} #{srcdir}/mkconstants.rb -o #{srcdir}/constdefs.h] end +# TODO: remove when dropping 2.7 support, as exported since 3.0 have_func('rb_deprecate_constant(Qnil, "None")') $distcleanfiles << "constdefs.h" diff --git a/ext/extmk.rb b/ext/extmk.rb index 4a087f294a..a440af27fc 100755 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -2,6 +2,9 @@ # -*- mode: ruby; coding: us-ascii -*- # frozen_string_literal: false +module Gem; end # only needs Gem::Platform +require 'rubygems/platform' + # :stopdoc: $extension = nil $extstatic = nil @@ -146,7 +149,7 @@ def extmake(target, basedir = 'ext', maybestatic = true) top_srcdir = $top_srcdir topdir = $topdir hdrdir = $hdrdir - prefix = "../" * (target.count("/")+1) + prefix = "../" * (basedir.count("/")+target.count("/")+1) $top_srcdir = relative_from(top_srcdir, prefix) $hdrdir = relative_from(hdrdir, prefix) $topdir = prefix + $topdir @@ -460,10 +463,11 @@ for dir in ["ext", File::join($top_srcdir, "ext")] end unless $extstatic @gemname = nil -if ARGV[0] - ext_prefix, exts = ARGV.shift.split('/', 2) +if exts = ARGV.shift + ext_prefix = exts[%r[\A(?>\.bundle/)?[^/]+(?:/(?=(.+)?)|\z)]] + exts = $1 $extension = [exts] if exts - if ext_prefix == 'gems' + if ext_prefix.start_with?('.') @gemname = exts elsif exts $static_ext.delete_if {|t, *| !File.fnmatch(t, exts)} @@ -515,7 +519,7 @@ cond = proc {|ext, *| exts.delete_if {|d| File.fnmatch?("-*", d)} end end -ext_prefix = File.basename(ext_prefix) +ext_prefix = ext_prefix[$top_srcdir.size+1..-2] extend Module.new { def timestamp_file(name, target_prefix = nil) @@ -534,11 +538,12 @@ extend Module.new { super(*args) do |conf| conf.find do |s| s.sub!(/^(TARGET_SO_DIR *= *)\$\(RUBYARCHDIR\)/) { - "TARGET_GEM_DIR = $(extout)/gems/$(arch)/#{@gemname}\n"\ + "TARGET_GEM_DIR = $(topdir)/.bundle/extensions/$(gem_platform)/$(ruby_version)/#{@gemname}\n"\ "#{$1}$(TARGET_GEM_DIR)$(target_prefix)" } end conf.any? {|s| /^TARGET *= *\S/ =~ s} and conf << %{ +gem_platform = #{Gem::Platform.local} # default target all: @@ -634,7 +639,7 @@ rubies = [] end } -Dir.chdir ".." +Dir.chdir dir unless $destdir.to_s.empty? $mflags.defined?("DESTDIR") or $mflags << "DESTDIR=#{$destdir}" end diff --git a/ext/fcntl/depend b/ext/fcntl/depend index 46a9e78172..718de62e26 100644 --- a/ext/fcntl/depend +++ b/ext/fcntl/depend @@ -14,6 +14,7 @@ fcntl.o: $(hdrdir)/ruby/backward/2/stdalign.h fcntl.o: $(hdrdir)/ruby/backward/2/stdarg.h fcntl.o: $(hdrdir)/ruby/defines.h fcntl.o: $(hdrdir)/ruby/intern.h +fcntl.o: $(hdrdir)/ruby/internal/abi.h fcntl.o: $(hdrdir)/ruby/internal/anyargs.h fcntl.o: $(hdrdir)/ruby/internal/arithmetic.h fcntl.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/fcntl/fcntl.c b/ext/fcntl/fcntl.c index ee42d2abe5..3bccc41e4c 100644 --- a/ext/fcntl/fcntl.c +++ b/ext/fcntl/fcntl.c @@ -256,4 +256,21 @@ Init_fcntl(void) */ rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_RDONLY | O_WRONLY | O_RDWR)); #endif +#ifdef F_DUP2FD + /* Document-const: F_DUP2FD + * + * It is a FreeBSD specific constant and equivalent + * to dup2 call. + */ + rb_define_const(mFcntl, "F_DUP2FD", INT2NUM(F_DUP2FD)); +#endif +#ifdef F_DUP2FD_CLOEXEC + /* Document-const: F_DUP2FD_CLOEXEC + * + * It is a FreeBSD specific constant and acts + * similarly as F_DUP2FD but set the FD_CLOEXEC + * flag in addition. + */ + rb_define_const(mFcntl, "F_DUP2FD_CLOEXEC", INT2NUM(F_DUP2FD_CLOEXEC)); +#endif } diff --git a/ext/fiddle/depend b/ext/fiddle/depend index 4d33d46d33..d6a053f05b 100644 --- a/ext/fiddle/depend +++ b/ext/fiddle/depend @@ -67,6 +67,7 @@ closure.o: $(hdrdir)/ruby/backward/2/stdalign.h closure.o: $(hdrdir)/ruby/backward/2/stdarg.h closure.o: $(hdrdir)/ruby/defines.h closure.o: $(hdrdir)/ruby/intern.h +closure.o: $(hdrdir)/ruby/internal/abi.h closure.o: $(hdrdir)/ruby/internal/anyargs.h closure.o: $(hdrdir)/ruby/internal/arithmetic.h closure.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -231,6 +232,7 @@ conversions.o: $(hdrdir)/ruby/backward/2/stdalign.h conversions.o: $(hdrdir)/ruby/backward/2/stdarg.h conversions.o: $(hdrdir)/ruby/defines.h conversions.o: $(hdrdir)/ruby/intern.h +conversions.o: $(hdrdir)/ruby/internal/abi.h conversions.o: $(hdrdir)/ruby/internal/anyargs.h conversions.o: $(hdrdir)/ruby/internal/arithmetic.h conversions.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -394,6 +396,7 @@ fiddle.o: $(hdrdir)/ruby/backward/2/stdalign.h fiddle.o: $(hdrdir)/ruby/backward/2/stdarg.h fiddle.o: $(hdrdir)/ruby/defines.h fiddle.o: $(hdrdir)/ruby/intern.h +fiddle.o: $(hdrdir)/ruby/internal/abi.h fiddle.o: $(hdrdir)/ruby/internal/anyargs.h fiddle.o: $(hdrdir)/ruby/internal/arithmetic.h fiddle.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -557,6 +560,7 @@ function.o: $(hdrdir)/ruby/backward/2/stdalign.h function.o: $(hdrdir)/ruby/backward/2/stdarg.h function.o: $(hdrdir)/ruby/defines.h function.o: $(hdrdir)/ruby/intern.h +function.o: $(hdrdir)/ruby/internal/abi.h function.o: $(hdrdir)/ruby/internal/anyargs.h function.o: $(hdrdir)/ruby/internal/arithmetic.h function.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -721,6 +725,7 @@ handle.o: $(hdrdir)/ruby/backward/2/stdalign.h handle.o: $(hdrdir)/ruby/backward/2/stdarg.h handle.o: $(hdrdir)/ruby/defines.h handle.o: $(hdrdir)/ruby/intern.h +handle.o: $(hdrdir)/ruby/internal/abi.h handle.o: $(hdrdir)/ruby/internal/anyargs.h handle.o: $(hdrdir)/ruby/internal/arithmetic.h handle.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -885,6 +890,7 @@ memory_view.o: $(hdrdir)/ruby/backward/2/stdarg.h memory_view.o: $(hdrdir)/ruby/defines.h memory_view.o: $(hdrdir)/ruby/encoding.h memory_view.o: $(hdrdir)/ruby/intern.h +memory_view.o: $(hdrdir)/ruby/internal/abi.h memory_view.o: $(hdrdir)/ruby/internal/anyargs.h memory_view.o: $(hdrdir)/ruby/internal/arithmetic.h memory_view.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1060,6 +1066,7 @@ pinned.o: $(hdrdir)/ruby/backward/2/stdalign.h pinned.o: $(hdrdir)/ruby/backward/2/stdarg.h pinned.o: $(hdrdir)/ruby/defines.h pinned.o: $(hdrdir)/ruby/intern.h +pinned.o: $(hdrdir)/ruby/internal/abi.h pinned.o: $(hdrdir)/ruby/internal/anyargs.h pinned.o: $(hdrdir)/ruby/internal/arithmetic.h pinned.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1224,6 +1231,7 @@ pointer.o: $(hdrdir)/ruby/backward/2/stdarg.h pointer.o: $(hdrdir)/ruby/defines.h pointer.o: $(hdrdir)/ruby/encoding.h pointer.o: $(hdrdir)/ruby/intern.h +pointer.o: $(hdrdir)/ruby/internal/abi.h pointer.o: $(hdrdir)/ruby/internal/anyargs.h pointer.o: $(hdrdir)/ruby/internal/arithmetic.h pointer.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/fiddle/extconf.rb b/ext/fiddle/extconf.rb index 053456d534..93b4f9d4fa 100644 --- a/ext/fiddle/extconf.rb +++ b/ext/fiddle/extconf.rb @@ -167,7 +167,7 @@ if libffi_version libffi_version = libffi_version.gsub(/-rc\d+/, '') libffi_version = (libffi_version.split('.').map(&:to_i) + [0,0])[0,3] $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % libffi_version }}) - warn "libffi_version: #{libffi_version.join('.')}" + puts "libffi_version: #{libffi_version.join('.')}" end case diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 5dec1a4c06..4ec24178c4 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -90,6 +90,10 @@ extern VALUE rb_scheduler_timeout(struct timeval *timeout); #define sys_fail_fptr(fptr) rb_sys_fail_str((fptr)->pathv) #ifndef HAVE_RB_F_SEND +#ifndef RB_PASS_CALLED_KEYWORDS +# define rb_funcallv_kw(recv, mid, arg, argv, kw_splat) rb_funcallv(recv, mid, arg, argv) +#endif + static ID id___send__; static VALUE @@ -104,7 +108,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv) else { vid = id___send__; } - return rb_funcallv(recv, vid, argc, argv); + return rb_funcallv_kw(recv, vid, argc, argv, RB_PASS_CALLED_KEYWORDS); } #endif @@ -555,8 +559,8 @@ console_getch(int argc, VALUE *argv, VALUE io) if (w < 0) rb_eof_error(); if (!(w & RB_WAITFD_IN)) return Qnil; # else - VALUE result = rb_io_wait(io, RUBY_IO_READABLE, timeout); - if (result == Qfalse) return Qnil; + VALUE result = rb_io_wait(io, RB_INT2NUM(RUBY_IO_READABLE), timeout); + if (!RTEST(result)) return Qnil; # endif } else if (optp->vtime) { diff --git a/ext/io/console/depend b/ext/io/console/depend index e6014dcc59..06ccdde70d 100644 --- a/ext/io/console/depend +++ b/ext/io/console/depend @@ -16,6 +16,7 @@ console.o: $(hdrdir)/ruby/defines.h console.o: $(hdrdir)/ruby/encoding.h console.o: $(hdrdir)/ruby/fiber/scheduler.h console.o: $(hdrdir)/ruby/intern.h +console.o: $(hdrdir)/ruby/internal/abi.h console.o: $(hdrdir)/ruby/internal/anyargs.h console.o: $(hdrdir)/ruby/internal/arithmetic.h console.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/io/console/io-console.gemspec b/ext/io/console/io-console.gemspec index dabe9e68f8..aa57f8ac52 100644 --- a/ext/io/console/io-console.gemspec +++ b/ext/io/console/io-console.gemspec @@ -1,5 +1,5 @@ # -*- ruby -*- -_VERSION = "0.5.9" +_VERSION = "0.5.11" Gem::Specification.new do |s| s.name = "io-console" @@ -7,7 +7,7 @@ Gem::Specification.new do |s| s.summary = "Console interface" s.email = "nobu@ruby-lang.org" s.description = "add console capabilities to IO instances." - s.required_ruby_version = ">= 2.4.0" + s.required_ruby_version = ">= 2.6.0" s.homepage = "https://github.com/ruby/io-console" s.metadata["source_code_url"] = s.homepage s.authors = ["Nobu Nakada"] diff --git a/ext/io/nonblock/depend b/ext/io/nonblock/depend index 664c262e35..7f2db65732 100644 --- a/ext/io/nonblock/depend +++ b/ext/io/nonblock/depend @@ -15,6 +15,7 @@ nonblock.o: $(hdrdir)/ruby/backward/2/stdarg.h nonblock.o: $(hdrdir)/ruby/defines.h nonblock.o: $(hdrdir)/ruby/encoding.h nonblock.o: $(hdrdir)/ruby/intern.h +nonblock.o: $(hdrdir)/ruby/internal/abi.h nonblock.o: $(hdrdir)/ruby/internal/anyargs.h nonblock.o: $(hdrdir)/ruby/internal/arithmetic.h nonblock.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/io/nonblock/io-nonblock.gemspec b/ext/io/nonblock/io-nonblock.gemspec index 34d736650b..f81d4fda0a 100644 --- a/ext/io/nonblock/io-nonblock.gemspec +++ b/ext/io/nonblock/io-nonblock.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "io-nonblock" - spec.version = "0.1.0" + spec.version = "0.1.1" spec.authors = ["Nobu Nakada"] spec.email = ["nobu@ruby-lang.org"] @@ -13,13 +13,13 @@ Gem::Specification.new do |spec| spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - %x[git ls-files -z].split("\x0").reject do |f| - f.match(%r{\A(?:test|spec|features)/|\A\.(?:git|travis)}) - end - end + spec.files = %w[ + COPYING + README.md + ext/io/nonblock/depend + ext/io/nonblock/extconf.rb + ext/io/nonblock/nonblock.c + ] spec.extensions = %w[ext/io/nonblock/extconf.rb] - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] end diff --git a/ext/io/nonblock/nonblock.c b/ext/io/nonblock/nonblock.c index 1c0bdc68e7..b8a40ff38e 100644 --- a/ext/io/nonblock/nonblock.c +++ b/ext/io/nonblock/nonblock.c @@ -19,14 +19,14 @@ #ifdef F_GETFL static int -io_nonblock_mode(int fd) +get_fcntl_flags(int fd) { int f = fcntl(fd, F_GETFL); if (f == -1) rb_sys_fail(0); return f; } #else -#define io_nonblock_mode(fd) ((void)(fd), 0) +#define get_fcntl_flags(fd) ((void)(fd), 0) #endif #ifdef F_GETFL @@ -41,7 +41,7 @@ rb_io_nonblock_p(VALUE io) { rb_io_t *fptr; GetOpenFile(io, fptr); - if (io_nonblock_mode(fptr->fd) & O_NONBLOCK) + if (get_fcntl_flags(fptr->fd) & O_NONBLOCK) return Qtrue; return Qfalse; } @@ -50,6 +50,13 @@ rb_io_nonblock_p(VALUE io) #endif #ifdef F_SETFL +static void +set_fcntl_flags(int fd, int f) +{ + if (fcntl(fd, F_SETFL, f) == -1) + rb_sys_fail(0); +} + static int io_nonblock_set(int fd, int f, int nb) { @@ -63,8 +70,7 @@ io_nonblock_set(int fd, int f, int nb) return 0; f &= ~O_NONBLOCK; } - if (fcntl(fd, F_SETFL, f) == -1) - rb_sys_fail(0); + set_fcntl_flags(fd, f); return 1; } @@ -74,6 +80,46 @@ io_nonblock_set(int fd, int f, int nb) * * Enables non-blocking mode on a stream when set to * +true+, and blocking mode when set to +false+. + * + * This method set or clear O_NONBLOCK flag for the file descriptor + * in <em>ios</em>. + * + * The behavior of most IO methods is not affected by this flag + * because they retry system calls to complete their task + * after EAGAIN and partial read/write. + * (An exception is IO#syswrite which doesn't retry.) + * + * This method can be used to clear non-blocking mode of standard I/O. + * Since nonblocking methods (read_nonblock, etc.) set non-blocking mode but + * they doesn't clear it, this method is usable as follows. + * + * END { STDOUT.nonblock = false } + * STDOUT.write_nonblock("foo") + * + * Since the flag is shared across processes and + * many non-Ruby commands doesn't expect standard I/O with non-blocking mode, + * it would be safe to clear the flag before Ruby program exits. + * + * For example following Ruby program leaves STDIN/STDOUT/STDER non-blocking mode. + * (STDIN, STDOUT and STDERR are connected to a terminal. + * So making one of them nonblocking-mode effects other two.) + * Thus cat command try to read from standard input and + * it causes "Resource temporarily unavailable" error (EAGAIN). + * + * % ruby -e ' + * STDOUT.write_nonblock("foo\n")'; cat + * foo + * cat: -: Resource temporarily unavailable + * + * Clearing the flag makes the behavior of cat command normal. + * (cat command waits input from standard input.) + * + * % ruby -rio/nonblock -e ' + * END { STDOUT.nonblock = false } + * STDOUT.write_nonblock("foo") + * '; cat + * foo + * */ static VALUE rb_io_nonblock_set(VALUE io, VALUE nb) @@ -83,7 +129,7 @@ rb_io_nonblock_set(VALUE io, VALUE nb) if (RTEST(nb)) rb_io_set_nonblock(fptr); else - io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb)); + io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb)); return io; } @@ -91,15 +137,14 @@ static VALUE io_nonblock_restore(VALUE arg) { int *restore = (int *)arg; - if (fcntl(restore[0], F_SETFL, restore[1]) == -1) - rb_sys_fail(0); + set_fcntl_flags(restore[0], restore[1]); return Qnil; } /* * call-seq: - * io.nonblock {|io| } -> io - * io.nonblock(boolean) {|io| } -> io + * io.nonblock {|io| } -> object + * io.nonblock(boolean) {|io| } -> object * * Yields +self+ in non-blocking mode. * @@ -119,7 +164,7 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io) rb_scan_args(argc, argv, "01", &v); nb = RTEST(v); } - f = io_nonblock_mode(fptr->fd); + f = get_fcntl_flags(fptr->fd); restore[0] = fptr->fd; restore[1] = f; if (!io_nonblock_set(fptr->fd, f, nb)) diff --git a/ext/io/wait/depend b/ext/io/wait/depend index 0426a6a1ed..51e1af8280 100644 --- a/ext/io/wait/depend +++ b/ext/io/wait/depend @@ -16,6 +16,7 @@ wait.o: $(hdrdir)/ruby/backward/2/stdarg.h wait.o: $(hdrdir)/ruby/defines.h wait.o: $(hdrdir)/ruby/encoding.h wait.o: $(hdrdir)/ruby/intern.h +wait.o: $(hdrdir)/ruby/internal/abi.h wait.o: $(hdrdir)/ruby/internal/anyargs.h wait.o: $(hdrdir)/ruby/internal/arithmetic.h wait.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/io/wait/extconf.rb b/ext/io/wait/extconf.rb index d20ff4553f..eecdcce99f 100644 --- a/ext/io/wait/extconf.rb +++ b/ext/io/wait/extconf.rb @@ -1,20 +1,24 @@ # frozen_string_literal: false require 'mkmf' -target = "io/wait" -have_func("rb_io_wait") -unless macro_defined?("DOSISH", "#include <ruby.h>") - have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil - fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h| - have_macro("FIONREAD", [h, ioctl_h].compact) - end - if fionread - $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\"" - create_makefile(target) - end +if RUBY_VERSION < "2.6" + File.write("Makefile", dummy_makefile($srcdir).join("")) else - if have_func("rb_w32_ioctlsocket", "ruby.h") - have_func("rb_w32_is_socket", "ruby.h") - create_makefile(target) + target = "io/wait" + have_func("rb_io_wait") + unless macro_defined?("DOSISH", "#include <ruby.h>") + have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil + fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h| + have_macro("FIONREAD", [h, ioctl_h].compact) + end + if fionread + $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\"" + create_makefile(target) + end + else + if have_func("rb_w32_ioctlsocket", "ruby.h") + have_func("rb_w32_is_socket", "ruby.h") + create_makefile(target) + end end end diff --git a/ext/io/wait/io-wait.gemspec b/ext/io/wait/io-wait.gemspec index 5150f14848..b633421e48 100644 --- a/ext/io/wait/io-wait.gemspec +++ b/ext/io/wait/io-wait.gemspec @@ -1,27 +1,38 @@ -_VERSION = "0.2.0" +_VERSION = "0.2.3" Gem::Specification.new do |spec| spec.name = "io-wait" spec.version = _VERSION - spec.authors = ["Nobu Nakada"] - spec.email = ["nobu@ruby-lang.org"] + spec.authors = ["Nobu Nakada", "Charles Oliver Nutter"] + spec.email = ["nobu@ruby-lang.org", "headius@headius.com"] spec.summary = %q{Waits until IO is readable or writable without blocking.} spec.description = %q{Waits until IO is readable or writable without blocking.} spec.homepage = "https://github.com/ruby/io-wait" spec.licenses = ["Ruby", "BSD-2-Clause"] - spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0") spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{\A(?:test|spec|features)/|\A\.(?:git|travis)}) + File.identical?(f, __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|rakelib)/|\.(?:git|travis|circleci)|appveyor|Rakefile)}) end end - spec.extensions = %w[ext/io/wait/extconf.rb] spec.bindir = "exe" spec.executables = [] spec.require_paths = ["lib"] + + jruby = true if Gem::Platform.new('java') =~ spec.platform or RUBY_ENGINE == 'jruby' + spec.files.delete_if do |f| + f.end_with?(".java") or + f.start_with?("ext/") && (jruby ^ f.start_with?("ext/java/")) + end + if jruby + spec.platform = 'java' + spec.files << "lib/io/wait.jar" + spec.require_paths += ["ext/java/lib"] + else + spec.extensions = %w[ext/io/wait/extconf.rb] + end end diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c index 8f0d16e168..568c7b54a8 100644 --- a/ext/io/wait/wait.c +++ b/ext/io/wait/wait.c @@ -77,6 +77,8 @@ wait_for_single_fd(rb_io_t *fptr, int events, struct timeval *tv) * * Returns number of bytes that can be read without blocking. * Returns zero if no information available. + * + * You must require 'io/wait' to use this method. */ static VALUE @@ -119,9 +121,12 @@ io_wait_event(VALUE io, int event, VALUE timeout) /* * call-seq: - * io.ready? -> true or false + * io.ready? -> truthy or falsy + * + * Returns a truthy value if input available without blocking, or a + * falsy value. * - * Returns +true+ if input available without blocking, or +false+. + * You must require 'io/wait' to use this method. */ static VALUE @@ -148,12 +153,14 @@ io_ready_p(VALUE io) /* * call-seq: - * io.wait_readable -> true or false - * io.wait_readable(timeout) -> true or false + * io.wait_readable -> truthy or falsy + * io.wait_readable(timeout) -> truthy or falsy + * + * Waits until IO is readable and returns a truthy value, or a falsy + * value when times out. Returns a truthy value immediately when + * buffered data is available. * - * Waits until IO is readable and returns +true+, or - * +false+ when times out. - * Returns +true+ immediately when buffered data is available. + * You must require 'io/wait' to use this method. */ static VALUE @@ -188,11 +195,13 @@ io_wait_readable(int argc, VALUE *argv, VALUE io) /* * call-seq: - * io.wait_writable -> true or false - * io.wait_writable(timeout) -> true or false + * io.wait_writable -> truthy or falsy + * io.wait_writable(timeout) -> truthy or falsy * - * Waits until IO is writable and returns +true+ or - * +false+ when times out. + * Waits until IO is writable and returns a truthy value or a falsy + * value when times out. + * + * You must require 'io/wait' to use this method. */ static VALUE io_wait_writable(int argc, VALUE *argv, VALUE io) @@ -223,11 +232,13 @@ io_wait_writable(int argc, VALUE *argv, VALUE io) #ifdef HAVE_RB_IO_WAIT /* * call-seq: - * io.wait_priority -> true or false - * io.wait_priority(timeout) -> true or false + * io.wait_priority -> truthy or falsy + * io.wait_priority(timeout) -> truthy or falsy + * + * Waits until IO is priority and returns a truthy value or a falsy + * value when times out. * - * Waits until IO is priority and returns +true+ or - * +false+ when times out. + * You must require 'io/wait' to use this method. */ static VALUE io_wait_priority(int argc, VALUE *argv, VALUE io) @@ -282,19 +293,21 @@ wait_mode_sym(VALUE mode) /* * call-seq: - * io.wait(events, timeout) -> event mask or false. - * io.wait(timeout = nil, mode = :read) -> event mask or false. + * io.wait(events, timeout) -> truthy or falsy + * io.wait(timeout = nil, mode = :read) -> truthy or falsy. * * Waits until the IO becomes ready for the specified events and returns the - * subset of events that become ready, or +false+ when times out. + * subset of events that become ready, or a falsy value when times out. * * The events can be a bit mask of +IO::READABLE+, +IO::WRITABLE+ or * +IO::PRIORITY+. * - * Returns +true+ immediately when buffered data is available. + * Returns a truthy value immediately when buffered data is available. * * Optional parameter +mode+ is one of +:read+, +:write+, or * +:read_write+. + * + * You must require 'io/wait' to use this method. */ static VALUE diff --git a/ext/json/VERSION b/ext/json/VERSION index 6a6a3d8e35..097a15a2af 100644 --- a/ext/json/VERSION +++ b/ext/json/VERSION @@ -1 +1 @@ -2.6.1 +2.6.2 diff --git a/ext/json/generator/depend b/ext/json/generator/depend index 1de5fb0b93..28ef06b36d 100644 --- a/ext/json/generator/depend +++ b/ext/json/generator/depend @@ -18,6 +18,7 @@ generator.o: $(hdrdir)/ruby/backward/2/stdarg.h generator.o: $(hdrdir)/ruby/defines.h generator.o: $(hdrdir)/ruby/encoding.h generator.o: $(hdrdir)/ruby/intern.h +generator.o: $(hdrdir)/ruby/internal/abi.h generator.o: $(hdrdir)/ruby/internal/anyargs.h generator.o: $(hdrdir)/ruby/internal/arithmetic.h generator.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/json/lib/json/version.rb b/ext/json/lib/json/version.rb index 35e8dd3252..9bedb65fa7 100644 --- a/ext/json/lib/json/version.rb +++ b/ext/json/lib/json/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module JSON # JSON version - VERSION = '2.6.1' + VERSION = '2.6.2' VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: diff --git a/ext/json/parser/depend b/ext/json/parser/depend index df261fdfbb..a8e066ce15 100644 --- a/ext/json/parser/depend +++ b/ext/json/parser/depend @@ -18,6 +18,7 @@ parser.o: $(hdrdir)/ruby/backward/2/stdarg.h parser.o: $(hdrdir)/ruby/defines.h parser.o: $(hdrdir)/ruby/encoding.h parser.o: $(hdrdir)/ruby/intern.h +parser.o: $(hdrdir)/ruby/internal/abi.h parser.o: $(hdrdir)/ruby/internal/anyargs.h parser.o: $(hdrdir)/ruby/internal/arithmetic.h parser.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index b1dc8810c3..8b860c4101 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -2363,9 +2363,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int char buf[4]; if (bufferSize > MAX_STACK_BUFFER_SIZE) { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOC_N(char, bufferSize); +# endif } else { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOCA_N(char, bufferSize); +# endif } while (pe < stringEnd) { @@ -2950,6 +2958,7 @@ static const char MAYBE_UNUSED(_JSON_nfa_pop_trans)[] = { * * Parses the current JSON text _source_ and returns the complete data * structure as a result. +* It raises JSON::ParseError if fail to parse. */ static VALUE cParser_parse(VALUE self) { diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index f7be1a5acc..2dee80ee3b 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -462,9 +462,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int char buf[4]; if (bufferSize > MAX_STACK_BUFFER_SIZE) { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOC_N(char, bufferSize); +# endif } else { +# ifdef HAVE_RB_ENC_INTERNED_STR + bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1); +# else bufferStart = buffer = ALLOCA_N(char, bufferSize); +# endif } while (pe < stringEnd) { @@ -839,6 +847,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) * * Parses the current JSON text _source_ and returns the complete data * structure as a result. + * It raises JSON::ParseError if fail to parse. */ static VALUE cParser_parse(VALUE self) { diff --git a/ext/monitor/depend b/ext/monitor/depend index a8fca7f0b7..3030da71d0 100644 --- a/ext/monitor/depend +++ b/ext/monitor/depend @@ -13,6 +13,7 @@ monitor.o: $(hdrdir)/ruby/backward/2/stdalign.h monitor.o: $(hdrdir)/ruby/backward/2/stdarg.h monitor.o: $(hdrdir)/ruby/defines.h monitor.o: $(hdrdir)/ruby/intern.h +monitor.o: $(hdrdir)/ruby/internal/abi.h monitor.o: $(hdrdir)/ruby/internal/anyargs.h monitor.o: $(hdrdir)/ruby/internal/arithmetic.h monitor.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/nkf/depend b/ext/nkf/depend index 8951e0b3d4..9e2f468ba1 100644 --- a/ext/nkf/depend +++ b/ext/nkf/depend @@ -18,6 +18,7 @@ nkf.o: $(hdrdir)/ruby/backward/2/stdarg.h nkf.o: $(hdrdir)/ruby/defines.h nkf.o: $(hdrdir)/ruby/encoding.h nkf.o: $(hdrdir)/ruby/intern.h +nkf.o: $(hdrdir)/ruby/internal/abi.h nkf.o: $(hdrdir)/ruby/internal/anyargs.h nkf.o: $(hdrdir)/ruby/internal/arithmetic.h nkf.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c index 533f9b782f..a8fd937c31 100644 --- a/ext/nkf/nkf.c +++ b/ext/nkf/nkf.c @@ -274,7 +274,7 @@ rb_nkf_guess(VALUE obj, VALUE src) * * {de/en}crypt ROT13/47 * - * === -h[123] --hiragana --katakana --katakana-hiragana + * === \-h[123] --hiragana --katakana --katakana-hiragana * * [-h1 --hiragana] Katakana to Hiragana conversion. * @@ -299,7 +299,7 @@ rb_nkf_guess(VALUE obj, VALUE src) * * New line preserving line folding. * - * === -Z[0-3] + * === \-Z[0-3] * * Convert X0208 alphabet (Fullwidth Alphabets) to ASCII. * @@ -318,7 +318,7 @@ rb_nkf_guess(VALUE obj, VALUE src) * With <b>-x</b>, try to preserve X0208 kana and do not convert X0201 kana to X0208. * In JIS output, ESC-(-I is used. In EUC output, SSO is used. * - * === -B[0-2] + * === \-B[0-2] * * Assume broken JIS-Kanji input, which lost ESC. * Useful when your site is using old B-News Nihongo patch. @@ -336,7 +336,7 @@ rb_nkf_guess(VALUE obj, VALUE src) * * Delete \r in line feed, Add \r in line feed. * - * === -m[BQN0] + * === \-m[BQN0] * * MIME ISO-2022-JP/ISO8859-1 decode. (DEFAULT) * To see ISO8859-1 (Latin-1) -l is necessary. @@ -365,7 +365,7 @@ rb_nkf_guess(VALUE obj, VALUE src) * Input and output code is ISO8859-1 (Latin-1) and ISO-2022-JP. * <b>-s</b>, <b>-e</b> and <b>-x</b> are not compatible with this option. * - * === -L[uwm] + * === \-L[uwm] * * new line mode * Without this option, nkf doesn't convert line breaks. diff --git a/ext/objspace/depend b/ext/objspace/depend index bea8ba2315..c4da8031cc 100644 --- a/ext/objspace/depend +++ b/ext/objspace/depend @@ -14,6 +14,7 @@ object_tracing.o: $(hdrdir)/ruby/backward/2/stdarg.h object_tracing.o: $(hdrdir)/ruby/debug.h object_tracing.o: $(hdrdir)/ruby/defines.h object_tracing.o: $(hdrdir)/ruby/intern.h +object_tracing.o: $(hdrdir)/ruby/internal/abi.h object_tracing.o: $(hdrdir)/ruby/internal/anyargs.h object_tracing.o: $(hdrdir)/ruby/internal/arithmetic.h object_tracing.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -176,6 +177,7 @@ objspace.o: $(hdrdir)/ruby/backward/2/stdarg.h objspace.o: $(hdrdir)/ruby/defines.h objspace.o: $(hdrdir)/ruby/encoding.h objspace.o: $(hdrdir)/ruby/intern.h +objspace.o: $(hdrdir)/ruby/internal/abi.h objspace.o: $(hdrdir)/ruby/internal/anyargs.h objspace.o: $(hdrdir)/ruby/internal/arithmetic.h objspace.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -369,6 +371,7 @@ objspace_dump.o: $(hdrdir)/ruby/debug.h objspace_dump.o: $(hdrdir)/ruby/defines.h objspace_dump.o: $(hdrdir)/ruby/encoding.h objspace_dump.o: $(hdrdir)/ruby/intern.h +objspace_dump.o: $(hdrdir)/ruby/internal/abi.h objspace_dump.o: $(hdrdir)/ruby/internal/anyargs.h objspace_dump.o: $(hdrdir)/ruby/internal/arithmetic.h objspace_dump.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -530,7 +533,6 @@ objspace_dump.o: $(top_srcdir)/ccan/check_type/check_type.h objspace_dump.o: $(top_srcdir)/ccan/container_of/container_of.h objspace_dump.o: $(top_srcdir)/ccan/list/list.h objspace_dump.o: $(top_srcdir)/ccan/str/str.h -objspace_dump.o: $(top_srcdir)/darray.h objspace_dump.o: $(top_srcdir)/gc.h objspace_dump.o: $(top_srcdir)/internal.h objspace_dump.o: $(top_srcdir)/internal/array.h diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c index 3fa4fd279b..9cc66bcfe8 100644 --- a/ext/objspace/objspace.c +++ b/ext/objspace/objspace.c @@ -61,14 +61,7 @@ total_i(VALUE v, void *ptr) { struct total_data *data = (struct total_data *)ptr; - switch (BUILTIN_TYPE(v)) { - case T_NONE: - case T_IMEMO: - case T_ICLASS: - case T_NODE: - case T_ZOMBIE: - return; - default: + if (!rb_objspace_internal_object_p(v)) { if (data->klass == 0 || rb_obj_is_kind_of(v, data->klass)) { data->total += rb_obj_memsize_of(v); } @@ -423,7 +416,6 @@ count_nodes(int argc, VALUE *argv, VALUE os) COUNT_NODE(NODE_MASGN); COUNT_NODE(NODE_LASGN); COUNT_NODE(NODE_DASGN); - COUNT_NODE(NODE_DASGN_CURR); COUNT_NODE(NODE_GASGN); COUNT_NODE(NODE_IASGN); COUNT_NODE(NODE_CDECL); @@ -637,20 +629,22 @@ count_imemo_objects(int argc, VALUE *argv, VALUE self) VALUE hash = setup_hash(argc, argv); if (imemo_type_ids[0] == 0) { - imemo_type_ids[0] = rb_intern("imemo_env"); - imemo_type_ids[1] = rb_intern("imemo_cref"); - imemo_type_ids[2] = rb_intern("imemo_svar"); - imemo_type_ids[3] = rb_intern("imemo_throw_data"); - imemo_type_ids[4] = rb_intern("imemo_ifunc"); - imemo_type_ids[5] = rb_intern("imemo_memo"); - imemo_type_ids[6] = rb_intern("imemo_ment"); - imemo_type_ids[7] = rb_intern("imemo_iseq"); - imemo_type_ids[8] = rb_intern("imemo_tmpbuf"); - imemo_type_ids[9] = rb_intern("imemo_ast"); - imemo_type_ids[10] = rb_intern("imemo_parser_strterm"); - imemo_type_ids[11] = rb_intern("imemo_callinfo"); - imemo_type_ids[12] = rb_intern("imemo_callcache"); - imemo_type_ids[13] = rb_intern("imemo_constcache"); +#define INIT_IMEMO_TYPE_ID(n) (imemo_type_ids[n] = rb_intern_const(#n)) + INIT_IMEMO_TYPE_ID(imemo_env); + INIT_IMEMO_TYPE_ID(imemo_cref); + INIT_IMEMO_TYPE_ID(imemo_svar); + INIT_IMEMO_TYPE_ID(imemo_throw_data); + INIT_IMEMO_TYPE_ID(imemo_ifunc); + INIT_IMEMO_TYPE_ID(imemo_memo); + INIT_IMEMO_TYPE_ID(imemo_ment); + INIT_IMEMO_TYPE_ID(imemo_iseq); + INIT_IMEMO_TYPE_ID(imemo_tmpbuf); + INIT_IMEMO_TYPE_ID(imemo_ast); + INIT_IMEMO_TYPE_ID(imemo_parser_strterm); + INIT_IMEMO_TYPE_ID(imemo_callinfo); + INIT_IMEMO_TYPE_ID(imemo_callcache); + INIT_IMEMO_TYPE_ID(imemo_constcache); +#undef INIT_IMEMO_TYPE_ID } each_object_with_flags(count_imemo_objects_i, (void *)hash); @@ -713,7 +707,7 @@ iow_internal_object_id(VALUE self) struct rof_data { VALUE refs; - VALUE internals; + VALUE values; }; static void @@ -724,11 +718,15 @@ reachable_object_from_i(VALUE obj, void *data_ptr) VALUE val = obj; if (rb_objspace_markable_object_p(obj)) { - if (rb_objspace_internal_object_p(obj)) { - val = iow_newobj(obj); - rb_ary_push(data->internals, val); - } - rb_hash_aset(data->refs, key, val); + if (NIL_P(rb_hash_lookup(data->refs, key))) { + rb_hash_aset(data->refs, key, Qtrue); + + if (rb_objspace_internal_object_p(obj)) { + val = iow_newobj(obj); + } + + rb_ary_push(data->values, val); + } } } @@ -786,21 +784,21 @@ static VALUE reachable_objects_from(VALUE self, VALUE obj) { if (rb_objspace_markable_object_p(obj)) { - struct rof_data data; + struct rof_data data; - if (rb_typeddata_is_kind_of(obj, &iow_data_type)) { - obj = (VALUE)DATA_PTR(obj); - } + if (rb_typeddata_is_kind_of(obj, &iow_data_type)) { + obj = (VALUE)DATA_PTR(obj); + } - data.refs = rb_ident_hash_new(); - data.internals = rb_ary_new(); + data.refs = rb_obj_hide(rb_ident_hash_new()); + data.values = rb_ary_new(); - rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &data); + rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &data); - return rb_funcall(data.refs, rb_intern("values"), 0); + return data.values; } else { - return Qnil; + return Qnil; } } diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index cf7acb5c6f..b570acbd95 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -35,6 +35,7 @@ struct dump_config { const char *root_category; VALUE cur_obj; VALUE cur_obj_klass; + size_t cur_page_slot_size; size_t cur_obj_references; unsigned int roots: 1; unsigned int full_heap: 1; @@ -360,6 +361,9 @@ dump_object(VALUE obj, struct dump_config *dc) dump_append(dc, obj_type(obj)); dump_append(dc, "\""); + dump_append(dc, ", \"slot_size\":"); + dump_append_sizet(dc, dc->cur_page_slot_size); + if (dc->cur_obj_klass) { dump_append(dc, ", \"class\":"); dump_append_ref(dc, dc->cur_obj_klass); @@ -415,7 +419,7 @@ dump_object(VALUE obj, struct dump_config *dc) dump_append_ld(dc, RARRAY_LEN(obj)); if (RARRAY_LEN(obj) > 0 && FL_TEST(obj, ELTS_SHARED)) dump_append(dc, ", \"shared\":true"); - if (RARRAY_LEN(obj) > 0 && FL_TEST(obj, RARRAY_EMBED_FLAG)) + if (FL_TEST(obj, RARRAY_EMBED_FLAG)) dump_append(dc, ", \"embedded\":true"); break; @@ -539,6 +543,7 @@ heap_i(void *vstart, void *vend, size_t stride, void *data) for (; v != (VALUE)vend; v += stride) { void *ptr = asan_poisoned_object_p(v); asan_unpoison_object(v, false); + dc->cur_page_slot_size = stride; if (dc->full_heap || RBASIC(v)->flags) dump_object(v, dc); @@ -616,6 +621,10 @@ static VALUE objspace_dump(VALUE os, VALUE obj, VALUE output) { struct dump_config dc = {0,}; + if (!RB_SPECIAL_CONST_P(obj)) { + dc.cur_page_slot_size = rb_gc_obj_slot_size(obj); + } + dump_output(&dc, output, Qnil, Qnil); dump_object(obj, &dc); diff --git a/ext/openssl/History.md b/ext/openssl/History.md index 255c0fc50b..479ec3b4a2 100644 --- a/ext/openssl/History.md +++ b/ext/openssl/History.md @@ -1,3 +1,105 @@ +Version 3.0.0 +============= + +Compatibility notes +------------------- + +* OpenSSL 1.0.1 and Ruby 2.3-2.5 are no longer supported. + [[GitHub #396]](https://github.com/ruby/openssl/pull/396) + [[GitHub #466]](https://github.com/ruby/openssl/pull/466) + +* OpenSSL 3.0 support is added. It is the first major version bump from OpenSSL + 1.1 and contains incompatible changes that affect Ruby/OpenSSL. + Note that OpenSSL 3.0 support is preliminary and not all features are + currently available: + [[GitHub #369]](https://github.com/ruby/openssl/issues/369) + + - Deprecate the ability to modify `OpenSSL::PKey::PKey` instances. OpenSSL 3.0 + made EVP_PKEY structure immutable, and hence the following methods are not + available when Ruby/OpenSSL is linked against OpenSSL 3.0. + [[GitHub #480]](https://github.com/ruby/openssl/pull/480) + + - `OpenSSL::PKey::RSA#set_key`, `#set_factors`, `#set_crt_params` + - `OpenSSL::PKey::DSA#set_pqg`, `#set_key` + - `OpenSSL::PKey::DH#set_pqg`, `#set_key`, `#generate_key!` + - `OpenSSL::PKey::EC#private_key=`, `#public_key=`, `#group=`, `#generate_key!` + + - Deprecate `OpenSSL::Engine`. The ENGINE API has been deprecated in OpenSSL 3.0 + in favor of the new "provider" concept and will be removed in a future + version. + [[GitHub #481]](https://github.com/ruby/openssl/pull/481) + +* `OpenSSL::SSL::SSLContext#tmp_ecdh_callback` has been removed. It has been + deprecated since v2.0.0 because it is incompatible with modern OpenSSL + versions. + [[GitHub #394]](https://github.com/ruby/openssl/pull/394) + +* `OpenSSL::SSL::SSLSocket#read` and `#write` now raise `OpenSSL::SSL::SSLError` + if called before a TLS connection is established. Historically, they + read/wrote unencrypted data to the underlying socket directly in that case. + [[GitHub #9]](https://github.com/ruby/openssl/issues/9) + [[GitHub #469]](https://github.com/ruby/openssl/pull/469) + + +Notable changes +--------------- + +* Enhance OpenSSL::PKey's common interface. + [[GitHub #370]](https://github.com/ruby/openssl/issues/370) + + - Key deserialization: Enhance `OpenSSL::PKey.read` to handle PEM encoding of + DH parameters, which used to be only deserialized by `OpenSSL::PKey::DH.new`. + [[GitHub #328]](https://github.com/ruby/openssl/issues/328) + - Key generation: Add `OpenSSL::PKey.generate_parameters` and + `OpenSSL::PKey.generate_key`. + [[GitHub #329]](https://github.com/ruby/openssl/issues/329) + - Public key signing: Enhance `OpenSSL::PKey::PKey#sign` and `#verify` to use + the new EVP_DigestSign() family to enable PureEdDSA support on OpenSSL 1.1.1 + or later. They also now take optional algorithm-specific parameters for more + control. + [[GitHub #329]](https://github.com/ruby/openssl/issues/329) + - Low-level public key signing and verification: Add + `OpenSSL::PKey::PKey#sign_raw`, `#verify_raw`, and `#verify_recover`. + [[GitHub #382]](https://github.com/ruby/openssl/issues/382) + - Public key encryption: Add `OpenSSL::PKey::PKey#encrypt` and `#decrypt`. + [[GitHub #382]](https://github.com/ruby/openssl/issues/382) + - Key agreement: Add `OpenSSL::PKey::PKey#derive`. + [[GitHub #329]](https://github.com/ruby/openssl/issues/329) + - Key comparison: Add `OpenSSL::PKey::PKey#compare?` to conveniently check + that two keys have common parameters and a public key. + [[GitHub #383]](https://github.com/ruby/openssl/issues/383) + +* Add `OpenSSL::BN#set_flags` and `#get_flags`. This can be used in combination + with `OpenSSL::BN::CONSTTIME` to force constant-time computation. + [[GitHub #417]](https://github.com/ruby/openssl/issues/417) + +* Add `OpenSSL::BN#abs` to get the absolute value of the BIGNUM. + [[GitHub #430]](https://github.com/ruby/openssl/issues/430) + +* Add `OpenSSL::SSL::SSLSocket#getbyte`. + [[GitHub #438]](https://github.com/ruby/openssl/issues/438) + +* Add `OpenSSL::SSL::SSLContext#tmp_dh=`. + [[GitHub #459]](https://github.com/ruby/openssl/pull/459) + +* Add `OpenSSL::X509::Certificate.load` to load a PEM-encoded and concatenated + list of X.509 certificates at once. + [[GitHub #441]](https://github.com/ruby/openssl/pull/441) + +* Change `OpenSSL::X509::Certificate.new` to attempt to deserialize the given + string first as DER encoding first and then as PEM encoding to ensure the + round-trip consistency. + [[GitHub #442]](https://github.com/ruby/openssl/pull/442) + +* Update various part of the code base to use the modern API. No breaking + changes are intended with this. This includes: + + - `OpenSSL::HMAC` uses the EVP API. + [[GitHub #371]](https://github.com/ruby/openssl/issues/371) + - `OpenSSL::Config` uses native OpenSSL API to parse config files. + [[GitHub #342]](https://github.com/ruby/openssl/issues/342) + + Version 2.2.1 ============= diff --git a/ext/openssl/depend b/ext/openssl/depend index 742c8bbd19..c38d224c85 100644 --- a/ext/openssl/depend +++ b/ext/openssl/depend @@ -19,6 +19,7 @@ ossl.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl.o: $(hdrdir)/ruby/defines.h ossl.o: $(hdrdir)/ruby/encoding.h ossl.o: $(hdrdir)/ruby/intern.h +ossl.o: $(hdrdir)/ruby/internal/abi.h ossl.o: $(hdrdir)/ruby/internal/anyargs.h ossl.o: $(hdrdir)/ruby/internal/arithmetic.h ossl.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -212,6 +213,7 @@ ossl_asn1.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_asn1.o: $(hdrdir)/ruby/defines.h ossl_asn1.o: $(hdrdir)/ruby/encoding.h ossl_asn1.o: $(hdrdir)/ruby/intern.h +ossl_asn1.o: $(hdrdir)/ruby/internal/abi.h ossl_asn1.o: $(hdrdir)/ruby/internal/anyargs.h ossl_asn1.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_asn1.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -405,6 +407,7 @@ ossl_bio.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_bio.o: $(hdrdir)/ruby/defines.h ossl_bio.o: $(hdrdir)/ruby/encoding.h ossl_bio.o: $(hdrdir)/ruby/intern.h +ossl_bio.o: $(hdrdir)/ruby/internal/abi.h ossl_bio.o: $(hdrdir)/ruby/internal/anyargs.h ossl_bio.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_bio.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -598,6 +601,7 @@ ossl_bn.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_bn.o: $(hdrdir)/ruby/defines.h ossl_bn.o: $(hdrdir)/ruby/encoding.h ossl_bn.o: $(hdrdir)/ruby/intern.h +ossl_bn.o: $(hdrdir)/ruby/internal/abi.h ossl_bn.o: $(hdrdir)/ruby/internal/anyargs.h ossl_bn.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_bn.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -792,6 +796,7 @@ ossl_cipher.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_cipher.o: $(hdrdir)/ruby/defines.h ossl_cipher.o: $(hdrdir)/ruby/encoding.h ossl_cipher.o: $(hdrdir)/ruby/intern.h +ossl_cipher.o: $(hdrdir)/ruby/internal/abi.h ossl_cipher.o: $(hdrdir)/ruby/internal/anyargs.h ossl_cipher.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_cipher.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -985,6 +990,7 @@ ossl_config.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_config.o: $(hdrdir)/ruby/defines.h ossl_config.o: $(hdrdir)/ruby/encoding.h ossl_config.o: $(hdrdir)/ruby/intern.h +ossl_config.o: $(hdrdir)/ruby/internal/abi.h ossl_config.o: $(hdrdir)/ruby/internal/anyargs.h ossl_config.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_config.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1178,6 +1184,7 @@ ossl_digest.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_digest.o: $(hdrdir)/ruby/defines.h ossl_digest.o: $(hdrdir)/ruby/encoding.h ossl_digest.o: $(hdrdir)/ruby/intern.h +ossl_digest.o: $(hdrdir)/ruby/internal/abi.h ossl_digest.o: $(hdrdir)/ruby/internal/anyargs.h ossl_digest.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_digest.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1371,6 +1378,7 @@ ossl_engine.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_engine.o: $(hdrdir)/ruby/defines.h ossl_engine.o: $(hdrdir)/ruby/encoding.h ossl_engine.o: $(hdrdir)/ruby/intern.h +ossl_engine.o: $(hdrdir)/ruby/internal/abi.h ossl_engine.o: $(hdrdir)/ruby/internal/anyargs.h ossl_engine.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_engine.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1564,6 +1572,7 @@ ossl_hmac.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_hmac.o: $(hdrdir)/ruby/defines.h ossl_hmac.o: $(hdrdir)/ruby/encoding.h ossl_hmac.o: $(hdrdir)/ruby/intern.h +ossl_hmac.o: $(hdrdir)/ruby/internal/abi.h ossl_hmac.o: $(hdrdir)/ruby/internal/anyargs.h ossl_hmac.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_hmac.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1757,6 +1766,7 @@ ossl_kdf.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_kdf.o: $(hdrdir)/ruby/defines.h ossl_kdf.o: $(hdrdir)/ruby/encoding.h ossl_kdf.o: $(hdrdir)/ruby/intern.h +ossl_kdf.o: $(hdrdir)/ruby/internal/abi.h ossl_kdf.o: $(hdrdir)/ruby/internal/anyargs.h ossl_kdf.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_kdf.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -1950,6 +1960,7 @@ ossl_ns_spki.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_ns_spki.o: $(hdrdir)/ruby/defines.h ossl_ns_spki.o: $(hdrdir)/ruby/encoding.h ossl_ns_spki.o: $(hdrdir)/ruby/intern.h +ossl_ns_spki.o: $(hdrdir)/ruby/internal/abi.h ossl_ns_spki.o: $(hdrdir)/ruby/internal/anyargs.h ossl_ns_spki.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_ns_spki.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2143,6 +2154,7 @@ ossl_ocsp.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_ocsp.o: $(hdrdir)/ruby/defines.h ossl_ocsp.o: $(hdrdir)/ruby/encoding.h ossl_ocsp.o: $(hdrdir)/ruby/intern.h +ossl_ocsp.o: $(hdrdir)/ruby/internal/abi.h ossl_ocsp.o: $(hdrdir)/ruby/internal/anyargs.h ossl_ocsp.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_ocsp.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2336,6 +2348,7 @@ ossl_pkcs12.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkcs12.o: $(hdrdir)/ruby/defines.h ossl_pkcs12.o: $(hdrdir)/ruby/encoding.h ossl_pkcs12.o: $(hdrdir)/ruby/intern.h +ossl_pkcs12.o: $(hdrdir)/ruby/internal/abi.h ossl_pkcs12.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkcs12.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkcs12.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2529,6 +2542,7 @@ ossl_pkcs7.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkcs7.o: $(hdrdir)/ruby/defines.h ossl_pkcs7.o: $(hdrdir)/ruby/encoding.h ossl_pkcs7.o: $(hdrdir)/ruby/intern.h +ossl_pkcs7.o: $(hdrdir)/ruby/internal/abi.h ossl_pkcs7.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkcs7.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkcs7.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2722,6 +2736,7 @@ ossl_pkey.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkey.o: $(hdrdir)/ruby/defines.h ossl_pkey.o: $(hdrdir)/ruby/encoding.h ossl_pkey.o: $(hdrdir)/ruby/intern.h +ossl_pkey.o: $(hdrdir)/ruby/internal/abi.h ossl_pkey.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkey.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkey.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -2915,6 +2930,7 @@ ossl_pkey_dh.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkey_dh.o: $(hdrdir)/ruby/defines.h ossl_pkey_dh.o: $(hdrdir)/ruby/encoding.h ossl_pkey_dh.o: $(hdrdir)/ruby/intern.h +ossl_pkey_dh.o: $(hdrdir)/ruby/internal/abi.h ossl_pkey_dh.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkey_dh.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkey_dh.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -3108,6 +3124,7 @@ ossl_pkey_dsa.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkey_dsa.o: $(hdrdir)/ruby/defines.h ossl_pkey_dsa.o: $(hdrdir)/ruby/encoding.h ossl_pkey_dsa.o: $(hdrdir)/ruby/intern.h +ossl_pkey_dsa.o: $(hdrdir)/ruby/internal/abi.h ossl_pkey_dsa.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkey_dsa.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkey_dsa.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -3301,6 +3318,7 @@ ossl_pkey_ec.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkey_ec.o: $(hdrdir)/ruby/defines.h ossl_pkey_ec.o: $(hdrdir)/ruby/encoding.h ossl_pkey_ec.o: $(hdrdir)/ruby/intern.h +ossl_pkey_ec.o: $(hdrdir)/ruby/internal/abi.h ossl_pkey_ec.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkey_ec.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkey_ec.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -3494,6 +3512,7 @@ ossl_pkey_rsa.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_pkey_rsa.o: $(hdrdir)/ruby/defines.h ossl_pkey_rsa.o: $(hdrdir)/ruby/encoding.h ossl_pkey_rsa.o: $(hdrdir)/ruby/intern.h +ossl_pkey_rsa.o: $(hdrdir)/ruby/internal/abi.h ossl_pkey_rsa.o: $(hdrdir)/ruby/internal/anyargs.h ossl_pkey_rsa.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_pkey_rsa.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -3687,6 +3706,7 @@ ossl_rand.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_rand.o: $(hdrdir)/ruby/defines.h ossl_rand.o: $(hdrdir)/ruby/encoding.h ossl_rand.o: $(hdrdir)/ruby/intern.h +ossl_rand.o: $(hdrdir)/ruby/internal/abi.h ossl_rand.o: $(hdrdir)/ruby/internal/anyargs.h ossl_rand.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_rand.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -3880,6 +3900,7 @@ ossl_ssl.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_ssl.o: $(hdrdir)/ruby/defines.h ossl_ssl.o: $(hdrdir)/ruby/encoding.h ossl_ssl.o: $(hdrdir)/ruby/intern.h +ossl_ssl.o: $(hdrdir)/ruby/internal/abi.h ossl_ssl.o: $(hdrdir)/ruby/internal/anyargs.h ossl_ssl.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_ssl.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -4073,6 +4094,7 @@ ossl_ssl_session.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_ssl_session.o: $(hdrdir)/ruby/defines.h ossl_ssl_session.o: $(hdrdir)/ruby/encoding.h ossl_ssl_session.o: $(hdrdir)/ruby/intern.h +ossl_ssl_session.o: $(hdrdir)/ruby/internal/abi.h ossl_ssl_session.o: $(hdrdir)/ruby/internal/anyargs.h ossl_ssl_session.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_ssl_session.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -4266,6 +4288,7 @@ ossl_ts.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_ts.o: $(hdrdir)/ruby/defines.h ossl_ts.o: $(hdrdir)/ruby/encoding.h ossl_ts.o: $(hdrdir)/ruby/intern.h +ossl_ts.o: $(hdrdir)/ruby/internal/abi.h ossl_ts.o: $(hdrdir)/ruby/internal/anyargs.h ossl_ts.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_ts.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -4459,6 +4482,7 @@ ossl_x509.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509.o: $(hdrdir)/ruby/defines.h ossl_x509.o: $(hdrdir)/ruby/encoding.h ossl_x509.o: $(hdrdir)/ruby/intern.h +ossl_x509.o: $(hdrdir)/ruby/internal/abi.h ossl_x509.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -4652,6 +4676,7 @@ ossl_x509attr.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509attr.o: $(hdrdir)/ruby/defines.h ossl_x509attr.o: $(hdrdir)/ruby/encoding.h ossl_x509attr.o: $(hdrdir)/ruby/intern.h +ossl_x509attr.o: $(hdrdir)/ruby/internal/abi.h ossl_x509attr.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509attr.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509attr.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -4845,6 +4870,7 @@ ossl_x509cert.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509cert.o: $(hdrdir)/ruby/defines.h ossl_x509cert.o: $(hdrdir)/ruby/encoding.h ossl_x509cert.o: $(hdrdir)/ruby/intern.h +ossl_x509cert.o: $(hdrdir)/ruby/internal/abi.h ossl_x509cert.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509cert.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509cert.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -5038,6 +5064,7 @@ ossl_x509crl.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509crl.o: $(hdrdir)/ruby/defines.h ossl_x509crl.o: $(hdrdir)/ruby/encoding.h ossl_x509crl.o: $(hdrdir)/ruby/intern.h +ossl_x509crl.o: $(hdrdir)/ruby/internal/abi.h ossl_x509crl.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509crl.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509crl.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -5231,6 +5258,7 @@ ossl_x509ext.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509ext.o: $(hdrdir)/ruby/defines.h ossl_x509ext.o: $(hdrdir)/ruby/encoding.h ossl_x509ext.o: $(hdrdir)/ruby/intern.h +ossl_x509ext.o: $(hdrdir)/ruby/internal/abi.h ossl_x509ext.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509ext.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509ext.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -5424,6 +5452,7 @@ ossl_x509name.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509name.o: $(hdrdir)/ruby/defines.h ossl_x509name.o: $(hdrdir)/ruby/encoding.h ossl_x509name.o: $(hdrdir)/ruby/intern.h +ossl_x509name.o: $(hdrdir)/ruby/internal/abi.h ossl_x509name.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509name.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509name.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -5617,6 +5646,7 @@ ossl_x509req.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509req.o: $(hdrdir)/ruby/defines.h ossl_x509req.o: $(hdrdir)/ruby/encoding.h ossl_x509req.o: $(hdrdir)/ruby/intern.h +ossl_x509req.o: $(hdrdir)/ruby/internal/abi.h ossl_x509req.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509req.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509req.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -5810,6 +5840,7 @@ ossl_x509revoked.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509revoked.o: $(hdrdir)/ruby/defines.h ossl_x509revoked.o: $(hdrdir)/ruby/encoding.h ossl_x509revoked.o: $(hdrdir)/ruby/intern.h +ossl_x509revoked.o: $(hdrdir)/ruby/internal/abi.h ossl_x509revoked.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509revoked.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509revoked.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -6003,6 +6034,7 @@ ossl_x509store.o: $(hdrdir)/ruby/backward/2/stdarg.h ossl_x509store.o: $(hdrdir)/ruby/defines.h ossl_x509store.o: $(hdrdir)/ruby/encoding.h ossl_x509store.o: $(hdrdir)/ruby/intern.h +ossl_x509store.o: $(hdrdir)/ruby/internal/abi.h ossl_x509store.o: $(hdrdir)/ruby/internal/anyargs.h ossl_x509store.o: $(hdrdir)/ruby/internal/arithmetic.h ossl_x509store.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb index 1d38b56990..467f7e7a86 100644 --- a/ext/openssl/extconf.rb +++ b/ext/openssl/extconf.rb @@ -171,6 +171,7 @@ have_func("SSL_CTX_set_post_handshake_auth") have_func("EVP_PKEY_check") # added in 3.0.0 +openssl_3 = have_func("SSL_set0_tmp_dh_pkey") have_func("ERR_get_error_all") have_func("TS_VERIFY_CTX_set_certs(NULL, NULL)", "openssl/ts.h") @@ -179,9 +180,16 @@ have_func("BN_check_prime") have_func("EVP_MD_CTX_get0_md") have_func("EVP_MD_CTX_get_pkey_ctx") have_func("EVP_PKEY_eq") +have_func("EVP_PKEY_dup") Logging::message "=== Checking done. ===\n" +if openssl_3 + if $warnflags.sub!(/-W\K(?=deprecated-declarations)/, 'no-') + $warnflags << " -Wno-incompatible-pointer-types-discards-qualifiers" + end +end + create_header create_makefile("openssl") Logging::message "Done.\n" diff --git a/ext/openssl/lib/openssl/pkey.rb b/ext/openssl/lib/openssl/pkey.rb index f6bf5892b0..c3e0629091 100644 --- a/ext/openssl/lib/openssl/pkey.rb +++ b/ext/openssl/lib/openssl/pkey.rb @@ -47,9 +47,19 @@ module OpenSSL::PKey # * _pub_bn_ is a OpenSSL::BN, *not* the DH instance returned by # DH#public_key as that contains the DH parameters only. def compute_key(pub_bn) - peer = dup - peer.set_key(pub_bn, nil) - derive(peer) + # FIXME: This is constructing an X.509 SubjectPublicKeyInfo and is very + # inefficient + obj = OpenSSL::ASN1.Sequence([ + OpenSSL::ASN1.Sequence([ + OpenSSL::ASN1.ObjectId("dhKeyAgreement"), + OpenSSL::ASN1.Sequence([ + OpenSSL::ASN1.Integer(p), + OpenSSL::ASN1.Integer(g), + ]), + ]), + OpenSSL::ASN1.BitString(OpenSSL::ASN1.Integer(pub_bn).to_der), + ]) + derive(OpenSSL::PKey.read(obj.to_der)) end # :call-seq: @@ -61,14 +71,29 @@ module OpenSSL::PKey # called first in order to generate the per-session keys before performing # the actual key exchange. # + # <b>Deprecated in version 3.0</b>. This method is incompatible with + # OpenSSL 3.0.0 or later. + # # See also OpenSSL::PKey.generate_key. # # Example: - # dh = OpenSSL::PKey::DH.new(2048) - # public_key = dh.public_key #contains no private/public key yet - # public_key.generate_key! - # puts public_key.private? # => true + # # DEPRECATED USAGE: This will not work on OpenSSL 3.0 or later + # dh0 = OpenSSL::PKey::DH.new(2048) + # dh = dh0.public_key # #public_key only copies the DH parameters (contrary to the name) + # dh.generate_key! + # puts dh.private? # => true + # puts dh0.pub_key == dh.pub_key #=> false + # + # # With OpenSSL::PKey.generate_key + # dh0 = OpenSSL::PKey::DH.new(2048) + # dh = OpenSSL::PKey.generate_key(dh0) + # puts dh0.pub_key == dh.pub_key #=> false def generate_key! + if OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000 + raise DHError, "OpenSSL::PKey::DH is immutable on OpenSSL 3.0; " \ + "use OpenSSL::PKey.generate_key instead" + end + unless priv_key tmp = OpenSSL::PKey.generate_key(self) set_key(tmp.pub_key, tmp.priv_key) @@ -249,9 +274,14 @@ module OpenSSL::PKey # This method is provided for backwards compatibility, and calls #derive # internally. def dh_compute_key(pubkey) - peer = OpenSSL::PKey::EC.new(group) - peer.public_key = pubkey - derive(peer) + obj = OpenSSL::ASN1.Sequence([ + OpenSSL::ASN1.Sequence([ + OpenSSL::ASN1.ObjectId("id-ecPublicKey"), + group.to_der, + ]), + OpenSSL::ASN1.BitString(pubkey.to_octet_string(:uncompressed)), + ]) + derive(OpenSSL::PKey.read(obj.to_der)) end end diff --git a/ext/openssl/lib/openssl/version.rb b/ext/openssl/lib/openssl/version.rb index acd53d440d..5e60604353 100644 --- a/ext/openssl/lib/openssl/version.rb +++ b/ext/openssl/lib/openssl/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module OpenSSL - VERSION = "3.0.0.pre" + VERSION = "3.0.0" end diff --git a/ext/openssl/openssl.gemspec b/ext/openssl/openssl.gemspec index 38bcb9db5f..c6cd818336 100644 --- a/ext/openssl/openssl.gemspec +++ b/ext/openssl/openssl.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "openssl" - spec.version = "3.0.0.pre" + spec.version = "3.0.0" spec.authors = ["Martin Bosslet", "SHIBATA Hiroshi", "Zachary Scott", "Kazuki Yamaguchi"] spec.email = ["ruby-core@ruby-lang.org"] spec.summary = %q{OpenSSL provides SSL, TLS and general purpose cryptography.} diff --git a/ext/openssl/openssl_missing.c b/ext/openssl/openssl_missing.c index 8b93cba6d4..4415703db4 100644 --- a/ext/openssl/openssl_missing.c +++ b/ext/openssl/openssl_missing.c @@ -10,9 +10,6 @@ #include RUBY_EXTCONF_H #include <string.h> /* memcpy() */ -#if !defined(OPENSSL_NO_ENGINE) -# include <openssl/engine.h> -#endif #include <openssl/x509_vfy.h> #include "openssl_missing.h" diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h index 3a0ab1e593..4b5126893b 100644 --- a/ext/openssl/ossl.h +++ b/ext/openssl/ossl.h @@ -18,6 +18,7 @@ #include <ruby/io.h> #include <ruby/thread.h> #include <openssl/opensslv.h> + #include <openssl/err.h> #include <openssl/asn1.h> #include <openssl/x509v3.h> @@ -30,9 +31,6 @@ #include <openssl/ts.h> #endif #include <openssl/crypto.h> -#if !defined(OPENSSL_NO_ENGINE) -# include <openssl/engine.h> -#endif #if !defined(OPENSSL_NO_OCSP) # include <openssl/ocsp.h> #endif @@ -54,6 +52,10 @@ (LIBRESSL_VERSION_NUMBER >= (maj << 28) | (min << 20) | (pat << 12)) #endif +#if !defined(OPENSSL_NO_ENGINE) && !OSSL_OPENSSL_PREREQ(3, 0, 0) +# define OSSL_USE_ENGINE +#endif + /* * Common Module */ diff --git a/ext/openssl/ossl_engine.c b/ext/openssl/ossl_engine.c index 661a1368e2..1abde7f766 100644 --- a/ext/openssl/ossl_engine.c +++ b/ext/openssl/ossl_engine.c @@ -9,7 +9,8 @@ */ #include "ossl.h" -#if !defined(OPENSSL_NO_ENGINE) +#ifdef OSSL_USE_ENGINE +# include <openssl/engine.h> #define NewEngine(klass) \ TypedData_Wrap_Struct((klass), &ossl_engine_type, 0) diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c index f89ff2f9a1..bfe3a74b12 100644 --- a/ext/openssl/ossl_hmac.c +++ b/ext/openssl/ossl_hmac.c @@ -175,7 +175,7 @@ static VALUE ossl_hmac_digest(VALUE self) { EVP_MD_CTX *ctx; - size_t buf_len; + size_t buf_len = EVP_MAX_MD_SIZE; VALUE ret; GetHMAC(self, ctx); @@ -200,7 +200,7 @@ ossl_hmac_hexdigest(VALUE self) { EVP_MD_CTX *ctx; unsigned char buf[EVP_MAX_MD_SIZE]; - size_t buf_len; + size_t buf_len = EVP_MAX_MD_SIZE; VALUE ret; GetHMAC(self, ctx); diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index f9f5162e41..2a4835a28d 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -9,6 +9,10 @@ */ #include "ossl.h" +#ifdef OSSL_USE_ENGINE +# include <openssl/engine.h> +#endif + /* * Classes */ @@ -39,12 +43,8 @@ pkey_new0(VALUE arg) { EVP_PKEY *pkey = (EVP_PKEY *)arg; VALUE klass, obj; - int type; - - if (!pkey || (type = EVP_PKEY_base_id(pkey)) == EVP_PKEY_NONE) - ossl_raise(rb_eRuntimeError, "pkey is empty"); - switch (type) { + switch (EVP_PKEY_base_id(pkey)) { #if !defined(OPENSSL_NO_RSA) case EVP_PKEY_RSA: klass = cRSA; break; #endif @@ -59,8 +59,8 @@ pkey_new0(VALUE arg) #endif default: klass = cPKey; break; } - obj = NewPKey(klass); - SetPKey(obj, pkey); + obj = rb_obj_alloc(klass); + RTYPEDDATA_DATA(obj) = pkey; return obj; } @@ -79,6 +79,45 @@ ossl_pkey_new(EVP_PKEY *pkey) return obj; } +#if OSSL_OPENSSL_PREREQ(3, 0, 0) +# include <openssl/decoder.h> + +EVP_PKEY * +ossl_pkey_read_generic(BIO *bio, VALUE pass) +{ + void *ppass = (void *)pass; + OSSL_DECODER_CTX *dctx; + EVP_PKEY *pkey = NULL; + int pos = 0, pos2; + + dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "DER", NULL, NULL, 0, NULL, NULL); + if (!dctx) + goto out; + if (OSSL_DECODER_CTX_set_pem_password_cb(dctx, ossl_pem_passwd_cb, ppass) != 1) + goto out; + + /* First check DER */ + if (OSSL_DECODER_from_bio(dctx, bio) == 1) + goto out; + + /* Then check PEM; multiple OSSL_DECODER_from_bio() calls may be needed */ + OSSL_BIO_reset(bio); + if (OSSL_DECODER_CTX_set_input_type(dctx, "PEM") != 1) + goto out; + while (OSSL_DECODER_from_bio(dctx, bio) != 1) { + if (BIO_eof(bio)) + goto out; + pos2 = BIO_tell(bio); + if (pos2 < 0 || pos2 <= pos) + goto out; + pos = pos2; + } + + out: + OSSL_DECODER_CTX_free(dctx); + return pkey; +} +#else EVP_PKEY * ossl_pkey_read_generic(BIO *bio, VALUE pass) { @@ -107,6 +146,7 @@ ossl_pkey_read_generic(BIO *bio, VALUE pass) out: return pkey; } +#endif /* * call-seq: @@ -276,6 +316,11 @@ pkey_generate(int argc, VALUE *argv, VALUE self, int genparam) ossl_raise(ePKeyError, "EVP_PKEY_CTX_new"); } else { +#if OSSL_OPENSSL_PREREQ(3, 0, 0) + ctx = EVP_PKEY_CTX_new_from_name(NULL, StringValueCStr(alg), NULL); + if (!ctx) + ossl_raise(ePKeyError, "EVP_PKEY_CTX_new_from_name"); +#else const EVP_PKEY_ASN1_METHOD *ameth; ENGINE *tmpeng; int pkey_id; @@ -294,6 +339,7 @@ pkey_generate(int argc, VALUE *argv, VALUE self, int genparam) ctx = EVP_PKEY_CTX_new_id(pkey_id, NULL/* engine */); if (!ctx) ossl_raise(ePKeyError, "EVP_PKEY_CTX_new_id"); +#endif } if (genparam && EVP_PKEY_paramgen_init(ctx) <= 0) { @@ -389,9 +435,19 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self) return pkey_generate(argc, argv, self, 0); } +/* + * TODO: There is no convenient way to check the presence of public key + * components on OpenSSL 3.0. But since keys are immutable on 3.0, pkeys without + * these should only be created by OpenSSL::PKey.generate_parameters or by + * parsing DER-/PEM-encoded string. We would need another flag for that. + */ void ossl_pkey_check_public_key(const EVP_PKEY *pkey) { +#if OSSL_OPENSSL_PREREQ(3, 0, 0) + if (EVP_PKEY_missing_parameters(pkey)) + ossl_raise(ePKeyError, "parameters missing"); +#else void *ptr; const BIGNUM *n, *e, *pubkey; @@ -427,6 +483,7 @@ ossl_pkey_check_public_key(const EVP_PKEY *pkey) return; } ossl_raise(ePKeyError, "public key missing"); +#endif } EVP_PKEY * @@ -476,16 +533,7 @@ DupPKeyPtr(VALUE obj) static VALUE ossl_pkey_alloc(VALUE klass) { - EVP_PKEY *pkey; - VALUE obj; - - obj = NewPKey(klass); - if (!(pkey = EVP_PKEY_new())) { - ossl_raise(ePKeyError, NULL); - } - SetPKey(obj, pkey); - - return obj; + return TypedData_Wrap_Struct(klass, &ossl_evp_pkey_type, NULL); } /* @@ -504,6 +552,26 @@ ossl_pkey_initialize(VALUE self) return self; } +#ifdef HAVE_EVP_PKEY_DUP +static VALUE +ossl_pkey_initialize_copy(VALUE self, VALUE other) +{ + EVP_PKEY *pkey, *pkey_other; + + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + TypedData_Get_Struct(other, EVP_PKEY, &ossl_evp_pkey_type, pkey_other); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); + if (pkey_other) { + pkey = EVP_PKEY_dup(pkey_other); + if (!pkey) + ossl_raise(ePKeyError, "EVP_PKEY_dup"); + RTYPEDDATA_DATA(self) = pkey; + } + return self; +} +#endif + /* * call-seq: * pkey.oid -> string @@ -1481,6 +1549,11 @@ Init_ossl_pkey(void) rb_define_alloc_func(cPKey, ossl_pkey_alloc); rb_define_method(cPKey, "initialize", ossl_pkey_initialize, 0); +#ifdef HAVE_EVP_PKEY_DUP + rb_define_method(cPKey, "initialize_copy", ossl_pkey_initialize_copy, 1); +#else + rb_undef_method(cPKey, "initialize_copy"); +#endif rb_define_method(cPKey, "oid", ossl_pkey_oid, 0); rb_define_method(cPKey, "inspect", ossl_pkey_inspect, 0); rb_define_method(cPKey, "to_text", ossl_pkey_to_text, 0); diff --git a/ext/openssl/ossl_pkey.h b/ext/openssl/ossl_pkey.h index 4beede22b5..38fb9fad10 100644 --- a/ext/openssl/ossl_pkey.h +++ b/ext/openssl/ossl_pkey.h @@ -15,19 +15,10 @@ extern VALUE cPKey; extern VALUE ePKeyError; extern const rb_data_type_t ossl_evp_pkey_type; -#define OSSL_PKEY_SET_PRIVATE(obj) rb_iv_set((obj), "private", Qtrue) -#define OSSL_PKEY_SET_PUBLIC(obj) rb_iv_set((obj), "private", Qfalse) -#define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue) +/* For ENGINE */ +#define OSSL_PKEY_SET_PRIVATE(obj) rb_ivar_set((obj), rb_intern("private"), Qtrue) +#define OSSL_PKEY_IS_PRIVATE(obj) (rb_attr_get((obj), rb_intern("private")) == Qtrue) -#define NewPKey(klass) \ - TypedData_Wrap_Struct((klass), &ossl_evp_pkey_type, 0) -#define SetPKey(obj, pkey) do { \ - if (!(pkey)) { \ - rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \ - } \ - RTYPEDDATA_DATA(obj) = (pkey); \ - OSSL_PKEY_SET_PUBLIC(obj); \ -} while (0) #define GetPKey(obj, pkey) do {\ TypedData_Get_Struct((obj), EVP_PKEY, &ossl_evp_pkey_type, (pkey)); \ if (!(pkey)) { \ @@ -35,6 +26,7 @@ extern const rb_data_type_t ossl_evp_pkey_type; } \ } while (0) +/* Takes ownership of the EVP_PKEY */ VALUE ossl_pkey_new(EVP_PKEY *); void ossl_pkey_check_public_key(const EVP_PKEY *); EVP_PKEY *ossl_pkey_read_generic(BIO *, VALUE); @@ -124,6 +116,7 @@ static VALUE ossl_##_keytype##_get_##_name(VALUE self) \ OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \ _type##_get0_##_group(obj, NULL, &bn)) +#if !OSSL_OPENSSL_PREREQ(3, 0, 0) #define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \ /* \ * call-seq: \ @@ -181,6 +174,21 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \ } \ return self; \ } +#else +#define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \ +static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALUE v3) \ +{ \ + rb_raise(ePKeyError, \ + #_keytype"#set_"#_group"= is incompatible with OpenSSL 3.0"); \ +} + +#define OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2) \ +static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \ +{ \ + rb_raise(ePKeyError, \ + #_keytype"#set_"#_group"= is incompatible with OpenSSL 3.0"); \ +} +#endif #define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3) \ OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \ diff --git a/ext/openssl/ossl_pkey_dh.c b/ext/openssl/ossl_pkey_dh.c index ca782bbe59..696455dcfd 100644 --- a/ext/openssl/ossl_pkey_dh.c +++ b/ext/openssl/ossl_pkey_dh.c @@ -58,51 +58,76 @@ VALUE eDHError; * * Examples: * # Creating an instance from scratch - * dh = DH.new + * # Note that this is deprecated and will not work on OpenSSL 3.0 or later. + * dh = OpenSSL::PKey::DH.new * dh.set_pqg(bn_p, nil, bn_g) * * # Generating a parameters and a key pair - * dh = DH.new(2048) # An alias of DH.generate(2048) + * dh = OpenSSL::PKey::DH.new(2048) # An alias of OpenSSL::PKey::DH.generate(2048) * * # Reading DH parameters - * dh = DH.new(File.read('parameters.pem')) # -> dh, but no public/private key yet - * dh.generate_key! # -> dh with public and private key + * dh_params = OpenSSL::PKey::DH.new(File.read('parameters.pem')) # loads parameters only + * dh = OpenSSL::PKey.generate_key(dh_params) # generates a key pair */ static VALUE ossl_dh_initialize(int argc, VALUE *argv, VALUE self) { EVP_PKEY *pkey; + int type; DH *dh; - BIO *in; + BIO *in = NULL; VALUE arg; - GetPKey(self, pkey); + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); + /* The DH.new(size, generator) form is handled by lib/openssl/pkey.rb */ if (rb_scan_args(argc, argv, "01", &arg) == 0) { dh = DH_new(); if (!dh) ossl_raise(eDHError, "DH_new"); + goto legacy; } - else { - arg = ossl_to_der_if_possible(arg); - in = ossl_obj2bio(&arg); - dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL); - if (!dh){ - OSSL_BIO_reset(in); - dh = d2i_DHparams_bio(in, NULL); - } - BIO_free(in); - if (!dh) { - ossl_raise(eDHError, NULL); - } + + arg = ossl_to_der_if_possible(arg); + in = ossl_obj2bio(&arg); + + /* + * On OpenSSL <= 1.1.1 and current versions of LibreSSL, the generic + * routine does not support DER-encoded parameters + */ + dh = d2i_DHparams_bio(in, NULL); + if (dh) + goto legacy; + OSSL_BIO_reset(in); + + pkey = ossl_pkey_read_generic(in, Qnil); + BIO_free(in); + if (!pkey) + ossl_raise(eDHError, "could not parse pkey"); + + type = EVP_PKEY_base_id(pkey); + if (type != EVP_PKEY_DH) { + EVP_PKEY_free(pkey); + rb_raise(eDHError, "incorrect pkey type: %s", OBJ_nid2sn(type)); } - if (!EVP_PKEY_assign_DH(pkey, dh)) { - DH_free(dh); - ossl_raise(eDHError, NULL); + RTYPEDDATA_DATA(self) = pkey; + return self; + + legacy: + BIO_free(in); + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_DH(pkey, dh) != 1) { + EVP_PKEY_free(pkey); + DH_free(dh); + ossl_raise(eDHError, "EVP_PKEY_assign_DH"); } + RTYPEDDATA_DATA(self) = pkey; return self; } +#ifndef HAVE_EVP_PKEY_DUP static VALUE ossl_dh_initialize_copy(VALUE self, VALUE other) { @@ -110,15 +135,14 @@ ossl_dh_initialize_copy(VALUE self, VALUE other) DH *dh, *dh_other; const BIGNUM *pub, *priv; - GetPKey(self, pkey); - if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE) - ossl_raise(eDHError, "DH already initialized"); + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); GetDH(other, dh_other); dh = DHparams_dup(dh_other); if (!dh) ossl_raise(eDHError, "DHparams_dup"); - EVP_PKEY_assign_DH(pkey, dh); DH_get0_key(dh_other, &pub, &priv); if (pub) { @@ -133,8 +157,16 @@ ossl_dh_initialize_copy(VALUE self, VALUE other) DH_set0_key(dh, pub2, priv2); } + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_DH(pkey, dh) != 1) { + EVP_PKEY_free(pkey); + DH_free(dh); + ossl_raise(eDHError, "EVP_PKEY_assign_DH"); + } + RTYPEDDATA_DATA(self) = pkey; return self; } +#endif /* * call-seq: @@ -378,7 +410,9 @@ Init_ossl_dh(void) */ cDH = rb_define_class_under(mPKey, "DH", cPKey); rb_define_method(cDH, "initialize", ossl_dh_initialize, -1); +#ifndef HAVE_EVP_PKEY_DUP rb_define_method(cDH, "initialize_copy", ossl_dh_initialize_copy, 1); +#endif rb_define_method(cDH, "public?", ossl_dh_is_public, 0); rb_define_method(cDH, "private?", ossl_dh_is_private, 0); rb_define_method(cDH, "export", ossl_dh_export, 0); diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c index 7af00eebec..25404aa7f5 100644 --- a/ext/openssl/ossl_pkey_dsa.c +++ b/ext/openssl/ossl_pkey_dsa.c @@ -83,72 +83,91 @@ VALUE eDSAError; static VALUE ossl_dsa_initialize(int argc, VALUE *argv, VALUE self) { - EVP_PKEY *pkey, *tmp; - DSA *dsa = NULL; - BIO *in; + EVP_PKEY *pkey; + DSA *dsa; + BIO *in = NULL; VALUE arg, pass; + int type; + + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); - GetPKey(self, pkey); /* The DSA.new(size, generator) form is handled by lib/openssl/pkey.rb */ rb_scan_args(argc, argv, "02", &arg, &pass); if (argc == 0) { dsa = DSA_new(); if (!dsa) ossl_raise(eDSAError, "DSA_new"); + goto legacy; } - else { - pass = ossl_pem_passwd_value(pass); - arg = ossl_to_der_if_possible(arg); - in = ossl_obj2bio(&arg); - - tmp = ossl_pkey_read_generic(in, pass); - if (tmp) { - if (EVP_PKEY_base_id(tmp) != EVP_PKEY_DSA) - rb_raise(eDSAError, "incorrect pkey type: %s", - OBJ_nid2sn(EVP_PKEY_base_id(tmp))); - dsa = EVP_PKEY_get1_DSA(tmp); - EVP_PKEY_free(tmp); - } - if (!dsa) { - OSSL_BIO_reset(in); -#define PEM_read_bio_DSAPublicKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ - (d2i_of_void *)d2i_DSAPublicKey, PEM_STRING_DSA_PUBLIC, (bp), (void **)(x), (cb), (u)) - dsa = PEM_read_bio_DSAPublicKey(in, NULL, NULL, NULL); -#undef PEM_read_bio_DSAPublicKey - } - BIO_free(in); - if (!dsa) { - ossl_clear_error(); - ossl_raise(eDSAError, "Neither PUB key nor PRIV key"); - } - } - if (!EVP_PKEY_assign_DSA(pkey, dsa)) { - DSA_free(dsa); - ossl_raise(eDSAError, NULL); + + pass = ossl_pem_passwd_value(pass); + arg = ossl_to_der_if_possible(arg); + in = ossl_obj2bio(&arg); + + /* DER-encoded DSAPublicKey format isn't supported by the generic routine */ + dsa = (DSA *)PEM_ASN1_read_bio((d2i_of_void *)d2i_DSAPublicKey, + PEM_STRING_DSA_PUBLIC, + in, NULL, NULL, NULL); + if (dsa) + goto legacy; + OSSL_BIO_reset(in); + + pkey = ossl_pkey_read_generic(in, pass); + BIO_free(in); + if (!pkey) + ossl_raise(eDSAError, "Neither PUB key nor PRIV key"); + + type = EVP_PKEY_base_id(pkey); + if (type != EVP_PKEY_DSA) { + EVP_PKEY_free(pkey); + rb_raise(eDSAError, "incorrect pkey type: %s", OBJ_nid2sn(type)); } + RTYPEDDATA_DATA(self) = pkey; + return self; + legacy: + BIO_free(in); + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_DSA(pkey, dsa) != 1) { + EVP_PKEY_free(pkey); + DSA_free(dsa); + ossl_raise(eDSAError, "EVP_PKEY_assign_DSA"); + } + RTYPEDDATA_DATA(self) = pkey; return self; } +#ifndef HAVE_EVP_PKEY_DUP static VALUE ossl_dsa_initialize_copy(VALUE self, VALUE other) { EVP_PKEY *pkey; DSA *dsa, *dsa_new; - GetPKey(self, pkey); - if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE) - ossl_raise(eDSAError, "DSA already initialized"); + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); GetDSA(other, dsa); - dsa_new = ASN1_dup((i2d_of_void *)i2d_DSAPrivateKey, (d2i_of_void *)d2i_DSAPrivateKey, (char *)dsa); + dsa_new = (DSA *)ASN1_dup((i2d_of_void *)i2d_DSAPrivateKey, + (d2i_of_void *)d2i_DSAPrivateKey, + (char *)dsa); if (!dsa_new) ossl_raise(eDSAError, "ASN1_dup"); - EVP_PKEY_assign_DSA(pkey, dsa_new); + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_DSA(pkey, dsa_new) != 1) { + EVP_PKEY_free(pkey); + DSA_free(dsa_new); + ossl_raise(eDSAError, "EVP_PKEY_assign_DSA"); + } + RTYPEDDATA_DATA(self) = pkey; return self; } +#endif /* * call-seq: @@ -310,7 +329,9 @@ Init_ossl_dsa(void) cDSA = rb_define_class_under(mPKey, "DSA", cPKey); rb_define_method(cDSA, "initialize", ossl_dsa_initialize, -1); +#ifndef HAVE_EVP_PKEY_DUP rb_define_method(cDSA, "initialize_copy", ossl_dsa_initialize_copy, 1); +#endif rb_define_method(cDSA, "public?", ossl_dsa_is_public, 0); rb_define_method(cDSA, "private?", ossl_dsa_is_private, 0); diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c index db80d112a0..dee215447d 100644 --- a/ext/openssl/ossl_pkey_ec.c +++ b/ext/openssl/ossl_pkey_ec.c @@ -109,13 +109,16 @@ ossl_ec_key_s_generate(VALUE klass, VALUE arg) VALUE obj; obj = rb_obj_alloc(klass); - GetPKey(obj, pkey); ec = ec_key_new_from_group(arg); - if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) { + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) { + EVP_PKEY_free(pkey); EC_KEY_free(ec); ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY"); } + RTYPEDDATA_DATA(obj) = pkey; + if (!EC_KEY_generate_key(ec)) ossl_raise(eECError, "EC_KEY_generate_key"); @@ -136,75 +139,83 @@ ossl_ec_key_s_generate(VALUE klass, VALUE arg) static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self) { EVP_PKEY *pkey; - EC_KEY *ec = NULL; + EC_KEY *ec; + BIO *in; VALUE arg, pass; + int type; - GetPKey(self, pkey); - if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE) - ossl_raise(eECError, "EC_KEY already initialized"); + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); rb_scan_args(argc, argv, "02", &arg, &pass); - if (NIL_P(arg)) { if (!(ec = EC_KEY_new())) - ossl_raise(eECError, NULL); - } else if (rb_obj_is_kind_of(arg, cEC)) { - EC_KEY *other_ec = NULL; + ossl_raise(eECError, "EC_KEY_new"); + goto legacy; + } + else if (rb_obj_is_kind_of(arg, cEC_GROUP)) { + ec = ec_key_new_from_group(arg); + goto legacy; + } - GetEC(arg, other_ec); - if (!(ec = EC_KEY_dup(other_ec))) - ossl_raise(eECError, NULL); - } else if (rb_obj_is_kind_of(arg, cEC_GROUP)) { - ec = ec_key_new_from_group(arg); - } else { - BIO *in = ossl_obj2bio(&arg); - EVP_PKEY *tmp; - pass = ossl_pem_passwd_value(pass); - tmp = ossl_pkey_read_generic(in, pass); - if (tmp) { - if (EVP_PKEY_base_id(tmp) != EVP_PKEY_EC) - rb_raise(eECError, "incorrect pkey type: %s", - OBJ_nid2sn(EVP_PKEY_base_id(tmp))); - ec = EVP_PKEY_get1_EC_KEY(tmp); - EVP_PKEY_free(tmp); - } - BIO_free(in); + pass = ossl_pem_passwd_value(pass); + arg = ossl_to_der_if_possible(arg); + in = ossl_obj2bio(&arg); - if (!ec) { - ossl_clear_error(); - ec = ec_key_new_from_group(arg); - } + pkey = ossl_pkey_read_generic(in, pass); + BIO_free(in); + if (!pkey) { + ossl_clear_error(); + ec = ec_key_new_from_group(arg); + goto legacy; } - if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) { - EC_KEY_free(ec); - ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY"); + type = EVP_PKEY_base_id(pkey); + if (type != EVP_PKEY_EC) { + EVP_PKEY_free(pkey); + rb_raise(eDSAError, "incorrect pkey type: %s", OBJ_nid2sn(type)); } + RTYPEDDATA_DATA(self) = pkey; + return self; + legacy: + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) { + EVP_PKEY_free(pkey); + EC_KEY_free(ec); + ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY"); + } + RTYPEDDATA_DATA(self) = pkey; return self; } +#ifndef HAVE_EVP_PKEY_DUP static VALUE ossl_ec_key_initialize_copy(VALUE self, VALUE other) { EVP_PKEY *pkey; EC_KEY *ec, *ec_new; - GetPKey(self, pkey); - if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE) - ossl_raise(eECError, "EC already initialized"); + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); GetEC(other, ec); ec_new = EC_KEY_dup(ec); if (!ec_new) ossl_raise(eECError, "EC_KEY_dup"); - if (!EVP_PKEY_assign_EC_KEY(pkey, ec_new)) { - EC_KEY_free(ec_new); - ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY"); + + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec_new) != 1) { + EC_KEY_free(ec_new); + ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY"); } + RTYPEDDATA_DATA(self) = pkey; return self; } +#endif /* * call-seq: @@ -237,6 +248,9 @@ ossl_ec_key_get_group(VALUE self) static VALUE ossl_ec_key_set_group(VALUE self, VALUE group_v) { +#if OSSL_OPENSSL_PREREQ(3, 0, 0) + rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0"); +#else EC_KEY *ec; EC_GROUP *group; @@ -247,6 +261,7 @@ ossl_ec_key_set_group(VALUE self, VALUE group_v) ossl_raise(eECError, "EC_KEY_set_group"); return group_v; +#endif } /* @@ -275,6 +290,9 @@ static VALUE ossl_ec_key_get_private_key(VALUE self) */ static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key) { +#if OSSL_OPENSSL_PREREQ(3, 0, 0) + rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0"); +#else EC_KEY *ec; BIGNUM *bn = NULL; @@ -294,6 +312,7 @@ static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key) } return private_key; +#endif } /* @@ -322,6 +341,9 @@ static VALUE ossl_ec_key_get_public_key(VALUE self) */ static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key) { +#if OSSL_OPENSSL_PREREQ(3, 0, 0) + rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0"); +#else EC_KEY *ec; EC_POINT *point = NULL; @@ -341,6 +363,7 @@ static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key) } return public_key; +#endif } /* @@ -430,6 +453,9 @@ ossl_ec_key_to_der(VALUE self) */ static VALUE ossl_ec_key_generate_key(VALUE self) { +#if OSSL_OPENSSL_PREREQ(3, 0, 0) + rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0"); +#else EC_KEY *ec; GetEC(self, ec); @@ -437,6 +463,7 @@ static VALUE ossl_ec_key_generate_key(VALUE self) ossl_raise(eECError, "EC_KEY_generate_key"); return self; +#endif } /* @@ -1514,8 +1541,9 @@ void Init_ossl_ec(void) rb_define_singleton_method(cEC, "generate", ossl_ec_key_s_generate, 1); rb_define_method(cEC, "initialize", ossl_ec_key_initialize, -1); +#ifndef HAVE_EVP_PKEY_DUP rb_define_method(cEC, "initialize_copy", ossl_ec_key_initialize_copy, 1); -/* copy/dup/cmp */ +#endif rb_define_method(cEC, "group", ossl_ec_key_get_group, 0); rb_define_method(cEC, "group=", ossl_ec_key_set_group, 1); diff --git a/ext/openssl/ossl_pkey_rsa.c b/ext/openssl/ossl_pkey_rsa.c index 8ebd3ec559..4d66010f49 100644 --- a/ext/openssl/ossl_pkey_rsa.c +++ b/ext/openssl/ossl_pkey_rsa.c @@ -76,73 +76,93 @@ VALUE eRSAError; static VALUE ossl_rsa_initialize(int argc, VALUE *argv, VALUE self) { - EVP_PKEY *pkey, *tmp; - RSA *rsa = NULL; - BIO *in; + EVP_PKEY *pkey; + RSA *rsa; + BIO *in = NULL; VALUE arg, pass; + int type; + + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); - GetPKey(self, pkey); /* The RSA.new(size, generator) form is handled by lib/openssl/pkey.rb */ rb_scan_args(argc, argv, "02", &arg, &pass); if (argc == 0) { rsa = RSA_new(); if (!rsa) ossl_raise(eRSAError, "RSA_new"); + goto legacy; } - else { - pass = ossl_pem_passwd_value(pass); - arg = ossl_to_der_if_possible(arg); - in = ossl_obj2bio(&arg); - - tmp = ossl_pkey_read_generic(in, pass); - if (tmp) { - if (EVP_PKEY_base_id(tmp) != EVP_PKEY_RSA) - rb_raise(eRSAError, "incorrect pkey type: %s", - OBJ_nid2sn(EVP_PKEY_base_id(tmp))); - rsa = EVP_PKEY_get1_RSA(tmp); - EVP_PKEY_free(tmp); - } - if (!rsa) { - OSSL_BIO_reset(in); - rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL); - } - if (!rsa) { - OSSL_BIO_reset(in); - rsa = d2i_RSAPublicKey_bio(in, NULL); - } - BIO_free(in); - if (!rsa) { - ossl_clear_error(); - ossl_raise(eRSAError, "Neither PUB key nor PRIV key"); - } - } - if (!EVP_PKEY_assign_RSA(pkey, rsa)) { - RSA_free(rsa); - ossl_raise(eRSAError, "EVP_PKEY_assign_RSA"); + + pass = ossl_pem_passwd_value(pass); + arg = ossl_to_der_if_possible(arg); + in = ossl_obj2bio(&arg); + + /* First try RSAPublicKey format */ + rsa = d2i_RSAPublicKey_bio(in, NULL); + if (rsa) + goto legacy; + OSSL_BIO_reset(in); + rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL); + if (rsa) + goto legacy; + OSSL_BIO_reset(in); + + /* Use the generic routine */ + pkey = ossl_pkey_read_generic(in, pass); + BIO_free(in); + if (!pkey) + ossl_raise(eRSAError, "Neither PUB key nor PRIV key"); + + type = EVP_PKEY_base_id(pkey); + if (type != EVP_PKEY_RSA) { + EVP_PKEY_free(pkey); + rb_raise(eRSAError, "incorrect pkey type: %s", OBJ_nid2sn(type)); } + RTYPEDDATA_DATA(self) = pkey; + return self; + legacy: + BIO_free(in); + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_RSA(pkey, rsa) != 1) { + EVP_PKEY_free(pkey); + RSA_free(rsa); + ossl_raise(eRSAError, "EVP_PKEY_assign_RSA"); + } + RTYPEDDATA_DATA(self) = pkey; return self; } +#ifndef HAVE_EVP_PKEY_DUP static VALUE ossl_rsa_initialize_copy(VALUE self, VALUE other) { EVP_PKEY *pkey; RSA *rsa, *rsa_new; - GetPKey(self, pkey); - if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE) - ossl_raise(eRSAError, "RSA already initialized"); + TypedData_Get_Struct(self, EVP_PKEY, &ossl_evp_pkey_type, pkey); + if (pkey) + rb_raise(rb_eTypeError, "pkey already initialized"); GetRSA(other, rsa); - rsa_new = ASN1_dup((i2d_of_void *)i2d_RSAPrivateKey, (d2i_of_void *)d2i_RSAPrivateKey, (char *)rsa); + rsa_new = (RSA *)ASN1_dup((i2d_of_void *)i2d_RSAPrivateKey, + (d2i_of_void *)d2i_RSAPrivateKey, + (char *)rsa); if (!rsa_new) ossl_raise(eRSAError, "ASN1_dup"); - EVP_PKEY_assign_RSA(pkey, rsa_new); + pkey = EVP_PKEY_new(); + if (!pkey || EVP_PKEY_assign_RSA(pkey, rsa_new) != 1) { + RSA_free(rsa_new); + ossl_raise(eRSAError, "EVP_PKEY_assign_RSA"); + } + RTYPEDDATA_DATA(self) = pkey; return self; } +#endif /* * call-seq: @@ -517,7 +537,9 @@ Init_ossl_rsa(void) cRSA = rb_define_class_under(mPKey, "RSA", cPKey); rb_define_method(cRSA, "initialize", ossl_rsa_initialize, -1); +#ifndef HAVE_EVP_PKEY_DUP rb_define_method(cRSA, "initialize_copy", ossl_rsa_initialize_copy, 1); +#endif rb_define_method(cRSA, "public?", ossl_rsa_is_public, 0); rb_define_method(cRSA, "private?", ossl_rsa_is_private, 0); diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index 3b425ca759..9a0682a7cd 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -2825,9 +2825,24 @@ Init_ossl_ssl(void) rb_define_const(mSSL, "VERIFY_CLIENT_ONCE", INT2NUM(SSL_VERIFY_CLIENT_ONCE)); rb_define_const(mSSL, "OP_ALL", ULONG2NUM(SSL_OP_ALL)); +#ifdef SSL_OP_CLEANSE_PLAINTEXT /* OpenSSL 3.0 */ + rb_define_const(mSSL, "OP_CLEANSE_PLAINTEXT", ULONG2NUM(SSL_OP_CLEANSE_PLAINTEXT)); +#endif rb_define_const(mSSL, "OP_LEGACY_SERVER_CONNECT", ULONG2NUM(SSL_OP_LEGACY_SERVER_CONNECT)); +#ifdef SSL_OP_ENABLE_KTLS /* OpenSSL 3.0 */ + rb_define_const(mSSL, "OP_ENABLE_KTLS", ULONG2NUM(SSL_OP_ENABLE_KTLS)); +#endif rb_define_const(mSSL, "OP_TLSEXT_PADDING", ULONG2NUM(SSL_OP_TLSEXT_PADDING)); rb_define_const(mSSL, "OP_SAFARI_ECDHE_ECDSA_BUG", ULONG2NUM(SSL_OP_SAFARI_ECDHE_ECDSA_BUG)); +#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF /* OpenSSL 3.0 */ + rb_define_const(mSSL, "OP_IGNORE_UNEXPECTED_EOF", ULONG2NUM(SSL_OP_IGNORE_UNEXPECTED_EOF)); +#endif +#ifdef SSL_OP_ALLOW_CLIENT_RENEGOTIATION /* OpenSSL 3.0 */ + rb_define_const(mSSL, "OP_ALLOW_CLIENT_RENEGOTIATION", ULONG2NUM(SSL_OP_ALLOW_CLIENT_RENEGOTIATION)); +#endif +#ifdef SSL_OP_DISABLE_TLSEXT_CA_NAMES /* OpenSSL 3.0 */ + rb_define_const(mSSL, "OP_DISABLE_TLSEXT_CA_NAMES", ULONG2NUM(SSL_OP_DISABLE_TLSEXT_CA_NAMES)); +#endif #ifdef SSL_OP_ALLOW_NO_DHE_KEX /* OpenSSL 1.1.1 */ rb_define_const(mSSL, "OP_ALLOW_NO_DHE_KEX", ULONG2NUM(SSL_OP_ALLOW_NO_DHE_KEX)); #endif @@ -2839,13 +2854,15 @@ Init_ossl_ssl(void) #ifdef SSL_OP_NO_ENCRYPT_THEN_MAC /* OpenSSL 1.1.1 */ rb_define_const(mSSL, "OP_NO_ENCRYPT_THEN_MAC", ULONG2NUM(SSL_OP_NO_ENCRYPT_THEN_MAC)); #endif - rb_define_const(mSSL, "OP_CIPHER_SERVER_PREFERENCE", ULONG2NUM(SSL_OP_CIPHER_SERVER_PREFERENCE)); - rb_define_const(mSSL, "OP_TLS_ROLLBACK_BUG", ULONG2NUM(SSL_OP_TLS_ROLLBACK_BUG)); -#ifdef SSL_OP_NO_RENEGOTIATION /* OpenSSL 1.1.1 */ - rb_define_const(mSSL, "OP_NO_RENEGOTIATION", ULONG2NUM(SSL_OP_NO_RENEGOTIATION)); +#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT /* OpenSSL 1.1.1 */ + rb_define_const(mSSL, "OP_ENABLE_MIDDLEBOX_COMPAT", ULONG2NUM(SSL_OP_ENABLE_MIDDLEBOX_COMPAT)); +#endif +#ifdef SSL_OP_PRIORITIZE_CHACHA /* OpenSSL 1.1.1 */ + rb_define_const(mSSL, "OP_PRIORITIZE_CHACHA", ULONG2NUM(SSL_OP_PRIORITIZE_CHACHA)); +#endif +#ifdef SSL_OP_NO_ANTI_REPLAY /* OpenSSL 1.1.1 */ + rb_define_const(mSSL, "OP_NO_ANTI_REPLAY", ULONG2NUM(SSL_OP_NO_ANTI_REPLAY)); #endif - rb_define_const(mSSL, "OP_CRYPTOPRO_TLSEXT_BUG", ULONG2NUM(SSL_OP_CRYPTOPRO_TLSEXT_BUG)); - rb_define_const(mSSL, "OP_NO_SSLv3", ULONG2NUM(SSL_OP_NO_SSLv3)); rb_define_const(mSSL, "OP_NO_TLSv1", ULONG2NUM(SSL_OP_NO_TLSv1)); rb_define_const(mSSL, "OP_NO_TLSv1_1", ULONG2NUM(SSL_OP_NO_TLSv1_1)); @@ -2853,6 +2870,12 @@ Init_ossl_ssl(void) #ifdef SSL_OP_NO_TLSv1_3 /* OpenSSL 1.1.1 */ rb_define_const(mSSL, "OP_NO_TLSv1_3", ULONG2NUM(SSL_OP_NO_TLSv1_3)); #endif + rb_define_const(mSSL, "OP_CIPHER_SERVER_PREFERENCE", ULONG2NUM(SSL_OP_CIPHER_SERVER_PREFERENCE)); + rb_define_const(mSSL, "OP_TLS_ROLLBACK_BUG", ULONG2NUM(SSL_OP_TLS_ROLLBACK_BUG)); +#ifdef SSL_OP_NO_RENEGOTIATION /* OpenSSL 1.1.1 */ + rb_define_const(mSSL, "OP_NO_RENEGOTIATION", ULONG2NUM(SSL_OP_NO_RENEGOTIATION)); +#endif + rb_define_const(mSSL, "OP_CRYPTOPRO_TLSEXT_BUG", ULONG2NUM(SSL_OP_CRYPTOPRO_TLSEXT_BUG)); /* SSL_OP_* flags for DTLS */ #if 0 diff --git a/ext/pathname/depend b/ext/pathname/depend index 53041d2ef8..a6b000e305 100644 --- a/ext/pathname/depend +++ b/ext/pathname/depend @@ -15,6 +15,7 @@ pathname.o: $(hdrdir)/ruby/backward/2/stdarg.h pathname.o: $(hdrdir)/ruby/defines.h pathname.o: $(hdrdir)/ruby/encoding.h pathname.o: $(hdrdir)/ruby/intern.h +pathname.o: $(hdrdir)/ruby/internal/abi.h pathname.o: $(hdrdir)/ruby/internal/anyargs.h pathname.o: $(hdrdir)/ruby/internal/arithmetic.h pathname.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 3799d589d5..41e5c171a7 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -588,11 +588,12 @@ class Pathname # * FileUtils * # Recursively deletes a directory, including all directories beneath it. # - # See FileUtils.rm_r - def rmtree + # See FileUtils.rm_rf + def rmtree(noop: nil, verbose: nil, secure: nil) # The name "rmtree" is borrowed from File::Path of Perl. # File::Path provides "mkpath" and "rmtree". - FileUtils.rm_r(@path) + require 'fileutils' + FileUtils.rm_rf(@path, noop: noop, verbose: verbose, secure: secure) nil end end diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 1d4ed2814b..e2c3c36dbf 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -35,6 +35,7 @@ static ID id_lchmod; static ID id_lchown; static ID id_link; static ID id_lstat; +static ID id_lutime; static ID id_mkdir; static ID id_mtime; static ID id_open; @@ -765,6 +766,19 @@ path_utime(VALUE self, VALUE atime, VALUE mtime) } /* + * Update the access and modification times of the file. + * + * Same as Pathname#utime, but does not follow symbolic links. + * + * See File.lutime. + */ +static VALUE +path_lutime(VALUE self, VALUE atime, VALUE mtime) +{ + return rb_funcall(rb_cFile, id_lutime, 3, atime, mtime, get_strpath(self)); +} + +/* * Returns the last component of the path. * * See File.basename. @@ -1274,6 +1288,7 @@ static VALUE path_each_entry(VALUE self) { VALUE args[1]; + RETURN_ENUMERATOR(self, 0, 0); args[0] = get_strpath(self); return rb_block_call(rb_cDir, id_foreach, 1, args, each_entry_i, rb_obj_class(self)); @@ -1464,6 +1479,7 @@ path_f_pathname(VALUE self, VALUE str) * - #make_symlink(old) * - #truncate(length) * - #utime(atime, mtime) + * - #lutime(atime, mtime) * - #basename(*args) * - #dirname * - #extname @@ -1562,6 +1578,7 @@ Init_pathname(void) rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1); rb_define_method(rb_cPathname, "truncate", path_truncate, 1); rb_define_method(rb_cPathname, "utime", path_utime, 2); + rb_define_method(rb_cPathname, "lutime", path_lutime, 2); rb_define_method(rb_cPathname, "basename", path_basename, -1); rb_define_method(rb_cPathname, "dirname", path_dirname, 0); rb_define_method(rb_cPathname, "extname", path_extname, 0); @@ -1645,6 +1662,7 @@ InitVM_pathname(void) id_lchown = rb_intern("lchown"); id_link = rb_intern("link"); id_lstat = rb_intern("lstat"); + id_lutime = rb_intern("lutime"); id_mkdir = rb_intern("mkdir"); id_mtime = rb_intern("mtime"); id_open = rb_intern("open"); diff --git a/ext/pathname/pathname.gemspec b/ext/pathname/pathname.gemspec index 5aaa8f8dd7..c9c0b84e69 100644 --- a/ext/pathname/pathname.gemspec +++ b/ext/pathname/pathname.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |spec| spec.summary = %q{Representation of the name of a file or directory on the filesystem} spec.description = %q{Representation of the name of a file or directory on the filesystem} spec.homepage = "https://github.com/ruby/pathname" - spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0") spec.licenses = ["Ruby", "BSD-2-Clause"] spec.metadata["homepage_uri"] = spec.homepage diff --git a/ext/psych/.gitignore b/ext/psych/.gitignore new file mode 100644 index 0000000000..92946455b0 --- /dev/null +++ b/ext/psych/.gitignore @@ -0,0 +1 @@ +/yaml-[0-9]*.*.* diff --git a/ext/psych/depend b/ext/psych/depend index 4448663531..78bde9a53d 100644 --- a/ext/psych/depend +++ b/ext/psych/depend @@ -1,4 +1,16 @@ -$(OBJS): $(YAML_H) +$(TARGET_SO): $(LIBYAML) + +libyaml $(LIBYAML): + cd libyaml && $(MAKE) + $(AR) $(ARFLAGS) $(LIBYAML) $(LIBYAML_OBJDIR)/*.$(OBJEXT) + $(RANLIB) $(LIBYAML) + +clean-so:: + -cd libyaml && $(MAKE) clean + +distclean-so:: + -cd libyaml && $(MAKE) distclean + -$(Q)$(RMDIRS) libyaml/* libyaml # AUTOGENERATED DEPENDENCIES START psych.o: $(RUBY_EXTCONF_H) @@ -17,6 +29,7 @@ psych.o: $(hdrdir)/ruby/backward/2/stdarg.h psych.o: $(hdrdir)/ruby/defines.h psych.o: $(hdrdir)/ruby/encoding.h psych.o: $(hdrdir)/ruby/intern.h +psych.o: $(hdrdir)/ruby/internal/abi.h psych.o: $(hdrdir)/ruby/internal/anyargs.h psych.o: $(hdrdir)/ruby/internal/arithmetic.h psych.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -193,6 +206,7 @@ psych_emitter.o: $(hdrdir)/ruby/backward/2/stdarg.h psych_emitter.o: $(hdrdir)/ruby/defines.h psych_emitter.o: $(hdrdir)/ruby/encoding.h psych_emitter.o: $(hdrdir)/ruby/intern.h +psych_emitter.o: $(hdrdir)/ruby/internal/abi.h psych_emitter.o: $(hdrdir)/ruby/internal/anyargs.h psych_emitter.o: $(hdrdir)/ruby/internal/arithmetic.h psych_emitter.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -369,6 +383,7 @@ psych_parser.o: $(hdrdir)/ruby/backward/2/stdarg.h psych_parser.o: $(hdrdir)/ruby/defines.h psych_parser.o: $(hdrdir)/ruby/encoding.h psych_parser.o: $(hdrdir)/ruby/intern.h +psych_parser.o: $(hdrdir)/ruby/internal/abi.h psych_parser.o: $(hdrdir)/ruby/internal/anyargs.h psych_parser.o: $(hdrdir)/ruby/internal/arithmetic.h psych_parser.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -545,6 +560,7 @@ psych_to_ruby.o: $(hdrdir)/ruby/backward/2/stdarg.h psych_to_ruby.o: $(hdrdir)/ruby/defines.h psych_to_ruby.o: $(hdrdir)/ruby/encoding.h psych_to_ruby.o: $(hdrdir)/ruby/intern.h +psych_to_ruby.o: $(hdrdir)/ruby/internal/abi.h psych_to_ruby.o: $(hdrdir)/ruby/internal/anyargs.h psych_to_ruby.o: $(hdrdir)/ruby/internal/arithmetic.h psych_to_ruby.o: $(hdrdir)/ruby/internal/arithmetic/char.h @@ -721,6 +737,7 @@ psych_yaml_tree.o: $(hdrdir)/ruby/backward/2/stdarg.h psych_yaml_tree.o: $(hdrdir)/ruby/defines.h psych_yaml_tree.o: $(hdrdir)/ruby/encoding.h psych_yaml_tree.o: $(hdrdir)/ruby/intern.h +psych_yaml_tree.o: $(hdrdir)/ruby/internal/abi.h psych_yaml_tree.o: $(hdrdir)/ruby/internal/anyargs.h psych_yaml_tree.o: $(hdrdir)/ruby/internal/arithmetic.h psych_yaml_tree.o: $(hdrdir)/ruby/internal/arithmetic/char.h diff --git a/ext/psych/extconf.rb b/ext/psych/extconf.rb index 857f8e68c4..b9cd12033d 100644 --- a/ext/psych/extconf.rb +++ b/ext/psych/extconf.rb @@ -1,43 +1,76 @@ # -*- coding: us-ascii -*- # frozen_string_literal: true require 'mkmf' -require 'fileutils' -# :stopdoc: - -dir_config 'libyaml' - -if enable_config("bundled-libyaml", false) || !(find_header('yaml.h') && find_library('yaml', 'yaml_get_version')) - # Embed libyaml since we could not find it. - - $VPATH << "$(srcdir)/yaml" - $INCFLAGS << " -I$(srcdir)/yaml" - - $srcs = Dir.glob("#{$srcdir}/{,yaml/}*.c").map {|n| File.basename(n)}.sort +if $mswin or $mingw or $cygwin + $CPPFLAGS << " -DYAML_DECLARE_STATIC" +end - header = 'yaml/yaml.h' - header = "{$(VPATH)}#{header}" if $nmake - if have_macro("_WIN32") - $CPPFLAGS << " -DYAML_DECLARE_STATIC -DHAVE_CONFIG_H" +yaml_source = with_config("libyaml-source-dir") || enable_config("bundled-libyaml", false) +unless yaml_source # default to pre-installed libyaml + pkg_config('yaml-0.1') + dir_config('libyaml') + unless find_header('yaml.h') && find_library('yaml', 'yaml_get_version') + yaml_source = true # fallback to the bundled source if exists end +end - have_header 'dlfcn.h' - have_header 'inttypes.h' - have_header 'memory.h' - have_header 'stdint.h' - have_header 'stdlib.h' - have_header 'strings.h' - have_header 'string.h' - have_header 'sys/stat.h' - have_header 'sys/types.h' - have_header 'unistd.h' +if yaml_source == true + # search the latest libyaml source under $srcdir + yaml_source = Dir.glob("#{$srcdir}/yaml{,-*}/").max_by {|n| File.basename(n).scan(/\d+/).map(&:to_i)} + unless yaml_source + download_failure = "failed to download libyaml source" + begin + require_relative '../../tool/extlibs.rb' + extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir)) + unless extlibs.process_under($srcdir) + raise download_failure + end + rescue + # Implicitly captures Exception#cause. Newer rubies show it in the backtrace. + raise download_failure + end + yaml_source, = Dir.glob("#{$srcdir}/yaml-*/") + raise "libyaml not found" unless yaml_source + end +elsif yaml_source + yaml_source = yaml_source.gsub(/\$\((\w+)\)|\$\{(\w+)\}/) {ENV[$1||$2]} +end +if yaml_source + yaml_source = yaml_source.chomp("/") + yaml_configure = "#{File.expand_path(yaml_source)}/configure" + unless File.exist?(yaml_configure) + raise "Configure script not found in #{yaml_source.quote}" + end - find_header 'yaml.h' - have_header 'config.h' + puts("Configuring libyaml source in #{yaml_source.quote}") + yaml = "libyaml" + Dir.mkdir(yaml) unless File.directory?(yaml) + shared = $enable_shared || !$static + args = [ + yaml_configure, + "--enable-#{shared ? 'shared' : 'static'}", + "--host=#{RbConfig::CONFIG['host'].sub(/-unknown-/, '-')}", + "CC=#{RbConfig::CONFIG['CC']}", + *(["CFLAGS=-w"] if RbConfig::CONFIG["GCC"] == "yes"), + ] + puts(args.quote.join(' ')) + unless system(*args, chdir: yaml) + raise "failed to configure libyaml" + end + inc = yaml_source.start_with?("#$srcdir/") ? "$(srcdir)#{yaml_source[$srcdir.size..-1]}" : yaml_source + $INCFLAGS << " -I#{yaml}/include -I#{inc}/include" + puts("INCFLAGS=#$INCFLAGS") + libyaml = "libyaml.#$LIBEXT" + $cleanfiles << libyaml + $LOCAL_LIBS.prepend("$(LIBYAML) ") end create_makefile 'psych' do |mk| - mk << "YAML_H = #{header}".strip << "\n" + mk << "LIBYAML = #{libyaml}".strip << "\n" + mk << "LIBYAML_OBJDIR = libyaml/src#{shared ? '/.libs' : ''}\n" + mk << "OBJEXT = #$OBJEXT" + mk << "RANLIB = #{config_string('RANLIB') || config_string('NULLCMD')}\n" end # :startdoc: diff --git a/ext/psych/extlibs b/ext/psych/extlibs new file mode 100644 index 0000000000..108aad42af --- /dev/null +++ b/ext/psych/extlibs @@ -0,0 +1,11 @@ +ver = 0.2.5 +pkg = yaml-$(ver) + +https://github.com/yaml/libyaml/releases/download/$(ver)/$(pkg).tar.gz \ + rmd160:cc175ed640046722fb7790de828002633407b6b9 \ + sha256:c642ae9b75fee120b2d96c712538bd2cf283228d2337df2cf2988e3c02678ef4 \ + sha512:dadd7d8e0d88b5ebab005e5d521d56d541580198aa497370966b98c904586e642a1cd4f3881094eb57624f218d50db77417bbfd0ffdce50340f011e35e8c4c02 \ + # + +$(pkg)/config/config.guess -> /tool/config.guess +$(pkg)/config/config.sub -> /tool/config.sub diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index 383078788f..42d79efb83 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -268,12 +268,11 @@ module Psych # YAML documents that are supplied via user input. Instead, please use the # load method or the safe_load method. # - def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false + def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false, strict_integer: false result = parse(yaml, filename: filename) return fallback unless result - result.to_ruby(symbolize_names: symbolize_names, freeze: freeze) + result.to_ruby(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer) end - class << self; alias :load :unsafe_load; end ### # Safely load the yaml string in +yaml+. By default, only the following @@ -320,13 +319,13 @@ module Psych # Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"} # Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"} # - def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false + def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false, strict_integer: false result = parse(yaml, filename: filename) return fallback unless result class_loader = ClassLoader::Restricted.new(permitted_classes.map(&:to_s), permitted_symbols.map(&:to_s)) - scanner = ScalarScanner.new class_loader + scanner = ScalarScanner.new class_loader, strict_integer: strict_integer visitor = if aliases Visitors::ToRuby.new scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze else @@ -366,14 +365,15 @@ module Psych # Raises a TypeError when `yaml` parameter is NilClass. This method is # similar to `safe_load` except that `Symbol` objects are allowed by default. # - def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false + def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false, strict_integer: false safe_load yaml, permitted_classes: permitted_classes, permitted_symbols: permitted_symbols, aliases: aliases, filename: filename, fallback: fallback, symbolize_names: symbolize_names, - freeze: freeze + freeze: freeze, + strict_integer: strict_integer end ### diff --git a/ext/psych/lib/psych/nodes/node.rb b/ext/psych/lib/psych/nodes/node.rb index 1f841625ca..f44fce5f05 100644 --- a/ext/psych/lib/psych/nodes/node.rb +++ b/ext/psych/lib/psych/nodes/node.rb @@ -46,8 +46,8 @@ module Psych # Convert this node to Ruby. # # See also Psych::Visitors::ToRuby - def to_ruby(symbolize_names: false, freeze: false) - Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze).accept(self) + def to_ruby(symbolize_names: false, freeze: false, strict_integer: false) + Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer).accept(self) end alias :transform :to_ruby diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb index b66ff9938c..b50667c315 100644 --- a/ext/psych/lib/psych/scalar_scanner.rb +++ b/ext/psych/lib/psych/scalar_scanner.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require 'strscan' module Psych ### @@ -13,24 +12,32 @@ module Psych FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x # Taken from http://yaml.org/type/int.html - INTEGER = /^(?:[-+]?0b[0-1_,]+ (?# base 2) - |[-+]?0[0-7_,]+ (?# base 8) - |[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10) - |[-+]?0x[0-9a-fA-F_,]+ (?# base 16))$/x + INTEGER_STRICT = /^(?:[-+]?0b[0-1_]+ (?# base 2) + |[-+]?0[0-7_]+ (?# base 8) + |[-+]?(0|[1-9][0-9_]*) (?# base 10) + |[-+]?0x[0-9a-fA-F_]+ (?# base 16))$/x + + # Same as above, but allows commas. + # Not to YML spec, but kept for backwards compatibility + INTEGER_LEGACY = /^(?:[-+]?0b[0-1_,]+ (?# base 2) + |[-+]?0[0-7_,]+ (?# base 8) + |[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10) + |[-+]?0x[0-9a-fA-F_,]+ (?# base 16))$/x attr_reader :class_loader # Create a new scanner - def initialize class_loader + def initialize class_loader, strict_integer: false @symbol_cache = {} @class_loader = class_loader + @strict_integer = strict_integer end # Tokenize +string+ returning the Ruby object def tokenize string return nil if string.empty? return @symbol_cache[string] if @symbol_cache.key?(string) - + integer_regex = @strict_integer ? INTEGER_STRICT : INTEGER_LEGACY # Check for a String type, being careful not to get caught by hash keys, hex values, and # special floats (e.g., -.inf). if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/) @@ -88,9 +95,9 @@ module Psych if string.match?(/\A[-+]?\.\Z/) string else - Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1')) + Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1')) end - elsif string.match?(INTEGER) + elsif string.match?(integer_regex) parse_int string else string @@ -100,7 +107,7 @@ module Psych ### # Parse and return an int from +string+ def parse_int string - Integer(string.gsub(/[,_]/, '')) + Integer(string.delete(',_')) end ### diff --git a/ext/psych/lib/psych/versions.rb b/ext/psych/lib/psych/versions.rb index 0519d9c8ab..0fdead154c 100644 --- a/ext/psych/lib/psych/versions.rb +++ b/ext/psych/lib/psych/versions.rb @@ -2,7 +2,7 @@ module Psych # The version of Psych you are using - VERSION = '4.0.2' + VERSION = '5.0.0.dev' if RUBY_ENGINE == 'jruby' DEFAULT_SNAKEYAML_VERSION = '1.28'.freeze diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 4c1f561070..935bc74f21 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -12,9 +12,9 @@ module Psych ### # This class walks a YAML AST, converting each node to Ruby class ToRuby < Psych::Visitors::Visitor - def self.create(symbolize_names: false, freeze: false) + def self.create(symbolize_names: false, freeze: false, strict_integer: false) class_loader = ClassLoader.new - scanner = ScalarScanner.new class_loader + scanner = ScalarScanner.new class_loader, strict_integer: strict_integer new(scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze) end diff --git a/ext/psych/psych.gemspec b/ext/psych/psych.gemspec index 291d8345b4..5f5168ddb0 100644 --- a/ext/psych/psych.gemspec +++ b/ext/psych/psych.gemspec @@ -27,9 +27,6 @@ DESCRIPTION "bin/setup", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h", "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h", "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h", - "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c", - "ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c", - "ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h", "lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/exception.rb", "lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb", "lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb", @@ -63,7 +60,7 @@ DESCRIPTION s.add_dependency 'jar-dependencies', '>= 0.1.7' else s.extensions = ["ext/psych/extconf.rb"] + s.add_dependency 'stringio' end - s.add_dependency 'stringio' end diff --git a/ext/psych/yaml/api.c b/ext/psych/yaml/api.c deleted file mode 100644 index 6add8b2661..0000000000 --- a/ext/psych/yaml/api.c +++ /dev/null @@ -1,1393 +0,0 @@ - -#include "yaml_private.h" - -/* - * Get the library version. - */ - -YAML_DECLARE(const char *) -yaml_get_version_string(void) -{ - return YAML_VERSION_STRING; -} - -/* - * Get the library version numbers. - */ - -YAML_DECLARE(void) -yaml_get_version(int *major, int *minor, int *patch) -{ - *major = YAML_VERSION_MAJOR; - *minor = YAML_VERSION_MINOR; - *patch = YAML_VERSION_PATCH; -} - -/* - * Allocate a dynamic memory block. - */ - -YAML_DECLARE(void *) -yaml_malloc(size_t size) -{ - return malloc(size ? size : 1); -} - -/* - * Reallocate a dynamic memory block. - */ - -YAML_DECLARE(void *) -yaml_realloc(void *ptr, size_t size) -{ - return ptr ? realloc(ptr, size ? size : 1) : malloc(size ? size : 1); -} - -/* - * Free a dynamic memory block. - */ - -YAML_DECLARE(void) -yaml_free(void *ptr) -{ - if (ptr) free(ptr); -} - -/* - * Duplicate a string. - */ - -YAML_DECLARE(yaml_char_t *) -yaml_strdup(const yaml_char_t *str) -{ - if (!str) - return NULL; - - return (yaml_char_t *)strdup((char *)str); -} - -/* - * Extend a string. - */ - -YAML_DECLARE(int) -yaml_string_extend(yaml_char_t **start, - yaml_char_t **pointer, yaml_char_t **end) -{ - yaml_char_t *new_start = (yaml_char_t *)yaml_realloc((void*)*start, (*end - *start)*2); - - if (!new_start) return 0; - - memset(new_start + (*end - *start), 0, *end - *start); - - *pointer = new_start + (*pointer - *start); - *end = new_start + (*end - *start)*2; - *start = new_start; - - return 1; -} - -/* - * Append a string B to a string A. - */ - -YAML_DECLARE(int) -yaml_string_join( - yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end, - yaml_char_t **b_start, yaml_char_t **b_pointer, SHIM(yaml_char_t **b_end)) -{ - UNUSED_PARAM(b_end) - if (*b_start == *b_pointer) - return 1; - - while (*a_end - *a_pointer <= *b_pointer - *b_start) { - if (!yaml_string_extend(a_start, a_pointer, a_end)) - return 0; - } - - memcpy(*a_pointer, *b_start, *b_pointer - *b_start); - *a_pointer += *b_pointer - *b_start; - - return 1; -} - -/* - * Extend a stack. - */ - -YAML_DECLARE(int) -yaml_stack_extend(void **start, void **top, void **end) -{ - void *new_start; - - if ((char *)*end - (char *)*start >= INT_MAX / 2) - return 0; - - new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); - - if (!new_start) return 0; - - *top = (char *)new_start + ((char *)*top - (char *)*start); - *end = (char *)new_start + ((char *)*end - (char *)*start)*2; - *start = new_start; - - return 1; -} - -/* - * Extend or move a queue. - */ - -YAML_DECLARE(int) -yaml_queue_extend(void **start, void **head, void **tail, void **end) -{ - /* Check if we need to resize the queue. */ - - if (*start == *head && *tail == *end) { - void *new_start = yaml_realloc(*start, - ((char *)*end - (char *)*start)*2); - - if (!new_start) return 0; - - *head = (char *)new_start + ((char *)*head - (char *)*start); - *tail = (char *)new_start + ((char *)*tail - (char *)*start); - *end = (char *)new_start + ((char *)*end - (char *)*start)*2; - *start = new_start; - } - - /* Check if we need to move the queue at the beginning of the buffer. */ - - if (*tail == *end) { - if (*head != *tail) { - memmove(*start, *head, (char *)*tail - (char *)*head); - } - *tail = (char *)*tail - (char *)*head + (char *)*start; - *head = *start; - } - - return 1; -} - - -/* - * Create a new parser object. - */ - -YAML_DECLARE(int) -yaml_parser_initialize(yaml_parser_t *parser) -{ - assert(parser); /* Non-NULL parser object expected. */ - - memset(parser, 0, sizeof(yaml_parser_t)); - if (!BUFFER_INIT(parser, parser->raw_buffer, INPUT_RAW_BUFFER_SIZE)) - goto error; - if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) - goto error; - if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*)) - goto error; - if (!STACK_INIT(parser, parser->indents, int*)) - goto error; - if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*)) - goto error; - if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*)) - goto error; - if (!STACK_INIT(parser, parser->marks, yaml_mark_t*)) - goto error; - if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*)) - goto error; - - return 1; - -error: - - BUFFER_DEL(parser, parser->raw_buffer); - BUFFER_DEL(parser, parser->buffer); - QUEUE_DEL(parser, parser->tokens); - STACK_DEL(parser, parser->indents); - STACK_DEL(parser, parser->simple_keys); - STACK_DEL(parser, parser->states); - STACK_DEL(parser, parser->marks); - STACK_DEL(parser, parser->tag_directives); - - return 0; -} - -/* - * Destroy a parser object. - */ - -YAML_DECLARE(void) -yaml_parser_delete(yaml_parser_t *parser) -{ - assert(parser); /* Non-NULL parser object expected. */ - - BUFFER_DEL(parser, parser->raw_buffer); - BUFFER_DEL(parser, parser->buffer); - while (!QUEUE_EMPTY(parser, parser->tokens)) { - yaml_token_delete(&DEQUEUE(parser, parser->tokens)); - } - QUEUE_DEL(parser, parser->tokens); - STACK_DEL(parser, parser->indents); - STACK_DEL(parser, parser->simple_keys); - STACK_DEL(parser, parser->states); - STACK_DEL(parser, parser->marks); - while (!STACK_EMPTY(parser, parser->tag_directives)) { - yaml_tag_directive_t tag_directive = POP(parser, parser->tag_directives); - yaml_free(tag_directive.handle); - yaml_free(tag_directive.prefix); - } - STACK_DEL(parser, parser->tag_directives); - - memset(parser, 0, sizeof(yaml_parser_t)); -} - -/* - * String read handler. - */ - -static int -yaml_string_read_handler(void *data, unsigned char *buffer, size_t size, - size_t *size_read) -{ - yaml_parser_t *parser = (yaml_parser_t *)data; - - if (parser->input.string.current == parser->input.string.end) { - *size_read = 0; - return 1; - } - - if (size > (size_t)(parser->input.string.end - - parser->input.string.current)) { - size = parser->input.string.end - parser->input.string.current; - } - - memcpy(buffer, parser->input.string.current, size); - parser->input.string.current += size; - *size_read = size; - return 1; -} - -/* - * File read handler. - */ - -static int -yaml_file_read_handler(void *data, unsigned char *buffer, size_t size, - size_t *size_read) -{ - yaml_parser_t *parser = (yaml_parser_t *)data; - - *size_read = fread(buffer, 1, size, parser->input.file); - return !ferror(parser->input.file); -} - -/* - * Set a string input. - */ - -YAML_DECLARE(void) -yaml_parser_set_input_string(yaml_parser_t *parser, - const unsigned char *input, size_t size) -{ - assert(parser); /* Non-NULL parser object expected. */ - assert(!parser->read_handler); /* You can set the source only once. */ - assert(input); /* Non-NULL input string expected. */ - - parser->read_handler = yaml_string_read_handler; - parser->read_handler_data = parser; - - parser->input.string.start = input; - parser->input.string.current = input; - parser->input.string.end = input+size; -} - -/* - * Set a file input. - */ - -YAML_DECLARE(void) -yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file) -{ - assert(parser); /* Non-NULL parser object expected. */ - assert(!parser->read_handler); /* You can set the source only once. */ - assert(file); /* Non-NULL file object expected. */ - - parser->read_handler = yaml_file_read_handler; - parser->read_handler_data = parser; - - parser->input.file = file; -} - -/* - * Set a generic input. - */ - -YAML_DECLARE(void) -yaml_parser_set_input(yaml_parser_t *parser, - yaml_read_handler_t *handler, void *data) -{ - assert(parser); /* Non-NULL parser object expected. */ - assert(!parser->read_handler); /* You can set the source only once. */ - assert(handler); /* Non-NULL read handler expected. */ - - parser->read_handler = handler; - parser->read_handler_data = data; -} - -/* - * Set the source encoding. - */ - -YAML_DECLARE(void) -yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding) -{ - assert(parser); /* Non-NULL parser object expected. */ - assert(!parser->encoding); /* Encoding is already set or detected. */ - - parser->encoding = encoding; -} - -/* - * Create a new emitter object. - */ - -YAML_DECLARE(int) -yaml_emitter_initialize(yaml_emitter_t *emitter) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - memset(emitter, 0, sizeof(yaml_emitter_t)); - if (!BUFFER_INIT(emitter, emitter->buffer, OUTPUT_BUFFER_SIZE)) - goto error; - if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) - goto error; - if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*)) - goto error; - if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*)) - goto error; - if (!STACK_INIT(emitter, emitter->indents, int*)) - goto error; - if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*)) - goto error; - - return 1; - -error: - - BUFFER_DEL(emitter, emitter->buffer); - BUFFER_DEL(emitter, emitter->raw_buffer); - STACK_DEL(emitter, emitter->states); - QUEUE_DEL(emitter, emitter->events); - STACK_DEL(emitter, emitter->indents); - STACK_DEL(emitter, emitter->tag_directives); - - return 0; -} - -/* - * Destroy an emitter object. - */ - -YAML_DECLARE(void) -yaml_emitter_delete(yaml_emitter_t *emitter) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - BUFFER_DEL(emitter, emitter->buffer); - BUFFER_DEL(emitter, emitter->raw_buffer); - STACK_DEL(emitter, emitter->states); - while (!QUEUE_EMPTY(emitter, emitter->events)) { - yaml_event_delete(&DEQUEUE(emitter, emitter->events)); - } - QUEUE_DEL(emitter, emitter->events); - STACK_DEL(emitter, emitter->indents); - while (!STACK_EMPTY(empty, emitter->tag_directives)) { - yaml_tag_directive_t tag_directive = POP(emitter, emitter->tag_directives); - yaml_free(tag_directive.handle); - yaml_free(tag_directive.prefix); - } - STACK_DEL(emitter, emitter->tag_directives); - yaml_free(emitter->anchors); - - memset(emitter, 0, sizeof(yaml_emitter_t)); -} - -/* - * String write handler. - */ - -static int -yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) -{ - yaml_emitter_t *emitter = (yaml_emitter_t *)data; - - if (emitter->output.string.size - *emitter->output.string.size_written - < size) { - memcpy(emitter->output.string.buffer - + *emitter->output.string.size_written, - buffer, - emitter->output.string.size - - *emitter->output.string.size_written); - *emitter->output.string.size_written = emitter->output.string.size; - return 0; - } - - memcpy(emitter->output.string.buffer - + *emitter->output.string.size_written, buffer, size); - *emitter->output.string.size_written += size; - return 1; -} - -/* - * File write handler. - */ - -static int -yaml_file_write_handler(void *data, unsigned char *buffer, size_t size) -{ - yaml_emitter_t *emitter = (yaml_emitter_t *)data; - - return (fwrite(buffer, 1, size, emitter->output.file) == size); -} -/* - * Set a string output. - */ - -YAML_DECLARE(void) -yaml_emitter_set_output_string(yaml_emitter_t *emitter, - unsigned char *output, size_t size, size_t *size_written) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - assert(!emitter->write_handler); /* You can set the output only once. */ - assert(output); /* Non-NULL output string expected. */ - - emitter->write_handler = yaml_string_write_handler; - emitter->write_handler_data = emitter; - - emitter->output.string.buffer = output; - emitter->output.string.size = size; - emitter->output.string.size_written = size_written; - *size_written = 0; -} - -/* - * Set a file output. - */ - -YAML_DECLARE(void) -yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - assert(!emitter->write_handler); /* You can set the output only once. */ - assert(file); /* Non-NULL file object expected. */ - - emitter->write_handler = yaml_file_write_handler; - emitter->write_handler_data = emitter; - - emitter->output.file = file; -} - -/* - * Set a generic output handler. - */ - -YAML_DECLARE(void) -yaml_emitter_set_output(yaml_emitter_t *emitter, - yaml_write_handler_t *handler, void *data) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - assert(!emitter->write_handler); /* You can set the output only once. */ - assert(handler); /* Non-NULL handler object expected. */ - - emitter->write_handler = handler; - emitter->write_handler_data = data; -} - -/* - * Set the output encoding. - */ - -YAML_DECLARE(void) -yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - assert(!emitter->encoding); /* You can set encoding only once. */ - - emitter->encoding = encoding; -} - -/* - * Set the canonical output style. - */ - -YAML_DECLARE(void) -yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - emitter->canonical = (canonical != 0); -} - -/* - * Set the indentation increment. - */ - -YAML_DECLARE(void) -yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - emitter->best_indent = (1 < indent && indent < 10) ? indent : 2; -} - -/* - * Set the preferred line width. - */ - -YAML_DECLARE(void) -yaml_emitter_set_width(yaml_emitter_t *emitter, int width) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - emitter->best_width = (width >= 0) ? width : -1; -} - -/* - * Set if unescaped non-ASCII characters are allowed. - */ - -YAML_DECLARE(void) -yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - emitter->unicode = (unicode != 0); -} - -/* - * Set the preferred line break character. - */ - -YAML_DECLARE(void) -yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break) -{ - assert(emitter); /* Non-NULL emitter object expected. */ - - emitter->line_break = line_break; -} - -/* - * Destroy a token object. - */ - -YAML_DECLARE(void) -yaml_token_delete(yaml_token_t *token) -{ - assert(token); /* Non-NULL token object expected. */ - - switch (token->type) - { - case YAML_TAG_DIRECTIVE_TOKEN: - yaml_free(token->data.tag_directive.handle); - yaml_free(token->data.tag_directive.prefix); - break; - - case YAML_ALIAS_TOKEN: - yaml_free(token->data.alias.value); - break; - - case YAML_ANCHOR_TOKEN: - yaml_free(token->data.anchor.value); - break; - - case YAML_TAG_TOKEN: - yaml_free(token->data.tag.handle); - yaml_free(token->data.tag.suffix); - break; - - case YAML_SCALAR_TOKEN: - yaml_free(token->data.scalar.value); - break; - - default: - break; - } - - memset(token, 0, sizeof(yaml_token_t)); -} - -/* - * Check if a string is a valid UTF-8 sequence. - * - * Check 'reader.c' for more details on UTF-8 encoding. - */ - -static int -yaml_check_utf8(const yaml_char_t *start, size_t length) -{ - const yaml_char_t *end = start+length; - const yaml_char_t *pointer = start; - - while (pointer < end) { - unsigned char octet; - unsigned int width; - unsigned int value; - size_t k; - - octet = pointer[0]; - width = (octet & 0x80) == 0x00 ? 1 : - (octet & 0xE0) == 0xC0 ? 2 : - (octet & 0xF0) == 0xE0 ? 3 : - (octet & 0xF8) == 0xF0 ? 4 : 0; - value = (octet & 0x80) == 0x00 ? octet & 0x7F : - (octet & 0xE0) == 0xC0 ? octet & 0x1F : - (octet & 0xF0) == 0xE0 ? octet & 0x0F : - (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; - if (!width) return 0; - if (pointer+width > end) return 0; - for (k = 1; k < width; k ++) { - octet = pointer[k]; - if ((octet & 0xC0) != 0x80) return 0; - value = (value << 6) + (octet & 0x3F); - } - if (!((width == 1) || - (width == 2 && value >= 0x80) || - (width == 3 && value >= 0x800) || - (width == 4 && value >= 0x10000))) return 0; - - pointer += width; - } - - return 1; -} - -/* - * Create STREAM-START. - */ - -YAML_DECLARE(int) -yaml_stream_start_event_initialize(yaml_event_t *event, - yaml_encoding_t encoding) -{ - yaml_mark_t mark = { 0, 0, 0 }; - - assert(event); /* Non-NULL event object is expected. */ - - STREAM_START_EVENT_INIT(*event, encoding, mark, mark); - - return 1; -} - -/* - * Create STREAM-END. - */ - -YAML_DECLARE(int) -yaml_stream_end_event_initialize(yaml_event_t *event) -{ - yaml_mark_t mark = { 0, 0, 0 }; - - assert(event); /* Non-NULL event object is expected. */ - - STREAM_END_EVENT_INIT(*event, mark, mark); - - return 1; -} - -/* - * Create DOCUMENT-START. - */ - -YAML_DECLARE(int) -yaml_document_start_event_initialize(yaml_event_t *event, - yaml_version_directive_t *version_directive, - yaml_tag_directive_t *tag_directives_start, - yaml_tag_directive_t *tag_directives_end, - int implicit) -{ - struct { - yaml_error_type_t error; - } context; - yaml_mark_t mark = { 0, 0, 0 }; - yaml_version_directive_t *version_directive_copy = NULL; - struct { - yaml_tag_directive_t *start; - yaml_tag_directive_t *end; - yaml_tag_directive_t *top; - } tag_directives_copy = { NULL, NULL, NULL }; - yaml_tag_directive_t value = { NULL, NULL }; - - assert(event); /* Non-NULL event object is expected. */ - assert((tag_directives_start && tag_directives_end) || - (tag_directives_start == tag_directives_end)); - /* Valid tag directives are expected. */ - - if (version_directive) { - version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); - if (!version_directive_copy) goto error; - version_directive_copy->major = version_directive->major; - version_directive_copy->minor = version_directive->minor; - } - - if (tag_directives_start != tag_directives_end) { - yaml_tag_directive_t *tag_directive; - if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) - goto error; - for (tag_directive = tag_directives_start; - tag_directive != tag_directives_end; tag_directive ++) { - assert(tag_directive->handle); - assert(tag_directive->prefix); - if (!yaml_check_utf8(tag_directive->handle, - strlen((char *)tag_directive->handle))) - goto error; - if (!yaml_check_utf8(tag_directive->prefix, - strlen((char *)tag_directive->prefix))) - goto error; - value.handle = yaml_strdup(tag_directive->handle); - value.prefix = yaml_strdup(tag_directive->prefix); - if (!value.handle || !value.prefix) goto error; - if (!PUSH(&context, tag_directives_copy, value)) - goto error; - value.handle = NULL; - value.prefix = NULL; - } - } - - DOCUMENT_START_EVENT_INIT(*event, version_directive_copy, - tag_directives_copy.start, tag_directives_copy.top, - implicit, mark, mark); - - return 1; - -error: - yaml_free(version_directive_copy); - while (!STACK_EMPTY(context, tag_directives_copy)) { - yaml_tag_directive_t value = POP(context, tag_directives_copy); - yaml_free(value.handle); - yaml_free(value.prefix); - } - STACK_DEL(context, tag_directives_copy); - yaml_free(value.handle); - yaml_free(value.prefix); - - return 0; -} - -/* - * Create DOCUMENT-END. - */ - -YAML_DECLARE(int) -yaml_document_end_event_initialize(yaml_event_t *event, int implicit) -{ - yaml_mark_t mark = { 0, 0, 0 }; - - assert(event); /* Non-NULL emitter object is expected. */ - - DOCUMENT_END_EVENT_INIT(*event, implicit, mark, mark); - - return 1; -} - -/* - * Create ALIAS. - */ - -YAML_DECLARE(int) -yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor) -{ - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *anchor_copy = NULL; - - assert(event); /* Non-NULL event object is expected. */ - assert(anchor); /* Non-NULL anchor is expected. */ - - if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0; - - anchor_copy = yaml_strdup(anchor); - if (!anchor_copy) - return 0; - - ALIAS_EVENT_INIT(*event, anchor_copy, mark, mark); - - return 1; -} - -/* - * Create SCALAR. - */ - -YAML_DECLARE(int) -yaml_scalar_event_initialize(yaml_event_t *event, - const yaml_char_t *anchor, const yaml_char_t *tag, - const yaml_char_t *value, int length, - int plain_implicit, int quoted_implicit, - yaml_scalar_style_t style) -{ - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *anchor_copy = NULL; - yaml_char_t *tag_copy = NULL; - yaml_char_t *value_copy = NULL; - - assert(event); /* Non-NULL event object is expected. */ - assert(value); /* Non-NULL anchor is expected. */ - - if (anchor) { - if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; - anchor_copy = yaml_strdup(anchor); - if (!anchor_copy) goto error; - } - - if (tag) { - if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; - tag_copy = yaml_strdup(tag); - if (!tag_copy) goto error; - } - - if (length < 0) { - length = (int)strlen((char *)value); - } - - if (!yaml_check_utf8(value, length)) goto error; - value_copy = YAML_MALLOC(length+1); - if (!value_copy) goto error; - memcpy(value_copy, value, length); - value_copy[length] = '\0'; - - SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, length, - plain_implicit, quoted_implicit, style, mark, mark); - - return 1; - -error: - yaml_free(anchor_copy); - yaml_free(tag_copy); - yaml_free(value_copy); - - return 0; -} - -/* - * Create SEQUENCE-START. - */ - -YAML_DECLARE(int) -yaml_sequence_start_event_initialize(yaml_event_t *event, - const yaml_char_t *anchor, const yaml_char_t *tag, int implicit, - yaml_sequence_style_t style) -{ - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *anchor_copy = NULL; - yaml_char_t *tag_copy = NULL; - - assert(event); /* Non-NULL event object is expected. */ - - if (anchor) { - if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; - anchor_copy = yaml_strdup(anchor); - if (!anchor_copy) goto error; - } - - if (tag) { - if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; - tag_copy = yaml_strdup(tag); - if (!tag_copy) goto error; - } - - SEQUENCE_START_EVENT_INIT(*event, anchor_copy, tag_copy, - implicit, style, mark, mark); - - return 1; - -error: - yaml_free(anchor_copy); - yaml_free(tag_copy); - - return 0; -} - -/* - * Create SEQUENCE-END. - */ - -YAML_DECLARE(int) -yaml_sequence_end_event_initialize(yaml_event_t *event) -{ - yaml_mark_t mark = { 0, 0, 0 }; - - assert(event); /* Non-NULL event object is expected. */ - - SEQUENCE_END_EVENT_INIT(*event, mark, mark); - - return 1; -} - -/* - * Create MAPPING-START. - */ - -YAML_DECLARE(int) -yaml_mapping_start_event_initialize(yaml_event_t *event, - const yaml_char_t *anchor, const yaml_char_t *tag, int implicit, - yaml_mapping_style_t style) -{ - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *anchor_copy = NULL; - yaml_char_t *tag_copy = NULL; - - assert(event); /* Non-NULL event object is expected. */ - - if (anchor) { - if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; - anchor_copy = yaml_strdup(anchor); - if (!anchor_copy) goto error; - } - - if (tag) { - if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; - tag_copy = yaml_strdup(tag); - if (!tag_copy) goto error; - } - - MAPPING_START_EVENT_INIT(*event, anchor_copy, tag_copy, - implicit, style, mark, mark); - - return 1; - -error: - yaml_free(anchor_copy); - yaml_free(tag_copy); - - return 0; -} - -/* - * Create MAPPING-END. - */ - -YAML_DECLARE(int) -yaml_mapping_end_event_initialize(yaml_event_t *event) -{ - yaml_mark_t mark = { 0, 0, 0 }; - - assert(event); /* Non-NULL event object is expected. */ - - MAPPING_END_EVENT_INIT(*event, mark, mark); - - return 1; -} - -/* - * Destroy an event object. - */ - -YAML_DECLARE(void) -yaml_event_delete(yaml_event_t *event) -{ - yaml_tag_directive_t *tag_directive; - - assert(event); /* Non-NULL event object expected. */ - - switch (event->type) - { - case YAML_DOCUMENT_START_EVENT: - yaml_free(event->data.document_start.version_directive); - for (tag_directive = event->data.document_start.tag_directives.start; - tag_directive != event->data.document_start.tag_directives.end; - tag_directive++) { - yaml_free(tag_directive->handle); - yaml_free(tag_directive->prefix); - } - yaml_free(event->data.document_start.tag_directives.start); - break; - - case YAML_ALIAS_EVENT: - yaml_free(event->data.alias.anchor); - break; - - case YAML_SCALAR_EVENT: - yaml_free(event->data.scalar.anchor); - yaml_free(event->data.scalar.tag); - yaml_free(event->data.scalar.value); - break; - - case YAML_SEQUENCE_START_EVENT: - yaml_free(event->data.sequence_start.anchor); - yaml_free(event->data.sequence_start.tag); - break; - - case YAML_MAPPING_START_EVENT: - yaml_free(event->data.mapping_start.anchor); - yaml_free(event->data.mapping_start.tag); - break; - - default: - break; - } - - memset(event, 0, sizeof(yaml_event_t)); -} - -/* - * Create a document object. - */ - -YAML_DECLARE(int) -yaml_document_initialize(yaml_document_t *document, - yaml_version_directive_t *version_directive, - yaml_tag_directive_t *tag_directives_start, - yaml_tag_directive_t *tag_directives_end, - int start_implicit, int end_implicit) -{ - struct { - yaml_error_type_t error; - } context; - struct { - yaml_node_t *start; - yaml_node_t *end; - yaml_node_t *top; - } nodes = { NULL, NULL, NULL }; - yaml_version_directive_t *version_directive_copy = NULL; - struct { - yaml_tag_directive_t *start; - yaml_tag_directive_t *end; - yaml_tag_directive_t *top; - } tag_directives_copy = { NULL, NULL, NULL }; - yaml_tag_directive_t value = { NULL, NULL }; - yaml_mark_t mark = { 0, 0, 0 }; - - assert(document); /* Non-NULL document object is expected. */ - assert((tag_directives_start && tag_directives_end) || - (tag_directives_start == tag_directives_end)); - /* Valid tag directives are expected. */ - - if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error; - - if (version_directive) { - version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); - if (!version_directive_copy) goto error; - version_directive_copy->major = version_directive->major; - version_directive_copy->minor = version_directive->minor; - } - - if (tag_directives_start != tag_directives_end) { - yaml_tag_directive_t *tag_directive; - if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) - goto error; - for (tag_directive = tag_directives_start; - tag_directive != tag_directives_end; tag_directive ++) { - assert(tag_directive->handle); - assert(tag_directive->prefix); - if (!yaml_check_utf8(tag_directive->handle, - strlen((char *)tag_directive->handle))) - goto error; - if (!yaml_check_utf8(tag_directive->prefix, - strlen((char *)tag_directive->prefix))) - goto error; - value.handle = yaml_strdup(tag_directive->handle); - value.prefix = yaml_strdup(tag_directive->prefix); - if (!value.handle || !value.prefix) goto error; - if (!PUSH(&context, tag_directives_copy, value)) - goto error; - value.handle = NULL; - value.prefix = NULL; - } - } - - DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy, - tag_directives_copy.start, tag_directives_copy.top, - start_implicit, end_implicit, mark, mark); - - return 1; - -error: - STACK_DEL(&context, nodes); - yaml_free(version_directive_copy); - while (!STACK_EMPTY(&context, tag_directives_copy)) { - yaml_tag_directive_t value = POP(&context, tag_directives_copy); - yaml_free(value.handle); - yaml_free(value.prefix); - } - STACK_DEL(&context, tag_directives_copy); - yaml_free(value.handle); - yaml_free(value.prefix); - - return 0; -} - -/* - * Destroy a document object. - */ - -YAML_DECLARE(void) -yaml_document_delete(yaml_document_t *document) -{ - yaml_tag_directive_t *tag_directive; - - assert(document); /* Non-NULL document object is expected. */ - - while (!STACK_EMPTY(&context, document->nodes)) { - yaml_node_t node = POP(&context, document->nodes); - yaml_free(node.tag); - switch (node.type) { - case YAML_SCALAR_NODE: - yaml_free(node.data.scalar.value); - break; - case YAML_SEQUENCE_NODE: - STACK_DEL(&context, node.data.sequence.items); - break; - case YAML_MAPPING_NODE: - STACK_DEL(&context, node.data.mapping.pairs); - break; - default: - assert(0); /* Should not happen. */ - } - } - STACK_DEL(&context, document->nodes); - - yaml_free(document->version_directive); - for (tag_directive = document->tag_directives.start; - tag_directive != document->tag_directives.end; - tag_directive++) { - yaml_free(tag_directive->handle); - yaml_free(tag_directive->prefix); - } - yaml_free(document->tag_directives.start); - - memset(document, 0, sizeof(yaml_document_t)); -} - -/** - * Get a document node. - */ - -YAML_DECLARE(yaml_node_t *) -yaml_document_get_node(yaml_document_t *document, int index) -{ - assert(document); /* Non-NULL document object is expected. */ - - if (index > 0 && document->nodes.start + index <= document->nodes.top) { - return document->nodes.start + index - 1; - } - return NULL; -} - -/** - * Get the root object. - */ - -YAML_DECLARE(yaml_node_t *) -yaml_document_get_root_node(yaml_document_t *document) -{ - assert(document); /* Non-NULL document object is expected. */ - - if (document->nodes.top != document->nodes.start) { - return document->nodes.start; - } - return NULL; -} - -/* - * Add a scalar node to a document. - */ - -YAML_DECLARE(int) -yaml_document_add_scalar(yaml_document_t *document, - const yaml_char_t *tag, const yaml_char_t *value, int length, - yaml_scalar_style_t style) -{ - struct { - yaml_error_type_t error; - } context; - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *tag_copy = NULL; - yaml_char_t *value_copy = NULL; - yaml_node_t node; - - assert(document); /* Non-NULL document object is expected. */ - assert(value); /* Non-NULL value is expected. */ - - if (!tag) { - tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG; - } - - if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; - tag_copy = yaml_strdup(tag); - if (!tag_copy) goto error; - - if (length < 0) { - length = (int)strlen((char *)value); - } - - if (!yaml_check_utf8(value, length)) goto error; - value_copy = YAML_MALLOC(length+1); - if (!value_copy) goto error; - memcpy(value_copy, value, length); - value_copy[length] = '\0'; - - SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark); - if (!PUSH(&context, document->nodes, node)) goto error; - - return (int)(document->nodes.top - document->nodes.start); - -error: - yaml_free(tag_copy); - yaml_free(value_copy); - - return 0; -} - -/* - * Add a sequence node to a document. - */ - -YAML_DECLARE(int) -yaml_document_add_sequence(yaml_document_t *document, - const yaml_char_t *tag, yaml_sequence_style_t style) -{ - struct { - yaml_error_type_t error; - } context; - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *tag_copy = NULL; - struct { - yaml_node_item_t *start; - yaml_node_item_t *end; - yaml_node_item_t *top; - } items = { NULL, NULL, NULL }; - yaml_node_t node; - - assert(document); /* Non-NULL document object is expected. */ - - if (!tag) { - tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG; - } - - if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; - tag_copy = yaml_strdup(tag); - if (!tag_copy) goto error; - - if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error; - - SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, - style, mark, mark); - if (!PUSH(&context, document->nodes, node)) goto error; - - return (int)(document->nodes.top - document->nodes.start); - -error: - STACK_DEL(&context, items); - yaml_free(tag_copy); - - return 0; -} - -/* - * Add a mapping node to a document. - */ - -YAML_DECLARE(int) -yaml_document_add_mapping(yaml_document_t *document, - const yaml_char_t *tag, yaml_mapping_style_t style) -{ - struct { - yaml_error_type_t error; - } context; - yaml_mark_t mark = { 0, 0, 0 }; - yaml_char_t *tag_copy = NULL; - struct { - yaml_node_pair_t *start; - yaml_node_pair_t *end; - yaml_node_pair_t *top; - } pairs = { NULL, NULL, NULL }; - yaml_node_t node; - - assert(document); /* Non-NULL document object is expected. */ - - if (!tag) { - tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG; - } - - if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; - tag_copy = yaml_strdup(tag); - if (!tag_copy) goto error; - - if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error; - - MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, - style, mark, mark); - if (!PUSH(&context, document->nodes, node)) goto error; - - return (int)(document->nodes.top - document->nodes.start); - -error: - STACK_DEL(&context, pairs); - yaml_free(tag_copy); - - return 0; -} - -/* - * Append an item to a sequence node. - */ - -YAML_DECLARE(int) -yaml_document_append_sequence_item(yaml_document_t *document, - int sequence, int item) -{ - struct { - yaml_error_type_t error; - } context; - - assert(document); /* Non-NULL document is required. */ - assert(sequence > 0 - && document->nodes.start + sequence <= document->nodes.top); - /* Valid sequence id is required. */ - assert(document->nodes.start[sequence-1].type == YAML_SEQUENCE_NODE); - /* A sequence node is required. */ - assert(item > 0 && document->nodes.start + item <= document->nodes.top); - /* Valid item id is required. */ - - if (!PUSH(&context, - document->nodes.start[sequence-1].data.sequence.items, item)) - return 0; - - return 1; -} - -/* - * Append a pair of a key and a value to a mapping node. - */ - -YAML_DECLARE(int) -yaml_document_append_mapping_pair(yaml_document_t *document, - int mapping, int key, int value) -{ - struct { - yaml_error_type_t error; - } context; - - yaml_node_pair_t pair; - - assert(document); /* Non-NULL document is required. */ - assert(mapping > 0 - && document->nodes.start + mapping <= document->nodes.top); - /* Valid mapping id is required. */ - assert(document->nodes.start[mapping-1].type == YAML_MAPPING_NODE); - /* A mapping node is required. */ - assert(key > 0 && document->nodes.start + key <= document->nodes.top); - /* Valid key id is required. */ - assert(value > 0 && document->nodes.start + value <= document->nodes.top); - /* Valid value id is required. */ - - pair.key = key; - pair.value = value; - - if (!PUSH(&context, - document->nodes.start[mapping-1].data.mapping.pairs, pair)) - return 0; - - return 1; -} - - diff --git a/ext/psych/yaml/config.h b/ext/psych/yaml/config.h deleted file mode 100644 index 4b1150f5e4..0000000000 --- a/ext/psych/yaml/config.h +++ /dev/null @@ -1,80 +0,0 @@ -/* include/config.h. Generated from config.h.in by configure. */ -/* include/config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the <dlfcn.h> header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the <inttypes.h> header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the <memory.h> header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the <stdint.h> header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the <stdlib.h> header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the <strings.h> header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the <string.h> header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the <sys/stat.h> header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the <sys/types.h> header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the <unistd.h> header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to the sub-directory where libtool stores uninstalled libraries. */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "yaml" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "https://github.com/yaml/libyaml/issues/new" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "yaml" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "yaml 0.2.5" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "yaml" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.2.5" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "0.2.5" - -/* Define the major version number. */ -#define YAML_VERSION_MAJOR 0 - -/* Define the minor version number. */ -#define YAML_VERSION_MINOR 2 - -/* Define the patch version number. */ -#define YAML_VERSION_PATCH 5 - -/* Define the version string. */ -#define YAML_VERSION_STRING "0.2.5" - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `unsigned int' if <sys/types.h> does not define. */ -/* #undef size_t */ diff --git a/ext/psych/yaml/dumper.c b/ext/psych/yaml/dumper.c deleted file mode 100644 index 1fe940b674..0000000000 --- a/ext/psych/yaml/dumper.c +++ /dev/null @@ -1,394 +0,0 @@ - -#include "yaml_private.h" - -/* - * API functions. - */ - -YAML_DECLARE(int) -yaml_emitter_open(yaml_emitter_t *emitter); - -YAML_DECLARE(int) -yaml_emitter_close(yaml_emitter_t *emitter); - -YAML_DECLARE(int) -yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document); - -/* - * Clean up functions. - */ - -static void -yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter); - -/* - * Anchor functions. - */ - -static void -yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index); - -static yaml_char_t * -yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id); - - -/* - * Serialize functions. - */ - -static int -yaml_emitter_dump_node(yaml_emitter_t *emitter, int index); - -static int -yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor); - -static int -yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node, - yaml_char_t *anchor); - -static int -yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node, - yaml_char_t *anchor); - -static int -yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node, - yaml_char_t *anchor); - -/* - * Issue a STREAM-START event. - */ - -YAML_DECLARE(int) -yaml_emitter_open(yaml_emitter_t *emitter) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - assert(emitter); /* Non-NULL emitter object is required. */ - assert(!emitter->opened); /* Emitter should not be opened yet. */ - - STREAM_START_EVENT_INIT(event, YAML_ANY_ENCODING, mark, mark); - - if (!yaml_emitter_emit(emitter, &event)) { - return 0; - } - - emitter->opened = 1; - - return 1; -} - -/* - * Issue a STREAM-END event. - */ - -YAML_DECLARE(int) -yaml_emitter_close(yaml_emitter_t *emitter) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - assert(emitter); /* Non-NULL emitter object is required. */ - assert(emitter->opened); /* Emitter should be opened. */ - - if (emitter->closed) return 1; - - STREAM_END_EVENT_INIT(event, mark, mark); - - if (!yaml_emitter_emit(emitter, &event)) { - return 0; - } - - emitter->closed = 1; - - return 1; -} - -/* - * Dump a YAML document. - */ - -YAML_DECLARE(int) -yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - assert(emitter); /* Non-NULL emitter object is required. */ - assert(document); /* Non-NULL emitter object is expected. */ - - emitter->document = document; - - if (!emitter->opened) { - if (!yaml_emitter_open(emitter)) goto error; - } - - if (STACK_EMPTY(emitter, document->nodes)) { - if (!yaml_emitter_close(emitter)) goto error; - yaml_emitter_delete_document_and_anchors(emitter); - return 1; - } - - assert(emitter->opened); /* Emitter should be opened. */ - - emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors)) - * (document->nodes.top - document->nodes.start)); - if (!emitter->anchors) goto error; - memset(emitter->anchors, 0, sizeof(*(emitter->anchors)) - * (document->nodes.top - document->nodes.start)); - - DOCUMENT_START_EVENT_INIT(event, document->version_directive, - document->tag_directives.start, document->tag_directives.end, - document->start_implicit, mark, mark); - if (!yaml_emitter_emit(emitter, &event)) goto error; - - yaml_emitter_anchor_node(emitter, 1); - if (!yaml_emitter_dump_node(emitter, 1)) goto error; - - DOCUMENT_END_EVENT_INIT(event, document->end_implicit, mark, mark); - if (!yaml_emitter_emit(emitter, &event)) goto error; - - yaml_emitter_delete_document_and_anchors(emitter); - - return 1; - -error: - - yaml_emitter_delete_document_and_anchors(emitter); - - return 0; -} - -/* - * Clean up the emitter object after a document is dumped. - */ - -static void -yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter) -{ - int index; - - if (!emitter->anchors) { - yaml_document_delete(emitter->document); - emitter->document = NULL; - return; - } - - for (index = 0; emitter->document->nodes.start + index - < emitter->document->nodes.top; index ++) { - yaml_node_t node = emitter->document->nodes.start[index]; - if (!emitter->anchors[index].serialized) { - yaml_free(node.tag); - if (node.type == YAML_SCALAR_NODE) { - yaml_free(node.data.scalar.value); - } - } - if (node.type == YAML_SEQUENCE_NODE) { - STACK_DEL(emitter, node.data.sequence.items); - } - if (node.type == YAML_MAPPING_NODE) { - STACK_DEL(emitter, node.data.mapping.pairs); - } - } - - STACK_DEL(emitter, emitter->document->nodes); - yaml_free(emitter->anchors); - - emitter->anchors = NULL; - emitter->last_anchor_id = 0; - emitter->document = NULL; -} - -/* - * Check the references of a node and assign the anchor id if needed. - */ - -static void -yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index) -{ - yaml_node_t *node = emitter->document->nodes.start + index - 1; - yaml_node_item_t *item; - yaml_node_pair_t *pair; - - emitter->anchors[index-1].references ++; - - if (emitter->anchors[index-1].references == 1) { - switch (node->type) { - case YAML_SEQUENCE_NODE: - for (item = node->data.sequence.items.start; - item < node->data.sequence.items.top; item ++) { - yaml_emitter_anchor_node(emitter, *item); - } - break; - case YAML_MAPPING_NODE: - for (pair = node->data.mapping.pairs.start; - pair < node->data.mapping.pairs.top; pair ++) { - yaml_emitter_anchor_node(emitter, pair->key); - yaml_emitter_anchor_node(emitter, pair->value); - } - break; - default: - break; - } - } - - else if (emitter->anchors[index-1].references == 2) { - emitter->anchors[index-1].anchor = (++ emitter->last_anchor_id); - } -} - -/* - * Generate a textual representation for an anchor. - */ - -#define ANCHOR_TEMPLATE "id%03d" -#define ANCHOR_TEMPLATE_LENGTH 16 - -static yaml_char_t * -yaml_emitter_generate_anchor(SHIM(yaml_emitter_t *emitter), int anchor_id) -{ - yaml_char_t *anchor = YAML_MALLOC(ANCHOR_TEMPLATE_LENGTH); - - if (!anchor) return NULL; - - sprintf((char *)anchor, ANCHOR_TEMPLATE, anchor_id); - - return anchor; -} - -/* - * Serialize a node. - */ - -static int -yaml_emitter_dump_node(yaml_emitter_t *emitter, int index) -{ - yaml_node_t *node = emitter->document->nodes.start + index - 1; - int anchor_id = emitter->anchors[index-1].anchor; - yaml_char_t *anchor = NULL; - - if (anchor_id) { - anchor = yaml_emitter_generate_anchor(emitter, anchor_id); - if (!anchor) return 0; - } - - if (emitter->anchors[index-1].serialized) { - return yaml_emitter_dump_alias(emitter, anchor); - } - - emitter->anchors[index-1].serialized = 1; - - switch (node->type) { - case YAML_SCALAR_NODE: - return yaml_emitter_dump_scalar(emitter, node, anchor); - case YAML_SEQUENCE_NODE: - return yaml_emitter_dump_sequence(emitter, node, anchor); - case YAML_MAPPING_NODE: - return yaml_emitter_dump_mapping(emitter, node, anchor); - default: - assert(0); /* Could not happen. */ - break; - } - - return 0; /* Could not happen. */ -} - -/* - * Serialize an alias. - */ - -static int -yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - ALIAS_EVENT_INIT(event, anchor, mark, mark); - - return yaml_emitter_emit(emitter, &event); -} - -/* - * Serialize a scalar. - */ - -static int -yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node, - yaml_char_t *anchor) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - int plain_implicit = (strcmp((char *)node->tag, - YAML_DEFAULT_SCALAR_TAG) == 0); - int quoted_implicit = (strcmp((char *)node->tag, - YAML_DEFAULT_SCALAR_TAG) == 0); - - SCALAR_EVENT_INIT(event, anchor, node->tag, node->data.scalar.value, - node->data.scalar.length, plain_implicit, quoted_implicit, - node->data.scalar.style, mark, mark); - - return yaml_emitter_emit(emitter, &event); -} - -/* - * Serialize a sequence. - */ - -static int -yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node, - yaml_char_t *anchor) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_SEQUENCE_TAG) == 0); - - yaml_node_item_t *item; - - SEQUENCE_START_EVENT_INIT(event, anchor, node->tag, implicit, - node->data.sequence.style, mark, mark); - if (!yaml_emitter_emit(emitter, &event)) return 0; - - for (item = node->data.sequence.items.start; - item < node->data.sequence.items.top; item ++) { - if (!yaml_emitter_dump_node(emitter, *item)) return 0; - } - - SEQUENCE_END_EVENT_INIT(event, mark, mark); - if (!yaml_emitter_emit(emitter, &event)) return 0; - - return 1; -} - -/* - * Serialize a mapping. - */ - -static int -yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node, - yaml_char_t *anchor) -{ - yaml_event_t event; - yaml_mark_t mark = { 0, 0, 0 }; - - int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_MAPPING_TAG) == 0); - - yaml_node_pair_t *pair; - - MAPPING_START_EVENT_INIT(event, anchor, node->tag, implicit, - node->data.mapping.style, mark, mark); - if (!yaml_emitter_emit(emitter, &event)) return 0; - - for (pair = node->data.mapping.pairs.start; - pair < node->data.mapping.pairs.top; pair ++) { - if (!yaml_emitter_dump_node(emitter, pair->key)) return 0; - if (!yaml_emitter_dump_node(emitter, pair->value)) return 0; - } - - MAPPING_END_EVENT_INIT(event, mark, mark); - if (!yaml_emitter_emit(emitter, &event)) return 0; - - return 1; -} - diff --git a/ext/psych/yaml/emitter.c b/ext/psych/yaml/emitter.c deleted file mode 100644 index 796294ccdf..0000000000 --- a/ext/psych/yaml/emitter.c +++ /dev/null @@ -1,2358 +0,0 @@ - -#include "yaml_private.h" - -/* - * Flush the buffer if needed. - */ - -#define FLUSH(emitter) \ - ((emitter->buffer.pointer+5 < emitter->buffer.end) \ - || yaml_emitter_flush(emitter)) - -/* - * Put a character to the output buffer. - */ - -#define PUT(emitter,value) \ - (FLUSH(emitter) \ - && (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \ - emitter->column++, \ - 1)) - -/* - * Put a line break to the output buffer. - */ - -#define PUT_BREAK(emitter) \ - (FLUSH(emitter) ? \ - ((emitter->line_break == YAML_CR_BREAK ? \ - (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') : \ - emitter->line_break == YAML_LN_BREAK ? \ - (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') : \ - emitter->line_break == YAML_CRLN_BREAK ? \ - (*(emitter->buffer.pointer++) = (yaml_char_t) '\r', \ - *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0), \ - emitter->column = 0, \ - emitter->line ++, \ - 1) : 0) - -/* - * Copy a character from a string into buffer. - */ - -#define WRITE(emitter,string) \ - (FLUSH(emitter) \ - && (COPY(emitter->buffer,string), \ - emitter->column ++, \ - 1)) - -/* - * Copy a line break character from a string into buffer. - */ - -#define WRITE_BREAK(emitter,string) \ - (FLUSH(emitter) \ - && (CHECK(string,'\n') ? \ - (PUT_BREAK(emitter), \ - string.pointer ++, \ - 1) : \ - (COPY(emitter->buffer,string), \ - emitter->column = 0, \ - emitter->line ++, \ - 1))) - -/* - * API functions. - */ - -YAML_DECLARE(int) -yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event); - -/* - * Utility functions. - */ - -static int -yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem); - -static int -yaml_emitter_need_more_events(yaml_emitter_t *emitter); - -static int -yaml_emitter_append_tag_directive(yaml_emitter_t *emitter, - yaml_tag_directive_t value, int allow_duplicates); - -static int -yaml_emitter_increase_indent(yaml_emitter_t *emitter, - int flow, int indentless); - -/* - * State functions. - */ - -static int -yaml_emitter_state_machine(yaml_emitter_t *emitter, yaml_event_t *event); - -static int -yaml_emitter_emit_stream_start(yaml_emitter_t *emitter, - yaml_event_t *event); - -static int -yaml_emitter_emit_document_start(yaml_emitter_t *emitter, - yaml_event_t *event, int first); - -static int -yaml_emitter_emit_document_content(yaml_emitter_t *emitter, - yaml_event_t *event); - -static int -yaml_emitter_emit_document_end(yaml_emitter_t *emitter, - yaml_event_t *event); - -static int -yaml_emitter_emit_flow_sequence_item(yaml_emitter_t *emitter, - yaml_event_t *event, int first); - -static int -yaml_emitter_emit_flow_mapping_key(yaml_emitter_t *emitter, - yaml_event_t *event, int first); - -static int -yaml_emitter_emit_flow_mapping_value(yaml_emitter_t *emitter, - yaml_event_t *event, int simple); - -static int -yaml_emitter_emit_block_sequence_item(yaml_emitter_t *emitter, - yaml_event_t *event, int first); - -static int -yaml_emitter_emit_block_mapping_key(yaml_emitter_t *emitter, - yaml_event_t *event, int first); - -static int -yaml_emitter_emit_block_mapping_value(yaml_emitter_t *emitter, - yaml_event_t *event, int simple); - -static int -yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, - int root, int sequence, int mapping, int simple_key); - -static int -yaml_emitter_emit_alias(yaml_emitter_t *emitter, yaml_event_t *event); - -static int -yaml_emitter_emit_scalar(yaml_emitter_t *emitter, yaml_event_t *event); - -static int -yaml_emitter_emit_sequence_start(yaml_emitter_t *emitter, yaml_event_t *event); - -static int -yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter, yaml_event_t *event); - -/* - * Checkers. - */ - -static int -yaml_emitter_check_empty_document(yaml_emitter_t *emitter); - -static int -yaml_emitter_check_empty_sequence(yaml_emitter_t *emitter); - -static int -yaml_emitter_check_empty_mapping(yaml_emitter_t *emitter); - -static int -yaml_emitter_check_simple_key(yaml_emitter_t *emitter); - -static int -yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event); - -/* - * Processors. - */ - -static int -yaml_emitter_process_anchor(yaml_emitter_t *emitter); - -static int -yaml_emitter_process_tag(yaml_emitter_t *emitter); - -static int -yaml_emitter_process_scalar(yaml_emitter_t *emitter); - -/* - * Analyzers. - */ - -static int -yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter, - yaml_version_directive_t version_directive); - -static int -yaml_emitter_analyze_tag_directive(yaml_emitter_t *emitter, - yaml_tag_directive_t tag_directive); - -static int -yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, - yaml_char_t *anchor, int alias); - -static int -yaml_emitter_analyze_tag(yaml_emitter_t *emitter, - yaml_char_t *tag); - -static int -yaml_emitter_analyze_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length); - -static int -yaml_emitter_analyze_event(yaml_emitter_t *emitter, - yaml_event_t *event); - -/* - * Writers. - */ - -static int -yaml_emitter_write_bom(yaml_emitter_t *emitter); - -static int -yaml_emitter_write_indent(yaml_emitter_t *emitter); - -static int -yaml_emitter_write_indicator(yaml_emitter_t *emitter, - const char *indicator, int need_whitespace, - int is_whitespace, int is_indention); - -static int -yaml_emitter_write_anchor(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length); - -static int -yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length); - -static int -yaml_emitter_write_tag_content(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int need_whitespace); - -static int -yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int allow_breaks); - -static int -yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int allow_breaks); - -static int -yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int allow_breaks); - -static int -yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, - yaml_string_t string); - -static int -yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length); - -static int -yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length); - -/* - * Set an emitter error and return 0. - */ - -static int -yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem) -{ - emitter->error = YAML_EMITTER_ERROR; - emitter->problem = problem; - - return 0; -} - -/* - * Emit an event. - */ - -YAML_DECLARE(int) -yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event) -{ - if (!ENQUEUE(emitter, emitter->events, *event)) { - yaml_event_delete(event); - return 0; - } - - while (!yaml_emitter_need_more_events(emitter)) { - if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) - return 0; - if (!yaml_emitter_state_machine(emitter, emitter->events.head)) - return 0; - yaml_event_delete(&DEQUEUE(emitter, emitter->events)); - } - - return 1; -} - -/* - * Check if we need to accumulate more events before emitting. - * - * We accumulate extra - * - 1 event for DOCUMENT-START - * - 2 events for SEQUENCE-START - * - 3 events for MAPPING-START - */ - -static int -yaml_emitter_need_more_events(yaml_emitter_t *emitter) -{ - int level = 0; - int accumulate = 0; - yaml_event_t *event; - - if (QUEUE_EMPTY(emitter, emitter->events)) - return 1; - - switch (emitter->events.head->type) { - case YAML_DOCUMENT_START_EVENT: - accumulate = 1; - break; - case YAML_SEQUENCE_START_EVENT: - accumulate = 2; - break; - case YAML_MAPPING_START_EVENT: - accumulate = 3; - break; - default: - return 0; - } - - if (emitter->events.tail - emitter->events.head > accumulate) - return 0; - - for (event = emitter->events.head; event != emitter->events.tail; event ++) { - switch (event->type) { - case YAML_STREAM_START_EVENT: - case YAML_DOCUMENT_START_EVENT: - case YAML_SEQUENCE_START_EVENT: - case YAML_MAPPING_START_EVENT: - level += 1; - break; - case YAML_STREAM_END_EVENT: - case YAML_DOCUMENT_END_EVENT: - case YAML_SEQUENCE_END_EVENT: - case YAML_MAPPING_END_EVENT: - level -= 1; - break; - default: - break; - } - if (!level) - return 0; - } - - return 1; -} - -/* - * Append a directive to the directives stack. - */ - -static int -yaml_emitter_append_tag_directive(yaml_emitter_t *emitter, - yaml_tag_directive_t value, int allow_duplicates) -{ - yaml_tag_directive_t *tag_directive; - yaml_tag_directive_t copy = { NULL, NULL }; - - for (tag_directive = emitter->tag_directives.start; - tag_directive != emitter->tag_directives.top; tag_directive ++) { - if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { - if (allow_duplicates) - return 1; - return yaml_emitter_set_emitter_error(emitter, - "duplicate %TAG directive"); - } - } - - copy.handle = yaml_strdup(value.handle); - copy.prefix = yaml_strdup(value.prefix); - if (!copy.handle || !copy.prefix) { - emitter->error = YAML_MEMORY_ERROR; - goto error; - } - - if (!PUSH(emitter, emitter->tag_directives, copy)) - goto error; - - return 1; - -error: - yaml_free(copy.handle); - yaml_free(copy.prefix); - return 0; -} - -/* - * Increase the indentation level. - */ - -static int -yaml_emitter_increase_indent(yaml_emitter_t *emitter, - int flow, int indentless) -{ - if (!PUSH(emitter, emitter->indents, emitter->indent)) - return 0; - - if (emitter->indent < 0) { - emitter->indent = flow ? emitter->best_indent : 0; - } - else if (!indentless) { - emitter->indent += emitter->best_indent; - } - - return 1; -} - -/* - * State dispatcher. - */ - -static int -yaml_emitter_state_machine(yaml_emitter_t *emitter, yaml_event_t *event) -{ - switch (emitter->state) - { - case YAML_EMIT_STREAM_START_STATE: - return yaml_emitter_emit_stream_start(emitter, event); - - case YAML_EMIT_FIRST_DOCUMENT_START_STATE: - return yaml_emitter_emit_document_start(emitter, event, 1); - - case YAML_EMIT_DOCUMENT_START_STATE: - return yaml_emitter_emit_document_start(emitter, event, 0); - - case YAML_EMIT_DOCUMENT_CONTENT_STATE: - return yaml_emitter_emit_document_content(emitter, event); - - case YAML_EMIT_DOCUMENT_END_STATE: - return yaml_emitter_emit_document_end(emitter, event); - - case YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE: - return yaml_emitter_emit_flow_sequence_item(emitter, event, 1); - - case YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE: - return yaml_emitter_emit_flow_sequence_item(emitter, event, 0); - - case YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE: - return yaml_emitter_emit_flow_mapping_key(emitter, event, 1); - - case YAML_EMIT_FLOW_MAPPING_KEY_STATE: - return yaml_emitter_emit_flow_mapping_key(emitter, event, 0); - - case YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE: - return yaml_emitter_emit_flow_mapping_value(emitter, event, 1); - - case YAML_EMIT_FLOW_MAPPING_VALUE_STATE: - return yaml_emitter_emit_flow_mapping_value(emitter, event, 0); - - case YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE: - return yaml_emitter_emit_block_sequence_item(emitter, event, 1); - - case YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE: - return yaml_emitter_emit_block_sequence_item(emitter, event, 0); - - case YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE: - return yaml_emitter_emit_block_mapping_key(emitter, event, 1); - - case YAML_EMIT_BLOCK_MAPPING_KEY_STATE: - return yaml_emitter_emit_block_mapping_key(emitter, event, 0); - - case YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE: - return yaml_emitter_emit_block_mapping_value(emitter, event, 1); - - case YAML_EMIT_BLOCK_MAPPING_VALUE_STATE: - return yaml_emitter_emit_block_mapping_value(emitter, event, 0); - - case YAML_EMIT_END_STATE: - return yaml_emitter_set_emitter_error(emitter, - "expected nothing after STREAM-END"); - - default: - assert(1); /* Invalid state. */ - } - - return 0; -} - -/* - * Expect STREAM-START. - */ - -static int -yaml_emitter_emit_stream_start(yaml_emitter_t *emitter, - yaml_event_t *event) -{ - emitter->open_ended = 0; - if (event->type == YAML_STREAM_START_EVENT) - { - if (!emitter->encoding) { - emitter->encoding = event->data.stream_start.encoding; - } - - if (!emitter->encoding) { - emitter->encoding = YAML_UTF8_ENCODING; - } - - if (emitter->best_indent < 2 || emitter->best_indent > 9) { - emitter->best_indent = 2; - } - - if (emitter->best_width >= 0 - && emitter->best_width <= emitter->best_indent*2) { - emitter->best_width = 80; - } - - if (emitter->best_width < 0) { - emitter->best_width = INT_MAX; - } - - if (!emitter->line_break) { - emitter->line_break = YAML_LN_BREAK; - } - - emitter->indent = -1; - - emitter->line = 0; - emitter->column = 0; - emitter->whitespace = 1; - emitter->indention = 1; - - if (emitter->encoding != YAML_UTF8_ENCODING) { - if (!yaml_emitter_write_bom(emitter)) - return 0; - } - - emitter->state = YAML_EMIT_FIRST_DOCUMENT_START_STATE; - - return 1; - } - - return yaml_emitter_set_emitter_error(emitter, - "expected STREAM-START"); -} - -/* - * Expect DOCUMENT-START or STREAM-END. - */ - -static int -yaml_emitter_emit_document_start(yaml_emitter_t *emitter, - yaml_event_t *event, int first) -{ - if (event->type == YAML_DOCUMENT_START_EVENT) - { - yaml_tag_directive_t default_tag_directives[] = { - {(yaml_char_t *)"!", (yaml_char_t *)"!"}, - {(yaml_char_t *)"!!", (yaml_char_t *)"tag:yaml.org,2002:"}, - {NULL, NULL} - }; - yaml_tag_directive_t *tag_directive; - int implicit; - - if (event->data.document_start.version_directive) { - if (!yaml_emitter_analyze_version_directive(emitter, - *event->data.document_start.version_directive)) - return 0; - } - - for (tag_directive = event->data.document_start.tag_directives.start; - tag_directive != event->data.document_start.tag_directives.end; - tag_directive ++) { - if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) - return 0; - if (!yaml_emitter_append_tag_directive(emitter, *tag_directive, 0)) - return 0; - } - - for (tag_directive = default_tag_directives; - tag_directive->handle; tag_directive ++) { - if (!yaml_emitter_append_tag_directive(emitter, *tag_directive, 1)) - return 0; - } - - implicit = event->data.document_start.implicit; - if (!first || emitter->canonical) { - implicit = 0; - } - - if ((event->data.document_start.version_directive || - (event->data.document_start.tag_directives.start - != event->data.document_start.tag_directives.end)) && - emitter->open_ended) - { - if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) - return 0; - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - emitter->open_ended = 0; - - if (event->data.document_start.version_directive) { - implicit = 0; - if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) - return 0; - if (event->data.document_start.version_directive->minor == 1) { - if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0)) - return 0; - } - else { - if (!yaml_emitter_write_indicator(emitter, "1.2", 1, 0, 0)) - return 0; - } - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - - if (event->data.document_start.tag_directives.start - != event->data.document_start.tag_directives.end) { - implicit = 0; - for (tag_directive = event->data.document_start.tag_directives.start; - tag_directive != event->data.document_start.tag_directives.end; - tag_directive ++) { - if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) - return 0; - if (!yaml_emitter_write_tag_handle(emitter, tag_directive->handle, - strlen((char *)tag_directive->handle))) - return 0; - if (!yaml_emitter_write_tag_content(emitter, tag_directive->prefix, - strlen((char *)tag_directive->prefix), 1)) - return 0; - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - } - - if (yaml_emitter_check_empty_document(emitter)) { - implicit = 0; - } - - if (!implicit) { - if (!yaml_emitter_write_indent(emitter)) - return 0; - if (!yaml_emitter_write_indicator(emitter, "---", 1, 0, 0)) - return 0; - if (emitter->canonical) { - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - } - - emitter->state = YAML_EMIT_DOCUMENT_CONTENT_STATE; - - emitter->open_ended = 0; - return 1; - } - - else if (event->type == YAML_STREAM_END_EVENT) - { - - /** - * This can happen if a block scalar with trailing empty lines - * is at the end of the stream - */ - if (emitter->open_ended == 2) - { - if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) - return 0; - emitter->open_ended = 0; - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - if (!yaml_emitter_flush(emitter)) - return 0; - - emitter->state = YAML_EMIT_END_STATE; - - return 1; - } - - return yaml_emitter_set_emitter_error(emitter, - "expected DOCUMENT-START or STREAM-END"); -} - -/* - * Expect the root node. - */ - -static int -yaml_emitter_emit_document_content(yaml_emitter_t *emitter, - yaml_event_t *event) -{ - if (!PUSH(emitter, emitter->states, YAML_EMIT_DOCUMENT_END_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 1, 0, 0, 0); -} - -/* - * Expect DOCUMENT-END. - */ - -static int -yaml_emitter_emit_document_end(yaml_emitter_t *emitter, - yaml_event_t *event) -{ - if (event->type == YAML_DOCUMENT_END_EVENT) - { - if (!yaml_emitter_write_indent(emitter)) - return 0; - if (!event->data.document_end.implicit) { - if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) - return 0; - emitter->open_ended = 0; - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - else if (!emitter->open_ended) - emitter->open_ended = 1; - if (!yaml_emitter_flush(emitter)) - return 0; - - emitter->state = YAML_EMIT_DOCUMENT_START_STATE; - - while (!STACK_EMPTY(emitter, emitter->tag_directives)) { - yaml_tag_directive_t tag_directive = POP(emitter, - emitter->tag_directives); - yaml_free(tag_directive.handle); - yaml_free(tag_directive.prefix); - } - - return 1; - } - - return yaml_emitter_set_emitter_error(emitter, - "expected DOCUMENT-END"); -} - -/* - * - * Expect a flow item node. - */ - -static int -yaml_emitter_emit_flow_sequence_item(yaml_emitter_t *emitter, - yaml_event_t *event, int first) -{ - if (first) - { - if (!yaml_emitter_write_indicator(emitter, "[", 1, 1, 0)) - return 0; - if (!yaml_emitter_increase_indent(emitter, 1, 0)) - return 0; - emitter->flow_level ++; - } - - if (event->type == YAML_SEQUENCE_END_EVENT) - { - emitter->flow_level --; - emitter->indent = POP(emitter, emitter->indents); - if (emitter->canonical && !first) { - if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) - return 0; - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - if (!yaml_emitter_write_indicator(emitter, "]", 0, 0, 0)) - return 0; - emitter->state = POP(emitter, emitter->states); - - return 1; - } - - if (!first) { - if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) - return 0; - } - - if (emitter->canonical || emitter->column > emitter->best_width) { - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - if (!PUSH(emitter, emitter->states, YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 1, 0, 0); -} - -/* - * Expect a flow key node. - */ - -static int -yaml_emitter_emit_flow_mapping_key(yaml_emitter_t *emitter, - yaml_event_t *event, int first) -{ - if (first) - { - if (!yaml_emitter_write_indicator(emitter, "{", 1, 1, 0)) - return 0; - if (!yaml_emitter_increase_indent(emitter, 1, 0)) - return 0; - emitter->flow_level ++; - } - - if (event->type == YAML_MAPPING_END_EVENT) - { - emitter->flow_level --; - emitter->indent = POP(emitter, emitter->indents); - if (emitter->canonical && !first) { - if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) - return 0; - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - if (!yaml_emitter_write_indicator(emitter, "}", 0, 0, 0)) - return 0; - emitter->state = POP(emitter, emitter->states); - - return 1; - } - - if (!first) { - if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) - return 0; - } - if (emitter->canonical || emitter->column > emitter->best_width) { - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - - if (!emitter->canonical && yaml_emitter_check_simple_key(emitter)) - { - if (!PUSH(emitter, emitter->states, - YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 1); - } - else - { - if (!yaml_emitter_write_indicator(emitter, "?", 1, 0, 0)) - return 0; - if (!PUSH(emitter, emitter->states, - YAML_EMIT_FLOW_MAPPING_VALUE_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 0); - } -} - -/* - * Expect a flow value node. - */ - -static int -yaml_emitter_emit_flow_mapping_value(yaml_emitter_t *emitter, - yaml_event_t *event, int simple) -{ - if (simple) { - if (!yaml_emitter_write_indicator(emitter, ":", 0, 0, 0)) - return 0; - } - else { - if (emitter->canonical || emitter->column > emitter->best_width) { - if (!yaml_emitter_write_indent(emitter)) - return 0; - } - if (!yaml_emitter_write_indicator(emitter, ":", 1, 0, 0)) - return 0; - } - if (!PUSH(emitter, emitter->states, YAML_EMIT_FLOW_MAPPING_KEY_STATE)) - return 0; - return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 0); -} - -/* - * Expect a block item node. - */ - -static int -yaml_emitter_emit_block_sequence_item(yaml_emitter_t *emitter, - yaml_event_t *event, int first) -{ - if (first) - { - if (!yaml_emitter_increase_indent(emitter, 0, - (emitter->mapping_context && !emitter->indention))) - return 0; - } - - if (event->type == YAML_SEQUENCE_END_EVENT) - { - emitter->indent = POP(emitter, emitter->indents); - emitter->state = POP(emitter, emitter->states); - - return 1; - } - - if (!yaml_emitter_write_indent(emitter)) - return 0; - if (!yaml_emitter_write_indicator(emitter, "-", 1, 0, 1)) - return 0; - if (!PUSH(emitter, emitter->states, - YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 1, 0, 0); -} - -/* - * Expect a block key node. - */ - -static int -yaml_emitter_emit_block_mapping_key(yaml_emitter_t *emitter, - yaml_event_t *event, int first) -{ - if (first) - { - if (!yaml_emitter_increase_indent(emitter, 0, 0)) - return 0; - } - - if (event->type == YAML_MAPPING_END_EVENT) - { - emitter->indent = POP(emitter, emitter->indents); - emitter->state = POP(emitter, emitter->states); - - return 1; - } - - if (!yaml_emitter_write_indent(emitter)) - return 0; - - if (yaml_emitter_check_simple_key(emitter)) - { - if (!PUSH(emitter, emitter->states, - YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 1); - } - else - { - if (!yaml_emitter_write_indicator(emitter, "?", 1, 0, 1)) - return 0; - if (!PUSH(emitter, emitter->states, - YAML_EMIT_BLOCK_MAPPING_VALUE_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 0); - } -} - -/* - * Expect a block value node. - */ - -static int -yaml_emitter_emit_block_mapping_value(yaml_emitter_t *emitter, - yaml_event_t *event, int simple) -{ - if (simple) { - if (!yaml_emitter_write_indicator(emitter, ":", 0, 0, 0)) - return 0; - } - else { - if (!yaml_emitter_write_indent(emitter)) - return 0; - if (!yaml_emitter_write_indicator(emitter, ":", 1, 0, 1)) - return 0; - } - if (!PUSH(emitter, emitter->states, - YAML_EMIT_BLOCK_MAPPING_KEY_STATE)) - return 0; - - return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 0); -} - -/* - * Expect a node. - */ - -static int -yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, - int root, int sequence, int mapping, int simple_key) -{ - emitter->root_context = root; - emitter->sequence_context = sequence; - emitter->mapping_context = mapping; - emitter->simple_key_context = simple_key; - - switch (event->type) - { - case YAML_ALIAS_EVENT: - return yaml_emitter_emit_alias(emitter, event); - - case YAML_SCALAR_EVENT: - return yaml_emitter_emit_scalar(emitter, event); - - case YAML_SEQUENCE_START_EVENT: - return yaml_emitter_emit_sequence_start(emitter, event); - - case YAML_MAPPING_START_EVENT: - return yaml_emitter_emit_mapping_start(emitter, event); - - default: - return yaml_emitter_set_emitter_error(emitter, - "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"); - } - - return 0; -} - -/* - * Expect ALIAS. - */ - -static int -yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event)) -{ - if (!yaml_emitter_process_anchor(emitter)) - return 0; - if (emitter->simple_key_context) - if (!PUT(emitter, ' ')) return 0; - emitter->state = POP(emitter, emitter->states); - - return 1; -} - -/* - * Expect SCALAR. - */ - -static int -yaml_emitter_emit_scalar(yaml_emitter_t *emitter, yaml_event_t *event) -{ - if (!yaml_emitter_select_scalar_style(emitter, event)) - return 0; - if (!yaml_emitter_process_anchor(emitter)) - return 0; - if (!yaml_emitter_process_tag(emitter)) - return 0; - if (!yaml_emitter_increase_indent(emitter, 1, 0)) - return 0; - if (!yaml_emitter_process_scalar(emitter)) - return 0; - emitter->indent = POP(emitter, emitter->indents); - emitter->state = POP(emitter, emitter->states); - - return 1; -} - -/* - * Expect SEQUENCE-START. - */ - -static int -yaml_emitter_emit_sequence_start(yaml_emitter_t *emitter, yaml_event_t *event) -{ - if (!yaml_emitter_process_anchor(emitter)) - return 0; - if (!yaml_emitter_process_tag(emitter)) - return 0; - - if (emitter->flow_level || emitter->canonical - || event->data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE - || yaml_emitter_check_empty_sequence(emitter)) { - emitter->state = YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE; - } - else { - emitter->state = YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE; - } - - return 1; -} - -/* - * Expect MAPPING-START. - */ - -static int -yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter, yaml_event_t *event) -{ - if (!yaml_emitter_process_anchor(emitter)) - return 0; - if (!yaml_emitter_process_tag(emitter)) - return 0; - - if (emitter->flow_level || emitter->canonical - || event->data.mapping_start.style == YAML_FLOW_MAPPING_STYLE - || yaml_emitter_check_empty_mapping(emitter)) { - emitter->state = YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE; - } - else { - emitter->state = YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE; - } - - return 1; -} - -/* - * Check if the document content is an empty scalar. - */ - -static int -yaml_emitter_check_empty_document(SHIM(yaml_emitter_t *emitter)) -{ - return 0; -} - -/* - * Check if the next events represent an empty sequence. - */ - -static int -yaml_emitter_check_empty_sequence(yaml_emitter_t *emitter) -{ - if (emitter->events.tail - emitter->events.head < 2) - return 0; - - return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT - && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); -} - -/* - * Check if the next events represent an empty mapping. - */ - -static int -yaml_emitter_check_empty_mapping(yaml_emitter_t *emitter) -{ - if (emitter->events.tail - emitter->events.head < 2) - return 0; - - return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT - && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); -} - -/* - * Check if the next node can be expressed as a simple key. - */ - -static int -yaml_emitter_check_simple_key(yaml_emitter_t *emitter) -{ - yaml_event_t *event = emitter->events.head; - size_t length = 0; - - switch (event->type) - { - case YAML_ALIAS_EVENT: - length += emitter->anchor_data.anchor_length; - break; - - case YAML_SCALAR_EVENT: - if (emitter->scalar_data.multiline) - return 0; - length += emitter->anchor_data.anchor_length - + emitter->tag_data.handle_length - + emitter->tag_data.suffix_length - + emitter->scalar_data.length; - break; - - case YAML_SEQUENCE_START_EVENT: - if (!yaml_emitter_check_empty_sequence(emitter)) - return 0; - length += emitter->anchor_data.anchor_length - + emitter->tag_data.handle_length - + emitter->tag_data.suffix_length; - break; - - case YAML_MAPPING_START_EVENT: - if (!yaml_emitter_check_empty_mapping(emitter)) - return 0; - length += emitter->anchor_data.anchor_length - + emitter->tag_data.handle_length - + emitter->tag_data.suffix_length; - break; - - default: - return 0; - } - - if (length > 128) - return 0; - - return 1; -} - -/* - * Determine an acceptable scalar style. - */ - -static int -yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event) -{ - yaml_scalar_style_t style = event->data.scalar.style; - int no_tag = (!emitter->tag_data.handle && !emitter->tag_data.suffix); - - if (no_tag && !event->data.scalar.plain_implicit - && !event->data.scalar.quoted_implicit) { - return yaml_emitter_set_emitter_error(emitter, - "neither tag nor implicit flags are specified"); - } - - if (style == YAML_ANY_SCALAR_STYLE) - style = YAML_PLAIN_SCALAR_STYLE; - - if (emitter->canonical) - style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; - - if (emitter->simple_key_context && emitter->scalar_data.multiline) - style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; - - if (style == YAML_PLAIN_SCALAR_STYLE) - { - if ((emitter->flow_level && !emitter->scalar_data.flow_plain_allowed) - || (!emitter->flow_level && !emitter->scalar_data.block_plain_allowed)) - style = YAML_SINGLE_QUOTED_SCALAR_STYLE; - if (!emitter->scalar_data.length - && (emitter->flow_level || emitter->simple_key_context)) - style = YAML_SINGLE_QUOTED_SCALAR_STYLE; - if (no_tag && !event->data.scalar.plain_implicit) - style = YAML_SINGLE_QUOTED_SCALAR_STYLE; - } - - if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) - { - if (!emitter->scalar_data.single_quoted_allowed) - style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; - } - - if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) - { - if (!emitter->scalar_data.block_allowed - || emitter->flow_level || emitter->simple_key_context) - style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; - } - - if (no_tag && !event->data.scalar.quoted_implicit - && style != YAML_PLAIN_SCALAR_STYLE) - { - emitter->tag_data.handle = (yaml_char_t *)"!"; - emitter->tag_data.handle_length = 1; - } - - emitter->scalar_data.style = style; - - return 1; -} - -/* - * Write an anchor. - */ - -static int -yaml_emitter_process_anchor(yaml_emitter_t *emitter) -{ - if (!emitter->anchor_data.anchor) - return 1; - - if (!yaml_emitter_write_indicator(emitter, - (emitter->anchor_data.alias ? "*" : "&"), 1, 0, 0)) - return 0; - - return yaml_emitter_write_anchor(emitter, - emitter->anchor_data.anchor, emitter->anchor_data.anchor_length); -} - -/* - * Write a tag. - */ - -static int -yaml_emitter_process_tag(yaml_emitter_t *emitter) -{ - if (!emitter->tag_data.handle && !emitter->tag_data.suffix) - return 1; - - if (emitter->tag_data.handle) - { - if (!yaml_emitter_write_tag_handle(emitter, emitter->tag_data.handle, - emitter->tag_data.handle_length)) - return 0; - if (emitter->tag_data.suffix) { - if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix, - emitter->tag_data.suffix_length, 0)) - return 0; - } - } - else - { - if (!yaml_emitter_write_indicator(emitter, "!<", 1, 0, 0)) - return 0; - if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix, - emitter->tag_data.suffix_length, 0)) - return 0; - if (!yaml_emitter_write_indicator(emitter, ">", 0, 0, 0)) - return 0; - } - - return 1; -} - -/* - * Write a scalar. - */ - -static int -yaml_emitter_process_scalar(yaml_emitter_t *emitter) -{ - switch (emitter->scalar_data.style) - { - case YAML_PLAIN_SCALAR_STYLE: - return yaml_emitter_write_plain_scalar(emitter, - emitter->scalar_data.value, emitter->scalar_data.length, - !emitter->simple_key_context); - - case YAML_SINGLE_QUOTED_SCALAR_STYLE: - return yaml_emitter_write_single_quoted_scalar(emitter, - emitter->scalar_data.value, emitter->scalar_data.length, - !emitter->simple_key_context); - - case YAML_DOUBLE_QUOTED_SCALAR_STYLE: - return yaml_emitter_write_double_quoted_scalar(emitter, - emitter->scalar_data.value, emitter->scalar_data.length, - !emitter->simple_key_context); - - case YAML_LITERAL_SCALAR_STYLE: - return yaml_emitter_write_literal_scalar(emitter, - emitter->scalar_data.value, emitter->scalar_data.length); - - case YAML_FOLDED_SCALAR_STYLE: - return yaml_emitter_write_folded_scalar(emitter, - emitter->scalar_data.value, emitter->scalar_data.length); - - default: - assert(1); /* Impossible. */ - } - - return 0; -} - -/* - * Check if a %YAML directive is valid. - */ - -static int -yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter, - yaml_version_directive_t version_directive) -{ - if (version_directive.major != 1 || ( - version_directive.minor != 1 - && version_directive.minor != 2 - )) { - return yaml_emitter_set_emitter_error(emitter, - "incompatible %YAML directive"); - } - - return 1; -} - -/* - * Check if a %TAG directive is valid. - */ - -static int -yaml_emitter_analyze_tag_directive(yaml_emitter_t *emitter, - yaml_tag_directive_t tag_directive) -{ - yaml_string_t handle; - yaml_string_t prefix; - size_t handle_length; - size_t prefix_length; - - handle_length = strlen((char *)tag_directive.handle); - prefix_length = strlen((char *)tag_directive.prefix); - STRING_ASSIGN(handle, tag_directive.handle, handle_length); - STRING_ASSIGN(prefix, tag_directive.prefix, prefix_length); - - if (handle.start == handle.end) { - return yaml_emitter_set_emitter_error(emitter, - "tag handle must not be empty"); - } - - if (handle.start[0] != '!') { - return yaml_emitter_set_emitter_error(emitter, - "tag handle must start with '!'"); - } - - if (handle.end[-1] != '!') { - return yaml_emitter_set_emitter_error(emitter, - "tag handle must end with '!'"); - } - - handle.pointer ++; - - while (handle.pointer < handle.end-1) { - if (!IS_ALPHA(handle)) { - return yaml_emitter_set_emitter_error(emitter, - "tag handle must contain alphanumerical characters only"); - } - MOVE(handle); - } - - if (prefix.start == prefix.end) { - return yaml_emitter_set_emitter_error(emitter, - "tag prefix must not be empty"); - } - - return 1; -} - -/* - * Check if an anchor is valid. - */ - -static int -yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, - yaml_char_t *anchor, int alias) -{ - size_t anchor_length; - yaml_string_t string; - - anchor_length = strlen((char *)anchor); - STRING_ASSIGN(string, anchor, anchor_length); - - if (string.start == string.end) { - return yaml_emitter_set_emitter_error(emitter, alias ? - "alias value must not be empty" : - "anchor value must not be empty"); - } - - while (string.pointer != string.end) { - if (!IS_ALPHA(string)) { - return yaml_emitter_set_emitter_error(emitter, alias ? - "alias value must contain alphanumerical characters only" : - "anchor value must contain alphanumerical characters only"); - } - MOVE(string); - } - - emitter->anchor_data.anchor = string.start; - emitter->anchor_data.anchor_length = string.end - string.start; - emitter->anchor_data.alias = alias; - - return 1; -} - -/* - * Check if a tag is valid. - */ - -static int -yaml_emitter_analyze_tag(yaml_emitter_t *emitter, - yaml_char_t *tag) -{ - size_t tag_length; - yaml_string_t string; - yaml_tag_directive_t *tag_directive; - - tag_length = strlen((char *)tag); - STRING_ASSIGN(string, tag, tag_length); - - if (string.start == string.end) { - return yaml_emitter_set_emitter_error(emitter, - "tag value must not be empty"); - } - - for (tag_directive = emitter->tag_directives.start; - tag_directive != emitter->tag_directives.top; tag_directive ++) { - size_t prefix_length = strlen((char *)tag_directive->prefix); - if (prefix_length < (size_t)(string.end - string.start) - && strncmp((char *)tag_directive->prefix, (char *)string.start, - prefix_length) == 0) - { - emitter->tag_data.handle = tag_directive->handle; - emitter->tag_data.handle_length = - strlen((char *)tag_directive->handle); - emitter->tag_data.suffix = string.start + prefix_length; - emitter->tag_data.suffix_length = - (string.end - string.start) - prefix_length; - return 1; - } - } - - emitter->tag_data.suffix = string.start; - emitter->tag_data.suffix_length = string.end - string.start; - - return 1; -} - -/* - * Check if a scalar is valid. - */ - -static int -yaml_emitter_analyze_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length) -{ - yaml_string_t string; - - int block_indicators = 0; - int flow_indicators = 0; - int line_breaks = 0; - int special_characters = 0; - - int leading_space = 0; - int leading_break = 0; - int trailing_space = 0; - int trailing_break = 0; - int break_space = 0; - int space_break = 0; - - int preceded_by_whitespace = 0; - int followed_by_whitespace = 0; - int previous_space = 0; - int previous_break = 0; - - STRING_ASSIGN(string, value, length); - - emitter->scalar_data.value = value; - emitter->scalar_data.length = length; - - if (string.start == string.end) - { - emitter->scalar_data.multiline = 0; - emitter->scalar_data.flow_plain_allowed = 0; - emitter->scalar_data.block_plain_allowed = 1; - emitter->scalar_data.single_quoted_allowed = 1; - emitter->scalar_data.block_allowed = 0; - - return 1; - } - - if ((CHECK_AT(string, '-', 0) - && CHECK_AT(string, '-', 1) - && CHECK_AT(string, '-', 2)) - || (CHECK_AT(string, '.', 0) - && CHECK_AT(string, '.', 1) - && CHECK_AT(string, '.', 2))) { - block_indicators = 1; - flow_indicators = 1; - } - - preceded_by_whitespace = 1; - followed_by_whitespace = IS_BLANKZ_AT(string, WIDTH(string)); - - while (string.pointer != string.end) - { - if (string.start == string.pointer) - { - if (CHECK(string, '#') || CHECK(string, ',') - || CHECK(string, '[') || CHECK(string, ']') - || CHECK(string, '{') || CHECK(string, '}') - || CHECK(string, '&') || CHECK(string, '*') - || CHECK(string, '!') || CHECK(string, '|') - || CHECK(string, '>') || CHECK(string, '\'') - || CHECK(string, '"') || CHECK(string, '%') - || CHECK(string, '@') || CHECK(string, '`')) { - flow_indicators = 1; - block_indicators = 1; - } - - if (CHECK(string, '?') || CHECK(string, ':')) { - flow_indicators = 1; - if (followed_by_whitespace) { - block_indicators = 1; - } - } - - if (CHECK(string, '-') && followed_by_whitespace) { - flow_indicators = 1; - block_indicators = 1; - } - } - else - { - if (CHECK(string, ',') || CHECK(string, '?') - || CHECK(string, '[') || CHECK(string, ']') - || CHECK(string, '{') || CHECK(string, '}')) { - flow_indicators = 1; - } - - if (CHECK(string, ':')) { - flow_indicators = 1; - if (followed_by_whitespace) { - block_indicators = 1; - } - } - - if (CHECK(string, '#') && preceded_by_whitespace) { - flow_indicators = 1; - block_indicators = 1; - } - } - - if (!IS_PRINTABLE(string) - || (!IS_ASCII(string) && !emitter->unicode)) { - special_characters = 1; - } - - if (IS_BREAK(string)) { - line_breaks = 1; - } - - if (IS_SPACE(string)) - { - if (string.start == string.pointer) { - leading_space = 1; - } - if (string.pointer+WIDTH(string) == string.end) { - trailing_space = 1; - } - if (previous_break) { - break_space = 1; - } - previous_space = 1; - previous_break = 0; - } - else if (IS_BREAK(string)) - { - if (string.start == string.pointer) { - leading_break = 1; - } - if (string.pointer+WIDTH(string) == string.end) { - trailing_break = 1; - } - if (previous_space) { - space_break = 1; - } - previous_space = 0; - previous_break = 1; - } - else - { - previous_space = 0; - previous_break = 0; - } - - preceded_by_whitespace = IS_BLANKZ(string); - MOVE(string); - if (string.pointer != string.end) { - followed_by_whitespace = IS_BLANKZ_AT(string, WIDTH(string)); - } - } - - emitter->scalar_data.multiline = line_breaks; - - emitter->scalar_data.flow_plain_allowed = 1; - emitter->scalar_data.block_plain_allowed = 1; - emitter->scalar_data.single_quoted_allowed = 1; - emitter->scalar_data.block_allowed = 1; - - if (leading_space || leading_break || trailing_space || trailing_break) { - emitter->scalar_data.flow_plain_allowed = 0; - emitter->scalar_data.block_plain_allowed = 0; - } - - if (trailing_space) { - emitter->scalar_data.block_allowed = 0; - } - - if (break_space) { - emitter->scalar_data.flow_plain_allowed = 0; - emitter->scalar_data.block_plain_allowed = 0; - emitter->scalar_data.single_quoted_allowed = 0; - } - - if (space_break || special_characters) { - emitter->scalar_data.flow_plain_allowed = 0; - emitter->scalar_data.block_plain_allowed = 0; - emitter->scalar_data.single_quoted_allowed = 0; - emitter->scalar_data.block_allowed = 0; - } - - if (line_breaks) { - emitter->scalar_data.flow_plain_allowed = 0; - emitter->scalar_data.block_plain_allowed = 0; - } - - if (flow_indicators) { - emitter->scalar_data.flow_plain_allowed = 0; - } - - if (block_indicators) { - emitter->scalar_data.block_plain_allowed = 0; - } - - return 1; -} - -/* - * Check if the event data is valid. - */ - -static int -yaml_emitter_analyze_event(yaml_emitter_t *emitter, - yaml_event_t *event) -{ - emitter->anchor_data.anchor = NULL; - emitter->anchor_data.anchor_length = 0; - emitter->tag_data.handle = NULL; - emitter->tag_data.handle_length = 0; - emitter->tag_data.suffix = NULL; - emitter->tag_data.suffix_length = 0; - emitter->scalar_data.value = NULL; - emitter->scalar_data.length = 0; - - switch (event->type) - { - case YAML_ALIAS_EVENT: - if (!yaml_emitter_analyze_anchor(emitter, - event->data.alias.anchor, 1)) - return 0; - return 1; - - case YAML_SCALAR_EVENT: - if (event->data.scalar.anchor) { - if (!yaml_emitter_analyze_anchor(emitter, - event->data.scalar.anchor, 0)) - return 0; - } - if (event->data.scalar.tag && (emitter->canonical || - (!event->data.scalar.plain_implicit - && !event->data.scalar.quoted_implicit))) { - if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) - return 0; - } - if (!yaml_emitter_analyze_scalar(emitter, - event->data.scalar.value, event->data.scalar.length)) - return 0; - return 1; - - case YAML_SEQUENCE_START_EVENT: - if (event->data.sequence_start.anchor) { - if (!yaml_emitter_analyze_anchor(emitter, - event->data.sequence_start.anchor, 0)) - return 0; - } - if (event->data.sequence_start.tag && (emitter->canonical || - !event->data.sequence_start.implicit)) { - if (!yaml_emitter_analyze_tag(emitter, - event->data.sequence_start.tag)) - return 0; - } - return 1; - - case YAML_MAPPING_START_EVENT: - if (event->data.mapping_start.anchor) { - if (!yaml_emitter_analyze_anchor(emitter, - event->data.mapping_start.anchor, 0)) - return 0; - } - if (event->data.mapping_start.tag && (emitter->canonical || - !event->data.mapping_start.implicit)) { - if (!yaml_emitter_analyze_tag(emitter, - event->data.mapping_start.tag)) - return 0; - } - return 1; - - default: - return 1; - } -} - -/* - * Write the BOM character. - */ - -static int -yaml_emitter_write_bom(yaml_emitter_t *emitter) -{ - if (!FLUSH(emitter)) return 0; - - *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF'; - *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB'; - *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF'; - - return 1; -} - -static int -yaml_emitter_write_indent(yaml_emitter_t *emitter) -{ - int indent = (emitter->indent >= 0) ? emitter->indent : 0; - - if (!emitter->indention || emitter->column > indent - || (emitter->column == indent && !emitter->whitespace)) { - if (!PUT_BREAK(emitter)) return 0; - } - - while (emitter->column < indent) { - if (!PUT(emitter, ' ')) return 0; - } - - emitter->whitespace = 1; - emitter->indention = 1; - - return 1; -} - -static int -yaml_emitter_write_indicator(yaml_emitter_t *emitter, - const char *indicator, int need_whitespace, - int is_whitespace, int is_indention) -{ - size_t indicator_length; - yaml_string_t string; - - indicator_length = strlen(indicator); - STRING_ASSIGN(string, (yaml_char_t *)indicator, indicator_length); - - if (need_whitespace && !emitter->whitespace) { - if (!PUT(emitter, ' ')) return 0; - } - - while (string.pointer != string.end) { - if (!WRITE(emitter, string)) return 0; - } - - emitter->whitespace = is_whitespace; - emitter->indention = (emitter->indention && is_indention); - - return 1; -} - -static int -yaml_emitter_write_anchor(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length) -{ - yaml_string_t string; - STRING_ASSIGN(string, value, length); - - while (string.pointer != string.end) { - if (!WRITE(emitter, string)) return 0; - } - - emitter->whitespace = 0; - emitter->indention = 0; - - return 1; -} - -static int -yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length) -{ - yaml_string_t string; - STRING_ASSIGN(string, value, length); - - if (!emitter->whitespace) { - if (!PUT(emitter, ' ')) return 0; - } - - while (string.pointer != string.end) { - if (!WRITE(emitter, string)) return 0; - } - - emitter->whitespace = 0; - emitter->indention = 0; - - return 1; -} - -static int -yaml_emitter_write_tag_content(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, - int need_whitespace) -{ - yaml_string_t string; - STRING_ASSIGN(string, value, length); - - if (need_whitespace && !emitter->whitespace) { - if (!PUT(emitter, ' ')) return 0; - } - - while (string.pointer != string.end) { - if (IS_ALPHA(string) - || CHECK(string, ';') || CHECK(string, '/') - || CHECK(string, '?') || CHECK(string, ':') - || CHECK(string, '@') || CHECK(string, '&') - || CHECK(string, '=') || CHECK(string, '+') - || CHECK(string, '$') || CHECK(string, ',') - || CHECK(string, '_') || CHECK(string, '.') - || CHECK(string, '~') || CHECK(string, '*') - || CHECK(string, '\'') || CHECK(string, '(') - || CHECK(string, ')') || CHECK(string, '[') - || CHECK(string, ']')) { - if (!WRITE(emitter, string)) return 0; - } - else { - int width = WIDTH(string); - unsigned int value; - while (width --) { - value = *(string.pointer++); - if (!PUT(emitter, '%')) return 0; - if (!PUT(emitter, (value >> 4) - + ((value >> 4) < 10 ? '0' : 'A' - 10))) - return 0; - if (!PUT(emitter, (value & 0x0F) - + ((value & 0x0F) < 10 ? '0' : 'A' - 10))) - return 0; - } - } - } - - emitter->whitespace = 0; - emitter->indention = 0; - - return 1; -} - -static int -yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int allow_breaks) -{ - yaml_string_t string; - int spaces = 0; - int breaks = 0; - - STRING_ASSIGN(string, value, length); - - /** - * Avoid trailing spaces for empty values in block mode. - * In flow mode, we still want the space to prevent ambiguous things - * like {a:}. - * Currently, the emitter forbids any plain empty scalar in flow mode - * (e.g. it outputs {a: ''} instead), so emitter->flow_level will - * never be true here. - * But if the emitter is ever changed to allow emitting empty values, - * the check for flow_level is already here. - */ - if (!emitter->whitespace && (length || emitter->flow_level)) { - if (!PUT(emitter, ' ')) return 0; - } - - while (string.pointer != string.end) - { - if (IS_SPACE(string)) - { - if (allow_breaks && !spaces - && emitter->column > emitter->best_width - && !IS_SPACE_AT(string, 1)) { - if (!yaml_emitter_write_indent(emitter)) return 0; - MOVE(string); - } - else { - if (!WRITE(emitter, string)) return 0; - } - spaces = 1; - } - else if (IS_BREAK(string)) - { - if (!breaks && CHECK(string, '\n')) { - if (!PUT_BREAK(emitter)) return 0; - } - if (!WRITE_BREAK(emitter, string)) return 0; - emitter->indention = 1; - breaks = 1; - } - else - { - if (breaks) { - if (!yaml_emitter_write_indent(emitter)) return 0; - } - if (!WRITE(emitter, string)) return 0; - emitter->indention = 0; - spaces = 0; - breaks = 0; - } - } - - emitter->whitespace = 0; - emitter->indention = 0; - - return 1; -} - -static int -yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int allow_breaks) -{ - yaml_string_t string; - int spaces = 0; - int breaks = 0; - - STRING_ASSIGN(string, value, length); - - if (!yaml_emitter_write_indicator(emitter, "'", 1, 0, 0)) - return 0; - - while (string.pointer != string.end) - { - if (IS_SPACE(string)) - { - if (allow_breaks && !spaces - && emitter->column > emitter->best_width - && string.pointer != string.start - && string.pointer != string.end - 1 - && !IS_SPACE_AT(string, 1)) { - if (!yaml_emitter_write_indent(emitter)) return 0; - MOVE(string); - } - else { - if (!WRITE(emitter, string)) return 0; - } - spaces = 1; - } - else if (IS_BREAK(string)) - { - if (!breaks && CHECK(string, '\n')) { - if (!PUT_BREAK(emitter)) return 0; - } - if (!WRITE_BREAK(emitter, string)) return 0; - emitter->indention = 1; - breaks = 1; - } - else - { - if (breaks) { - if (!yaml_emitter_write_indent(emitter)) return 0; - } - if (CHECK(string, '\'')) { - if (!PUT(emitter, '\'')) return 0; - } - if (!WRITE(emitter, string)) return 0; - emitter->indention = 0; - spaces = 0; - breaks = 0; - } - } - - if (breaks) - if (!yaml_emitter_write_indent(emitter)) return 0; - - if (!yaml_emitter_write_indicator(emitter, "'", 0, 0, 0)) - return 0; - - emitter->whitespace = 0; - emitter->indention = 0; - - return 1; -} - -static int -yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length, int allow_breaks) -{ - yaml_string_t string; - int spaces = 0; - - STRING_ASSIGN(string, value, length); - - if (!yaml_emitter_write_indicator(emitter, "\"", 1, 0, 0)) - return 0; - - while (string.pointer != string.end) - { - if (!IS_PRINTABLE(string) || (!emitter->unicode && !IS_ASCII(string)) - || IS_BOM(string) || IS_BREAK(string) - || CHECK(string, '"') || CHECK(string, '\\')) - { - unsigned char octet; - unsigned int width; - unsigned int value; - int k; - - octet = string.pointer[0]; - width = (octet & 0x80) == 0x00 ? 1 : - (octet & 0xE0) == 0xC0 ? 2 : - (octet & 0xF0) == 0xE0 ? 3 : - (octet & 0xF8) == 0xF0 ? 4 : 0; - value = (octet & 0x80) == 0x00 ? octet & 0x7F : - (octet & 0xE0) == 0xC0 ? octet & 0x1F : - (octet & 0xF0) == 0xE0 ? octet & 0x0F : - (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; - for (k = 1; k < (int)width; k ++) { - octet = string.pointer[k]; - value = (value << 6) + (octet & 0x3F); - } - string.pointer += width; - - if (!PUT(emitter, '\\')) return 0; - - switch (value) - { - case 0x00: - if (!PUT(emitter, '0')) return 0; - break; - - case 0x07: - if (!PUT(emitter, 'a')) return 0; - break; - - case 0x08: - if (!PUT(emitter, 'b')) return 0; - break; - - case 0x09: - if (!PUT(emitter, 't')) return 0; - break; - - case 0x0A: - if (!PUT(emitter, 'n')) return 0; - break; - - case 0x0B: - if (!PUT(emitter, 'v')) return 0; - break; - - case 0x0C: - if (!PUT(emitter, 'f')) return 0; - break; - - case 0x0D: - if (!PUT(emitter, 'r')) return 0; - break; - - case 0x1B: - if (!PUT(emitter, 'e')) return 0; - break; - - case 0x22: - if (!PUT(emitter, '\"')) return 0; - break; - - case 0x5C: - if (!PUT(emitter, '\\')) return 0; - break; - - case 0x85: - if (!PUT(emitter, 'N')) return 0; - break; - - case 0xA0: - if (!PUT(emitter, '_')) return 0; - break; - - case 0x2028: - if (!PUT(emitter, 'L')) return 0; - break; - - case 0x2029: - if (!PUT(emitter, 'P')) return 0; - break; - - default: - if (value <= 0xFF) { - if (!PUT(emitter, 'x')) return 0; - width = 2; - } - else if (value <= 0xFFFF) { - if (!PUT(emitter, 'u')) return 0; - width = 4; - } - else { - if (!PUT(emitter, 'U')) return 0; - width = 8; - } - for (k = (width-1)*4; k >= 0; k -= 4) { - int digit = (value >> k) & 0x0F; - if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) - return 0; - } - } - spaces = 0; - } - else if (IS_SPACE(string)) - { - if (allow_breaks && !spaces - && emitter->column > emitter->best_width - && string.pointer != string.start - && string.pointer != string.end - 1) { - if (!yaml_emitter_write_indent(emitter)) return 0; - if (IS_SPACE_AT(string, 1)) { - if (!PUT(emitter, '\\')) return 0; - } - MOVE(string); - } - else { - if (!WRITE(emitter, string)) return 0; - } - spaces = 1; - } - else - { - if (!WRITE(emitter, string)) return 0; - spaces = 0; - } - } - - if (!yaml_emitter_write_indicator(emitter, "\"", 0, 0, 0)) - return 0; - - emitter->whitespace = 0; - emitter->indention = 0; - - return 1; -} - -static int -yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, - yaml_string_t string) -{ - char indent_hint[2]; - const char *chomp_hint = NULL; - - if (IS_SPACE(string) || IS_BREAK(string)) - { - indent_hint[0] = '0' + (char)emitter->best_indent; - indent_hint[1] = '\0'; - if (!yaml_emitter_write_indicator(emitter, indent_hint, 0, 0, 0)) - return 0; - } - - emitter->open_ended = 0; - - string.pointer = string.end; - if (string.start == string.pointer) - { - chomp_hint = "-"; - } - else - { - do { - string.pointer --; - } while ((*string.pointer & 0xC0) == 0x80); - if (!IS_BREAK(string)) - { - chomp_hint = "-"; - } - else if (string.start == string.pointer) - { - chomp_hint = "+"; - emitter->open_ended = 2; - } - else - { - do { - string.pointer --; - } while ((*string.pointer & 0xC0) == 0x80); - if (IS_BREAK(string)) - { - chomp_hint = "+"; - emitter->open_ended = 2; - } - } - } - - if (chomp_hint) - { - if (!yaml_emitter_write_indicator(emitter, chomp_hint, 0, 0, 0)) - return 0; - } - - return 1; -} - -static int -yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length) -{ - yaml_string_t string; - int breaks = 1; - - STRING_ASSIGN(string, value, length); - - if (!yaml_emitter_write_indicator(emitter, "|", 1, 0, 0)) - return 0; - if (!yaml_emitter_write_block_scalar_hints(emitter, string)) - return 0; - if (!PUT_BREAK(emitter)) return 0; - emitter->indention = 1; - emitter->whitespace = 1; - - while (string.pointer != string.end) - { - if (IS_BREAK(string)) - { - if (!WRITE_BREAK(emitter, string)) return 0; - emitter->indention = 1; - breaks = 1; - } - else - { - if (breaks) { - if (!yaml_emitter_write_indent(emitter)) return 0; - } - if (!WRITE(emitter, string)) return 0; - emitter->indention = 0; - breaks = 0; - } - } - - return 1; -} - -static int -yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, - yaml_char_t *value, size_t length) -{ - yaml_string_t string; - int breaks = 1; - int leading_spaces = 1; - - STRING_ASSIGN(string, value, length); - - if (!yaml_emitter_write_indicator(emitter, ">", 1, 0, 0)) - return 0; - if (!yaml_emitter_write_block_scalar_hints(emitter, string)) - return 0; - if (!PUT_BREAK(emitter)) return 0; - emitter->indention = 1; - emitter->whitespace = 1; - - while (string.pointer != string.end) - { - if (IS_BREAK(string)) - { - if (!breaks && !leading_spaces && CHECK(string, '\n')) { - int k = 0; - while (IS_BREAK_AT(string, k)) { - k += WIDTH_AT(string, k); - } - if (!IS_BLANKZ_AT(string, k)) { - if (!PUT_BREAK(emitter)) return 0; - } - } - if (!WRITE_BREAK(emitter, string)) return 0; - emitter->indention = 1; - breaks = 1; - } - else - { - if (breaks) { - if (!yaml_emitter_write_indent(emitter)) return 0; - leading_spaces = IS_BLANK(string); - } - if (!breaks && IS_SPACE(string) && !IS_SPACE_AT(string, 1) - && emitter->column > emitter->best_width) { - if (!yaml_emitter_write_indent(emitter)) return 0; - MOVE(string); - } - else { - if (!WRITE(emitter, string)) return 0; - } - emitter->indention = 0; - breaks = 0; - } - } - - return 1; -} diff --git a/ext/psych/yaml/loader.c b/ext/psych/yaml/loader.c deleted file mode 100644 index bcf3aee8cb..0000000000 --- a/ext/psych/yaml/loader.c +++ /dev/null @@ -1,544 +0,0 @@ - -#include "yaml_private.h" - -/* - * API functions. - */ - -YAML_DECLARE(int) -yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document); - -/* - * Error handling. - */ - -static int -yaml_parser_set_composer_error(yaml_parser_t *parser, - const char *problem, yaml_mark_t problem_mark); - -static int -yaml_parser_set_composer_error_context(yaml_parser_t *parser, - const char *context, yaml_mark_t context_mark, - const char *problem, yaml_mark_t problem_mark); - - -/* - * Alias handling. - */ - -static int -yaml_parser_register_anchor(yaml_parser_t *parser, - int index, yaml_char_t *anchor); - -/* - * Clean up functions. - */ - -static void -yaml_parser_delete_aliases(yaml_parser_t *parser); - -/* - * Document loading context. - */ -struct loader_ctx { - int *start; - int *end; - int *top; -}; - -/* - * Composer functions. - */ -static int -yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx); - -static int -yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event); - -static int -yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx); - -static int -yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx); - -static int -yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx); - -static int -yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx); - -static int -yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx); - -static int -yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx); - -/* - * Load the next document of the stream. - */ - -YAML_DECLARE(int) -yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document) -{ - yaml_event_t event; - - assert(parser); /* Non-NULL parser object is expected. */ - assert(document); /* Non-NULL document object is expected. */ - - memset(document, 0, sizeof(yaml_document_t)); - if (!STACK_INIT(parser, document->nodes, yaml_node_t*)) - goto error; - - if (!parser->stream_start_produced) { - if (!yaml_parser_parse(parser, &event)) goto error; - assert(event.type == YAML_STREAM_START_EVENT); - /* STREAM-START is expected. */ - } - - if (parser->stream_end_produced) { - return 1; - } - - if (!yaml_parser_parse(parser, &event)) goto error; - if (event.type == YAML_STREAM_END_EVENT) { - return 1; - } - - if (!STACK_INIT(parser, parser->aliases, yaml_alias_data_t*)) - goto error; - - parser->document = document; - - if (!yaml_parser_load_document(parser, &event)) goto error; - - yaml_parser_delete_aliases(parser); - parser->document = NULL; - - return 1; - -error: - - yaml_parser_delete_aliases(parser); - yaml_document_delete(document); - parser->document = NULL; - - return 0; -} - -/* - * Set composer error. - */ - -static int -yaml_parser_set_composer_error(yaml_parser_t *parser, - const char *problem, yaml_mark_t problem_mark) -{ - parser->error = YAML_COMPOSER_ERROR; - parser->problem = problem; - parser->problem_mark = problem_mark; - - return 0; -} - -/* - * Set composer error with context. - */ - -static int -yaml_parser_set_composer_error_context(yaml_parser_t *parser, - const char *context, yaml_mark_t context_mark, - const char *problem, yaml_mark_t problem_mark) -{ - parser->error = YAML_COMPOSER_ERROR; - parser->context = context; - parser->context_mark = context_mark; - parser->problem = problem; - parser->problem_mark = problem_mark; - - return 0; -} - -/* - * Delete the stack of aliases. - */ - -static void -yaml_parser_delete_aliases(yaml_parser_t *parser) -{ - while (!STACK_EMPTY(parser, parser->aliases)) { - yaml_free(POP(parser, parser->aliases).anchor); - } - STACK_DEL(parser, parser->aliases); -} - -/* - * Compose a document object. - */ - -static int -yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event) -{ - struct loader_ctx ctx = { NULL, NULL, NULL }; - - assert(event->type == YAML_DOCUMENT_START_EVENT); - /* DOCUMENT-START is expected. */ - - parser->document->version_directive - = event->data.document_start.version_directive; - parser->document->tag_directives.start - = event->data.document_start.tag_directives.start; - parser->document->tag_directives.end - = event->data.document_start.tag_directives.end; - parser->document->start_implicit - = event->data.document_start.implicit; - parser->document->start_mark = event->start_mark; - - if (!STACK_INIT(parser, ctx, int*)) return 0; - if (!yaml_parser_load_nodes(parser, &ctx)) { - STACK_DEL(parser, ctx); - return 0; - } - STACK_DEL(parser, ctx); - - return 1; -} - -/* - * Compose a node tree. - */ - -static int -yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx) -{ - yaml_event_t event; - - do { - if (!yaml_parser_parse(parser, &event)) return 0; - - switch (event.type) { - case YAML_ALIAS_EVENT: - if (!yaml_parser_load_alias(parser, &event, ctx)) return 0; - break; - case YAML_SCALAR_EVENT: - if (!yaml_parser_load_scalar(parser, &event, ctx)) return 0; - break; - case YAML_SEQUENCE_START_EVENT: - if (!yaml_parser_load_sequence(parser, &event, ctx)) return 0; - break; - case YAML_SEQUENCE_END_EVENT: - if (!yaml_parser_load_sequence_end(parser, &event, ctx)) - return 0; - break; - case YAML_MAPPING_START_EVENT: - if (!yaml_parser_load_mapping(parser, &event, ctx)) return 0; - break; - case YAML_MAPPING_END_EVENT: - if (!yaml_parser_load_mapping_end(parser, &event, ctx)) - return 0; - break; - default: - assert(0); /* Could not happen. */ - return 0; - case YAML_DOCUMENT_END_EVENT: - break; - } - } while (event.type != YAML_DOCUMENT_END_EVENT); - - parser->document->end_implicit = event.data.document_end.implicit; - parser->document->end_mark = event.end_mark; - - return 1; -} - -/* - * Add an anchor. - */ - -static int -yaml_parser_register_anchor(yaml_parser_t *parser, - int index, yaml_char_t *anchor) -{ - yaml_alias_data_t data; - yaml_alias_data_t *alias_data; - - if (!anchor) return 1; - - data.anchor = anchor; - data.index = index; - data.mark = parser->document->nodes.start[index-1].start_mark; - - for (alias_data = parser->aliases.start; - alias_data != parser->aliases.top; alias_data ++) { - if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) { - yaml_free(anchor); - return yaml_parser_set_composer_error_context(parser, - "found duplicate anchor; first occurrence", - alias_data->mark, "second occurrence", data.mark); - } - } - - if (!PUSH(parser, parser->aliases, data)) { - yaml_free(anchor); - return 0; - } - - return 1; -} - -/* - * Compose node into its parent in the stree. - */ - -static int -yaml_parser_load_node_add(yaml_parser_t *parser, struct loader_ctx *ctx, - int index) -{ - struct yaml_node_s *parent; - int parent_index; - - if (STACK_EMPTY(parser, *ctx)) { - /* This is the root node, there's no tree to add it to. */ - return 1; - } - - parent_index = *((*ctx).top - 1); - parent = &parser->document->nodes.start[parent_index-1]; - - switch (parent->type) { - case YAML_SEQUENCE_NODE: - if (!STACK_LIMIT(parser, parent->data.sequence.items, INT_MAX-1)) - return 0; - if (!PUSH(parser, parent->data.sequence.items, index)) - return 0; - break; - case YAML_MAPPING_NODE: { - yaml_node_pair_t pair; - if (!STACK_EMPTY(parser, parent->data.mapping.pairs)) { - yaml_node_pair_t *p = parent->data.mapping.pairs.top - 1; - if (p->key != 0 && p->value == 0) { - p->value = index; - break; - } - } - - pair.key = index; - pair.value = 0; - if (!STACK_LIMIT(parser, parent->data.mapping.pairs, INT_MAX-1)) - return 0; - if (!PUSH(parser, parent->data.mapping.pairs, pair)) - return 0; - - break; - } - default: - assert(0); /* Could not happen. */ - return 0; - } - return 1; -} - -/* - * Compose a node corresponding to an alias. - */ - -static int -yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx) -{ - yaml_char_t *anchor = event->data.alias.anchor; - yaml_alias_data_t *alias_data; - - for (alias_data = parser->aliases.start; - alias_data != parser->aliases.top; alias_data ++) { - if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) { - yaml_free(anchor); - return yaml_parser_load_node_add(parser, ctx, alias_data->index); - } - } - - yaml_free(anchor); - return yaml_parser_set_composer_error(parser, "found undefined alias", - event->start_mark); -} - -/* - * Compose a scalar node. - */ - -static int -yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx) -{ - yaml_node_t node; - int index; - yaml_char_t *tag = event->data.scalar.tag; - - if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; - - if (!tag || strcmp((char *)tag, "!") == 0) { - yaml_free(tag); - tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SCALAR_TAG); - if (!tag) goto error; - } - - SCALAR_NODE_INIT(node, tag, event->data.scalar.value, - event->data.scalar.length, event->data.scalar.style, - event->start_mark, event->end_mark); - - if (!PUSH(parser, parser->document->nodes, node)) goto error; - - index = (int)(parser->document->nodes.top - parser->document->nodes.start); - - if (!yaml_parser_register_anchor(parser, index, - event->data.scalar.anchor)) return 0; - - return yaml_parser_load_node_add(parser, ctx, index); - -error: - yaml_free(tag); - yaml_free(event->data.scalar.anchor); - yaml_free(event->data.scalar.value); - return 0; -} - -/* - * Compose a sequence node. - */ - -static int -yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx) -{ - yaml_node_t node; - struct { - yaml_node_item_t *start; - yaml_node_item_t *end; - yaml_node_item_t *top; - } items = { NULL, NULL, NULL }; - int index; - yaml_char_t *tag = event->data.sequence_start.tag; - - if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; - - if (!tag || strcmp((char *)tag, "!") == 0) { - yaml_free(tag); - tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG); - if (!tag) goto error; - } - - if (!STACK_INIT(parser, items, yaml_node_item_t*)) goto error; - - SEQUENCE_NODE_INIT(node, tag, items.start, items.end, - event->data.sequence_start.style, - event->start_mark, event->end_mark); - - if (!PUSH(parser, parser->document->nodes, node)) goto error; - - index = (int)(parser->document->nodes.top - parser->document->nodes.start); - - if (!yaml_parser_register_anchor(parser, index, - event->data.sequence_start.anchor)) return 0; - - if (!yaml_parser_load_node_add(parser, ctx, index)) return 0; - - if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0; - if (!PUSH(parser, *ctx, index)) return 0; - - return 1; - -error: - yaml_free(tag); - yaml_free(event->data.sequence_start.anchor); - return 0; -} - -static int -yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx) -{ - int index; - - assert(((*ctx).top - (*ctx).start) > 0); - - index = *((*ctx).top - 1); - assert(parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE); - parser->document->nodes.start[index-1].end_mark = event->end_mark; - - (void)POP(parser, *ctx); - - return 1; -} - -/* - * Compose a mapping node. - */ - -static int -yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx) -{ - yaml_node_t node; - struct { - yaml_node_pair_t *start; - yaml_node_pair_t *end; - yaml_node_pair_t *top; - } pairs = { NULL, NULL, NULL }; - int index; - yaml_char_t *tag = event->data.mapping_start.tag; - - if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; - - if (!tag || strcmp((char *)tag, "!") == 0) { - yaml_free(tag); - tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG); - if (!tag) goto error; - } - - if (!STACK_INIT(parser, pairs, yaml_node_pair_t*)) goto error; - - MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end, - event->data.mapping_start.style, - event->start_mark, event->end_mark); - - if (!PUSH(parser, parser->document->nodes, node)) goto error; - - index = (int)(parser->document->nodes.top - parser->document->nodes.start); - - if (!yaml_parser_register_anchor(parser, index, - event->data.mapping_start.anchor)) return 0; - - if (!yaml_parser_load_node_add(parser, ctx, index)) return 0; - - if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0; - if (!PUSH(parser, *ctx, index)) return 0; - - return 1; - -error: - yaml_free(tag); - yaml_free(event->data.mapping_start.anchor); - return 0; -} - -static int -yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event, - struct loader_ctx *ctx) -{ - int index; - - assert(((*ctx).top - (*ctx).start) > 0); - - index = *((*ctx).top - 1); - assert(parser->document->nodes.start[index-1].type == YAML_MAPPING_NODE); - parser->document->nodes.start[index-1].end_mark = event->end_mark; - - (void)POP(parser, *ctx); - - return 1; -} diff --git a/ext/psych/yaml/parser.c b/ext/psych/yaml/parser.c deleted file mode 100644 index ec2f8d3e05..0000000000 --- a/ext/psych/yaml/parser.c +++ /dev/null @@ -1,1375 +0,0 @@ - -/* - * The parser implements the following grammar: - * - * stream ::= STREAM-START implicit_document? explicit_document* STREAM-END - * implicit_document ::= block_node DOCUMENT-END* - * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* - * block_node_or_indentless_sequence ::= - * ALIAS - * | properties (block_content | indentless_block_sequence)? - * | block_content - * | indentless_block_sequence - * block_node ::= ALIAS - * | properties block_content? - * | block_content - * flow_node ::= ALIAS - * | properties flow_content? - * | flow_content - * properties ::= TAG ANCHOR? | ANCHOR TAG? - * block_content ::= block_collection | flow_collection | SCALAR - * flow_content ::= flow_collection | SCALAR - * block_collection ::= block_sequence | block_mapping - * flow_collection ::= flow_sequence | flow_mapping - * block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END - * indentless_sequence ::= (BLOCK-ENTRY block_node?)+ - * block_mapping ::= BLOCK-MAPPING_START - * ((KEY block_node_or_indentless_sequence?)? - * (VALUE block_node_or_indentless_sequence?)?)* - * BLOCK-END - * flow_sequence ::= FLOW-SEQUENCE-START - * (flow_sequence_entry FLOW-ENTRY)* - * flow_sequence_entry? - * FLOW-SEQUENCE-END - * flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * flow_mapping ::= FLOW-MAPPING-START - * (flow_mapping_entry FLOW-ENTRY)* - * flow_mapping_entry? - * FLOW-MAPPING-END - * flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - */ - -#include "yaml_private.h" - -/* - * Peek the next token in the token queue. - */ - -#define PEEK_TOKEN(parser) \ - ((parser->token_available || yaml_parser_fetch_more_tokens(parser)) ? \ - parser->tokens.head : NULL) - -/* - * Remove the next token from the queue (must be called after PEEK_TOKEN). - */ - -#define SKIP_TOKEN(parser) \ - (parser->token_available = 0, \ - parser->tokens_parsed ++, \ - parser->stream_end_produced = \ - (parser->tokens.head->type == YAML_STREAM_END_TOKEN), \ - parser->tokens.head ++) - -/* - * Public API declarations. - */ - -YAML_DECLARE(int) -yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event); - -/* - * Error handling. - */ - -static int -yaml_parser_set_parser_error(yaml_parser_t *parser, - const char *problem, yaml_mark_t problem_mark); - -static int -yaml_parser_set_parser_error_context(yaml_parser_t *parser, - const char *context, yaml_mark_t context_mark, - const char *problem, yaml_mark_t problem_mark); - -/* - * State functions. - */ - -static int -yaml_parser_state_machine(yaml_parser_t *parser, yaml_event_t *event); - -static int -yaml_parser_parse_stream_start(yaml_parser_t *parser, yaml_event_t *event); - -static int -yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event, - int implicit); - -static int -yaml_parser_parse_document_content(yaml_parser_t *parser, yaml_event_t *event); - -static int -yaml_parser_parse_document_end(yaml_parser_t *parser, yaml_event_t *event); - -static int -yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event, - int block, int indentless_sequence); - -static int -yaml_parser_parse_block_sequence_entry(yaml_parser_t *parser, - yaml_event_t *event, int first); - -static int -yaml_parser_parse_indentless_sequence_entry(yaml_parser_t *parser, - yaml_event_t *event); - -static int -yaml_parser_parse_block_mapping_key(yaml_parser_t *parser, - yaml_event_t *event, int first); - -static int -yaml_parser_parse_block_mapping_value(yaml_parser_t *parser, - yaml_event_t *event); - -static int -yaml_parser_parse_flow_sequence_entry(yaml_parser_t *parser, - yaml_event_t *event, int first); - -static int -yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser, - yaml_event_t *event); - -static int -yaml_parser_parse_flow_sequence_entry_mapping_value(yaml_parser_t *parser, - yaml_event_t *event); - -static int -yaml_parser_parse_flow_sequence_entry_mapping_end(yaml_parser_t *parser, - yaml_event_t *event); - -static int -yaml_parser_parse_flow_mapping_key(yaml_parser_t *parser, - yaml_event_t *event, int first); - -static int -yaml_parser_parse_flow_mapping_value(yaml_parser_t *parser, - yaml_event_t *event, int empty); - -/* - * Utility functions. - */ - -static int -yaml_parser_process_empty_scalar(yaml_parser_t *parser, - yaml_event_t *event, yaml_mark_t mark); - -static int -yaml_parser_process_directives(yaml_parser_t *parser, - yaml_version_directive_t **version_directive_ref, - yaml_tag_directive_t **tag_directives_start_ref, - yaml_tag_directive_t **tag_directives_end_ref); - -static int -yaml_parser_append_tag_directive(yaml_parser_t *parser, - yaml_tag_directive_t value, int allow_duplicates, yaml_mark_t mark); - -/* - * Get the next event. - */ - -YAML_DECLARE(int) -yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event) -{ - assert(parser); /* Non-NULL parser object is expected. */ - assert(event); /* Non-NULL event object is expected. */ - - /* Erase the event object. */ - - memset(event, 0, sizeof(yaml_event_t)); - - /* No events after the end of the stream or error. */ - - if (parser->stream_end_produced || parser->error || - parser->state == YAML_PARSE_END_STATE) { - return 1; - } - - /* Generate the next event. */ - - return yaml_parser_state_machine(parser, event); -} - -/* - * Set parser error. - */ - -static int -yaml_parser_set_parser_error(yaml_parser_t *parser, - const char *problem, yaml_mark_t problem_mark) -{ - parser->error = YAML_PARSER_ERROR; - parser->problem = problem; - parser->problem_mark = problem_mark; - - return 0; -} - -static int -yaml_parser_set_parser_error_context(yaml_parser_t *parser, - const char *context, yaml_mark_t context_mark, - const char *problem, yaml_mark_t problem_mark) -{ - parser->error = YAML_PARSER_ERROR; - parser->context = context; - parser->context_mark = context_mark; - parser->problem = problem; - parser->problem_mark = problem_mark; - - return 0; -} - - -/* - * State dispatcher. - */ - -static int -yaml_parser_state_machine(yaml_parser_t *parser, yaml_event_t *event) -{ - switch (parser->state) - { - case YAML_PARSE_STREAM_START_STATE: - return yaml_parser_parse_stream_start(parser, event); - - case YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE: - return yaml_parser_parse_document_start(parser, event, 1); - - case YAML_PARSE_DOCUMENT_START_STATE: - return yaml_parser_parse_document_start(parser, event, 0); - - case YAML_PARSE_DOCUMENT_CONTENT_STATE: - return yaml_parser_parse_document_content(parser, event); - - case YAML_PARSE_DOCUMENT_END_STATE: - return yaml_parser_parse_document_end(parser, event); - - case YAML_PARSE_BLOCK_NODE_STATE: - return yaml_parser_parse_node(parser, event, 1, 0); - - case YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: - return yaml_parser_parse_node(parser, event, 1, 1); - - case YAML_PARSE_FLOW_NODE_STATE: - return yaml_parser_parse_node(parser, event, 0, 0); - - case YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: - return yaml_parser_parse_block_sequence_entry(parser, event, 1); - - case YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_block_sequence_entry(parser, event, 0); - - case YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_indentless_sequence_entry(parser, event); - - case YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: - return yaml_parser_parse_block_mapping_key(parser, event, 1); - - case YAML_PARSE_BLOCK_MAPPING_KEY_STATE: - return yaml_parser_parse_block_mapping_key(parser, event, 0); - - case YAML_PARSE_BLOCK_MAPPING_VALUE_STATE: - return yaml_parser_parse_block_mapping_value(parser, event); - - case YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: - return yaml_parser_parse_flow_sequence_entry(parser, event, 1); - - case YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_flow_sequence_entry(parser, event, 0); - - case YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_key(parser, event); - - case YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_value(parser, event); - - case YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_end(parser, event); - - case YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: - return yaml_parser_parse_flow_mapping_key(parser, event, 1); - - case YAML_PARSE_FLOW_MAPPING_KEY_STATE: - return yaml_parser_parse_flow_mapping_key(parser, event, 0); - - case YAML_PARSE_FLOW_MAPPING_VALUE_STATE: - return yaml_parser_parse_flow_mapping_value(parser, event, 0); - - case YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: - return yaml_parser_parse_flow_mapping_value(parser, event, 1); - - default: - assert(1); /* Invalid state. */ - } - - return 0; -} - -/* - * Parse the production: - * stream ::= STREAM-START implicit_document? explicit_document* STREAM-END - * ************ - */ - -static int -yaml_parser_parse_stream_start(yaml_parser_t *parser, yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type != YAML_STREAM_START_TOKEN) { - return yaml_parser_set_parser_error(parser, - "did not find expected <stream-start>", token->start_mark); - } - - parser->state = YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE; - STREAM_START_EVENT_INIT(*event, token->data.stream_start.encoding, - token->start_mark, token->start_mark); - SKIP_TOKEN(parser); - - return 1; -} - -/* - * Parse the productions: - * implicit_document ::= block_node DOCUMENT-END* - * * - * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* - * ************************* - */ - -static int -yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event, - int implicit) -{ - yaml_token_t *token; - yaml_version_directive_t *version_directive = NULL; - struct { - yaml_tag_directive_t *start; - yaml_tag_directive_t *end; - } tag_directives = { NULL, NULL }; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - /* Parse extra document end indicators. */ - - if (!implicit) - { - while (token->type == YAML_DOCUMENT_END_TOKEN) { - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - } - } - - /* Parse an implicit document. */ - - if (implicit && token->type != YAML_VERSION_DIRECTIVE_TOKEN && - token->type != YAML_TAG_DIRECTIVE_TOKEN && - token->type != YAML_DOCUMENT_START_TOKEN && - token->type != YAML_STREAM_END_TOKEN) - { - if (!yaml_parser_process_directives(parser, NULL, NULL, NULL)) - return 0; - if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE)) - return 0; - parser->state = YAML_PARSE_BLOCK_NODE_STATE; - DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, NULL, 1, - token->start_mark, token->start_mark); - return 1; - } - - /* Parse an explicit document. */ - - else if (token->type != YAML_STREAM_END_TOKEN) - { - yaml_mark_t start_mark, end_mark; - start_mark = token->start_mark; - if (!yaml_parser_process_directives(parser, &version_directive, - &tag_directives.start, &tag_directives.end)) - return 0; - token = PEEK_TOKEN(parser); - if (!token) goto error; - if (token->type != YAML_DOCUMENT_START_TOKEN) { - yaml_parser_set_parser_error(parser, - "did not find expected <document start>", token->start_mark); - goto error; - } - if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE)) - goto error; - parser->state = YAML_PARSE_DOCUMENT_CONTENT_STATE; - end_mark = token->end_mark; - DOCUMENT_START_EVENT_INIT(*event, version_directive, - tag_directives.start, tag_directives.end, 0, - start_mark, end_mark); - SKIP_TOKEN(parser); - version_directive = NULL; - tag_directives.start = tag_directives.end = NULL; - return 1; - } - - /* Parse the stream end. */ - - else - { - parser->state = YAML_PARSE_END_STATE; - STREAM_END_EVENT_INIT(*event, token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; - } - -error: - yaml_free(version_directive); - while (tag_directives.start != tag_directives.end) { - yaml_free(tag_directives.end[-1].handle); - yaml_free(tag_directives.end[-1].prefix); - tag_directives.end --; - } - yaml_free(tag_directives.start); - return 0; -} - -/* - * Parse the productions: - * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* - * *********** - */ - -static int -yaml_parser_parse_document_content(yaml_parser_t *parser, yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_VERSION_DIRECTIVE_TOKEN || - token->type == YAML_TAG_DIRECTIVE_TOKEN || - token->type == YAML_DOCUMENT_START_TOKEN || - token->type == YAML_DOCUMENT_END_TOKEN || - token->type == YAML_STREAM_END_TOKEN) { - parser->state = POP(parser, parser->states); - return yaml_parser_process_empty_scalar(parser, event, - token->start_mark); - } - else { - return yaml_parser_parse_node(parser, event, 1, 0); - } -} - -/* - * Parse the productions: - * implicit_document ::= block_node DOCUMENT-END* - * ************* - * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* - * ************* - */ - -static int -yaml_parser_parse_document_end(yaml_parser_t *parser, yaml_event_t *event) -{ - yaml_token_t *token; - yaml_mark_t start_mark, end_mark; - int implicit = 1; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - start_mark = end_mark = token->start_mark; - - if (token->type == YAML_DOCUMENT_END_TOKEN) { - end_mark = token->end_mark; - SKIP_TOKEN(parser); - implicit = 0; - } - - while (!STACK_EMPTY(parser, parser->tag_directives)) { - yaml_tag_directive_t tag_directive = POP(parser, parser->tag_directives); - yaml_free(tag_directive.handle); - yaml_free(tag_directive.prefix); - } - - parser->state = YAML_PARSE_DOCUMENT_START_STATE; - DOCUMENT_END_EVENT_INIT(*event, implicit, start_mark, end_mark); - - return 1; -} - -/* - * Parse the productions: - * block_node_or_indentless_sequence ::= - * ALIAS - * ***** - * | properties (block_content | indentless_block_sequence)? - * ********** * - * | block_content | indentless_block_sequence - * * - * block_node ::= ALIAS - * ***** - * | properties block_content? - * ********** * - * | block_content - * * - * flow_node ::= ALIAS - * ***** - * | properties flow_content? - * ********** * - * | flow_content - * * - * properties ::= TAG ANCHOR? | ANCHOR TAG? - * ************************* - * block_content ::= block_collection | flow_collection | SCALAR - * ****** - * flow_content ::= flow_collection | SCALAR - * ****** - */ - -static int -yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event, - int block, int indentless_sequence) -{ - yaml_token_t *token; - yaml_char_t *anchor = NULL; - yaml_char_t *tag_handle = NULL; - yaml_char_t *tag_suffix = NULL; - yaml_char_t *tag = NULL; - yaml_mark_t start_mark, end_mark, tag_mark; - int implicit; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_ALIAS_TOKEN) - { - parser->state = POP(parser, parser->states); - ALIAS_EVENT_INIT(*event, token->data.alias.value, - token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; - } - - else - { - start_mark = end_mark = token->start_mark; - - if (token->type == YAML_ANCHOR_TOKEN) - { - anchor = token->data.anchor.value; - start_mark = token->start_mark; - end_mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) goto error; - if (token->type == YAML_TAG_TOKEN) - { - tag_handle = token->data.tag.handle; - tag_suffix = token->data.tag.suffix; - tag_mark = token->start_mark; - end_mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) goto error; - } - } - else if (token->type == YAML_TAG_TOKEN) - { - tag_handle = token->data.tag.handle; - tag_suffix = token->data.tag.suffix; - start_mark = tag_mark = token->start_mark; - end_mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) goto error; - if (token->type == YAML_ANCHOR_TOKEN) - { - anchor = token->data.anchor.value; - end_mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) goto error; - } - } - - if (tag_handle) { - if (!*tag_handle) { - tag = tag_suffix; - yaml_free(tag_handle); - tag_handle = tag_suffix = NULL; - } - else { - yaml_tag_directive_t *tag_directive; - for (tag_directive = parser->tag_directives.start; - tag_directive != parser->tag_directives.top; - tag_directive ++) { - if (strcmp((char *)tag_directive->handle, (char *)tag_handle) == 0) { - size_t prefix_len = strlen((char *)tag_directive->prefix); - size_t suffix_len = strlen((char *)tag_suffix); - tag = YAML_MALLOC(prefix_len+suffix_len+1); - if (!tag) { - parser->error = YAML_MEMORY_ERROR; - goto error; - } - memcpy(tag, tag_directive->prefix, prefix_len); - memcpy(tag+prefix_len, tag_suffix, suffix_len); - tag[prefix_len+suffix_len] = '\0'; - yaml_free(tag_handle); - yaml_free(tag_suffix); - tag_handle = tag_suffix = NULL; - break; - } - } - if (!tag) { - yaml_parser_set_parser_error_context(parser, - "while parsing a node", start_mark, - "found undefined tag handle", tag_mark); - goto error; - } - } - } - - implicit = (!tag || !*tag); - if (indentless_sequence && token->type == YAML_BLOCK_ENTRY_TOKEN) { - end_mark = token->end_mark; - parser->state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE; - SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit, - YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark); - return 1; - } - else { - if (token->type == YAML_SCALAR_TOKEN) { - int plain_implicit = 0; - int quoted_implicit = 0; - end_mark = token->end_mark; - if ((token->data.scalar.style == YAML_PLAIN_SCALAR_STYLE && !tag) - || (tag && strcmp((char *)tag, "!") == 0)) { - plain_implicit = 1; - } - else if (!tag) { - quoted_implicit = 1; - } - parser->state = POP(parser, parser->states); - SCALAR_EVENT_INIT(*event, anchor, tag, - token->data.scalar.value, token->data.scalar.length, - plain_implicit, quoted_implicit, - token->data.scalar.style, start_mark, end_mark); - SKIP_TOKEN(parser); - return 1; - } - else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) { - end_mark = token->end_mark; - parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE; - SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit, - YAML_FLOW_SEQUENCE_STYLE, start_mark, end_mark); - return 1; - } - else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) { - end_mark = token->end_mark; - parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE; - MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit, - YAML_FLOW_MAPPING_STYLE, start_mark, end_mark); - return 1; - } - else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) { - end_mark = token->end_mark; - parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE; - SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit, - YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark); - return 1; - } - else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) { - end_mark = token->end_mark; - parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE; - MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit, - YAML_BLOCK_MAPPING_STYLE, start_mark, end_mark); - return 1; - } - else if (anchor || tag) { - yaml_char_t *value = YAML_MALLOC(1); - if (!value) { - parser->error = YAML_MEMORY_ERROR; - goto error; - } - value[0] = '\0'; - parser->state = POP(parser, parser->states); - SCALAR_EVENT_INIT(*event, anchor, tag, value, 0, - implicit, 0, YAML_PLAIN_SCALAR_STYLE, - start_mark, end_mark); - return 1; - } - else { - yaml_parser_set_parser_error_context(parser, - (block ? "while parsing a block node" - : "while parsing a flow node"), start_mark, - "did not find expected node content", token->start_mark); - goto error; - } - } - } - -error: - yaml_free(anchor); - yaml_free(tag_handle); - yaml_free(tag_suffix); - yaml_free(tag); - - return 0; -} - -/* - * Parse the productions: - * block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END - * ******************** *********** * ********* - */ - -static int -yaml_parser_parse_block_sequence_entry(yaml_parser_t *parser, - yaml_event_t *event, int first) -{ - yaml_token_t *token; - - if (first) { - token = PEEK_TOKEN(parser); - if (!PUSH(parser, parser->marks, token->start_mark)) - return 0; - SKIP_TOKEN(parser); - } - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_BLOCK_ENTRY_TOKEN) - { - yaml_mark_t mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_BLOCK_ENTRY_TOKEN && - token->type != YAML_BLOCK_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 1, 0); - } - else { - parser->state = YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE; - return yaml_parser_process_empty_scalar(parser, event, mark); - } - } - - else if (token->type == YAML_BLOCK_END_TOKEN) - { - parser->state = POP(parser, parser->states); - (void)POP(parser, parser->marks); - SEQUENCE_END_EVENT_INIT(*event, token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; - } - - else - { - return yaml_parser_set_parser_error_context(parser, - "while parsing a block collection", POP(parser, parser->marks), - "did not find expected '-' indicator", token->start_mark); - } -} - -/* - * Parse the productions: - * indentless_sequence ::= (BLOCK-ENTRY block_node?)+ - * *********** * - */ - -static int -yaml_parser_parse_indentless_sequence_entry(yaml_parser_t *parser, - yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_BLOCK_ENTRY_TOKEN) - { - yaml_mark_t mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_BLOCK_ENTRY_TOKEN && - token->type != YAML_KEY_TOKEN && - token->type != YAML_VALUE_TOKEN && - token->type != YAML_BLOCK_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 1, 0); - } - else { - parser->state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE; - return yaml_parser_process_empty_scalar(parser, event, mark); - } - } - - else - { - parser->state = POP(parser, parser->states); - SEQUENCE_END_EVENT_INIT(*event, token->start_mark, token->start_mark); - return 1; - } -} - -/* - * Parse the productions: - * block_mapping ::= BLOCK-MAPPING_START - * ******************* - * ((KEY block_node_or_indentless_sequence?)? - * *** * - * (VALUE block_node_or_indentless_sequence?)?)* - * - * BLOCK-END - * ********* - */ - -static int -yaml_parser_parse_block_mapping_key(yaml_parser_t *parser, - yaml_event_t *event, int first) -{ - yaml_token_t *token; - - if (first) { - token = PEEK_TOKEN(parser); - if (!PUSH(parser, parser->marks, token->start_mark)) - return 0; - SKIP_TOKEN(parser); - } - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_KEY_TOKEN) - { - yaml_mark_t mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_KEY_TOKEN && - token->type != YAML_VALUE_TOKEN && - token->type != YAML_BLOCK_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_BLOCK_MAPPING_VALUE_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 1, 1); - } - else { - parser->state = YAML_PARSE_BLOCK_MAPPING_VALUE_STATE; - return yaml_parser_process_empty_scalar(parser, event, mark); - } - } - - else if (token->type == YAML_BLOCK_END_TOKEN) - { - parser->state = POP(parser, parser->states); - (void)POP(parser, parser->marks); - MAPPING_END_EVENT_INIT(*event, token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; - } - - else - { - return yaml_parser_set_parser_error_context(parser, - "while parsing a block mapping", POP(parser, parser->marks), - "did not find expected key", token->start_mark); - } -} - -/* - * Parse the productions: - * block_mapping ::= BLOCK-MAPPING_START - * - * ((KEY block_node_or_indentless_sequence?)? - * - * (VALUE block_node_or_indentless_sequence?)?)* - * ***** * - * BLOCK-END - * - */ - -static int -yaml_parser_parse_block_mapping_value(yaml_parser_t *parser, - yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_VALUE_TOKEN) - { - yaml_mark_t mark = token->end_mark; - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_KEY_TOKEN && - token->type != YAML_VALUE_TOKEN && - token->type != YAML_BLOCK_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_BLOCK_MAPPING_KEY_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 1, 1); - } - else { - parser->state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE; - return yaml_parser_process_empty_scalar(parser, event, mark); - } - } - - else - { - parser->state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE; - return yaml_parser_process_empty_scalar(parser, event, token->start_mark); - } -} - -/* - * Parse the productions: - * flow_sequence ::= FLOW-SEQUENCE-START - * ******************* - * (flow_sequence_entry FLOW-ENTRY)* - * * ********** - * flow_sequence_entry? - * * - * FLOW-SEQUENCE-END - * ***************** - * flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * * - */ - -static int -yaml_parser_parse_flow_sequence_entry(yaml_parser_t *parser, - yaml_event_t *event, int first) -{ - yaml_token_t *token; - - if (first) { - token = PEEK_TOKEN(parser); - if (!PUSH(parser, parser->marks, token->start_mark)) - return 0; - SKIP_TOKEN(parser); - } - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type != YAML_FLOW_SEQUENCE_END_TOKEN) - { - if (!first) { - if (token->type == YAML_FLOW_ENTRY_TOKEN) { - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - } - else { - return yaml_parser_set_parser_error_context(parser, - "while parsing a flow sequence", POP(parser, parser->marks), - "did not find expected ',' or ']'", token->start_mark); - } - } - - if (token->type == YAML_KEY_TOKEN) { - parser->state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE; - MAPPING_START_EVENT_INIT(*event, NULL, NULL, - 1, YAML_FLOW_MAPPING_STYLE, - token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; - } - - else if (token->type != YAML_FLOW_SEQUENCE_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 0, 0); - } - } - - parser->state = POP(parser, parser->states); - (void)POP(parser, parser->marks); - SEQUENCE_END_EVENT_INIT(*event, token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; -} - -/* - * Parse the productions: - * flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * *** * - */ - -static int -yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser, - yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type != YAML_VALUE_TOKEN && token->type != YAML_FLOW_ENTRY_TOKEN - && token->type != YAML_FLOW_SEQUENCE_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 0, 0); - } - else { - yaml_mark_t mark = token->end_mark; - SKIP_TOKEN(parser); - parser->state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE; - return yaml_parser_process_empty_scalar(parser, event, mark); - } -} - -/* - * Parse the productions: - * flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * ***** * - */ - -static int -yaml_parser_parse_flow_sequence_entry_mapping_value(yaml_parser_t *parser, - yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type == YAML_VALUE_TOKEN) { - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_FLOW_ENTRY_TOKEN - && token->type != YAML_FLOW_SEQUENCE_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 0, 0); - } - } - parser->state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE; - return yaml_parser_process_empty_scalar(parser, event, token->start_mark); -} - -/* - * Parse the productions: - * flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * * - */ - -static int -yaml_parser_parse_flow_sequence_entry_mapping_end(yaml_parser_t *parser, - yaml_event_t *event) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - parser->state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE; - - MAPPING_END_EVENT_INIT(*event, token->start_mark, token->start_mark); - return 1; -} - -/* - * Parse the productions: - * flow_mapping ::= FLOW-MAPPING-START - * ****************** - * (flow_mapping_entry FLOW-ENTRY)* - * * ********** - * flow_mapping_entry? - * ****************** - * FLOW-MAPPING-END - * **************** - * flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * * *** * - */ - -static int -yaml_parser_parse_flow_mapping_key(yaml_parser_t *parser, - yaml_event_t *event, int first) -{ - yaml_token_t *token; - - if (first) { - token = PEEK_TOKEN(parser); - if (!PUSH(parser, parser->marks, token->start_mark)) - return 0; - SKIP_TOKEN(parser); - } - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (token->type != YAML_FLOW_MAPPING_END_TOKEN) - { - if (!first) { - if (token->type == YAML_FLOW_ENTRY_TOKEN) { - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - } - else { - return yaml_parser_set_parser_error_context(parser, - "while parsing a flow mapping", POP(parser, parser->marks), - "did not find expected ',' or '}'", token->start_mark); - } - } - - if (token->type == YAML_KEY_TOKEN) { - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_VALUE_TOKEN - && token->type != YAML_FLOW_ENTRY_TOKEN - && token->type != YAML_FLOW_MAPPING_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_FLOW_MAPPING_VALUE_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 0, 0); - } - else { - parser->state = YAML_PARSE_FLOW_MAPPING_VALUE_STATE; - return yaml_parser_process_empty_scalar(parser, event, - token->start_mark); - } - } - else if (token->type != YAML_FLOW_MAPPING_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 0, 0); - } - } - - parser->state = POP(parser, parser->states); - (void)POP(parser, parser->marks); - MAPPING_END_EVENT_INIT(*event, token->start_mark, token->end_mark); - SKIP_TOKEN(parser); - return 1; -} - -/* - * Parse the productions: - * flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - * * ***** * - */ - -static int -yaml_parser_parse_flow_mapping_value(yaml_parser_t *parser, - yaml_event_t *event, int empty) -{ - yaml_token_t *token; - - token = PEEK_TOKEN(parser); - if (!token) return 0; - - if (empty) { - parser->state = YAML_PARSE_FLOW_MAPPING_KEY_STATE; - return yaml_parser_process_empty_scalar(parser, event, - token->start_mark); - } - - if (token->type == YAML_VALUE_TOKEN) { - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) return 0; - if (token->type != YAML_FLOW_ENTRY_TOKEN - && token->type != YAML_FLOW_MAPPING_END_TOKEN) { - if (!PUSH(parser, parser->states, - YAML_PARSE_FLOW_MAPPING_KEY_STATE)) - return 0; - return yaml_parser_parse_node(parser, event, 0, 0); - } - } - - parser->state = YAML_PARSE_FLOW_MAPPING_KEY_STATE; - return yaml_parser_process_empty_scalar(parser, event, token->start_mark); -} - -/* - * Generate an empty scalar event. - */ - -static int -yaml_parser_process_empty_scalar(yaml_parser_t *parser, yaml_event_t *event, - yaml_mark_t mark) -{ - yaml_char_t *value; - - value = YAML_MALLOC(1); - if (!value) { - parser->error = YAML_MEMORY_ERROR; - return 0; - } - value[0] = '\0'; - - SCALAR_EVENT_INIT(*event, NULL, NULL, value, 0, - 1, 0, YAML_PLAIN_SCALAR_STYLE, mark, mark); - - return 1; -} - -/* - * Parse directives. - */ - -static int -yaml_parser_process_directives(yaml_parser_t *parser, - yaml_version_directive_t **version_directive_ref, - yaml_tag_directive_t **tag_directives_start_ref, - yaml_tag_directive_t **tag_directives_end_ref) -{ - yaml_tag_directive_t default_tag_directives[] = { - {(yaml_char_t *)"!", (yaml_char_t *)"!"}, - {(yaml_char_t *)"!!", (yaml_char_t *)"tag:yaml.org,2002:"}, - {NULL, NULL} - }; - yaml_tag_directive_t *default_tag_directive; - yaml_version_directive_t *version_directive = NULL; - struct { - yaml_tag_directive_t *start; - yaml_tag_directive_t *end; - yaml_tag_directive_t *top; - } tag_directives = { NULL, NULL, NULL }; - yaml_token_t *token; - - if (!STACK_INIT(parser, tag_directives, yaml_tag_directive_t*)) - goto error; - - token = PEEK_TOKEN(parser); - if (!token) goto error; - - while (token->type == YAML_VERSION_DIRECTIVE_TOKEN || - token->type == YAML_TAG_DIRECTIVE_TOKEN) - { - if (token->type == YAML_VERSION_DIRECTIVE_TOKEN) { - if (version_directive) { - yaml_parser_set_parser_error(parser, - "found duplicate %YAML directive", token->start_mark); - goto error; - } - if (token->data.version_directive.major != 1 - || ( - token->data.version_directive.minor != 1 - && token->data.version_directive.minor != 2 - )) { - yaml_parser_set_parser_error(parser, - "found incompatible YAML document", token->start_mark); - goto error; - } - version_directive = YAML_MALLOC_STATIC(yaml_version_directive_t); - if (!version_directive) { - parser->error = YAML_MEMORY_ERROR; - goto error; - } - version_directive->major = token->data.version_directive.major; - version_directive->minor = token->data.version_directive.minor; - } - - else if (token->type == YAML_TAG_DIRECTIVE_TOKEN) { - yaml_tag_directive_t value; - value.handle = token->data.tag_directive.handle; - value.prefix = token->data.tag_directive.prefix; - - if (!yaml_parser_append_tag_directive(parser, value, 0, - token->start_mark)) - goto error; - if (!PUSH(parser, tag_directives, value)) - goto error; - } - - SKIP_TOKEN(parser); - token = PEEK_TOKEN(parser); - if (!token) goto error; - } - - for (default_tag_directive = default_tag_directives; - default_tag_directive->handle; default_tag_directive++) { - if (!yaml_parser_append_tag_directive(parser, *default_tag_directive, 1, - token->start_mark)) - goto error; - } - - if (version_directive_ref) { - *version_directive_ref = version_directive; - } - if (tag_directives_start_ref) { - if (STACK_EMPTY(parser, tag_directives)) { - *tag_directives_start_ref = *tag_directives_end_ref = NULL; - STACK_DEL(parser, tag_directives); - } - else { - *tag_directives_start_ref = tag_directives.start; - *tag_directives_end_ref = tag_directives.top; - } - } - else { - STACK_DEL(parser, tag_directives); - } - - if (!version_directive_ref) - yaml_free(version_directive); - return 1; - -error: - yaml_free(version_directive); - while (!STACK_EMPTY(parser, tag_directives)) { - yaml_tag_directive_t tag_directive = POP(parser, tag_directives); - yaml_free(tag_directive.handle); - yaml_free(tag_directive.prefix); - } - STACK_DEL(parser, tag_directives); - return 0; -} - -/* - * Append a tag directive to the directives stack. - */ - -static int -yaml_parser_append_tag_directive(yaml_parser_t *parser, - yaml_tag_directive_t value, int allow_duplicates, yaml_mark_t mark) -{ - yaml_tag_directive_t *tag_directive; - yaml_tag_directive_t copy = { NULL, NULL }; - - for (tag_directive = parser->tag_directives.start; - tag_directive != parser->tag_directives.top; tag_directive ++) { - if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { - if (allow_duplicates) - return 1; - return yaml_parser_set_parser_error(parser, - "found duplicate %TAG directive", mark); - } - } - - copy.handle = yaml_strdup(value.handle); - copy.prefix = yaml_strdup(value.prefix); - if (!copy.handle || !copy.prefix) { - parser->error = YAML_MEMORY_ERROR; - goto error; - } - - if (!PUSH(parser, parser->tag_directives, copy)) - goto error; - - return 1; - -error: - yaml_free(copy.handle); - yaml_free(copy.prefix); - return 0; -} - diff --git a/ext/psych/yaml/reader.c b/ext/psych/yaml/reader.c deleted file mode 100644 index f3ac54c251..0000000000 --- a/ext/psych/yaml/reader.c +++ /dev/null @@ -1,469 +0,0 @@ - -#include "yaml_private.h" - -/* - * Declarations. - */ - -static int -yaml_parser_set_reader_error(yaml_parser_t *parser, const char *problem, - size_t offset, int value); - -static int -yaml_parser_update_raw_buffer(yaml_parser_t *parser); - -static int -yaml_parser_determine_encoding(yaml_parser_t *parser); - -YAML_DECLARE(int) -yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); - -/* - * Set the reader error and return 0. - */ - -static int -yaml_parser_set_reader_error(yaml_parser_t *parser, const char *problem, - size_t offset, int value) -{ - parser->error = YAML_READER_ERROR; - parser->problem = problem; - parser->problem_offset = offset; - parser->problem_value = value; - - return 0; -} - -/* - * Byte order marks. - */ - -#define BOM_UTF8 "\xef\xbb\xbf" -#define BOM_UTF16LE "\xff\xfe" -#define BOM_UTF16BE "\xfe\xff" - -/* - * Determine the input stream encoding by checking the BOM symbol. If no BOM is - * found, the UTF-8 encoding is assumed. Return 1 on success, 0 on failure. - */ - -static int -yaml_parser_determine_encoding(yaml_parser_t *parser) -{ - /* Ensure that we had enough bytes in the raw buffer. */ - - while (!parser->eof - && parser->raw_buffer.last - parser->raw_buffer.pointer < 3) { - if (!yaml_parser_update_raw_buffer(parser)) { - return 0; - } - } - - /* Determine the encoding. */ - - if (parser->raw_buffer.last - parser->raw_buffer.pointer >= 2 - && !memcmp(parser->raw_buffer.pointer, BOM_UTF16LE, 2)) { - parser->encoding = YAML_UTF16LE_ENCODING; - parser->raw_buffer.pointer += 2; - parser->offset += 2; - } - else if (parser->raw_buffer.last - parser->raw_buffer.pointer >= 2 - && !memcmp(parser->raw_buffer.pointer, BOM_UTF16BE, 2)) { - parser->encoding = YAML_UTF16BE_ENCODING; - parser->raw_buffer.pointer += 2; - parser->offset += 2; - } - else if (parser->raw_buffer.last - parser->raw_buffer.pointer >= 3 - && !memcmp(parser->raw_buffer.pointer, BOM_UTF8, 3)) { - parser->encoding = YAML_UTF8_ENCODING; - parser->raw_buffer.pointer += 3; - parser->offset += 3; - } - else { - parser->encoding = YAML_UTF8_ENCODING; - } - - return 1; -} - -/* - * Update the raw buffer. - */ - -static int -yaml_parser_update_raw_buffer(yaml_parser_t *parser) -{ - size_t size_read = 0; - - /* Return if the raw buffer is full. */ - - if (parser->raw_buffer.start == parser->raw_buffer.pointer - && parser->raw_buffer.last == parser->raw_buffer.end) - return 1; - - /* Return on EOF. */ - - if (parser->eof) return 1; - - /* Move the remaining bytes in the raw buffer to the beginning. */ - - if (parser->raw_buffer.start < parser->raw_buffer.pointer - && parser->raw_buffer.pointer < parser->raw_buffer.last) { - memmove(parser->raw_buffer.start, parser->raw_buffer.pointer, - parser->raw_buffer.last - parser->raw_buffer.pointer); - } - parser->raw_buffer.last -= - parser->raw_buffer.pointer - parser->raw_buffer.start; - parser->raw_buffer.pointer = parser->raw_buffer.start; - - /* Call the read handler to fill the buffer. */ - - if (!parser->read_handler(parser->read_handler_data, parser->raw_buffer.last, - parser->raw_buffer.end - parser->raw_buffer.last, &size_read)) { - return yaml_parser_set_reader_error(parser, "input error", - parser->offset, -1); - } - parser->raw_buffer.last += size_read; - if (!size_read) { - parser->eof = 1; - } - - return 1; -} - -/* - * Ensure that the buffer contains at least `length` characters. - * Return 1 on success, 0 on failure. - * - * The length is supposed to be significantly less that the buffer size. - */ - -YAML_DECLARE(int) -yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) -{ - int first = 1; - - assert(parser->read_handler); /* Read handler must be set. */ - - /* If the EOF flag is set and the raw buffer is empty, do nothing. */ - - if (parser->eof && parser->raw_buffer.pointer == parser->raw_buffer.last) - return 1; - - /* Return if the buffer contains enough characters. */ - - if (parser->unread >= length) - return 1; - - /* Determine the input encoding if it is not known yet. */ - - if (!parser->encoding) { - if (!yaml_parser_determine_encoding(parser)) - return 0; - } - - /* Move the unread characters to the beginning of the buffer. */ - - if (parser->buffer.start < parser->buffer.pointer - && parser->buffer.pointer < parser->buffer.last) { - size_t size = parser->buffer.last - parser->buffer.pointer; - memmove(parser->buffer.start, parser->buffer.pointer, size); - parser->buffer.pointer = parser->buffer.start; - parser->buffer.last = parser->buffer.start + size; - } - else if (parser->buffer.pointer == parser->buffer.last) { - parser->buffer.pointer = parser->buffer.start; - parser->buffer.last = parser->buffer.start; - } - - /* Fill the buffer until it has enough characters. */ - - while (parser->unread < length) - { - /* Fill the raw buffer if necessary. */ - - if (!first || parser->raw_buffer.pointer == parser->raw_buffer.last) { - if (!yaml_parser_update_raw_buffer(parser)) return 0; - } - first = 0; - - /* Decode the raw buffer. */ - - while (parser->raw_buffer.pointer != parser->raw_buffer.last) - { - unsigned int value = 0, value2 = 0; - int incomplete = 0; - unsigned char octet; - unsigned int width = 0; - int low, high; - size_t k; - size_t raw_unread = parser->raw_buffer.last - parser->raw_buffer.pointer; - - /* Decode the next character. */ - - switch (parser->encoding) - { - case YAML_UTF8_ENCODING: - - /* - * Decode a UTF-8 character. Check RFC 3629 - * (http://www.ietf.org/rfc/rfc3629.txt) for more details. - * - * The following table (taken from the RFC) is used for - * decoding. - * - * Char. number range | UTF-8 octet sequence - * (hexadecimal) | (binary) - * --------------------+------------------------------------ - * 0000 0000-0000 007F | 0xxxxxxx - * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx - * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx - * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - * - * Additionally, the characters in the range 0xD800-0xDFFF - * are prohibited as they are reserved for use with UTF-16 - * surrogate pairs. - */ - - /* Determine the length of the UTF-8 sequence. */ - - octet = parser->raw_buffer.pointer[0]; - width = (octet & 0x80) == 0x00 ? 1 : - (octet & 0xE0) == 0xC0 ? 2 : - (octet & 0xF0) == 0xE0 ? 3 : - (octet & 0xF8) == 0xF0 ? 4 : 0; - - /* Check if the leading octet is valid. */ - - if (!width) - return yaml_parser_set_reader_error(parser, - "invalid leading UTF-8 octet", - parser->offset, octet); - - /* Check if the raw buffer contains an incomplete character. */ - - if (width > raw_unread) { - if (parser->eof) { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-8 octet sequence", - parser->offset, -1); - } - incomplete = 1; - break; - } - - /* Decode the leading octet. */ - - value = (octet & 0x80) == 0x00 ? octet & 0x7F : - (octet & 0xE0) == 0xC0 ? octet & 0x1F : - (octet & 0xF0) == 0xE0 ? octet & 0x0F : - (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; - - /* Check and decode the trailing octets. */ - - for (k = 1; k < width; k ++) - { - octet = parser->raw_buffer.pointer[k]; - - /* Check if the octet is valid. */ - - if ((octet & 0xC0) != 0x80) - return yaml_parser_set_reader_error(parser, - "invalid trailing UTF-8 octet", - parser->offset+k, octet); - - /* Decode the octet. */ - - value = (value << 6) + (octet & 0x3F); - } - - /* Check the length of the sequence against the value. */ - - if (!((width == 1) || - (width == 2 && value >= 0x80) || - (width == 3 && value >= 0x800) || - (width == 4 && value >= 0x10000))) - return yaml_parser_set_reader_error(parser, - "invalid length of a UTF-8 sequence", - parser->offset, -1); - - /* Check the range of the value. */ - - if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) - return yaml_parser_set_reader_error(parser, - "invalid Unicode character", - parser->offset, value); - - break; - - case YAML_UTF16LE_ENCODING: - case YAML_UTF16BE_ENCODING: - - low = (parser->encoding == YAML_UTF16LE_ENCODING ? 0 : 1); - high = (parser->encoding == YAML_UTF16LE_ENCODING ? 1 : 0); - - /* - * The UTF-16 encoding is not as simple as one might - * naively think. Check RFC 2781 - * (http://www.ietf.org/rfc/rfc2781.txt). - * - * Normally, two subsequent bytes describe a Unicode - * character. However a special technique (called a - * surrogate pair) is used for specifying character - * values larger than 0xFFFF. - * - * A surrogate pair consists of two pseudo-characters: - * high surrogate area (0xD800-0xDBFF) - * low surrogate area (0xDC00-0xDFFF) - * - * The following formulas are used for decoding - * and encoding characters using surrogate pairs: - * - * U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF) - * U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF) - * W1 = 110110yyyyyyyyyy - * W2 = 110111xxxxxxxxxx - * - * where U is the character value, W1 is the high surrogate - * area, W2 is the low surrogate area. - */ - - /* Check for incomplete UTF-16 character. */ - - if (raw_unread < 2) { - if (parser->eof) { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-16 character", - parser->offset, -1); - } - incomplete = 1; - break; - } - - /* Get the character. */ - - value = parser->raw_buffer.pointer[low] - + (parser->raw_buffer.pointer[high] << 8); - - /* Check for unexpected low surrogate area. */ - - if ((value & 0xFC00) == 0xDC00) - return yaml_parser_set_reader_error(parser, - "unexpected low surrogate area", - parser->offset, value); - - /* Check for a high surrogate area. */ - - if ((value & 0xFC00) == 0xD800) { - - width = 4; - - /* Check for incomplete surrogate pair. */ - - if (raw_unread < 4) { - if (parser->eof) { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-16 surrogate pair", - parser->offset, -1); - } - incomplete = 1; - break; - } - - /* Get the next character. */ - - value2 = parser->raw_buffer.pointer[low+2] - + (parser->raw_buffer.pointer[high+2] << 8); - - /* Check for a low surrogate area. */ - - if ((value2 & 0xFC00) != 0xDC00) - return yaml_parser_set_reader_error(parser, - "expected low surrogate area", - parser->offset+2, value2); - - /* Generate the value of the surrogate pair. */ - - value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF); - } - - else { - width = 2; - } - - break; - - default: - assert(1); /* Impossible. */ - } - - /* Check if the raw buffer contains enough bytes to form a character. */ - - if (incomplete) break; - - /* - * Check if the character is in the allowed range: - * #x9 | #xA | #xD | [#x20-#x7E] (8 bit) - * | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] (16 bit) - * | [#x10000-#x10FFFF] (32 bit) - */ - - if (! (value == 0x09 || value == 0x0A || value == 0x0D - || (value >= 0x20 && value <= 0x7E) - || (value == 0x85) || (value >= 0xA0 && value <= 0xD7FF) - || (value >= 0xE000 && value <= 0xFFFD) - || (value >= 0x10000 && value <= 0x10FFFF))) - return yaml_parser_set_reader_error(parser, - "control characters are not allowed", - parser->offset, value); - - /* Move the raw pointers. */ - - parser->raw_buffer.pointer += width; - parser->offset += width; - - /* Finally put the character into the buffer. */ - - /* 0000 0000-0000 007F -> 0xxxxxxx */ - if (value <= 0x7F) { - *(parser->buffer.last++) = value; - } - /* 0000 0080-0000 07FF -> 110xxxxx 10xxxxxx */ - else if (value <= 0x7FF) { - *(parser->buffer.last++) = 0xC0 + (value >> 6); - *(parser->buffer.last++) = 0x80 + (value & 0x3F); - } - /* 0000 0800-0000 FFFF -> 1110xxxx 10xxxxxx 10xxxxxx */ - else if (value <= 0xFFFF) { - *(parser->buffer.last++) = 0xE0 + (value >> 12); - *(parser->buffer.last++) = 0x80 + ((value >> 6) & 0x3F); - *(parser->buffer.last++) = 0x80 + (value & 0x3F); - } - /* 0001 0000-0010 FFFF -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - else { - *(parser->buffer.last++) = 0xF0 + (value >> 18); - *(parser->buffer.last++) = 0x80 + ((value >> 12) & 0x3F); - *(parser->buffer.last++) = 0x80 + ((value >> 6) & 0x3F); - *(parser->buffer.last++) = 0x80 + (value & 0x3F); - } - - parser->unread ++; - } - - /* On EOF, put NUL into the buffer and return. */ - - if (parser->eof) { - *(parser->buffer.last++) = '\0'; - parser->unread ++; - return 1; - } - - } - - if (parser->offset >= MAX_FILE_SIZE) { - return yaml_parser_set_reader_error(parser, "input is too long", - parser->offset, -1); - } - - return 1; -} diff --git a/ext/psych/yaml/scanner.c b/ext/psych/yaml/scanner.c deleted file mode 100644 index bb5d201274..0000000000 --- a/ext/psych/yaml/scanner.c +++ /dev/null @@ -1,3598 +0,0 @@ - -/* - * Introduction - * ************ - * - * The following notes assume that you are familiar with the YAML specification - * (http://yaml.org/spec/cvs/current.html). We mostly follow it, although in - * some cases we are less restrictive that it requires. - * - * The process of transforming a YAML stream into a sequence of events is - * divided on two steps: Scanning and Parsing. - * - * The Scanner transforms the input stream into a sequence of tokens, while the - * parser transform the sequence of tokens produced by the Scanner into a - * sequence of parsing events. - * - * The Scanner is rather clever and complicated. The Parser, on the contrary, - * is a straightforward implementation of a recursive-descendant parser (or, - * LL(1) parser, as it is usually called). - * - * Actually there are two issues of Scanning that might be called "clever", the - * rest is quite straightforward. The issues are "block collection start" and - * "simple keys". Both issues are explained below in details. - * - * Here the Scanning step is explained and implemented. We start with the list - * of all the tokens produced by the Scanner together with short descriptions. - * - * Now, tokens: - * - * STREAM-START(encoding) # The stream start. - * STREAM-END # The stream end. - * VERSION-DIRECTIVE(major,minor) # The '%YAML' directive. - * TAG-DIRECTIVE(handle,prefix) # The '%TAG' directive. - * DOCUMENT-START # '---' - * DOCUMENT-END # '...' - * BLOCK-SEQUENCE-START # Indentation increase denoting a block - * BLOCK-MAPPING-START # sequence or a block mapping. - * BLOCK-END # Indentation decrease. - * FLOW-SEQUENCE-START # '[' - * FLOW-SEQUENCE-END # ']' - * FLOW-MAPPING-START # '{' - * FLOW-MAPPING-END # '}' - * BLOCK-ENTRY # '-' - * FLOW-ENTRY # ',' - * KEY # '?' or nothing (simple keys). - * VALUE # ':' - * ALIAS(anchor) # '*anchor' - * ANCHOR(anchor) # '&anchor' - * TAG(handle,suffix) # '!handle!suffix' - * SCALAR(value,style) # A scalar. - * - * The following two tokens are "virtual" tokens denoting the beginning and the - * end of the stream: - * - * STREAM-START(encoding) - * STREAM-END - * - * We pass the information about the input stream encoding with the - * STREAM-START token. - * - * The next two tokens are responsible for tags: - * - * VERSION-DIRECTIVE(major,minor) - * TAG-DIRECTIVE(handle,prefix) - * - * Example: - * - * %YAML 1.1 - * %TAG ! !foo - * %TAG !yaml! tag:yaml.org,2002: - * --- - * - * The corresponding sequence of tokens: - * - * STREAM-START(utf-8) - * VERSION-DIRECTIVE(1,1) - * TAG-DIRECTIVE("!","!foo") - * TAG-DIRECTIVE("!yaml","tag:yaml.org,2002:") - * DOCUMENT-START - * STREAM-END - * - * Note that the VERSION-DIRECTIVE and TAG-DIRECTIVE tokens occupy a whole - * line. - * - * The document start and end indicators are represented by: - * - * DOCUMENT-START - * DOCUMENT-END - * - * Note that if a YAML stream contains an implicit document (without '---' - * and '...' indicators), no DOCUMENT-START and DOCUMENT-END tokens will be - * produced. - * - * In the following examples, we present whole documents together with the - * produced tokens. - * - * 1. An implicit document: - * - * 'a scalar' - * - * Tokens: - * - * STREAM-START(utf-8) - * SCALAR("a scalar",single-quoted) - * STREAM-END - * - * 2. An explicit document: - * - * --- - * 'a scalar' - * ... - * - * Tokens: - * - * STREAM-START(utf-8) - * DOCUMENT-START - * SCALAR("a scalar",single-quoted) - * DOCUMENT-END - * STREAM-END - * - * 3. Several documents in a stream: - * - * 'a scalar' - * --- - * 'another scalar' - * --- - * 'yet another scalar' - * - * Tokens: - * - * STREAM-START(utf-8) - * SCALAR("a scalar",single-quoted) - * DOCUMENT-START - * SCALAR("another scalar",single-quoted) - * DOCUMENT-START - * SCALAR("yet another scalar",single-quoted) - * STREAM-END - * - * We have already introduced the SCALAR token above. The following tokens are - * used to describe aliases, anchors, tag, and scalars: - * - * ALIAS(anchor) - * ANCHOR(anchor) - * TAG(handle,suffix) - * SCALAR(value,style) - * - * The following series of examples illustrate the usage of these tokens: - * - * 1. A recursive sequence: - * - * &A [ *A ] - * - * Tokens: - * - * STREAM-START(utf-8) - * ANCHOR("A") - * FLOW-SEQUENCE-START - * ALIAS("A") - * FLOW-SEQUENCE-END - * STREAM-END - * - * 2. A tagged scalar: - * - * !!float "3.14" # A good approximation. - * - * Tokens: - * - * STREAM-START(utf-8) - * TAG("!!","float") - * SCALAR("3.14",double-quoted) - * STREAM-END - * - * 3. Various scalar styles: - * - * --- # Implicit empty plain scalars do not produce tokens. - * --- a plain scalar - * --- 'a single-quoted scalar' - * --- "a double-quoted scalar" - * --- |- - * a literal scalar - * --- >- - * a folded - * scalar - * - * Tokens: - * - * STREAM-START(utf-8) - * DOCUMENT-START - * DOCUMENT-START - * SCALAR("a plain scalar",plain) - * DOCUMENT-START - * SCALAR("a single-quoted scalar",single-quoted) - * DOCUMENT-START - * SCALAR("a double-quoted scalar",double-quoted) - * DOCUMENT-START - * SCALAR("a literal scalar",literal) - * DOCUMENT-START - * SCALAR("a folded scalar",folded) - * STREAM-END - * - * Now it's time to review collection-related tokens. We will start with - * flow collections: - * - * FLOW-SEQUENCE-START - * FLOW-SEQUENCE-END - * FLOW-MAPPING-START - * FLOW-MAPPING-END - * FLOW-ENTRY - * KEY - * VALUE - * - * The tokens FLOW-SEQUENCE-START, FLOW-SEQUENCE-END, FLOW-MAPPING-START, and - * FLOW-MAPPING-END represent the indicators '[', ']', '{', and '}' - * correspondingly. FLOW-ENTRY represent the ',' indicator. Finally the - * indicators '?' and ':', which are used for denoting mapping keys and values, - * are represented by the KEY and VALUE tokens. - * - * The following examples show flow collections: - * - * 1. A flow sequence: - * - * [item 1, item 2, item 3] - * - * Tokens: - * - * STREAM-START(utf-8) - * FLOW-SEQUENCE-START - * SCALAR("item 1",plain) - * FLOW-ENTRY - * SCALAR("item 2",plain) - * FLOW-ENTRY - * SCALAR("item 3",plain) - * FLOW-SEQUENCE-END - * STREAM-END - * - * 2. A flow mapping: - * - * { - * a simple key: a value, # Note that the KEY token is produced. - * ? a complex key: another value, - * } - * - * Tokens: - * - * STREAM-START(utf-8) - * FLOW-MAPPING-START - * KEY - * SCALAR("a simple key",plain) - * VALUE - * SCALAR("a value",plain) - * FLOW-ENTRY - * KEY - * SCALAR("a complex key",plain) - * VALUE - * SCALAR("another value",plain) - * FLOW-ENTRY - * FLOW-MAPPING-END - * STREAM-END - * - * A simple key is a key which is not denoted by the '?' indicator. Note that - * the Scanner still produce the KEY token whenever it encounters a simple key. - * - * For scanning block collections, the following tokens are used (note that we - * repeat KEY and VALUE here): - * - * BLOCK-SEQUENCE-START - * BLOCK-MAPPING-START - * BLOCK-END - * BLOCK-ENTRY - * KEY - * VALUE - * - * The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation - * increase that precedes a block collection (cf. the INDENT token in Python). - * The token BLOCK-END denote indentation decrease that ends a block collection - * (cf. the DEDENT token in Python). However YAML has some syntax peculiarities - * that makes detections of these tokens more complex. - * - * The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators - * '-', '?', and ':' correspondingly. - * - * The following examples show how the tokens BLOCK-SEQUENCE-START, - * BLOCK-MAPPING-START, and BLOCK-END are emitted by the Scanner: - * - * 1. Block sequences: - * - * - item 1 - * - item 2 - * - - * - item 3.1 - * - item 3.2 - * - - * key 1: value 1 - * key 2: value 2 - * - * Tokens: - * - * STREAM-START(utf-8) - * BLOCK-SEQUENCE-START - * BLOCK-ENTRY - * SCALAR("item 1",plain) - * BLOCK-ENTRY - * SCALAR("item 2",plain) - * BLOCK-ENTRY - * BLOCK-SEQUENCE-START - * BLOCK-ENTRY - * SCALAR("item 3.1",plain) - * BLOCK-ENTRY - * SCALAR("item 3.2",plain) - * BLOCK-END - * BLOCK-ENTRY - * BLOCK-MAPPING-START - * KEY - * SCALAR("key 1",plain) - * VALUE - * SCALAR("value 1",plain) - * KEY - * SCALAR("key 2",plain) - * VALUE - * SCALAR("value 2",plain) - * BLOCK-END - * BLOCK-END - * STREAM-END - * - * 2. Block mappings: - * - * a simple key: a value # The KEY token is produced here. - * ? a complex key - * : another value - * a mapping: - * key 1: value 1 - * key 2: value 2 - * a sequence: - * - item 1 - * - item 2 - * - * Tokens: - * - * STREAM-START(utf-8) - * BLOCK-MAPPING-START - * KEY - * SCALAR("a simple key",plain) - * VALUE - * SCALAR("a value",plain) - * KEY - * SCALAR("a complex key",plain) - * VALUE - * SCALAR("another value",plain) - * KEY - * SCALAR("a mapping",plain) - * VALUE - * BLOCK-MAPPING-START - * KEY - * SCALAR("key 1",plain) - * VALUE - * SCALAR("value 1",plain) - * KEY - * SCALAR("key 2",plain) - * VALUE - * SCALAR("value 2",plain) - * BLOCK-END - * KEY - * SCALAR("a sequence",plain) - * VALUE - * BLOCK-SEQUENCE-START - * BLOCK-ENTRY - * SCALAR("item 1",plain) - * BLOCK-ENTRY - * SCALAR("item 2",plain) - * BLOCK-END - * BLOCK-END - * STREAM-END - * - * YAML does not always require to start a new block collection from a new - * line. If the current line contains only '-', '?', and ':' indicators, a new - * block collection may start at the current line. The following examples - * illustrate this case: - * - * 1. Collections in a sequence: - * - * - - item 1 - * - item 2 - * - key 1: value 1 - * key 2: value 2 - * - ? complex key - * : complex value - * - * Tokens: - * - * STREAM-START(utf-8) - * BLOCK-SEQUENCE-START - * BLOCK-ENTRY - * BLOCK-SEQUENCE-START - * BLOCK-ENTRY - * SCALAR("item 1",plain) - * BLOCK-ENTRY - * SCALAR("item 2",plain) - * BLOCK-END - * BLOCK-ENTRY - * BLOCK-MAPPING-START - * KEY - * SCALAR("key 1",plain) - * VALUE - * SCALAR("value 1",plain) - * KEY - * SCALAR("key 2",plain) - * VALUE - * SCALAR("value 2",plain) - * BLOCK-END - * BLOCK-ENTRY - * BLOCK-MAPPING-START - * KEY - * SCALAR("complex key") - * VALUE - * SCALAR("complex value") - * BLOCK-END - * BLOCK-END - * STREAM-END - * - * 2. Collections in a mapping: - * - * ? a sequence - * : - item 1 - * - item 2 - * ? a mapping - * : key 1: value 1 - * key 2: value 2 - * - * Tokens: - * - * STREAM-START(utf-8) - * BLOCK-MAPPING-START - * KEY - * SCALAR("a sequence",plain) - * VALUE - * BLOCK-SEQUENCE-START - * BLOCK-ENTRY - * SCALAR("item 1",plain) - * BLOCK-ENTRY - * SCALAR("item 2",plain) - * BLOCK-END - * KEY - * SCALAR("a mapping",plain) - * VALUE - * BLOCK-MAPPING-START - * KEY - * SCALAR("key 1",plain) - * VALUE - * SCALAR("value 1",plain) - * KEY - * SCALAR("key 2",plain) - * VALUE - * SCALAR("value 2",plain) - * BLOCK-END - * BLOCK-END - * STREAM-END - * - * YAML also permits non-indented sequences if they are included into a block - * mapping. In this case, the token BLOCK-SEQUENCE-START is not produced: - * - * key: - * - item 1 # BLOCK-SEQUENCE-START is NOT produced here. - * - item 2 - * - * Tokens: - * - * STREAM-START(utf-8) - * BLOCK-MAPPING-START - * KEY - * SCALAR("key",plain) - * VALUE - * BLOCK-ENTRY - * SCALAR("item 1",plain) - * BLOCK-ENTRY - * SCALAR("item 2",plain) - * BLOCK-END - */ - -#include "yaml_private.h" - -/* - * Ensure that the buffer contains the required number of characters. - * Return 1 on success, 0 on failure (reader error or memory error). - */ - -#define CACHE(parser,length) \ - (parser->unread >= (length) \ - ? 1 \ - : yaml_parser_update_buffer(parser, (length))) - -/* - * Advance the buffer pointer. - */ - -#define SKIP(parser) \ - (parser->mark.index ++, \ - parser->mark.column ++, \ - parser->unread --, \ - parser->buffer.pointer += WIDTH(parser->buffer)) - -#define SKIP_LINE(parser) \ - (IS_CRLF(parser->buffer) ? \ - (parser->mark.index += 2, \ - parser->mark.column = 0, \ - parser->mark.line ++, \ - parser->unread -= 2, \ - parser->buffer.pointer += 2) : \ - IS_BREAK(parser->buffer) ? \ - (parser->mark.index ++, \ - parser->mark.column = 0, \ - parser->mark.line ++, \ - parser->unread --, \ - parser->buffer.pointer += WIDTH(parser->buffer)) : 0) - -/* - * Copy a character to a string buffer and advance pointers. - */ - -#define READ(parser,string) \ - (STRING_EXTEND(parser,string) ? \ - (COPY(string,parser->buffer), \ - parser->mark.index ++, \ - parser->mark.column ++, \ - parser->unread --, \ - 1) : 0) - -/* - * Copy a line break character to a string buffer and advance pointers. - */ - -#define READ_LINE(parser,string) \ - (STRING_EXTEND(parser,string) ? \ - (((CHECK_AT(parser->buffer,'\r',0) \ - && CHECK_AT(parser->buffer,'\n',1)) ? /* CR LF -> LF */ \ - (*((string).pointer++) = (yaml_char_t) '\n', \ - parser->buffer.pointer += 2, \ - parser->mark.index += 2, \ - parser->mark.column = 0, \ - parser->mark.line ++, \ - parser->unread -= 2) : \ - (CHECK_AT(parser->buffer,'\r',0) \ - || CHECK_AT(parser->buffer,'\n',0)) ? /* CR|LF -> LF */ \ - (*((string).pointer++) = (yaml_char_t) '\n', \ - parser->buffer.pointer ++, \ - parser->mark.index ++, \ - parser->mark.column = 0, \ - parser->mark.line ++, \ - parser->unread --) : \ - (CHECK_AT(parser->buffer,'\xC2',0) \ - && CHECK_AT(parser->buffer,'\x85',1)) ? /* NEL -> LF */ \ - (*((string).pointer++) = (yaml_char_t) '\n', \ - parser->buffer.pointer += 2, \ - parser->mark.index ++, \ - parser->mark.column = 0, \ - parser->mark.line ++, \ - parser->unread --) : \ - (CHECK_AT(parser->buffer,'\xE2',0) && \ - CHECK_AT(parser->buffer,'\x80',1) && \ - (CHECK_AT(parser->buffer,'\xA8',2) || \ - CHECK_AT(parser->buffer,'\xA9',2))) ? /* LS|PS -> LS|PS */ \ - (*((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++), \ - parser->mark.index ++, \ - parser->mark.column = 0, \ - parser->mark.line ++, \ - parser->unread --) : 0), \ - 1) : 0) - -/* - * Public API declarations. - */ - -YAML_DECLARE(int) -yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token); - -/* - * Error handling. - */ - -static int -yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context, - yaml_mark_t context_mark, const char *problem); - -/* - * High-level token API. - */ - -YAML_DECLARE(int) -yaml_parser_fetch_more_tokens(yaml_parser_t *parser); - -static int -yaml_parser_fetch_next_token(yaml_parser_t *parser); - -/* - * Potential simple keys. - */ - -static int -yaml_parser_stale_simple_keys(yaml_parser_t *parser); - -static int -yaml_parser_save_simple_key(yaml_parser_t *parser); - -static int -yaml_parser_remove_simple_key(yaml_parser_t *parser); - -static int -yaml_parser_increase_flow_level(yaml_parser_t *parser); - -static int -yaml_parser_decrease_flow_level(yaml_parser_t *parser); - -/* - * Indentation treatment. - */ - -static int -yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, - ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark); - -static int -yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column); - -/* - * Token fetchers. - */ - -static int -yaml_parser_fetch_stream_start(yaml_parser_t *parser); - -static int -yaml_parser_fetch_stream_end(yaml_parser_t *parser); - -static int -yaml_parser_fetch_directive(yaml_parser_t *parser); - -static int -yaml_parser_fetch_document_indicator(yaml_parser_t *parser, - yaml_token_type_t type); - -static int -yaml_parser_fetch_flow_collection_start(yaml_parser_t *parser, - yaml_token_type_t type); - -static int -yaml_parser_fetch_flow_collection_end(yaml_parser_t *parser, - yaml_token_type_t type); - -static int -yaml_parser_fetch_flow_entry(yaml_parser_t *parser); - -static int -yaml_parser_fetch_block_entry(yaml_parser_t *parser); - -static int -yaml_parser_fetch_key(yaml_parser_t *parser); - -static int -yaml_parser_fetch_value(yaml_parser_t *parser); - -static int -yaml_parser_fetch_anchor(yaml_parser_t *parser, yaml_token_type_t type); - -static int -yaml_parser_fetch_tag(yaml_parser_t *parser); - -static int -yaml_parser_fetch_block_scalar(yaml_parser_t *parser, int literal); - -static int -yaml_parser_fetch_flow_scalar(yaml_parser_t *parser, int single); - -static int -yaml_parser_fetch_plain_scalar(yaml_parser_t *parser); - -/* - * Token scanners. - */ - -static int -yaml_parser_scan_to_next_token(yaml_parser_t *parser); - -static int -yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token); - -static int -yaml_parser_scan_directive_name(yaml_parser_t *parser, - yaml_mark_t start_mark, yaml_char_t **name); - -static int -yaml_parser_scan_version_directive_value(yaml_parser_t *parser, - yaml_mark_t start_mark, int *major, int *minor); - -static int -yaml_parser_scan_version_directive_number(yaml_parser_t *parser, - yaml_mark_t start_mark, int *number); - -static int -yaml_parser_scan_tag_directive_value(yaml_parser_t *parser, - yaml_mark_t mark, yaml_char_t **handle, yaml_char_t **prefix); - -static int -yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token, - yaml_token_type_t type); - -static int -yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token); - -static int -yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive, - yaml_mark_t start_mark, yaml_char_t **handle); - -static int -yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive, - yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri); - -static int -yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, - yaml_mark_t start_mark, yaml_string_t *string); - -static int -yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, - int literal); - -static int -yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser, - int *indent, yaml_string_t *breaks, - yaml_mark_t start_mark, yaml_mark_t *end_mark); - -static int -yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, - int single); - -static int -yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token); - -/* - * Get the next token. - */ - -YAML_DECLARE(int) -yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token) -{ - assert(parser); /* Non-NULL parser object is expected. */ - assert(token); /* Non-NULL token object is expected. */ - - /* Erase the token object. */ - - memset(token, 0, sizeof(yaml_token_t)); - - /* No tokens after STREAM-END or error. */ - - if (parser->stream_end_produced || parser->error) { - return 1; - } - - /* Ensure that the tokens queue contains enough tokens. */ - - if (!parser->token_available) { - if (!yaml_parser_fetch_more_tokens(parser)) - return 0; - } - - /* Fetch the next token from the queue. */ - - *token = DEQUEUE(parser, parser->tokens); - parser->token_available = 0; - parser->tokens_parsed ++; - - if (token->type == YAML_STREAM_END_TOKEN) { - parser->stream_end_produced = 1; - } - - return 1; -} - -/* - * Set the scanner error and return 0. - */ - -static int -yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context, - yaml_mark_t context_mark, const char *problem) -{ - parser->error = YAML_SCANNER_ERROR; - parser->context = context; - parser->context_mark = context_mark; - parser->problem = problem; - parser->problem_mark = parser->mark; - - return 0; -} - -/* - * Ensure that the tokens queue contains at least one token which can be - * returned to the Parser. - */ - -YAML_DECLARE(int) -yaml_parser_fetch_more_tokens(yaml_parser_t *parser) -{ - int need_more_tokens; - - /* While we need more tokens to fetch, do it. */ - - while (1) - { - /* - * Check if we really need to fetch more tokens. - */ - - need_more_tokens = 0; - - if (parser->tokens.head == parser->tokens.tail) - { - /* Queue is empty. */ - - need_more_tokens = 1; - } - else - { - yaml_simple_key_t *simple_key; - - /* Check if any potential simple key may occupy the head position. */ - - if (!yaml_parser_stale_simple_keys(parser)) - return 0; - - for (simple_key = parser->simple_keys.start; - simple_key != parser->simple_keys.top; simple_key++) { - if (simple_key->possible - && simple_key->token_number == parser->tokens_parsed) { - need_more_tokens = 1; - break; - } - } - } - - /* We are finished. */ - - if (!need_more_tokens) - break; - - /* Fetch the next token. */ - - if (!yaml_parser_fetch_next_token(parser)) - return 0; - } - - parser->token_available = 1; - - return 1; -} - -/* - * The dispatcher for token fetchers. - */ - -static int -yaml_parser_fetch_next_token(yaml_parser_t *parser) -{ - /* Ensure that the buffer is initialized. */ - - if (!CACHE(parser, 1)) - return 0; - - /* Check if we just started scanning. Fetch STREAM-START then. */ - - if (!parser->stream_start_produced) - return yaml_parser_fetch_stream_start(parser); - - /* Eat whitespaces and comments until we reach the next token. */ - - if (!yaml_parser_scan_to_next_token(parser)) - return 0; - - /* Remove obsolete potential simple keys. */ - - if (!yaml_parser_stale_simple_keys(parser)) - return 0; - - /* Check the indentation level against the current column. */ - - if (!yaml_parser_unroll_indent(parser, parser->mark.column)) - return 0; - - /* - * Ensure that the buffer contains at least 4 characters. 4 is the length - * of the longest indicators ('--- ' and '... '). - */ - - if (!CACHE(parser, 4)) - return 0; - - /* Is it the end of the stream? */ - - if (IS_Z(parser->buffer)) - return yaml_parser_fetch_stream_end(parser); - - /* Is it a directive? */ - - if (parser->mark.column == 0 && CHECK(parser->buffer, '%')) - return yaml_parser_fetch_directive(parser); - - /* Is it the document start indicator? */ - - if (parser->mark.column == 0 - && CHECK_AT(parser->buffer, '-', 0) - && CHECK_AT(parser->buffer, '-', 1) - && CHECK_AT(parser->buffer, '-', 2) - && IS_BLANKZ_AT(parser->buffer, 3)) - return yaml_parser_fetch_document_indicator(parser, - YAML_DOCUMENT_START_TOKEN); - - /* Is it the document end indicator? */ - - if (parser->mark.column == 0 - && CHECK_AT(parser->buffer, '.', 0) - && CHECK_AT(parser->buffer, '.', 1) - && CHECK_AT(parser->buffer, '.', 2) - && IS_BLANKZ_AT(parser->buffer, 3)) - return yaml_parser_fetch_document_indicator(parser, - YAML_DOCUMENT_END_TOKEN); - - /* Is it the flow sequence start indicator? */ - - if (CHECK(parser->buffer, '[')) - return yaml_parser_fetch_flow_collection_start(parser, - YAML_FLOW_SEQUENCE_START_TOKEN); - - /* Is it the flow mapping start indicator? */ - - if (CHECK(parser->buffer, '{')) - return yaml_parser_fetch_flow_collection_start(parser, - YAML_FLOW_MAPPING_START_TOKEN); - - /* Is it the flow sequence end indicator? */ - - if (CHECK(parser->buffer, ']')) - return yaml_parser_fetch_flow_collection_end(parser, - YAML_FLOW_SEQUENCE_END_TOKEN); - - /* Is it the flow mapping end indicator? */ - - if (CHECK(parser->buffer, '}')) - return yaml_parser_fetch_flow_collection_end(parser, - YAML_FLOW_MAPPING_END_TOKEN); - - /* Is it the flow entry indicator? */ - - if (CHECK(parser->buffer, ',')) - return yaml_parser_fetch_flow_entry(parser); - - /* Is it the block entry indicator? */ - - if (CHECK(parser->buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1)) - return yaml_parser_fetch_block_entry(parser); - - /* Is it the key indicator? */ - - if (CHECK(parser->buffer, '?') - && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) - return yaml_parser_fetch_key(parser); - - /* Is it the value indicator? */ - - if (CHECK(parser->buffer, ':') - && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) - return yaml_parser_fetch_value(parser); - - /* Is it an alias? */ - - if (CHECK(parser->buffer, '*')) - return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN); - - /* Is it an anchor? */ - - if (CHECK(parser->buffer, '&')) - return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN); - - /* Is it a tag? */ - - if (CHECK(parser->buffer, '!')) - return yaml_parser_fetch_tag(parser); - - /* Is it a literal scalar? */ - - if (CHECK(parser->buffer, '|') && !parser->flow_level) - return yaml_parser_fetch_block_scalar(parser, 1); - - /* Is it a folded scalar? */ - - if (CHECK(parser->buffer, '>') && !parser->flow_level) - return yaml_parser_fetch_block_scalar(parser, 0); - - /* Is it a single-quoted scalar? */ - - if (CHECK(parser->buffer, '\'')) - return yaml_parser_fetch_flow_scalar(parser, 1); - - /* Is it a double-quoted scalar? */ - - if (CHECK(parser->buffer, '"')) - return yaml_parser_fetch_flow_scalar(parser, 0); - - /* - * Is it a plain scalar? - * - * A plain scalar may start with any non-blank characters except - * - * '-', '?', ':', ',', '[', ']', '{', '}', - * '#', '&', '*', '!', '|', '>', '\'', '\"', - * '%', '@', '`'. - * - * In the block context (and, for the '-' indicator, in the flow context - * too), it may also start with the characters - * - * '-', '?', ':' - * - * if it is followed by a non-space character. - * - * The last rule is more restrictive than the specification requires. - */ - - if (!(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '-') - || CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':') - || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '[') - || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{') - || CHECK(parser->buffer, '}') || CHECK(parser->buffer, '#') - || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '*') - || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '|') - || CHECK(parser->buffer, '>') || CHECK(parser->buffer, '\'') - || CHECK(parser->buffer, '"') || CHECK(parser->buffer, '%') - || CHECK(parser->buffer, '@') || CHECK(parser->buffer, '`')) || - (CHECK(parser->buffer, '-') && !IS_BLANK_AT(parser->buffer, 1)) || - (!parser->flow_level && - (CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':')) - && !IS_BLANKZ_AT(parser->buffer, 1))) - return yaml_parser_fetch_plain_scalar(parser); - - /* - * If we don't determine the token type so far, it is an error. - */ - - return yaml_parser_set_scanner_error(parser, - "while scanning for the next token", parser->mark, - "found character that cannot start any token"); -} - -/* - * Check the list of potential simple keys and remove the positions that - * cannot contain simple keys anymore. - */ - -static int -yaml_parser_stale_simple_keys(yaml_parser_t *parser) -{ - yaml_simple_key_t *simple_key; - - /* Check for a potential simple key for each flow level. */ - - for (simple_key = parser->simple_keys.start; - simple_key != parser->simple_keys.top; simple_key ++) - { - /* - * The specification requires that a simple key - * - * - is limited to a single line, - * - is shorter than 1024 characters. - */ - - if (simple_key->possible - && (simple_key->mark.line < parser->mark.line - || simple_key->mark.index+1024 < parser->mark.index)) { - - /* Check if the potential simple key to be removed is required. */ - - if (simple_key->required) { - return yaml_parser_set_scanner_error(parser, - "while scanning a simple key", simple_key->mark, - "could not find expected ':'"); - } - - simple_key->possible = 0; - } - } - - return 1; -} - -/* - * Check if a simple key may start at the current position and add it if - * needed. - */ - -static int -yaml_parser_save_simple_key(yaml_parser_t *parser) -{ - /* - * A simple key is required at the current position if the scanner is in - * the block context and the current column coincides with the indentation - * level. - */ - - int required = (!parser->flow_level - && parser->indent == (ptrdiff_t)parser->mark.column); - - /* - * If the current position may start a simple key, save it. - */ - - if (parser->simple_key_allowed) - { - yaml_simple_key_t simple_key; - simple_key.possible = 1; - simple_key.required = required; - simple_key.token_number = - parser->tokens_parsed + (parser->tokens.tail - parser->tokens.head); - simple_key.mark = parser->mark; - - if (!yaml_parser_remove_simple_key(parser)) return 0; - - *(parser->simple_keys.top-1) = simple_key; - } - - return 1; -} - -/* - * Remove a potential simple key at the current flow level. - */ - -static int -yaml_parser_remove_simple_key(yaml_parser_t *parser) -{ - yaml_simple_key_t *simple_key = parser->simple_keys.top-1; - - if (simple_key->possible) - { - /* If the key is required, it is an error. */ - - if (simple_key->required) { - return yaml_parser_set_scanner_error(parser, - "while scanning a simple key", simple_key->mark, - "could not find expected ':'"); - } - } - - /* Remove the key from the stack. */ - - simple_key->possible = 0; - - return 1; -} - -/* - * Increase the flow level and resize the simple key list if needed. - */ - -static int -yaml_parser_increase_flow_level(yaml_parser_t *parser) -{ - yaml_simple_key_t empty_simple_key = { 0, 0, 0, { 0, 0, 0 } }; - - /* Reset the simple key on the next level. */ - - if (!PUSH(parser, parser->simple_keys, empty_simple_key)) - return 0; - - /* Increase the flow level. */ - - if (parser->flow_level == INT_MAX) { - parser->error = YAML_MEMORY_ERROR; - return 0; - } - - parser->flow_level++; - - return 1; -} - -/* - * Decrease the flow level. - */ - -static int -yaml_parser_decrease_flow_level(yaml_parser_t *parser) -{ - if (parser->flow_level) { - parser->flow_level --; - (void)POP(parser, parser->simple_keys); - } - - return 1; -} - -/* - * Push the current indentation level to the stack and set the new level - * the current column is greater than the indentation level. In this case, - * append or insert the specified token into the token queue. - * - */ - -static int -yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, - ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark) -{ - yaml_token_t token; - - /* In the flow context, do nothing. */ - - if (parser->flow_level) - return 1; - - if (parser->indent < column) - { - /* - * Push the current indentation level to the stack and set the new - * indentation level. - */ - - if (!PUSH(parser, parser->indents, parser->indent)) - return 0; - - if (column > INT_MAX) { - parser->error = YAML_MEMORY_ERROR; - return 0; - } - - parser->indent = (int)column; - - /* Create a token and insert it into the queue. */ - - TOKEN_INIT(token, type, mark, mark); - - if (number == -1) { - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - } - else { - if (!QUEUE_INSERT(parser, - parser->tokens, number - parser->tokens_parsed, token)) - return 0; - } - } - - return 1; -} - -/* - * Pop indentation levels from the indents stack until the current level - * becomes less or equal to the column. For each indentation level, append - * the BLOCK-END token. - */ - - -static int -yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column) -{ - yaml_token_t token; - - /* In the flow context, do nothing. */ - - if (parser->flow_level) - return 1; - - /* Loop through the indentation levels in the stack. */ - - while (parser->indent > column) - { - /* Create a token and append it to the queue. */ - - TOKEN_INIT(token, YAML_BLOCK_END_TOKEN, parser->mark, parser->mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - /* Pop the indentation level. */ - - parser->indent = POP(parser, parser->indents); - } - - return 1; -} - -/* - * Initialize the scanner and produce the STREAM-START token. - */ - -static int -yaml_parser_fetch_stream_start(yaml_parser_t *parser) -{ - yaml_simple_key_t simple_key = { 0, 0, 0, { 0, 0, 0 } }; - yaml_token_t token; - - /* Set the initial indentation. */ - - parser->indent = -1; - - /* Initialize the simple key stack. */ - - if (!PUSH(parser, parser->simple_keys, simple_key)) - return 0; - - /* A simple key is allowed at the beginning of the stream. */ - - parser->simple_key_allowed = 1; - - /* We have started. */ - - parser->stream_start_produced = 1; - - /* Create the STREAM-START token and append it to the queue. */ - - STREAM_START_TOKEN_INIT(token, parser->encoding, - parser->mark, parser->mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the STREAM-END token and shut down the scanner. - */ - -static int -yaml_parser_fetch_stream_end(yaml_parser_t *parser) -{ - yaml_token_t token; - - /* Force new line. */ - - if (parser->mark.column != 0) { - parser->mark.column = 0; - parser->mark.line ++; - } - - /* Reset the indentation level. */ - - if (!yaml_parser_unroll_indent(parser, -1)) - return 0; - - /* Reset simple keys. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - parser->simple_key_allowed = 0; - - /* Create the STREAM-END token and append it to the queue. */ - - STREAM_END_TOKEN_INIT(token, parser->mark, parser->mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce a VERSION-DIRECTIVE or TAG-DIRECTIVE token. - */ - -static int -yaml_parser_fetch_directive(yaml_parser_t *parser) -{ - yaml_token_t token; - - /* Reset the indentation level. */ - - if (!yaml_parser_unroll_indent(parser, -1)) - return 0; - - /* Reset simple keys. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - parser->simple_key_allowed = 0; - - /* Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. */ - - if (!yaml_parser_scan_directive(parser, &token)) - return 0; - - /* Append the token to the queue. */ - - if (!ENQUEUE(parser, parser->tokens, token)) { - yaml_token_delete(&token); - return 0; - } - - return 1; -} - -/* - * Produce the DOCUMENT-START or DOCUMENT-END token. - */ - -static int -yaml_parser_fetch_document_indicator(yaml_parser_t *parser, - yaml_token_type_t type) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - - /* Reset the indentation level. */ - - if (!yaml_parser_unroll_indent(parser, -1)) - return 0; - - /* Reset simple keys. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - parser->simple_key_allowed = 0; - - /* Consume the token. */ - - start_mark = parser->mark; - - SKIP(parser); - SKIP(parser); - SKIP(parser); - - end_mark = parser->mark; - - /* Create the DOCUMENT-START or DOCUMENT-END token. */ - - TOKEN_INIT(token, type, start_mark, end_mark); - - /* Append the token to the queue. */ - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the FLOW-SEQUENCE-START or FLOW-MAPPING-START token. - */ - -static int -yaml_parser_fetch_flow_collection_start(yaml_parser_t *parser, - yaml_token_type_t type) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - - /* The indicators '[' and '{' may start a simple key. */ - - if (!yaml_parser_save_simple_key(parser)) - return 0; - - /* Increase the flow level. */ - - if (!yaml_parser_increase_flow_level(parser)) - return 0; - - /* A simple key may follow the indicators '[' and '{'. */ - - parser->simple_key_allowed = 1; - - /* Consume the token. */ - - start_mark = parser->mark; - SKIP(parser); - end_mark = parser->mark; - - /* Create the FLOW-SEQUENCE-START of FLOW-MAPPING-START token. */ - - TOKEN_INIT(token, type, start_mark, end_mark); - - /* Append the token to the queue. */ - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the FLOW-SEQUENCE-END or FLOW-MAPPING-END token. - */ - -static int -yaml_parser_fetch_flow_collection_end(yaml_parser_t *parser, - yaml_token_type_t type) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - - /* Reset any potential simple key on the current flow level. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - /* Decrease the flow level. */ - - if (!yaml_parser_decrease_flow_level(parser)) - return 0; - - /* No simple keys after the indicators ']' and '}'. */ - - parser->simple_key_allowed = 0; - - /* Consume the token. */ - - start_mark = parser->mark; - SKIP(parser); - end_mark = parser->mark; - - /* Create the FLOW-SEQUENCE-END of FLOW-MAPPING-END token. */ - - TOKEN_INIT(token, type, start_mark, end_mark); - - /* Append the token to the queue. */ - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the FLOW-ENTRY token. - */ - -static int -yaml_parser_fetch_flow_entry(yaml_parser_t *parser) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - - /* Reset any potential simple keys on the current flow level. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - /* Simple keys are allowed after ','. */ - - parser->simple_key_allowed = 1; - - /* Consume the token. */ - - start_mark = parser->mark; - SKIP(parser); - end_mark = parser->mark; - - /* Create the FLOW-ENTRY token and append it to the queue. */ - - TOKEN_INIT(token, YAML_FLOW_ENTRY_TOKEN, start_mark, end_mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the BLOCK-ENTRY token. - */ - -static int -yaml_parser_fetch_block_entry(yaml_parser_t *parser) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - - /* Check if the scanner is in the block context. */ - - if (!parser->flow_level) - { - /* Check if we are allowed to start a new entry. */ - - if (!parser->simple_key_allowed) { - return yaml_parser_set_scanner_error(parser, NULL, parser->mark, - "block sequence entries are not allowed in this context"); - } - - /* Add the BLOCK-SEQUENCE-START token if needed. */ - - if (!yaml_parser_roll_indent(parser, parser->mark.column, -1, - YAML_BLOCK_SEQUENCE_START_TOKEN, parser->mark)) - return 0; - } - else - { - /* - * It is an error for the '-' indicator to occur in the flow context, - * but we let the Parser detect and report about it because the Parser - * is able to point to the context. - */ - } - - /* Reset any potential simple keys on the current flow level. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - /* Simple keys are allowed after '-'. */ - - parser->simple_key_allowed = 1; - - /* Consume the token. */ - - start_mark = parser->mark; - SKIP(parser); - end_mark = parser->mark; - - /* Create the BLOCK-ENTRY token and append it to the queue. */ - - TOKEN_INIT(token, YAML_BLOCK_ENTRY_TOKEN, start_mark, end_mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the KEY token. - */ - -static int -yaml_parser_fetch_key(yaml_parser_t *parser) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - - /* In the block context, additional checks are required. */ - - if (!parser->flow_level) - { - /* Check if we are allowed to start a new key (not necessary simple). */ - - if (!parser->simple_key_allowed) { - return yaml_parser_set_scanner_error(parser, NULL, parser->mark, - "mapping keys are not allowed in this context"); - } - - /* Add the BLOCK-MAPPING-START token if needed. */ - - if (!yaml_parser_roll_indent(parser, parser->mark.column, -1, - YAML_BLOCK_MAPPING_START_TOKEN, parser->mark)) - return 0; - } - - /* Reset any potential simple keys on the current flow level. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - /* Simple keys are allowed after '?' in the block context. */ - - parser->simple_key_allowed = (!parser->flow_level); - - /* Consume the token. */ - - start_mark = parser->mark; - SKIP(parser); - end_mark = parser->mark; - - /* Create the KEY token and append it to the queue. */ - - TOKEN_INIT(token, YAML_KEY_TOKEN, start_mark, end_mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the VALUE token. - */ - -static int -yaml_parser_fetch_value(yaml_parser_t *parser) -{ - yaml_mark_t start_mark, end_mark; - yaml_token_t token; - yaml_simple_key_t *simple_key = parser->simple_keys.top-1; - - /* Have we found a simple key? */ - - if (simple_key->possible) - { - - /* Create the KEY token and insert it into the queue. */ - - TOKEN_INIT(token, YAML_KEY_TOKEN, simple_key->mark, simple_key->mark); - - if (!QUEUE_INSERT(parser, parser->tokens, - simple_key->token_number - parser->tokens_parsed, token)) - return 0; - - /* In the block context, we may need to add the BLOCK-MAPPING-START token. */ - - if (!yaml_parser_roll_indent(parser, simple_key->mark.column, - simple_key->token_number, - YAML_BLOCK_MAPPING_START_TOKEN, simple_key->mark)) - return 0; - - /* Remove the simple key. */ - - simple_key->possible = 0; - - /* A simple key cannot follow another simple key. */ - - parser->simple_key_allowed = 0; - } - else - { - /* The ':' indicator follows a complex key. */ - - /* In the block context, extra checks are required. */ - - if (!parser->flow_level) - { - /* Check if we are allowed to start a complex value. */ - - if (!parser->simple_key_allowed) { - return yaml_parser_set_scanner_error(parser, NULL, parser->mark, - "mapping values are not allowed in this context"); - } - - /* Add the BLOCK-MAPPING-START token if needed. */ - - if (!yaml_parser_roll_indent(parser, parser->mark.column, -1, - YAML_BLOCK_MAPPING_START_TOKEN, parser->mark)) - return 0; - } - - /* Simple keys after ':' are allowed in the block context. */ - - parser->simple_key_allowed = (!parser->flow_level); - } - - /* Consume the token. */ - - start_mark = parser->mark; - SKIP(parser); - end_mark = parser->mark; - - /* Create the VALUE token and append it to the queue. */ - - TOKEN_INIT(token, YAML_VALUE_TOKEN, start_mark, end_mark); - - if (!ENQUEUE(parser, parser->tokens, token)) - return 0; - - return 1; -} - -/* - * Produce the ALIAS or ANCHOR token. - */ - -static int -yaml_parser_fetch_anchor(yaml_parser_t *parser, yaml_token_type_t type) -{ - yaml_token_t token; - - /* An anchor or an alias could be a simple key. */ - - if (!yaml_parser_save_simple_key(parser)) - return 0; - - /* A simple key cannot follow an anchor or an alias. */ - - parser->simple_key_allowed = 0; - - /* Create the ALIAS or ANCHOR token and append it to the queue. */ - - if (!yaml_parser_scan_anchor(parser, &token, type)) - return 0; - - if (!ENQUEUE(parser, parser->tokens, token)) { - yaml_token_delete(&token); - return 0; - } - return 1; -} - -/* - * Produce the TAG token. - */ - -static int -yaml_parser_fetch_tag(yaml_parser_t *parser) -{ - yaml_token_t token; - - /* A tag could be a simple key. */ - - if (!yaml_parser_save_simple_key(parser)) - return 0; - - /* A simple key cannot follow a tag. */ - - parser->simple_key_allowed = 0; - - /* Create the TAG token and append it to the queue. */ - - if (!yaml_parser_scan_tag(parser, &token)) - return 0; - - if (!ENQUEUE(parser, parser->tokens, token)) { - yaml_token_delete(&token); - return 0; - } - - return 1; -} - -/* - * Produce the SCALAR(...,literal) or SCALAR(...,folded) tokens. - */ - -static int -yaml_parser_fetch_block_scalar(yaml_parser_t *parser, int literal) -{ - yaml_token_t token; - - /* Remove any potential simple keys. */ - - if (!yaml_parser_remove_simple_key(parser)) - return 0; - - /* A simple key may follow a block scalar. */ - - parser->simple_key_allowed = 1; - - /* Create the SCALAR token and append it to the queue. */ - - if (!yaml_parser_scan_block_scalar(parser, &token, literal)) - return 0; - - if (!ENQUEUE(parser, parser->tokens, token)) { - yaml_token_delete(&token); - return 0; - } - - return 1; -} - -/* - * Produce the SCALAR(...,single-quoted) or SCALAR(...,double-quoted) tokens. - */ - -static int -yaml_parser_fetch_flow_scalar(yaml_parser_t *parser, int single) -{ - yaml_token_t token; - - /* A plain scalar could be a simple key. */ - - if (!yaml_parser_save_simple_key(parser)) - return 0; - - /* A simple key cannot follow a flow scalar. */ - - parser->simple_key_allowed = 0; - - /* Create the SCALAR token and append it to the queue. */ - - if (!yaml_parser_scan_flow_scalar(parser, &token, single)) - return 0; - - if (!ENQUEUE(parser, parser->tokens, token)) { - yaml_token_delete(&token); - return 0; - } - - return 1; -} - -/* - * Produce the SCALAR(...,plain) token. - */ - -static int -yaml_parser_fetch_plain_scalar(yaml_parser_t *parser) -{ - yaml_token_t token; - - /* A plain scalar could be a simple key. */ - - if (!yaml_parser_save_simple_key(parser)) - return 0; - - /* A simple key cannot follow a flow scalar. */ - - parser->simple_key_allowed = 0; - - /* Create the SCALAR token and append it to the queue. */ - - if (!yaml_parser_scan_plain_scalar(parser, &token)) - return 0; - - if (!ENQUEUE(parser, parser->tokens, token)) { - yaml_token_delete(&token); - return 0; - } - - return 1; -} - -/* - * Eat whitespaces and comments until the next token is found. - */ - -static int -yaml_parser_scan_to_next_token(yaml_parser_t *parser) -{ - /* Until the next token is not found. */ - - while (1) - { - /* Allow the BOM mark to start a line. */ - - if (!CACHE(parser, 1)) return 0; - - if (parser->mark.column == 0 && IS_BOM(parser->buffer)) - SKIP(parser); - - /* - * Eat whitespaces. - * - * Tabs are allowed: - * - * - in the flow context; - * - in the block context, but not at the beginning of the line or - * after '-', '?', or ':' (complex value). - */ - - if (!CACHE(parser, 1)) return 0; - - while (CHECK(parser->buffer,' ') || - ((parser->flow_level || !parser->simple_key_allowed) && - CHECK(parser->buffer, '\t'))) { - SKIP(parser); - if (!CACHE(parser, 1)) return 0; - } - - /* Eat a comment until a line break. */ - - if (CHECK(parser->buffer, '#')) { - while (!IS_BREAKZ(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) return 0; - } - } - - /* If it is a line break, eat it. */ - - if (IS_BREAK(parser->buffer)) - { - if (!CACHE(parser, 2)) return 0; - SKIP_LINE(parser); - - /* In the block context, a new line may start a simple key. */ - - if (!parser->flow_level) { - parser->simple_key_allowed = 1; - } - } - else - { - /* We have found a token. */ - - break; - } - } - - return 1; -} - -/* - * Scan a YAML-DIRECTIVE or TAG-DIRECTIVE token. - * - * Scope: - * %YAML 1.1 # a comment \n - * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - * %TAG !yaml! tag:yaml.org,2002: \n - * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - */ - -int -yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token) -{ - yaml_mark_t start_mark, end_mark; - yaml_char_t *name = NULL; - int major, minor; - yaml_char_t *handle = NULL, *prefix = NULL; - - /* Eat '%'. */ - - start_mark = parser->mark; - - SKIP(parser); - - /* Scan the directive name. */ - - if (!yaml_parser_scan_directive_name(parser, start_mark, &name)) - goto error; - - /* Is it a YAML directive? */ - - if (strcmp((char *)name, "YAML") == 0) - { - /* Scan the VERSION directive value. */ - - if (!yaml_parser_scan_version_directive_value(parser, start_mark, - &major, &minor)) - goto error; - - end_mark = parser->mark; - - /* Create a VERSION-DIRECTIVE token. */ - - VERSION_DIRECTIVE_TOKEN_INIT(*token, major, minor, - start_mark, end_mark); - } - - /* Is it a TAG directive? */ - - else if (strcmp((char *)name, "TAG") == 0) - { - /* Scan the TAG directive value. */ - - if (!yaml_parser_scan_tag_directive_value(parser, start_mark, - &handle, &prefix)) - goto error; - - end_mark = parser->mark; - - /* Create a TAG-DIRECTIVE token. */ - - TAG_DIRECTIVE_TOKEN_INIT(*token, handle, prefix, - start_mark, end_mark); - } - - /* Unknown directive. */ - - else - { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found unknown directive name"); - goto error; - } - - /* Eat the rest of the line including any comments. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_BLANK(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) goto error; - } - - if (CHECK(parser->buffer, '#')) { - while (!IS_BREAKZ(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) goto error; - } - } - - /* Check if we are at the end of the line. */ - - if (!IS_BREAKZ(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "did not find expected comment or line break"); - goto error; - } - - /* Eat a line break. */ - - if (IS_BREAK(parser->buffer)) { - if (!CACHE(parser, 2)) goto error; - SKIP_LINE(parser); - } - - yaml_free(name); - - return 1; - -error: - yaml_free(prefix); - yaml_free(handle); - yaml_free(name); - return 0; -} - -/* - * Scan the directive name. - * - * Scope: - * %YAML 1.1 # a comment \n - * ^^^^ - * %TAG !yaml! tag:yaml.org,2002: \n - * ^^^ - */ - -static int -yaml_parser_scan_directive_name(yaml_parser_t *parser, - yaml_mark_t start_mark, yaml_char_t **name) -{ - yaml_string_t string = NULL_STRING; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - - /* Consume the directive name. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_ALPHA(parser->buffer)) - { - if (!READ(parser, string)) goto error; - if (!CACHE(parser, 1)) goto error; - } - - /* Check if the name is empty. */ - - if (string.start == string.pointer) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "could not find expected directive name"); - goto error; - } - - /* Check for an blank character after the name. */ - - if (!IS_BLANKZ(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found unexpected non-alphabetical character"); - goto error; - } - - *name = string.start; - - return 1; - -error: - STRING_DEL(parser, string); - return 0; -} - -/* - * Scan the value of VERSION-DIRECTIVE. - * - * Scope: - * %YAML 1.1 # a comment \n - * ^^^^^^ - */ - -static int -yaml_parser_scan_version_directive_value(yaml_parser_t *parser, - yaml_mark_t start_mark, int *major, int *minor) -{ - /* Eat whitespaces. */ - - if (!CACHE(parser, 1)) return 0; - - while (IS_BLANK(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) return 0; - } - - /* Consume the major version number. */ - - if (!yaml_parser_scan_version_directive_number(parser, start_mark, major)) - return 0; - - /* Eat '.'. */ - - if (!CHECK(parser->buffer, '.')) { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "did not find expected digit or '.' character"); - } - - SKIP(parser); - - /* Consume the minor version number. */ - - if (!yaml_parser_scan_version_directive_number(parser, start_mark, minor)) - return 0; - - return 1; -} - -#define MAX_NUMBER_LENGTH 9 - -/* - * Scan the version number of VERSION-DIRECTIVE. - * - * Scope: - * %YAML 1.1 # a comment \n - * ^ - * %YAML 1.1 # a comment \n - * ^ - */ - -static int -yaml_parser_scan_version_directive_number(yaml_parser_t *parser, - yaml_mark_t start_mark, int *number) -{ - int value = 0; - size_t length = 0; - - /* Repeat while the next character is digit. */ - - if (!CACHE(parser, 1)) return 0; - - while (IS_DIGIT(parser->buffer)) - { - /* Check if the number is too long. */ - - if (++length > MAX_NUMBER_LENGTH) { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "found extremely long version number"); - } - - value = value*10 + AS_DIGIT(parser->buffer); - - SKIP(parser); - - if (!CACHE(parser, 1)) return 0; - } - - /* Check if the number was present. */ - - if (!length) { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "did not find expected version number"); - } - - *number = value; - - return 1; -} - -/* - * Scan the value of a TAG-DIRECTIVE token. - * - * Scope: - * %TAG !yaml! tag:yaml.org,2002: \n - * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - */ - -static int -yaml_parser_scan_tag_directive_value(yaml_parser_t *parser, - yaml_mark_t start_mark, yaml_char_t **handle, yaml_char_t **prefix) -{ - yaml_char_t *handle_value = NULL; - yaml_char_t *prefix_value = NULL; - - /* Eat whitespaces. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_BLANK(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) goto error; - } - - /* Scan a handle. */ - - if (!yaml_parser_scan_tag_handle(parser, 1, start_mark, &handle_value)) - goto error; - - /* Expect a whitespace. */ - - if (!CACHE(parser, 1)) goto error; - - if (!IS_BLANK(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", - start_mark, "did not find expected whitespace"); - goto error; - } - - /* Eat whitespaces. */ - - while (IS_BLANK(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) goto error; - } - - /* Scan a prefix. */ - - if (!yaml_parser_scan_tag_uri(parser, 1, 1, NULL, start_mark, &prefix_value)) - goto error; - - /* Expect a whitespace or line break. */ - - if (!CACHE(parser, 1)) goto error; - - if (!IS_BLANKZ(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", - start_mark, "did not find expected whitespace or line break"); - goto error; - } - - *handle = handle_value; - *prefix = prefix_value; - - return 1; - -error: - yaml_free(handle_value); - yaml_free(prefix_value); - return 0; -} - -static int -yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token, - yaml_token_type_t type) -{ - int length = 0; - yaml_mark_t start_mark, end_mark; - yaml_string_t string = NULL_STRING; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - - /* Eat the indicator character. */ - - start_mark = parser->mark; - - SKIP(parser); - - /* Consume the value. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_ALPHA(parser->buffer)) { - if (!READ(parser, string)) goto error; - if (!CACHE(parser, 1)) goto error; - length ++; - } - - end_mark = parser->mark; - - /* - * Check if length of the anchor is greater than 0 and it is followed by - * a whitespace character or one of the indicators: - * - * '?', ':', ',', ']', '}', '%', '@', '`'. - */ - - if (!length || !(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '?') - || CHECK(parser->buffer, ':') || CHECK(parser->buffer, ',') - || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '}') - || CHECK(parser->buffer, '%') || CHECK(parser->buffer, '@') - || CHECK(parser->buffer, '`'))) { - yaml_parser_set_scanner_error(parser, type == YAML_ANCHOR_TOKEN ? - "while scanning an anchor" : "while scanning an alias", start_mark, - "did not find expected alphabetic or numeric character"); - goto error; - } - - /* Create a token. */ - - if (type == YAML_ANCHOR_TOKEN) { - ANCHOR_TOKEN_INIT(*token, string.start, start_mark, end_mark); - } - else { - ALIAS_TOKEN_INIT(*token, string.start, start_mark, end_mark); - } - - return 1; - -error: - STRING_DEL(parser, string); - return 0; -} - -/* - * Scan a TAG token. - */ - -static int -yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token) -{ - yaml_char_t *handle = NULL; - yaml_char_t *suffix = NULL; - yaml_mark_t start_mark, end_mark; - - start_mark = parser->mark; - - /* Check if the tag is in the canonical form. */ - - if (!CACHE(parser, 2)) goto error; - - if (CHECK_AT(parser->buffer, '<', 1)) - { - /* Set the handle to '' */ - - handle = YAML_MALLOC(1); - if (!handle) goto error; - handle[0] = '\0'; - - /* Eat '!<' */ - - SKIP(parser); - SKIP(parser); - - /* Consume the tag value. */ - - if (!yaml_parser_scan_tag_uri(parser, 1, 0, NULL, start_mark, &suffix)) - goto error; - - /* Check for '>' and eat it. */ - - if (!CHECK(parser->buffer, '>')) { - yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not find the expected '>'"); - goto error; - } - - SKIP(parser); - } - else - { - /* The tag has either the '!suffix' or the '!handle!suffix' form. */ - - /* First, try to scan a handle. */ - - if (!yaml_parser_scan_tag_handle(parser, 0, start_mark, &handle)) - goto error; - - /* Check if it is, indeed, handle. */ - - if (handle[0] == '!' && handle[1] != '\0' && handle[strlen((char *)handle)-1] == '!') - { - /* Scan the suffix now. */ - - if (!yaml_parser_scan_tag_uri(parser, 0, 0, NULL, start_mark, &suffix)) - goto error; - } - else - { - /* It wasn't a handle after all. Scan the rest of the tag. */ - - if (!yaml_parser_scan_tag_uri(parser, 0, 0, handle, start_mark, &suffix)) - goto error; - - /* Set the handle to '!'. */ - - yaml_free(handle); - handle = YAML_MALLOC(2); - if (!handle) goto error; - handle[0] = '!'; - handle[1] = '\0'; - - /* - * A special case: the '!' tag. Set the handle to '' and the - * suffix to '!'. - */ - - if (suffix[0] == '\0') { - yaml_char_t *tmp = handle; - handle = suffix; - suffix = tmp; - } - } - } - - /* Check the character which ends the tag. */ - - if (!CACHE(parser, 1)) goto error; - - if (!IS_BLANKZ(parser->buffer)) { - if (!parser->flow_level || !CHECK(parser->buffer, ',') ) { - yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not find expected whitespace or line break"); - goto error; - } - } - - end_mark = parser->mark; - - /* Create a token. */ - - TAG_TOKEN_INIT(*token, handle, suffix, start_mark, end_mark); - - return 1; - -error: - yaml_free(handle); - yaml_free(suffix); - return 0; -} - -/* - * Scan a tag handle. - */ - -static int -yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive, - yaml_mark_t start_mark, yaml_char_t **handle) -{ - yaml_string_t string = NULL_STRING; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - - /* Check the initial '!' character. */ - - if (!CACHE(parser, 1)) goto error; - - if (!CHECK(parser->buffer, '!')) { - yaml_parser_set_scanner_error(parser, directive ? - "while scanning a tag directive" : "while scanning a tag", - start_mark, "did not find expected '!'"); - goto error; - } - - /* Copy the '!' character. */ - - if (!READ(parser, string)) goto error; - - /* Copy all subsequent alphabetical and numerical characters. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_ALPHA(parser->buffer)) - { - if (!READ(parser, string)) goto error; - if (!CACHE(parser, 1)) goto error; - } - - /* Check if the trailing character is '!' and copy it. */ - - if (CHECK(parser->buffer, '!')) - { - if (!READ(parser, string)) goto error; - } - else - { - /* - * It's either the '!' tag or not really a tag handle. If it's a %TAG - * directive, it's an error. If it's a tag token, it must be a part of - * URI. - */ - - if (directive && !(string.start[0] == '!' && string.start[1] == '\0')) { - yaml_parser_set_scanner_error(parser, "while parsing a tag directive", - start_mark, "did not find expected '!'"); - goto error; - } - } - - *handle = string.start; - - return 1; - -error: - STRING_DEL(parser, string); - return 0; -} - -/* - * Scan a tag. - */ - -static int -yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive, - yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri) -{ - size_t length = head ? strlen((char *)head) : 0; - yaml_string_t string = NULL_STRING; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - - /* Resize the string to include the head. */ - - while ((size_t)(string.end - string.start) <= length) { - if (!yaml_string_extend(&string.start, &string.pointer, &string.end)) { - parser->error = YAML_MEMORY_ERROR; - goto error; - } - } - - /* - * Copy the head if needed. - * - * Note that we don't copy the leading '!' character. - */ - - if (length > 1) { - memcpy(string.start, head+1, length-1); - string.pointer += length-1; - } - - /* Scan the tag. */ - - if (!CACHE(parser, 1)) goto error; - - /* - * The set of characters that may appear in URI is as follows: - * - * '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&', - * '=', '+', '$', '.', '!', '~', '*', '\'', '(', ')', '%'. - * - * If we are inside a verbatim tag <...> (parameter uri_char is true) - * then also the following flow indicators are allowed: - * ',', '[', ']' - */ - - while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';') - || CHECK(parser->buffer, '/') || CHECK(parser->buffer, '?') - || CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@') - || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=') - || CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$') - || CHECK(parser->buffer, '.') || CHECK(parser->buffer, '%') - || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~') - || CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'') - || CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')') - || (uri_char && ( - CHECK(parser->buffer, ',') - || CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']') - ) - )) - { - /* Check if it is a URI-escape sequence. */ - - if (CHECK(parser->buffer, '%')) { - if (!STRING_EXTEND(parser, string)) - goto error; - - if (!yaml_parser_scan_uri_escapes(parser, - directive, start_mark, &string)) goto error; - } - else { - if (!READ(parser, string)) goto error; - } - - length ++; - if (!CACHE(parser, 1)) goto error; - } - - /* Check if the tag is non-empty. */ - - if (!length) { - if (!STRING_EXTEND(parser, string)) - goto error; - - yaml_parser_set_scanner_error(parser, directive ? - "while parsing a %TAG directive" : "while parsing a tag", - start_mark, "did not find expected tag URI"); - goto error; - } - - *uri = string.start; - - return 1; - -error: - STRING_DEL(parser, string); - return 0; -} - -/* - * Decode an URI-escape sequence corresponding to a single UTF-8 character. - */ - -static int -yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, - yaml_mark_t start_mark, yaml_string_t *string) -{ - int width = 0; - - /* Decode the required number of characters. */ - - do { - - unsigned char octet = 0; - - /* Check for a URI-escaped octet. */ - - if (!CACHE(parser, 3)) return 0; - - if (!(CHECK(parser->buffer, '%') - && IS_HEX_AT(parser->buffer, 1) - && IS_HEX_AT(parser->buffer, 2))) { - return yaml_parser_set_scanner_error(parser, directive ? - "while parsing a %TAG directive" : "while parsing a tag", - start_mark, "did not find URI escaped octet"); - } - - /* Get the octet. */ - - octet = (AS_HEX_AT(parser->buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2); - - /* If it is the leading octet, determine the length of the UTF-8 sequence. */ - - if (!width) - { - width = (octet & 0x80) == 0x00 ? 1 : - (octet & 0xE0) == 0xC0 ? 2 : - (octet & 0xF0) == 0xE0 ? 3 : - (octet & 0xF8) == 0xF0 ? 4 : 0; - if (!width) { - return yaml_parser_set_scanner_error(parser, directive ? - "while parsing a %TAG directive" : "while parsing a tag", - start_mark, "found an incorrect leading UTF-8 octet"); - } - } - else - { - /* Check if the trailing octet is correct. */ - - if ((octet & 0xC0) != 0x80) { - return yaml_parser_set_scanner_error(parser, directive ? - "while parsing a %TAG directive" : "while parsing a tag", - start_mark, "found an incorrect trailing UTF-8 octet"); - } - } - - /* Copy the octet and move the pointers. */ - - *(string->pointer++) = octet; - SKIP(parser); - SKIP(parser); - SKIP(parser); - - } while (--width); - - return 1; -} - -/* - * Scan a block scalar. - */ - -static int -yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, - int literal) -{ - yaml_mark_t start_mark; - yaml_mark_t end_mark; - yaml_string_t string = NULL_STRING; - yaml_string_t leading_break = NULL_STRING; - yaml_string_t trailing_breaks = NULL_STRING; - int chomping = 0; - int increment = 0; - int indent = 0; - int leading_blank = 0; - int trailing_blank = 0; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error; - - /* Eat the indicator '|' or '>'. */ - - start_mark = parser->mark; - - SKIP(parser); - - /* Scan the additional block scalar indicators. */ - - if (!CACHE(parser, 1)) goto error; - - /* Check for a chomping indicator. */ - - if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) - { - /* Set the chomping method and eat the indicator. */ - - chomping = CHECK(parser->buffer, '+') ? +1 : -1; - - SKIP(parser); - - /* Check for an indentation indicator. */ - - if (!CACHE(parser, 1)) goto error; - - if (IS_DIGIT(parser->buffer)) - { - /* Check that the indentation is greater than 0. */ - - if (CHECK(parser->buffer, '0')) { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0"); - goto error; - } - - /* Get the indentation level and eat the indicator. */ - - increment = AS_DIGIT(parser->buffer); - - SKIP(parser); - } - } - - /* Do the same as above, but in the opposite order. */ - - else if (IS_DIGIT(parser->buffer)) - { - if (CHECK(parser->buffer, '0')) { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0"); - goto error; - } - - increment = AS_DIGIT(parser->buffer); - - SKIP(parser); - - if (!CACHE(parser, 1)) goto error; - - if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) { - chomping = CHECK(parser->buffer, '+') ? +1 : -1; - - SKIP(parser); - } - } - - /* Eat whitespaces and comments to the end of the line. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_BLANK(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) goto error; - } - - if (CHECK(parser->buffer, '#')) { - while (!IS_BREAKZ(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) goto error; - } - } - - /* Check if we are at the end of the line. */ - - if (!IS_BREAKZ(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "did not find expected comment or line break"); - goto error; - } - - /* Eat a line break. */ - - if (IS_BREAK(parser->buffer)) { - if (!CACHE(parser, 2)) goto error; - SKIP_LINE(parser); - } - - end_mark = parser->mark; - - /* Set the indentation level if it was specified. */ - - if (increment) { - indent = parser->indent >= 0 ? parser->indent+increment : increment; - } - - /* Scan the leading line breaks and determine the indentation level if needed. */ - - if (!yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, - start_mark, &end_mark)) goto error; - - /* Scan the block scalar content. */ - - if (!CACHE(parser, 1)) goto error; - - while ((int)parser->mark.column == indent && !(IS_Z(parser->buffer))) - { - /* - * We are at the beginning of a non-empty line. - */ - - /* Is it a trailing whitespace? */ - - trailing_blank = IS_BLANK(parser->buffer); - - /* Check if we need to fold the leading line break. */ - - if (!literal && (*leading_break.start == '\n') - && !leading_blank && !trailing_blank) - { - /* Do we need to join the lines by space? */ - - if (*trailing_breaks.start == '\0') { - if (!STRING_EXTEND(parser, string)) goto error; - *(string.pointer ++) = ' '; - } - - CLEAR(parser, leading_break); - } - else { - if (!JOIN(parser, string, leading_break)) goto error; - CLEAR(parser, leading_break); - } - - /* Append the remaining line breaks. */ - - if (!JOIN(parser, string, trailing_breaks)) goto error; - CLEAR(parser, trailing_breaks); - - /* Is it a leading whitespace? */ - - leading_blank = IS_BLANK(parser->buffer); - - /* Consume the current line. */ - - while (!IS_BREAKZ(parser->buffer)) { - if (!READ(parser, string)) goto error; - if (!CACHE(parser, 1)) goto error; - } - - /* Consume the line break. */ - - if (!CACHE(parser, 2)) goto error; - - if (!READ_LINE(parser, leading_break)) goto error; - - /* Eat the following indentation spaces and line breaks. */ - - if (!yaml_parser_scan_block_scalar_breaks(parser, - &indent, &trailing_breaks, start_mark, &end_mark)) goto error; - } - - /* Chomp the tail. */ - - if (chomping != -1) { - if (!JOIN(parser, string, leading_break)) goto error; - } - if (chomping == 1) { - if (!JOIN(parser, string, trailing_breaks)) goto error; - } - - /* Create a token. */ - - SCALAR_TOKEN_INIT(*token, string.start, string.pointer-string.start, - literal ? YAML_LITERAL_SCALAR_STYLE : YAML_FOLDED_SCALAR_STYLE, - start_mark, end_mark); - - STRING_DEL(parser, leading_break); - STRING_DEL(parser, trailing_breaks); - - return 1; - -error: - STRING_DEL(parser, string); - STRING_DEL(parser, leading_break); - STRING_DEL(parser, trailing_breaks); - - return 0; -} - -/* - * Scan indentation spaces and line breaks for a block scalar. Determine the - * indentation level if needed. - */ - -static int -yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser, - int *indent, yaml_string_t *breaks, - yaml_mark_t start_mark, yaml_mark_t *end_mark) -{ - int max_indent = 0; - - *end_mark = parser->mark; - - /* Eat the indentation spaces and line breaks. */ - - while (1) - { - /* Eat the indentation spaces. */ - - if (!CACHE(parser, 1)) return 0; - - while ((!*indent || (int)parser->mark.column < *indent) - && IS_SPACE(parser->buffer)) { - SKIP(parser); - if (!CACHE(parser, 1)) return 0; - } - - if ((int)parser->mark.column > max_indent) - max_indent = (int)parser->mark.column; - - /* Check for a tab character messing the indentation. */ - - if ((!*indent || (int)parser->mark.column < *indent) - && IS_TAB(parser->buffer)) { - return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found a tab character where an indentation space is expected"); - } - - /* Have we found a non-empty line? */ - - if (!IS_BREAK(parser->buffer)) break; - - /* Consume the line break. */ - - if (!CACHE(parser, 2)) return 0; - if (!READ_LINE(parser, *breaks)) return 0; - *end_mark = parser->mark; - } - - /* Determine the indentation level if needed. */ - - if (!*indent) { - *indent = max_indent; - if (*indent < parser->indent + 1) - *indent = parser->indent + 1; - if (*indent < 1) - *indent = 1; - } - - return 1; -} - -/* - * Scan a quoted scalar. - */ - -static int -yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, - int single) -{ - yaml_mark_t start_mark; - yaml_mark_t end_mark; - yaml_string_t string = NULL_STRING; - yaml_string_t leading_break = NULL_STRING; - yaml_string_t trailing_breaks = NULL_STRING; - yaml_string_t whitespaces = NULL_STRING; - int leading_blanks; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_SIZE)) goto error; - - /* Eat the left quote. */ - - start_mark = parser->mark; - - SKIP(parser); - - /* Consume the content of the quoted scalar. */ - - while (1) - { - /* Check that there are no document indicators at the beginning of the line. */ - - if (!CACHE(parser, 4)) goto error; - - if (parser->mark.column == 0 && - ((CHECK_AT(parser->buffer, '-', 0) && - CHECK_AT(parser->buffer, '-', 1) && - CHECK_AT(parser->buffer, '-', 2)) || - (CHECK_AT(parser->buffer, '.', 0) && - CHECK_AT(parser->buffer, '.', 1) && - CHECK_AT(parser->buffer, '.', 2))) && - IS_BLANKZ_AT(parser->buffer, 3)) - { - yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", - start_mark, "found unexpected document indicator"); - goto error; - } - - /* Check for EOF. */ - - if (IS_Z(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", - start_mark, "found unexpected end of stream"); - goto error; - } - - /* Consume non-blank characters. */ - - if (!CACHE(parser, 2)) goto error; - - leading_blanks = 0; - - while (!IS_BLANKZ(parser->buffer)) - { - /* Check for an escaped single quote. */ - - if (single && CHECK_AT(parser->buffer, '\'', 0) - && CHECK_AT(parser->buffer, '\'', 1)) - { - if (!STRING_EXTEND(parser, string)) goto error; - *(string.pointer++) = '\''; - SKIP(parser); - SKIP(parser); - } - - /* Check for the right quote. */ - - else if (CHECK(parser->buffer, single ? '\'' : '"')) - { - break; - } - - /* Check for an escaped line break. */ - - else if (!single && CHECK(parser->buffer, '\\') - && IS_BREAK_AT(parser->buffer, 1)) - { - if (!CACHE(parser, 3)) goto error; - SKIP(parser); - SKIP_LINE(parser); - leading_blanks = 1; - break; - } - - /* Check for an escape sequence. */ - - else if (!single && CHECK(parser->buffer, '\\')) - { - size_t code_length = 0; - - if (!STRING_EXTEND(parser, string)) goto error; - - /* Check the escape character. */ - - switch (parser->buffer.pointer[1]) - { - case '0': - *(string.pointer++) = '\0'; - break; - - case 'a': - *(string.pointer++) = '\x07'; - break; - - case 'b': - *(string.pointer++) = '\x08'; - break; - - case 't': - case '\t': - *(string.pointer++) = '\x09'; - break; - - case 'n': - *(string.pointer++) = '\x0A'; - break; - - case 'v': - *(string.pointer++) = '\x0B'; - break; - - case 'f': - *(string.pointer++) = '\x0C'; - break; - - case 'r': - *(string.pointer++) = '\x0D'; - break; - - case 'e': - *(string.pointer++) = '\x1B'; - break; - - case ' ': - *(string.pointer++) = '\x20'; - break; - - case '"': - *(string.pointer++) = '"'; - break; - - case '/': - *(string.pointer++) = '/'; - break; - - case '\\': - *(string.pointer++) = '\\'; - break; - - case 'N': /* NEL (#x85) */ - *(string.pointer++) = '\xC2'; - *(string.pointer++) = '\x85'; - break; - - case '_': /* #xA0 */ - *(string.pointer++) = '\xC2'; - *(string.pointer++) = '\xA0'; - break; - - case 'L': /* LS (#x2028) */ - *(string.pointer++) = '\xE2'; - *(string.pointer++) = '\x80'; - *(string.pointer++) = '\xA8'; - break; - - case 'P': /* PS (#x2029) */ - *(string.pointer++) = '\xE2'; - *(string.pointer++) = '\x80'; - *(string.pointer++) = '\xA9'; - break; - - case 'x': - code_length = 2; - break; - - case 'u': - code_length = 4; - break; - - case 'U': - code_length = 8; - break; - - default: - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "found unknown escape character"); - goto error; - } - - SKIP(parser); - SKIP(parser); - - /* Consume an arbitrary escape code. */ - - if (code_length) - { - unsigned int value = 0; - size_t k; - - /* Scan the character value. */ - - if (!CACHE(parser, code_length)) goto error; - - for (k = 0; k < code_length; k ++) { - if (!IS_HEX_AT(parser->buffer, k)) { - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "did not find expected hexdecimal number"); - goto error; - } - value = (value << 4) + AS_HEX_AT(parser->buffer, k); - } - - /* Check the value and write the character. */ - - if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) { - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "found invalid Unicode character escape code"); - goto error; - } - - if (value <= 0x7F) { - *(string.pointer++) = value; - } - else if (value <= 0x7FF) { - *(string.pointer++) = 0xC0 + (value >> 6); - *(string.pointer++) = 0x80 + (value & 0x3F); - } - else if (value <= 0xFFFF) { - *(string.pointer++) = 0xE0 + (value >> 12); - *(string.pointer++) = 0x80 + ((value >> 6) & 0x3F); - *(string.pointer++) = 0x80 + (value & 0x3F); - } - else { - *(string.pointer++) = 0xF0 + (value >> 18); - *(string.pointer++) = 0x80 + ((value >> 12) & 0x3F); - *(string.pointer++) = 0x80 + ((value >> 6) & 0x3F); - *(string.pointer++) = 0x80 + (value & 0x3F); - } - - /* Advance the pointer. */ - - for (k = 0; k < code_length; k ++) { - SKIP(parser); - } - } - } - - else - { - /* It is a non-escaped non-blank character. */ - - if (!READ(parser, string)) goto error; - } - - if (!CACHE(parser, 2)) goto error; - } - - /* Check if we are at the end of the scalar. */ - - /* Fix for crash uninitialized value crash - * Credit for the bug and input is to OSS Fuzz - * Credit for the fix to Alex Gaynor - */ - if (!CACHE(parser, 1)) goto error; - if (CHECK(parser->buffer, single ? '\'' : '"')) - break; - - /* Consume blank characters. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)) - { - if (IS_BLANK(parser->buffer)) - { - /* Consume a space or a tab character. */ - - if (!leading_blanks) { - if (!READ(parser, whitespaces)) goto error; - } - else { - SKIP(parser); - } - } - else - { - if (!CACHE(parser, 2)) goto error; - - /* Check if it is a first line break. */ - - if (!leading_blanks) - { - CLEAR(parser, whitespaces); - if (!READ_LINE(parser, leading_break)) goto error; - leading_blanks = 1; - } - else - { - if (!READ_LINE(parser, trailing_breaks)) goto error; - } - } - if (!CACHE(parser, 1)) goto error; - } - - /* Join the whitespaces or fold line breaks. */ - - if (leading_blanks) - { - /* Do we need to fold line breaks? */ - - if (leading_break.start[0] == '\n') { - if (trailing_breaks.start[0] == '\0') { - if (!STRING_EXTEND(parser, string)) goto error; - *(string.pointer++) = ' '; - } - else { - if (!JOIN(parser, string, trailing_breaks)) goto error; - CLEAR(parser, trailing_breaks); - } - CLEAR(parser, leading_break); - } - else { - if (!JOIN(parser, string, leading_break)) goto error; - if (!JOIN(parser, string, trailing_breaks)) goto error; - CLEAR(parser, leading_break); - CLEAR(parser, trailing_breaks); - } - } - else - { - if (!JOIN(parser, string, whitespaces)) goto error; - CLEAR(parser, whitespaces); - } - } - - /* Eat the right quote. */ - - SKIP(parser); - - end_mark = parser->mark; - - /* Create a token. */ - - SCALAR_TOKEN_INIT(*token, string.start, string.pointer-string.start, - single ? YAML_SINGLE_QUOTED_SCALAR_STYLE : YAML_DOUBLE_QUOTED_SCALAR_STYLE, - start_mark, end_mark); - - STRING_DEL(parser, leading_break); - STRING_DEL(parser, trailing_breaks); - STRING_DEL(parser, whitespaces); - - return 1; - -error: - STRING_DEL(parser, string); - STRING_DEL(parser, leading_break); - STRING_DEL(parser, trailing_breaks); - STRING_DEL(parser, whitespaces); - - return 0; -} - -/* - * Scan a plain scalar. - */ - -static int -yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token) -{ - yaml_mark_t start_mark; - yaml_mark_t end_mark; - yaml_string_t string = NULL_STRING; - yaml_string_t leading_break = NULL_STRING; - yaml_string_t trailing_breaks = NULL_STRING; - yaml_string_t whitespaces = NULL_STRING; - int leading_blanks = 0; - int indent = parser->indent+1; - - if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error; - if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_SIZE)) goto error; - - start_mark = end_mark = parser->mark; - - /* Consume the content of the plain scalar. */ - - while (1) - { - /* Check for a document indicator. */ - - if (!CACHE(parser, 4)) goto error; - - if (parser->mark.column == 0 && - ((CHECK_AT(parser->buffer, '-', 0) && - CHECK_AT(parser->buffer, '-', 1) && - CHECK_AT(parser->buffer, '-', 2)) || - (CHECK_AT(parser->buffer, '.', 0) && - CHECK_AT(parser->buffer, '.', 1) && - CHECK_AT(parser->buffer, '.', 2))) && - IS_BLANKZ_AT(parser->buffer, 3)) break; - - /* Check for a comment. */ - - if (CHECK(parser->buffer, '#')) - break; - - /* Consume non-blank characters. */ - - while (!IS_BLANKZ(parser->buffer)) - { - /* Check for "x:" + one of ',?[]{}' in the flow context. TODO: Fix the test "spec-08-13". - * This is not completely according to the spec - * See http://yaml.org/spec/1.1/#id907281 9.1.3. Plain - */ - - if (parser->flow_level - && CHECK(parser->buffer, ':') - && ( - CHECK_AT(parser->buffer, ',', 1) - || CHECK_AT(parser->buffer, '?', 1) - || CHECK_AT(parser->buffer, '[', 1) - || CHECK_AT(parser->buffer, ']', 1) - || CHECK_AT(parser->buffer, '{', 1) - || CHECK_AT(parser->buffer, '}', 1) - ) - ) { - yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", - start_mark, "found unexpected ':'"); - goto error; - } - - /* Check for indicators that may end a plain scalar. */ - - if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1)) - || (parser->flow_level && - (CHECK(parser->buffer, ',') - || CHECK(parser->buffer, '[') - || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{') - || CHECK(parser->buffer, '}')))) - break; - - /* Check if we need to join whitespaces and breaks. */ - - if (leading_blanks || whitespaces.start != whitespaces.pointer) - { - if (leading_blanks) - { - /* Do we need to fold line breaks? */ - - if (leading_break.start[0] == '\n') { - if (trailing_breaks.start[0] == '\0') { - if (!STRING_EXTEND(parser, string)) goto error; - *(string.pointer++) = ' '; - } - else { - if (!JOIN(parser, string, trailing_breaks)) goto error; - CLEAR(parser, trailing_breaks); - } - CLEAR(parser, leading_break); - } - else { - if (!JOIN(parser, string, leading_break)) goto error; - if (!JOIN(parser, string, trailing_breaks)) goto error; - CLEAR(parser, leading_break); - CLEAR(parser, trailing_breaks); - } - - leading_blanks = 0; - } - else - { - if (!JOIN(parser, string, whitespaces)) goto error; - CLEAR(parser, whitespaces); - } - } - - /* Copy the character. */ - - if (!READ(parser, string)) goto error; - - end_mark = parser->mark; - - if (!CACHE(parser, 2)) goto error; - } - - /* Is it the end? */ - - if (!(IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer))) - break; - - /* Consume blank characters. */ - - if (!CACHE(parser, 1)) goto error; - - while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)) - { - if (IS_BLANK(parser->buffer)) - { - /* Check for tab characters that abuse indentation. */ - - if (leading_blanks && (int)parser->mark.column < indent - && IS_TAB(parser->buffer)) { - yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", - start_mark, "found a tab character that violates indentation"); - goto error; - } - - /* Consume a space or a tab character. */ - - if (!leading_blanks) { - if (!READ(parser, whitespaces)) goto error; - } - else { - SKIP(parser); - } - } - else - { - if (!CACHE(parser, 2)) goto error; - - /* Check if it is a first line break. */ - - if (!leading_blanks) - { - CLEAR(parser, whitespaces); - if (!READ_LINE(parser, leading_break)) goto error; - leading_blanks = 1; - } - else - { - if (!READ_LINE(parser, trailing_breaks)) goto error; - } - } - if (!CACHE(parser, 1)) goto error; - } - - /* Check indentation level. */ - - if (!parser->flow_level && (int)parser->mark.column < indent) - break; - } - - /* Create a token. */ - - SCALAR_TOKEN_INIT(*token, string.start, string.pointer-string.start, - YAML_PLAIN_SCALAR_STYLE, start_mark, end_mark); - - /* Note that we change the 'simple_key_allowed' flag. */ - - if (leading_blanks) { - parser->simple_key_allowed = 1; - } - - STRING_DEL(parser, leadin |